<style lang="scss">
	.text {
		font-size: 12px;
		color: #666;
		margin-top: 5px;
	}

	.uni-px-5 {
		padding-left: 10px;
		padding-right: 10px;
	}

	.uni-pb-5 {
		padding-bottom: 10px;
	}

	.container {
		overflow: hidden;
	}

	.custom-cover {
		flex: 1;
		flex-direction: row;
		position: relative;
	}

	.cover-content {
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		height: 40px;
		background-color: rgba($color: #000000, $alpha: 0.4);
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 15px;
		font-size: 14px;
		color: #fff;
	}

	.card-actions {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		height: 45px;
		border-top: 1px #eee solid;
	}

	.card-actions-item {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.card-actions-item-text {
		font-size: 12px;
		color: #666;
		margin-left: 5px;
	}

	.cover-image {
		flex: 1;
		height: 150px;
	}

	.no-border {
		border-width: 0;
	}
</style>

<template>
	<view>
		<uni-collapse>
			<!-- <uni-collapse-item title="筛选单据"> -->
			<!-- <view class="content"> -->
			<uni-forms>
				<!-- 				<uni-forms-item label="生产领料任务单编码" label-align="center" :label-width="100">
					<uni-combox :candidates="taskListQuery" placeholder="请选择生产领料任务单编码"
						v-model="queryParams.drawTaskCode"></uni-combox>
				</uni-forms-item> -->
				<uni-forms-item label="生产工单号">
					<uni-combox :candidates="workOrderCodeArr" placeholder="请选择生产工单号"
						v-model="queryParams.workOrderCode"></uni-combox>
				</uni-forms-item>
				<!-- 				<uni-forms-item label="来源单据">
					<uni-combox :candidates="srcDocCodeArr" placeholder="请输入来源单据"
						v-model="queryParams.srcDocCode"></uni-combox>
				</uni-forms-item> -->
				<uni-forms-item label="仓库">
					<uni-data-select v-model="queryParams.warehouseCode"
						:localdata="warehouseOptions"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="状态">
					<uni-data-select v-model="queryParams.status" :localdata="statusOptions"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="领料类型">
					<uni-data-select v-model="queryParams.drawType" :localdata="drawTypeArr"></uni-data-select>
				</uni-forms-item>
				<button type="primary" @click="querySub">查询</button>

				<uni-collapse-item title="领料任务单" :open="isBool">
					<uni-card :is-shadow="false" is-full v-for="(item,index) in getListArr" :key="index">
						<uni-row class="demo-uni-row">
							<uni-col :span="24">
								<view>
									<uni-forms-item label="领料单号" :labelWidth='90'>
										<uni-easyinput :value="item.drawTaskCode" type="text" :disabled="true" />
									</uni-forms-item>
									<uni-forms-item label="来源单号" :labelWidth='90'>
										<uni-easyinput :value="item.srcDocCode" type="text" :disabled="true" />
									</uni-forms-item>
									<uni-forms-item label="工单单号" :labelWidth='90'>
										<uni-easyinput :value="item.workOrderCode" type="text" :disabled="true" />
									</uni-forms-item>
									<uni-forms-item label="状态" :labelWidth='90'>
										<uni-easyinput
											:value="statusOptions.find(items=>items.value == item.status).text"
											type="text" :disabled="true" />
									</uni-forms-item>
									<uni-forms-item label="仓库" :labelWidth='90'>
										<uni-easyinput
											:value="isNaN(warehouseOptions.find(items=>items.value == item.warehouseCode))?'':warehouseOptions.find(items=>items.value == item.warehouseCode).text"
											type="text" :disabled="true" />
									</uni-forms-item>
								</view>
							</uni-col>

						</uni-row>
						<uni-row>
							<uni-col :span="10">
								<button type="primary" @click="lokDetails(item,index)">查看明细</button>
							</uni-col>

							<uni-col :span="11" style="margin: 0 .5rem;">
								<button type="primary" @click="productionListFuc(item,index)">生成拣货单</button>

							</uni-col>
						</uni-row>
					</uni-card>




				</uni-collapse-item>
			</uni-forms>
		</uni-collapse>

	</view>
</template>

<script>
	import {
		listTask,
		listWarehouse, //仓库
		schedulePick,
	} from "@/api/wms/materRequisitiontask";
	import {
		getTask,
		listPick
	} from "@/api/wms/pdcMaterial"
	export default {
		created() {

			this.getDicts("wms_bill_status").then(response => { // 单据状态
				this.statusOptions = response.data.map(item => {
					return {
						text: item.dictLabel,
						value: item.dictValue
					}
				})
			});
			this.getDicts("wms_draw_type").then(response => { // 单据状态
				console.log(response, "response");
				this.drawTypeArr = response.data.map(item => {
					return {
						text: item.dictLabel,
						value: item.dictValue
					}
				})
			});

			listTask().then(response => {
				response.rows.forEach(item => {
					this.taskListQuery.push(item.drawTaskCode);
					this.workOrderCodeArr.push(item.workOrderCode);
					this.srcDocCodeArr.push(item.srcDocCode);
				});
				console.log(this.taskListQuery[0]);

			});
			// listEmployee().then(response => {
			//   this.listEmpoyeeOptions = response.rows;
			// });
			listWarehouse().then(response => { //仓库数据
				this.warehouseOptions = response.rows.map(item => {
					return {
						text: item.warehouseCode + ':' + item.warehouseName,
						value: item.warehouseCode
					}
				})
				this.listWarehouseOptions = response.rows;
			});

		},
		data() {
			return {
				taskListQuery: [],
				getListArr: [],
				workOrderCodeArr: [],
				srcDocCodeArr: [],
				warehouseOptions: [],
				listWarehouseOptions: [],
				statusOptions: [],
				drawTypeArr: [],
				isBool: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 50,
					orderByColumn: "id",
					isAsc: "desc",
					// drawTaskCode: null,
					workOrderCode: null,
					status: null,
					estimateDrawTime: null,
					drawBy: null,
					warehouseCode: null,
					transportBy: null,
					enclosure: null
				},

			}

		},
		methods: {
			productionListFuc(item, index) {
				const _this = this
				listPick({
					drawTaskCode: item.drawTaskCode,
				}).then(res => {
					if (res.total > 0) {
						_this.$model.msgError("已生成拣货单")
					} else {
						getTask(item.id).then(res => {
							console.log(res.data, "res");
							res.data.wmsDrawTaskDetailList.forEach(item => {
								item.secondPlanPickNumber = item.number
								item.planPickNumber = item.number
							})
							schedulePick(res.data).then(res => {
								_this.$modal.msgSuccess(res.mag)
							})


						})
					}
				})


			},
			getList() {
				listTask(this.queryParams).then(response => {
					console.log(response, "poe");
					this.getListArr = response.rows
					this.isBool = true;
				})

			},
			lokDetails(item, index) { //查看明细跳转
				this.$tab.navigateTo("/pages/wms/pdcMaterial/materRequisitiontask/materRequisitiontaskDetails?data=" +
					encodeURIComponent(JSON.stringify(item)));

			},
			querySub() {
				this.getList();
				this.queryParams = {
					drawTaskCode: null,
					workOrderCode: null,
					status: null,
					estimateDrawTime: null,
					drawBy: null,
					warehouseCode: null,
					transportBy: null,
					enclosure: null
				}

			}
		}

	}
</script>