﻿<template>
	<div class="mesMaterialTestTaskHead-container">
		<el-card shadow="hover" :body-style="{ padding: '20px 20px 16px 10px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
			<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%" @submit.prevent="handleQuery" >
				<el-row :gutter="10">
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5">
						<el-form-item label="关键字" prop="searchKey">
							<el-input v-model="state.queryParams.searchKey" placeholder="请输入模糊查询关键字" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="报检单号" prop="inspJobNo">
							<el-input v-model="state.queryParams.inspJobNo" placeholder="报检单号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<!-- <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="检验类型">
							<el-input-number v-model="state.queryParams.inspType" placeholder="请输入检验类型" clearable @keyup.enter.native="handleQuery" />
					</el-form-item>
					</el-col> -->
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="原材料编号" prop="productCode">
							<el-input v-model="state.queryParams.productCode" placeholder="原材料编号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="原材料名称" prop="productName">
							<el-input v-model="state.queryParams.productName" placeholder="原材料名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="原材料规格" prop="productModel">
							<el-input v-model="state.queryParams.productModel" placeholder="原材料规格" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<!-- <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="结论" prop="inspResult">
							<el-input v-model="state.queryParams.inspResult" placeholder="结论" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="不合格处置" prop="inPassHandle">
							<el-input v-model="state.queryParams.inPassHandle" placeholder="不合格处置" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="送检人账号" prop="sendPersonAccount">
							<el-input v-model="state.queryParams.sendPersonAccount" placeholder="送检人账号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="送检人名称" prop="sendPersonName">
							<el-input v-model="state.queryParams.sendPersonName" placeholder="送检人名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="送检时间" prop="sendDate">
							<el-date-picker type="daterange" v-model="state.queryParams.sendDateRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="检验人账号" prop="inspPersonAccount">
							<el-input v-model="state.queryParams.inspPersonAccount" placeholder="检验人账号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="检验人名称" prop="inspPersonName">
							<el-input v-model="state.queryParams.inspPersonName" placeholder="检验人名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="检验时间" prop="inspDate">
							<el-date-picker type="daterange" v-model="state.queryParams.inspDateRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="审核人账号" prop="examinePersonAccount">
							<el-input v-model="state.queryParams.examinePersonAccount" placeholder="审核人账号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="审核人名称" prop="examinePersonName">
							<el-input v-model="state.queryParams.examinePersonName" placeholder="审核人名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="审核时间" prop="examineDate">
							<el-date-picker type="daterange" v-model="state.queryParams.examineDateRange"  value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="供应商编码" prop="supplierCode">
							<el-input v-model="state.queryParams.supplierCode" placeholder="供应商编码" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="供应商名称" prop="supplierName">
							<el-input v-model="state.queryParams.supplierName" placeholder="供应商名称" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col> -->
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="产品名称规格" prop="partSpec">
							<el-input v-model="state.queryParams.partSpec" placeholder="产品名称规格" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="材料进厂批次" prop="materialSpec">
							<el-input v-model="state.queryParams.materialSpec" placeholder="材料进厂批次" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="检验批次" prop="testSpec">
							<el-input v-model="state.queryParams.testSpec" placeholder="检验批次" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="钢厂炉号" prop="heatNumber">
							<el-input v-model="state.queryParams.heatNumber" placeholder="钢厂炉号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="冷轧厂卡号" prop="cartNumber">
							<el-input v-model="state.queryParams.cartNumber" placeholder="冷轧厂卡号" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<!-- <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="进货数量" prop="purchaseNumber">
							<el-input v-model="state.queryParams.purchaseNumber" placeholder="进货数量" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="进货件数" prop="purchaseQuantity">
							<el-input v-model="state.queryParams.purchaseQuantity" placeholder="进货件数" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="排序">
							<el-input-number v-model="state.queryParams.sortCode" placeholder="请输入排序" clearable @keyup.enter.native="handleQuery" />
					</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb5" v-if="state.showAdvanceQueryUI">
						<el-form-item label="描述" prop="remark">
							<el-input v-model="state.queryParams.remark" placeholder="描述" clearable @keyup.enter.native="handleQuery" />
						</el-form-item>
					</el-col> -->
				</el-row>
			</el-form>

			<el-divider style="height: calc(100% - 5px); margin: 0 10px" direction="vertical" />

			<el-row>
				<el-col>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery"  :loading="options.loading" v-auth="'mesMaterialTestTaskHead/page'"> 查询 </el-button><!---->
						<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
						<el-button icon="ele-ZoomIn" @click="changeAdvanceQueryUI" v-if="!state.showAdvanceQueryUI" style="margin-left: 5px"> 高级查询 </el-button>
						<el-button icon="ele-ZoomOut" @click="changeAdvanceQueryUI" v-if="state.showAdvanceQueryUI" style="margin-left: 5px"> 隐藏 </el-button>
					</el-button-group>
				</el-col>
			</el-row>
		</el-card>

		<el-card class="full-table" shadow="hover" style="margin-top: 5px">
			<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" v-on="gridEvents">
				<template #toolbar_buttons>
					<el-button type="primary" icon="ele-Plus" @click="handleAdd" v-auth="'mesMaterialTestTaskHead/add'"> 新增 </el-button><!---->
					<el-button type="primary" style="margin-left:5px;" icon="ele-Promotion" @click="PlanPost" v-auth="'mesMaterialTestTaskHead/planpost'"> 审核 </el-button><!---->
				</template>
				<template #toolbar_tools> </template>
				<template #empty>
					<el-empty :image-size="200" />
				</template>
				<template #row_inspType="{ row }">
					<el-tag :type="di('materialchecktype', row.inspType)?.tagType"> {{di('materialchecktype', row.inspType)?.name}}</el-tag>
				</template>
				<template #row_inspJobStatus="{ row }">
					<el-tag v-if="row.inspJobStatus"> 是 </el-tag>
					<el-tag type="danger" v-else> 否 </el-tag>
				</template>
				<template #row_inspStatus="{ row }">
					<el-tag v-if="row.inspStatus"> 是 </el-tag>
					<el-tag type="danger" v-else> 否 </el-tag>
				</template>
				<template #row_record="{ row }">
					<ModifyRecord :data="row" />
				</template>
				<template #row_buttons="{ row }">
					<el-tooltip content="编辑" placement="top">
						<el-button icon="ele-Edit" size="small" text type="primary" @click="handleEdit(row)" v-auth="'mesMaterialTestTaskHead/update'" /><!---->
					</el-tooltip>
					<el-tooltip content="删除" placement="top">
						<el-button icon="ele-Delete" size="small" text type="danger" @click="handleDelete(row)"  v-auth="'mesMaterialTestTaskHead/delete'"/><!---->
					</el-tooltip>
				</template>
				<template #expand_content="{ row }">
                     <div style="padding:12px">
                         <el-tabs v-model="tabActive">
                           <el-tab-pane label="检验项目及标准" name="item"></el-tab-pane>
                         </el-tabs>
                           <MesQiInspTempItem :qiInspJobIds="row.id+'-'+row.samplingNumMax+'-显示'" v-if="tabActive == 'item'"></MesQiInspTempItem>
                    </div>
                </template>
			</vxe-grid>
		</el-card>

		<PrintDialog ref="printDialogRef" :title="state.title" @reloadTable="handleQuery" />
		<EditDialog ref="editDialogRef" :title="state.title" @reloadTable="handleQuery" />
	</div>
