<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="updateTime">
					<uni-datetime-picker v-model="formData.updateTime" type="datetimerange" rangeSeparator="至" />
				</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-item label="仓库" :labelWidth='90' name="formData.whCode">
					<zxz-uni-data-select v-model="formData.whCode" :localdata="whOptions"
						:filterable="true" :multiple="true"></zxz-uni-data-select>
					<!-- <uni-data-select v-model="formData.whCode" :localdata="whOptions"></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">
					<u-row :gutter="12">
						<u-col :span="8">
							<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>
						</u-col>
						<u-col :span="4">
							<button type="primary" size="mini" style="float: right;margin-top: 80px;" @click="handleconfirmWhIn(item.id)">确认入库</button>
						</u-col>
					</u-row>
					
					<!-- <view> -->
						
					<!-- </view> -->
				</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 {
		onLoad: function() {
			// 获取当前时间
			var currentDate = new Date();
            // 计算三天前的时间
            var threeDateAgo = new Date(currentDate);
            threeDateAgo.setDate(currentDate.getDate() - 3);
            // 计算昨天的时间
            var yesterday = new Date(currentDate);
            yesterday.setDate(currentDate.getDate() - 1);
			// 格式化为字符串（YYYY-MM-DD HH:mm:ss）
			var year = threeDateAgo.getFullYear();
            var year1 = yesterday.getFullYear();
            var month = String(threeDateAgo.getMonth() + 1).padStart(2, "0");
            var month1 = String(yesterday.getMonth() + 1).padStart(2, "0");
            var day = String(threeDateAgo.getDate()).padStart(2, "0");
            var day1 = String(yesterday.getDate()).padStart(2, "0");
			var beginTime = year + "-" + month + "-" + day + " " + "18:00:00";
			var endTime = year1 + "-" + month1 + "-" + day1 + " " + "18:00:00";
			// 将当前时间赋值给 formData.endTime
			this.formData.updateTime.push(beginTime)
			this.formData.updateTime.push(endTime)
		},
		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
				this.whOptions = res.rows.map(item => {
					return {
						text: item.warehouseCode + ':' + item.warehouseName,
						value: item.warehouseCode,
						diasble: false
					}
				});
			})
		},
		data() {
			return {
				whOptions: [],
				whList: [],
				mes_job_single_report_sign_status: [],
				datetimerange: [],
				reportList: [],
				formData: {
					ptNoTar: null,
					ptTitleTar: null,
					status: 1,
					specification1: null,
					updateTime: [],
					specification1: null,
					whCode: [],
				},
				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.whCode-0']: this.formData.whCode,
					['A.status-op']: 'eq',
					['A.whCode-op']: 'eq',
					['A.updateTime-0']: this.formData.updateTime.length > 0 ? (this.formData.updateTime[0]) : null,
					['A.updateTime-1']: this.formData.updateTime.length > 0 ? (this.formData.updateTime[1]) : null,
					['A.updateTime-op']: 'bt',
					gexpr: 'A',
					pageNum: 0,
					pageSize: 100
				}
				//多选，动态添加仓库
				if(this.formData.whCode.length==0){
					obj['A.whCode-0']=null
				}else{
					for(let i=0;i<this.formData.whCode.length;i++){
						obj['A.whCode-'+i]=this.formData.whCode[i]
					}
				}
				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
					})
				})
			},
			//确认入库
			handleconfirmWhIn(id){
				// console.log(id);
				whInConfirm(id).then(res => {
					this.$modal.msgSuccess("上传入库确认成功！");
				})
			},
		}
	}
</script>

<style>
</style>