<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>:{{item.remark?item.remark:''}}</div>
					<div><strong>状态</strong>:{{returnStatus(item.status)}}</div>
				</uni-card>
			</uni-collapse-item>
		</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: [],
				reportList: [],
				formData: {
					singleReportSign: null
				},
				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 ''
			},
			//合并标签编码
			scanBar() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.formData.singleReportSign = res.result;
					}
				});
			},
			query() {
				let obj = {
					['A.singleReportSign-0']: this.formData.singleReportSign,
					['A.singleReportSign-op']: 'ct',
					gexpr: 'A'
				}
				advListMesJobSingleReportSign(obj).then(res => {
					this.reportList = res.rows.map(item => {
						let obj = this.whList.find(i => i.warehouseCode == item.whCode)
						if (obj) {
							console.log(obj)
							item.whName = obj.warehouseName
						}
						return item
					})
				})
				// listMesJobSingleReportSign(this.formData).then(res => {
				// 	if (res.rows.length > 0) {
				// 		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("未查询到相关记录！");
				// 	}
				// })
			}
		}
	}
</script>

<style>
</style>