</template>

<script lang="ts" setup name="mesMaterialTestTaskHead">
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from "element-plus";
import { auth } from '/@/utils/authFunction';

import { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
import { Local } from '/@/utils/storage';

import { formatDate } from '/@/utils/formatTime';
import { getDictLabelByVal as di, getDictDataList as dl } from '/@/utils/dict-utils';
// 子窗口
import PrintDialog from '/@/views/system/print/component/hiprint/preview.vue';
import EditDialog from '/@/views/simple/mesMaterialTestTaskHead/component/editDialog.vue';
import ModifyRecord from '/@/components/table/modifyRecord.vue';
import MesQiInspTempItem from "/@/views/simple/mesMaterialTestTaskDetial/index.vue";
import { pageMesMaterialTestTaskHead, deleteMesMaterialTestTaskHead ,sendProducePlan} from '/@/api/simple/mesMaterialTestTaskHead';
import { getMesProcessProcessCodeDropdown } from '/@/api/mes/mesQiInspTemp';
// 子窗口对象
const xGrid = ref<VxeGridInstance>();
const printDialogRef = ref<InstanceType<typeof PrintDialog>>();
const editDialogRef = ref<InstanceType<typeof EditDialog>>();

// 变量
const state = reactive({
	showAdvanceQueryUI: false,
	queryParams: {
		searchKey: undefined,
		inspJobNo: undefined,
		inspType: undefined,
		inspJobStatus: undefined,
		inspStatus: undefined,
		productCode: undefined,
		productName: undefined,
		productModel: undefined,
		inspResult: undefined,
		inPassHandle: undefined,
		sendPersonAccount: undefined,
		sendPersonName: undefined,
		sendDate: undefined,
		inspPersonAccount: undefined,
		inspPersonName: undefined,
		inspDate: undefined,
		examinePersonAccount: undefined,
		examinePersonName: undefined,
		examineDate: undefined,
		supplierCode: undefined,
		supplierName: undefined,
		partSpec: undefined,
		materialSpec: undefined,
		testSpec: undefined,
		heatNumber: undefined,
		cartNumber: undefined,
		purchaseNumber: undefined,
		purchaseQuantity: undefined,
		sortCode: undefined,
		remark: undefined,
	},
	localPageParam: {
		pageSize: 50 as number,
		defaultSort: { field: 'createTime', order: 'asc', descStr: 'desc' },
	},
	visible: false,
	title: '',
});

// 本地存储参数
const localPageParamKey = 'localPageParam:mesMaterialTestTaskHead';
const tabActive = ref('item')
// 改变高级查询的控件显示状态
const changeAdvanceQueryUI = () => {
	state.showAdvanceQueryUI = !state.showAdvanceQueryUI;
};

// 表格参数配置
const options = useVxeTable<any>(
	{
		id: 'MesMaterialTestTaskHead',
		name: '原材料检验任务主表',
		columns: [
			{ type: 'seq', title: '序号', width: 60 },// 
			{ type: 'expand', width: 80, slots: { content: 'expand_content' } },
			{ type: 'checkbox', title: '', width: 40},
			{ field: 'inspJobNo', title: '报检单号', minWidth: 120, showOverflow: 'tooltip', sortable: false},
			{ field: 'inspType', title: '检验类型', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_inspType' },sortable: false},
			{ field: 'inspJobStatus', title: '检验状态', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_inspJobStatus' }, sortable: false },
			{ field: 'inspStatus', title: '审核状态', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_inspStatus' }, sortable: false },
			{ field: 'productCode', title: '原材料编号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'materialName', title: '材料名称', minWidth: 100, showOverflow: 'tooltip',sortable: false},
			{ field: 'productName', title: '所属类别', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'productModel', title: '原材料规格', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'inspResult', title: '结论', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'inPassHandle', title: '不合格处置', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'sendPersonAccount', title: '送检人账号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'sendPersonName', title: '送检人名称', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'sendDate', title: '送检时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			{ field: 'inspPersonAccount', title: '检验人账号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'inspPersonName', title: '检验人名称', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'inspDate', title: '检验时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			{ field: 'examinePersonAccount', title: '审核人账号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'examinePersonName', title: '审核人名称', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'examineDate', title: '审核时间', minWidth: 100, showOverflow: 'tooltip', formatter: ({ cellValue }) => cellValue == null ? '' : formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS'), sortable: false },
			{ field: 'supplierCode', title: '供应商编码', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'supplierName', title: '供应商名称', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'partSpec', title: '产品名称规格', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'materialSpec', title: '材料进厂批次', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'testSpec', title: '检验批次', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'heatNumber', title: '钢厂炉号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'cartNumber', title: '冷轧厂卡号', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'purchaseNumber', title: '进货数量', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'purchaseQuantity', title: '进货件数', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			//{ field: 'sortCode', title: '排序', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ field: 'remark', title: '描述', minWidth: 100, showOverflow: 'tooltip', sortable: false},
			{ title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
			{ title: '操作', fixed: 'right', width: 180, showOverflow: true, slots: { default: 'row_buttons' } },
		],
	},
	// vxeGrid配置参数(此处可覆写任何参数)，参考vxe-table官方文档
	{
		// 代理配置
		proxyConfig: { autoLoad: true, ajax: { query: ({ page, sort }) => handleQueryApi(page, sort) } },
		// 排序配置
		sortConfig: { defaultSort: Local.get(localPageParamKey)?.defaultSort || state.localPageParam.defaultSort },
		// 分页配置
		pagerConfig: { pageSize: Local.get(localPageParamKey)?.pageSize || state.localPageParam.pageSize },
		// 工具栏配置
		toolbarConfig: { export: false },
		// 行设置
		// rowConfig: { height: 80 },
	}
);

// 页面初始化
onMounted(() => {});

// 查询api
const handleQueryApi = async (page: VxeGridPropTypes.ProxyAjaxQueryPageParams, sort: VxeGridPropTypes.ProxyAjaxQuerySortCheckedParams) => {
	const params = Object.assign(state.queryParams, { page: page.currentPage, pageSize: page.pageSize, field: sort.field, order: sort.order, descStr: 'desc' }) as any;
	return pageMesMaterialTestTaskHead(params);
};

// 查询操作
const handleQuery = async (reset = false) => {
	options.loading = true;
	await xGrid.value?.commitProxy('query');
	options.loading = false;
};

// 重置操作
const resetQuery = async () => {
	state.queryParams.searchKey = undefined,
	state.queryParams.inspJobNo = undefined,
	state.queryParams.inspType = undefined,
	state.queryParams.inspJobStatus = undefined,
	state.queryParams.inspStatus = undefined,
	state.queryParams.productCode = undefined,
	state.queryParams.productName = undefined,
	state.queryParams.productModel = undefined,
	state.queryParams.inspResult = undefined,
	state.queryParams.inPassHandle = undefined,
	state.queryParams.sendPersonAccount = undefined,
	state.queryParams.sendPersonName = undefined,
	state.queryParams.sendDate = undefined,
	state.queryParams.inspPersonAccount = undefined,
	state.queryParams.inspPersonName = undefined,
	state.queryParams.inspDate = undefined,
	state.queryParams.examinePersonAccount = undefined,
	state.queryParams.examinePersonName = undefined,
	state.queryParams.examineDate = undefined,
	state.queryParams.supplierCode = undefined,
	state.queryParams.supplierName = undefined,
	state.queryParams.partSpec = undefined,
	state.queryParams.materialSpec = undefined,
	state.queryParams.testSpec = undefined,
	state.queryParams.heatNumber = undefined,
	state.queryParams.cartNumber = undefined,
	state.queryParams.purchaseNumber = undefined,
	state.queryParams.purchaseQuantity = undefined,
	state.queryParams.sortCode = undefined,
	state.queryParams.remark = undefined,
	await xGrid.value?.commitProxy('reload');
};

// 打开新增页面
const handleAdd = () => {
	state.title = '添加原材料检验任务主表';
	editDialogRef.value?.openDialog({ type: 1 });
};

// 打开编辑页面
const handleEdit = (row: any) => {
	if(row.inspStatus==true)
	{
		return ElMessage({
         message: `已审核的单据不允许进行修改！`,
         type: "error",
        });
	}
	state.title = '编辑原材料检验任务主表';
	editDialogRef.value?.openDialog(row);
};

// 打开打印页面
const handlePrint = async (row: any) => {
	state.title = '打印原材料检验任务主表';
};

// 删除
const handleDelete = (row: any) => {
	if(row.inspJobStatus==true)
	{
		return ElMessage({
         message: `已检验的不允许删除！`,
         type: "error",
        });
	}
	ElMessageBox.confirm(`确定删除原材料检验任务主表：【${row.inspJobNo}】?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	}).then(async () => {
		await deleteMesMaterialTestTaskHead(row);
		await handleQuery();
		ElMessage.success('删除成功');
	})
	.catch(() => {});
};

// 表格事件
const gridEvents: VxeGridListeners<any> = {
	// 只对 pager-config 配置时有效，分页发生改变时会触发该事件
	async pageChange({ pageSize }) {
		state.localPageParam.pageSize = pageSize;
		Local.set(localPageParamKey, state.localPageParam);
	},
	// 当排序条件发生变化时会触发该事件
	async sortChange({ field, order }) {
		state.localPageParam.defaultSort = { field: field, order: order!, descStr: 'desc' };
		Local.set(localPageParamKey, state.localPageParam);
	},
};

const mesProcessProcessCodeDropdownList = ref<any>([]);
const getMesProcessProcessCodeDropdownList = async () => {
		let list = await getMesProcessProcessCodeDropdown();
	    mesProcessProcessCodeDropdownList.value = list.data.result ?? [];
};
getMesProcessProcessCodeDropdownList();

//审核计划
const PlanPost = ()=>{
  const $grid = xGrid.value;
  const selectRecords = $grid?.getCheckboxRecords(true);
  console.log(selectRecords);
  if(selectRecords.length == 0) return ElMessage.warning('请选择检验单');


  const InspJobStatus=selectRecords?.map(item=> item.inspJobStatus).join(',');
  const stocknumber=InspJobStatus?.split(',');
  for(let i=0;i<stocknumber.length;i++) {
	if(stocknumber[i]=="false")
	{
      ElMessage({
	  message: `未检验的检验单据不允许审核，当前存在选中未检验的单据！`,
	  type: "error",
	 });
	  return;
	}
  };

  const InspStatus=selectRecords?.map(item=> item.inspStatus).join(',');
  const stocknum=InspStatus?.split(',');
  for(let i=0;i<stocknum.length;i++) {
	if(stocknum[i]=="true")
	{
      ElMessage({
	  message: `已审核的单据不允许进行二次审核，当前存在选中已审核的单据！`,
	  type: "error",
	 });
	  return;
	}
  };
  ElMessageBox.confirm('是否通过审核检验单?', '警告', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(async () => {
    await sendProducePlan({id:selectRecords?.map(item=> item.id).join(',')})
    ElMessage.success('操作成功');
    handleQuery();
  })
}
</script>

<style lang="scss" scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
	width: 100%;
}
</style>
