<template>
	<view class="table">
		<u-table border>
			<u-tr>
				<u-th>序号</u-th>
				<u-th>区域</u-th>
				<u-th>拣货任务数</u-th>
				<u-th>补货任务数</u-th>
			</u-tr>
			<u-tr v-for="(item, index) in result" :key="index">
				<u-td>{{ index + 1 }}</u-td>
				<u-td>{{ item.areaCode}}</u-td>
				<u-td>{{ item.pickTaskQty }}</u-td>
				<u-td>{{ item.replenishQty }}</u-td>
			</u-tr>
		</u-table>
		<view class="task">
			<span>索取任务数</span>
			<u-input v-model="wareHouse" border type="select" placeholder="请选择任务数" prop="wareHouse" class="u-input"
				placeholder-style="color:#000000" @click="show = true" />
			<u-select v-model="show" :list="list" @confirm="confirm"></u-select>
		</view>
		<view class="footer">
			<u-button type="success" @click="checkOutPick()">刷新</u-button>
			<u-button type="primary" @click="searchTaskNumber()">索取</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wareHouse: '',
				wareHouseValue: '',
				show: false,
				result: [],
				list: [
				]
			};
		},
		onLoad(options) {
			this.result = JSON.parse(options.list)
			this.getTaskNumber()
		},

		methods: {
			// 获取任务数
			getTaskNumber() {
				this.$u.api.getTaskNumber().then((res)=>{
					if(res.code===200) {
							this.list = res.data.map((item)=>({
								label: item.dictLabel,
								value: item.dictValue
							}))
					} else {
						this.$u.toast(res.msg)
					}
				})
			},
			checkOutPick() {
				this.$u.api.pickingManage.checkOutPick({
					taskType: 2
				}).then(res => {
					console.log(res)
					if (res.code === 200) {
						if(res.msg) {
							this.$u.toast(res.msg);
							return
						}
						//  进入索取页面
						if (res.data.pickType === 200) {
							// 整散合一
							this.$u.route({
								url: 'pages/dispersion/index',
								type: 'navigateTo',
								params: {
									list: JSON.stringify(res.data.taskStaticList)
								}
							})
						}
						//进入拣货页面
						if (res.data.pickType === 800) {
							// 整散合一
							this.$u.route({
								url: 'pages/dispersion/picking',
								type: 'navigateTo',
								params: {
									list: JSON.stringify(res.data.businOutPickDTaskVo),
									container: JSON.stringify(res.data.containrList)
								}
							})

						}
						// 进入绑定周转箱页面
						if (res.data.pickType === 801) {
							// 整件
							// if(params.taskType===1) {
							// 	this.$u.route({
							// 		url: 'pages/allPiece/bind',
							// 		type: 'navigateTo',
							// 		params: {
							// 			list: res.data.taskAndContainerList
							// 		}
							// 	})
							// }
							// 整散合一
							this.$u.route({
								url: 'pages/dispersion/bind',
								type: 'navigateTo',
								params: {
									list: JSON.stringify(res.data.taskAndContainerList)
								}
							})
						}
					} else {
						this.$u.toast(res.msg);
					}

				});
			},

			// 整零货任务索取
			searchTaskNumber() {
				if (this.wareHouseValue) {
					this.$u.api.pickingManage.pickCasePieceTask({
						oncePickTaskNumber: this.wareHouseValue
					}).then(res => {
						console.log(res)
						if (res.code === 200) {
							this.checkOutPick()
						} else {
							this.$u.toast(res.msg);
						}

					});
				} else {
					this.$u.toast("请先选择任务数量");
				}

			},
			confirm(e) {
				console.log(e)
				this.wareHouse = e[0].label
				this.wareHouseValue = e[0].value
			}
		}
	}
</script>

<style lang="scss">
	.table {
		padding: 40rpx 40rpx;
		position: relative;
	}

	.task {
		display: flex;
		align-items: center;
		margin-top: 40rpx;

		span {
			color: #333333;
			font-size: 32rpx;
			margin-right: 20rpx;
		}
	}

	.footer {
		position: fixed;
		width: 100%;
		bottom: 20rpx;
		display: flex;
		align-items: center;
	}
</style>
