<template>
	<view>
		<uni-collapse>
			<uni-forms ref="form" :modelValue="formData" :rules="rules">
				<uni-forms-item label="合并标签码" :labelWidth='90' name="singleReportSign">
					<uni-easyinput suffixIcon="scan" @iconClick="scanBar" @confirm="query"
						v-model="formData.singleReportSign" type="text" />
				</uni-forms-item>
			</uni-forms>
			<u-button type="primary" @click="query">查询</u-button>
			<uni-collapse-item :open="true">
				<uni-card :is-shadow="false" is-full v-for="item,index in reportList" :key="item.id">
					<div><strong>合并标签号</strong>:{{item.singleReportSign}}</div>
					<div><strong>物料编码</strong>:{{item.ptNoTar}}</div>
					<div><strong>物料名称</strong>:{{item.ptTitleTar}}</div>
					<div><strong>物料规格</strong>:{{item.specification1}}</div>
					<div><strong>数量</strong>:{{item.reportNumber}}</div>
					<div><strong>仓库</strong>:{{item.whName?item.whName:item.whCode}}</div>
					<div><strong>状态</strong>:检验未入库</div>
				</uni-card>
				<!-- <u-checkbox-group v-model="checked" @change="getCheckedList" :borderBottom="true" placement="column"
					iconPlacement="right">
					<u-checkbox size="25" iconSize="25" activeColor="green" v-for="(item, index) in reportList"
						:key="index" :disabled="item.disabled" :name="item.id" :label="'\n'+' 序号 : '+(index+1)+'\n\n'+
						'合并标签号 : '+(item.singleReportSign? item.singleReportSign:'')+'\n\n'+
						'物料编码 : '+(item.ptNoTar?item.ptNoTar:'')+'\n\n'+
						'物料名称 : '+(item.ptTitleTar?item.ptTitleTar:'')+'\n\n'+
						'物料规格 : '+(item.specification1?item.specification1:'')+'\n\n'+
						'数量 : '+(item.reportNumber?item.reportNumber:'')+'\n\n'+
						'仓库 : '+(item.whCode?item.whCode:'')+'\n\n'+
						'状态 : '+returnStatus(item.status)+'\n\n'
						">
					</u-checkbox>
				</u-checkbox-group> -->
			</uni-collapse-item>
			<u-button type="primary" @click="submit" v-if="reportList.length>0">提交</u-button>
		</uni-collapse>
	</view>
</template>

<script>
	import {
		listMesJobSingleReportSign,
		advListMesJobSingleReportSign,
		getMesJobSingleReportSign,
		delMesJobSingleReportSign,
		addMesJobSingleReportSign,
		updateMesJobSingleReportSign,
		reportConfirm,
		qualityConfirm,
		whInConfirm
	} from "@/api/mes/mesJobSingleReportSign";
	import {
		listWarehouse
	} from "@/api/wms/pdcIn.js";
	import {
		getDicts
	} from "@/api/system/dict/dictData.js";
	export default {
		mounted() {
			getDicts("mes_job_single_report_sign_status").then(res => {
				this.mes_job_single_report_sign_status = res.data.map(dict => {
					return {
						text: dict.dictLabel,
						value: dict.dictValue,
						diasble: false
					}
				});
			})
			listWarehouse().then(res => {
				this.whList = res.rows
			})
		},
		data() {
			return {
				whList: [],
				mes_job_single_report_sign_status: [],
				selectAllChecked: false,
				checked: [],
				reportList: [],
				formData: {
					singleReportSign: null
				},
				ids: [],
				rules: {

				}
			}
		},
		methods: {
			returnStatus(i) {
				console.log(i)
				let obj = this.mes_job_single_report_sign_status.find(dict => dict.value == i)
				console.log(obj)
				if (obj)
					return obj.text
				else
					return ''
			},
			getCheckedList(e) {
				this.ids = e;
				// 判断当前选中的复选框数量，决定全选框的状态
				if (this.ids.length === this.reportList.length) {
					this.selectAllChecked = true;
				} else {
					this.selectAllChecked = false;
				}
			},
			//物料编码
			scanBar() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.formData.singleReportSign = res.result;
					}
				});
			},
			query() {
				listMesJobSingleReportSign(this.formData).then(res => {
					if (res.rows.length > 0) {
						if (res.rows[0].status != 2) {
							let text = this.returnStatus(res.rows[0].status)
							this.$modal.msg("查询的记录当前处于'" + text + "'状态！");
						} else {
							if (!res.rows[0].whCode) {
								this.reportList = res.rows
							} else {
								let obj = this.whList.find(item => item.warehouseCode == res.rows[0].whCode)
								if (obj) {
									console.log(obj)
									res.rows[0].whName = obj.warehouseName
								}
								this.reportList = res.rows
							}

						}
					} else {
						this.$modal.msg("未查询到相关记录！");
					}
				})
			},
			selectAll() {
				// 点击全选按钮时，更新所有复选框的选中状态
				if (this.checked.length === this.reportList.length) {
					this.checked = [];
					this.selectAllChecked = false; // 全选框不选中
				} else {
					this.checked = this.reportList.map(item => item.id);
					this.selectAllChecked = true; // 全选框选中
				}
			},
			submit() {
				const _this = this;
				_this.$refs.form.validate().then(res => {
					uni.showModal({
						title: '提示',
						content: '您确定完成该入库确认吗？',
						success: function(res) {
							if (res.confirm) {
								_this.$modal.loading('提交中')
								whInConfirm([_this.reportList[0].id]).then(res => {
									_this.$modal.closeLoading();
									_this.$modal.msgSuccess("上传入库确认成功！");
									setTimeout(() => {
										_this.$tab.switchTab(
											"/pages/work/index");
									}, 500);
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				});
			},
		}
	}
</script>

<style>
</style>