<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="formData.whCode">
					<zxz-uni-data-select v-model="formData.whCode" :localdata="whOptions"
						:filterable="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">
				<u-checkbox size="25" iconSize="25" activeColor="green" labelSize='40rpx' :label="'全选'"
					@change="selectAll" v-if="reportList.length>0" :checked="selectAllChecked">
				</u-checkbox>
				<u-checkbox-group v-model="checked" @change="getCheckedList" :borderBottom="true" placement="column"
					iconPlacement="right" style="height: 50vh;overflow: scroll;">
					<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.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'+
						'合并标签号 : '+(item.singleReportSign? item.singleReportSign:'')+'\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";

	export default {
		mounted() {
			listWarehouse().then(res => {
				this.whOptions = res.rows.map(item => {
					return {
						text: item.warehouseCode + ':' + item.warehouseName,
						value: item.warehouseCode,
						diasble: false
					}
				});
			})
		},
		data() {
			return {
				selectAllChecked: false,
				checked: [],
				whOptions: [],
				reportList: [],
				formData: {
					ptNoTar: null,
					ptTitleTar: null,
					specification1: null,
					whCode: null,
					//报工未检验
					status: 1
				},
				ids: [],
				rules: {

				}
			}
		},
		methods: {
			getCheckedList(e) {
				this.ids = e;
				console.log(this.ids)
				// 判断当前选中的复选框数量，决定全选框的状态
				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.ptNoTar = res.result;
					}
				});
			},
			query() {
				listMesJobSingleReportSign(this.formData).then(res => {
					this.reportList = res.rows
				})
			},
			selectAll() {
				// 点击全选按钮时，更新所有复选框的选中状态
				if (this.checked.length === this.reportList.length) {
					this.checked = [];
					this.ids = this.checked;
					this.selectAllChecked = false; // 全选框不选中
				} else {
					this.checked = this.reportList.map(item => item.id);
					this.ids = this.checked
					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('提交中')
								console.log(_this.ids)
								qualityConfirm(_this.ids).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>