<template>
	<view>
		<uni-collapse>
			<uni-forms ref="form" :modelValue="formData" :rules="rules">
				<uni-forms-item label="物料编码" :labelWidth='90' name="ptNoTar">
					<uni-easyinput suffixIcon="scan" @iconClick="scanBar" @confirm="scanBarCode"
						v-model="formData.ptNoTar" type="text" />
				</uni-forms-item>
				<uni-forms-item label="物料名称" :labelWidth='90' name="ptTitleTar">
					<uni-easyinput v-model="formData.ptTitleTar" type="text" />
				</uni-forms-item>
				<uni-forms-item label="物料规格" :labelWidth='90' name="specification1">
					<uni-easyinput v-model="formData.specification1" type="text" />
				</uni-forms-item>
				<uni-forms-item label="状态" :labelWidth='90' name="status">
					<uni-data-select v-model="formData.status" :localdata="range"></uni-data-select>
				</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>:{{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 {
		getDicts
	} from "@/api/system/dict/dictData.js";
	import {
		listWarehouse
	} from "@/api/wms/pdcIn.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: [],
				datetimerange: [],
				reportList: [],
				formData: {
					ptNoTar: null,
					ptTitleTar: null,
					status: 1,
					specification1: null,
				},
				range: [{
						value: 1,
						text: "报工未检验"
					},
					{
						value: 2,
						text: "检验未入库"
					}
				],
				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.ptNoTar = res.result;
					}
				});
			},
			query() {
				let obj = {
					['A.ptNoTar-0']: this.formData.ptNoTar,
					['A.ptTitleTar-0']: this.formData.ptTitleTar,
					['A.specification1-0']: this.formData.specification1,
					['A.status-0']: this.formData.status,
					['A.ptNoTar-op']: 'ct',
					['A.ptTitleTar-op']: 'ct',
					['A.specification1-op']: 'ct',
					['A.status-op']: 'eq',
					gexpr: 'A',
					pageNum: 0,
					pageSize: 100
				}
				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
					})
				})
			}
		}
	}
</script>

<style>
</style>