<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: 1
				}).then(res => {
					console.log(res)
					if (res.code === 200) {
						if(res.msg) {
							this.$u.toast(res.msg)
						} else {
							//  进入索取页面
							if (res.data.pickType === 200) {
								// 整件
								this.$u.route({
									url: 'pages/allPiece/index',
									type: 'navigateTo',
									params: {
										list: JSON.stringify(res.data.taskStaticList)
									}
								})
							}
							//进入拣货页面
							if (res.data.pickType === 800) {
								// 整件
								this.$u.route({
									url: 'pages/allPiece/picking',
									type: 'navigateTo',
									params: {
										list: JSON.stringify(res.data.businOutPickDTaskVo)
									}
								})
							}				
						}
					} else {
						this.$u.toast(res.msg)
					}

				});
			},
			// 整货任务索取
			searchTaskNumber() {
				if (this.wareHouseValue) {
					this.$u.api.pickingManage.pickCaseTask({
						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>
