<template>
	<view class="page">
		<view class="step">
			<uni-steps active-color="#3387FF" :options="[{title: '扫码授权',url:'./qrCode'}, {title: '小程序配置',url:'./deploy'}, 
			{title: '提交版本',url:'./addVersion'},
		    {title: '提交审核',url:'./addExamine'},{title: '版本管理',url:'./Versioning'} ]" :active="2"></uni-steps>
		</view>

		<view style="height: 130rpx;"></view>

		<view class="home">

			<form @submit="addVersion">

				<view class="homeForm ft28">
					<picker mode="selector" :range="tableTypeList" range-key="title" @change="onTableTypeChange">
						<view class="item flex-y-center box-pack-between">
							<text>门店id(仅限审核使用)</text>

							<view>
								<text>{{tableTypeActive}}</text>
								<text class="iconfont icongengduo" style="font-size: 26rpx;"></text>
							</view>

						</view>
					</picker>
					<picker mode="selector" :range="tableList" range-key="id" @change="onTableChange">
						<view class="item flex-y-center box-pack-between">
							<text>位置id(仅限审核使用): </text>
							<view>
								<text>{{table_id}}</text>
								<text class="iconfont icongengduo" style="font-size: 26rpx;"></text>
							</view>

							<input type="text" :value="table_id" name="table_id" placeholder="请输入餐桌id"
								class="hide-input" />
						</view>
					</picker>

					<view class="item flex-y-center box-pack-between">
						<text>版本号:</text>
						<view class="border">
							<input type="text" :value="obj.user_version" name="user_version" placeholder="请输入版本号" />
						</view>
					</view>

					<view class="tip">
						Tip:进入门店列表(对应审核门店id)>进入位置管理>即可找到位置ID。提交的版本号需大于当前版本号。
					</view>

					<button hover-class="none" form-type="submit" class="flex-grow-1 flex-center submit ft28">
						提交版本
					</button>

				</view>
			</form>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				tableTypeList: [],
				tableTypeActive: "请选择",
				table_id: '',
				store_id: '',
				obj: {},
				tableList: []
			}
		},

		onLoad() {
			this.MiniVersion();
		},

		methods: {

			addVersion(e) {
				let {
					table_id,
					user_version
				} = e.detail.value;
				this.request({
					url: 'setting/uploadMiniVersion',
					data: {
						admin_id: uni.getStorageSync("admin_id"),
						store_id: this.store_id,
						table_id,
						user_version,
					}
				}).then(res => {
					if (res.code == '200') {
						console.log(res, "showModal")



						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: true,
							cancelText: '关闭',
							confirmText: '提交审核',
							success: r => {
								if (r.confirm) {
									uni.redirectTo({
										url: "./addExamine"
									})
								} else {
									uni.navigateBack({
										delta: 1
									})
								}
							},
							fail: () => {},
							complete: () => {}
						});
					}
				})
			},

			onTableTypeChange(e) {
				let store_id = this.tableTypeList[e.detail.value].id
				if (store_id != this.store_id) {
					this.tableTypeActive = this.tableTypeList[e.detail.value].title;
					this.store_id = store_id
					this.table_id = ""
					this.getTableList(this.store_id)
				}

			},
			onTableChange(e) {
				let table_id = this.tableList[e.detail.value].id
				this.table_id = table_id
			},

			// 版本列表
			MiniVersion(e) {
				this.request({
					url: 'setting/MiniVersion',
					data: {
						admin_id: uni.getStorageSync("admin_id"),
					}
				}).then(res => {
					if (res.code == 200) {
						this.obj = res.data;
						this.shop_store_index();

					}
				})
			},

			shop_store_index() {
				this.request({
					url: 'Smdcshop/shop_store_index',
					data: {
						admin_id: uni.getStorageSync("admin_id"),
					}
				}).then(res => {
					if (res.code == 200) {
						this.tableTypeList = res.data;
						if (this.obj.store_id) {
							let info = res.data.find((item) => item.id == this.obj.store_id)
							this.tableTypeActive = info.title;
							this.store_id = info.id;

						} else {
							this.tableTypeActive = res.data[0].title;
							this.store_id = res.data[0].id;
						}
						if (this.obj.table_id) {
							this.table_id = this.obj.table_id
						}
						this.getTableList(this.store_id)
					}
				})
			},
			getTableList(store_id) {
				this.request({
					url: 'setting/tablelist',
					data: {
						store_id
					}
				}).then(res => {
					if (res.code == 200) {
						this.tableList = res.data;
					}
				})
			},


		}
	}
</script>

<style>
	@import url("../css/style.css");

	.tip {
		color: red;
		font-size: 24rpx;
	}

	.homeForm {
		padding: 20rpx;
		padding-bottom: 40rpx;
	}

	.border {
		padding: 10rpx;
		border-bottom: 1rpx solid #F1F1F1;
		text-align: right;
	}

	.submit {
		background-color: #007AFF;
		color: #FFFFFF;
		width: 630rpx;
		margin: 0 auto;
		height: 98rpx;
		margin-top: 30rpx;
	}

	.Transfer {
		position: absolute;
		bottom: 100rpx;
		width: 100%;
		text-align: center;
		font-size: 28rpx;
		color: #007AFF;
	}

	.Transfer navigator {
		display: inline-block;
	}

	.hide-input {
		position: fixed;
		left: 1000px;
		top: -1000px;
		width: 0;
		height: 0;
	}
</style>
