<template>
	<!-- 弹出历史列表 -->
	<el-dialog v-model="dialogOrderHistoryVisible" title="修改历史记录" width="90%">
		<el-table :data="orderHistoryList" stripe style="width: 100%" >
			<el-table-column fixed type="index" width="40" />
			<el-table-column fixed prop="CreateTime" label="修改日期"  :formatter="formatTableDateTime" width="140" />
			<el-table-column fixed prop="CreateUserCode" label="修改帐号" width="80" />
			<el-table-column fixed prop="Qualified" label="合格" width="80" :formatter="formatQualified"/>
			<el-table-column prop="CompareResult" label="比对" width="80" :formatter="formatCompareResult"/>
			<el-table-column prop="TensionValue" label="张力均值" width="80" :formatter="formatNum"/>
			<el-table-column prop="HeightValue" label="膜厚均值" width="80" :formatter="formatNum"/>
			<el-table-column prop="LineWidthValue" label="线宽均值" width="120" :formatter="formatNum"/>
			<el-table-column prop="PTValue" label="PT均值" width="120" :formatter="formatNum"/>
			<el-table-column prop="DKCount" label="堵孔数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="ZWCount" label="脏污数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="GSYCCount" label="钢丝异常数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="XWSCount" label="纤维丝数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="QKCount" label="缺口数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="ZKCount" label="针孔数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="PPCount" label="泡泡数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="HSCount" label="划伤数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="YXCount" label="压线数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="XBCount" label="斜边数量" width="120" :formatter="formatNum"/>
			<el-table-column prop="SXCount" label="栅线数量" width="120" :formatter="formatNum"/>
		</el-table>
	</el-dialog>
	<!-- 弹出修改表单 -->
	<el-dialog v-model="dialogFormVisible" title="修改记录" width="60%">
		<el-form :model="editRowData" label-width="auto" size="small" :inline="false">
			<el-form-item label="" >
				比对结果:<el-radio-group v-model="editRowData.CompareResult" class="editNum">
					<el-radio border :label="0" size="small">未比对</el-radio>
					<el-radio border :label="1" size="small">通过</el-radio>
					<el-radio border :label="2" size="small">未通过</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label=""  >
				<template style="display:flex;">
					张力均值:<el-input-number v-model="editRowData.TensionValue" :precision="2" :step="0.01" :min="0" class="editNum" />
					膜厚均值:<el-input-number v-model="editRowData.HeightValue" :precision="2" :step="0.01" :min="0" class="editNum"/>
					线宽均值:<el-input-number v-model="editRowData.LineWidthValue" :precision="2" :step="0.01" :min="0" class="editNum"/>
					&nbsp;&nbsp;PT均值:<el-input-number v-model="editRowData.PTValue" :precision="4" :step="0.0001" :min="0" class="editNum"/>
				</template>
			</el-form-item>
			<el-form-item label=""  >
				<template style="display:flex;">
					堵孔数量:<el-input-number v-model="editRowData.ZWCount" :precision="0" :step="1" :min="0" class="editNum"/>
					脏污数量:<el-input-number v-model="editRowData.XXCount" :precision="0" :step="1" :min="0" class="editNum"/>
					钢丝异常:<el-input-number v-model="editRowData.GSYCCount" :precision="0" :step="1" :min="0" class="editNum"/>
					纤维丝数:<el-input-number v-model="editRowData.XWSCount" :precision="0" :step="1" :min="0" class="editNum"/>
				</template>
			</el-form-item>
			<el-form-item label=""  >
				<template style="display:flex;">
					缺口数量:<el-input-number v-model="editRowData.QKCount" :precision="0" :step="1" :min="0" class="editNum"/>
					针孔数量:<el-input-number v-model="editRowData.ZKCount" :precision="0" :step="1" :min="0" class="editNum"/>
					泡泡数量:<el-input-number v-model="editRowData.PPCount" :precision="0" :step="1" :min="0" class="editNum"/>
					划伤数量:<el-input-number v-model="editRowData.HSCount" :precision="0" :step="1" :min="0" class="editNum"/>
				</template>
			</el-form-item>
			<el-form-item label=""  >
				<template style="display:flex;">
					压线数量:<el-input-number v-model="editRowData.YXCount" :precision="0" :step="1" :min="0" class="editNum"/>
					斜边数量:<el-input-number v-model="editRowData.XBCount" :precision="0" :step="1" :min="0" class="editNum"/>
					栅线数量: <el-input-number v-model="editRowData.SXCount" :precision="0" :step="1" :min="0" class="editNum"/>
				</template>
			</el-form-item>
		</el-form>
		<template #footer>
			<span class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取消</el-button>
				<el-button type="primary" @click="save">
					保存
				</el-button>
			</span>
		</template>
	</el-dialog>
	<!-- 静态内容 -->
	<div class="filterDiv">
		<div>
				产品：
				<el-select v-model="productIdList" multiple collapse-tags collapse-tags-tooltip placeholder="可多选" style="width: 200px" >
					<el-option v-for="item in productList" :key="item.Id" :label="item.Name" :value="item.Id" />
				</el-select>
		</div>
		<div>
			流程：
			<el-select v-model="stepId" clearable collapse-tags collapse-tags-tooltip placeholder="选择" style="width: 200px" >
				<el-option v-for="item in stepList" :key="item.Id" :label="item.Name" :value="item.Id" />
			</el-select>
		</div>
		<div>
			比对：
			<el-select v-model="compareResult" clearable placeholder="选择"  style="width: 100px">
				<el-option v-for="item in CompareResultOptions" :key="item.value" :label="item.label" :value="item.value" />
			</el-select>
		</div>
		<div v-if="CustomerVer!='A'">
			合格：
			<el-select v-model="qualifiedValue" clearable placeholder="选择"  style="width: 100px">
				<el-option v-for="item in QualifiedOptions" :key="item.value" :label="item.label" :value="item.value" />
			</el-select>
		</div>
		<div>
			修复：
			<el-select v-model="repairfiedValue" clearable placeholder="选择"  style="width: 100px">
				<el-option v-for="item in RepairfiedOptions" :key="item.value" :label="item.label" :value="item.value" />
			</el-select>
		</div>
		<div>
			日期：
			<!-- <el-date-picker
				v-model="queryDate"
				type="date"
				placeholder="选择日期"
				style="width: 138px;"
			/> -->
			<el-date-picker
				v-model="queryDate"
				type="daterange"
				align="right"
				unlink-panels
				range-separator="至"
				start-placeholder="开始日期"
				end-placeholder="结束日期"
				:picker-options="pickerOptions">
			</el-date-picker>
		</div>
		<div class="filterButtonDiv">
			<el-button type="primary" @click="onClickQuery">查询</el-button>
			<el-button type="success" @click="loadData(true)">导出</el-button>
			<el-button :disabled="selIds.length<1" type="danger" @click="delSelList">删除</el-button>
		</div>
	</div>
	<el-table :data="dataList" @selection-change="handleSelectionChange" stripe style="width: 100%" >
		<el-table-column type="selection" width="30" />
		<el-table-column fixed type="index" width="50" />
		<el-table-column fixed prop="CreateTime" label="检验日期"  :formatter="formatTableDateTime" width="140" />
		<el-table-column fixed prop="ProductName" label="产品名称" width="130" />
		<el-table-column fixed prop="ProductCode" label="料号" width="120" />
		<!-- <el-table-column fixed prop="StepName" label="检测流程" width="120" /> -->
		<el-table-column fixed prop="SN" label="网版编码" width="150" />
		<el-table-column fixed prop="BatchId" label="批次" width="100" />
		<!-- <el-table-column v-if="CustomerVer!='A'" fixed prop="Qualified" label="合格" width="80" :formatter="formatQualified"/> -->
		<el-table-column v-if="CustomerVer!='A'" fixed label="合格" width="80">
			<template #default="scope">
				<el-tag size="small"
					:type="scope.row.Qualified==1 ? 'success' : 'danger'"
					disable-transitions
					>{{ formatQualified(scope.row) }}</el-tag>
			</template>
		</el-table-column>

		<el-table-column fixed label="修复" width="80" >
			<template #default="scope">
				<el-tag size="small"
				 	:type="scope.row.State==5?'success':scope.row.State==10?'danger':'primary'"
					disable-transitions
					>{{formatRepairfied(scope.row)}}</el-tag>
			</template>
		</el-table-column>
		<el-table-column fixed prop="Abnormalities" label="异常情况" width="150" />
		<el-table-column fixed prop="RepairCode" label="修复人员" width="100" />


		<el-table-column label="比对" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.CompareResult===2?'danger':'success'">{{formatCompareResult(scope.row)}}</el-text>
			</template>
		</el-table-column>
		
		
		
<!-- 		<el-table-column prop="Tension1" label="张力1" width="80" :formatter="formatNum" />
		<el-table-column prop="Tension2" label="张力2" width="80"  :formatter="formatNum"/>
		<el-table-column prop="Tension3" label="张力3" width="80" :formatter="formatNum"/>
		<el-table-column prop="Tension4" label="张力4" width="80" :formatter="formatNum"/>
		<el-table-column prop="Tension5" label="张力5" width="80" :formatter="formatNum" />
		<el-table-column prop="TensionValue" label="张力均值" width="80" :formatter="formatNum"/> -->
		<el-table-column label="张力1" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Tension1Verify?'success':'danger'">{{scope.row.Tension1==0?null:scope.row.Tension1}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="张力2" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Tension2Verify?'success':'danger'">{{scope.row.Tension2==0?null:scope.row.Tension2}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="张力3" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Tension3Verify?'success':'danger'">{{scope.row.Tension3==0?null:scope.row.Tension3}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="张力4" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Tension4Verify?'success':'danger'">{{scope.row.Tension4==0?null:scope.row.Tension4}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="张力5" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Tension5Verify?'success':'danger'">{{scope.row.Tension5==0?null:scope.row.Tension5}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="张力均值" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.TensionValueVerify?'success':'danger'">{{scope.row.TensionValue==0?null:scope.row.TensionValue}}</el-text>
			</template>
		</el-table-column>

<!-- 		<el-table-column prop="Height1" label="膜厚1" width="80" :formatter="formatNum"/>
		<el-table-column prop="Height2" label="膜厚2" width="80" :formatter="formatNum"/>
		<el-table-column prop="Height3" label="膜厚3" width="80" :formatter="formatNum"/>
		<el-table-column prop="Height4" label="膜厚4" width="80" :formatter="formatNum"/>
		<el-table-column prop="Height5" label="膜厚5" width="80" :formatter="formatNum"/>
		<el-table-column prop="HeightValue" label="膜厚均值" width="80" :formatter="formatNum"/> -->
		<el-table-column label="膜厚1" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Height1Verify?'success':'danger'">{{scope.row.Height1==0?null:scope.row.Height1}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="膜厚2" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Height2Verify?'success':'danger'">{{scope.row.Height2==0?null:scope.row.Height2}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="膜厚3" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Height3Verify?'success':'danger'">{{scope.row.Height3==0?null:scope.row.Height3}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="膜厚4" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Height4Verify?'success':'danger'">{{scope.row.Height4==0?null:scope.row.Height4}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="膜厚5" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.Height5Verify?'success':'danger'">{{scope.row.Height5==0?null:scope.row.Height5}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="膜厚均值" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.HeightValueVerify?'success':'danger'">{{scope.row.HeightValue==0?null:scope.row.HeightValue}}</el-text>
			</template>
		</el-table-column>

		<!-- <el-table-column prop="LineWidth1" label="线宽1" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth2" label="线宽2" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth3" label="线宽3" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth4" label="线宽4" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth5" label="线宽5" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth6" label="线宽6" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth7" label="线宽7" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth8" label="线宽8" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidth9" label="线宽9" width="120" :formatter="formatNum"/>
		<el-table-column prop="LineWidthValue" label="线宽均值" width="120" :formatter="formatNum"/> -->
		<el-table-column label="线宽1" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth1Verify?'success':'danger'">{{scope.row.LineWidth1==0?null:scope.row.LineWidth1}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽2" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth2Verify?'success':'danger'">{{scope.row.LineWidth2==0?null:scope.row.LineWidth2}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽3" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth3Verify?'success':'danger'">{{scope.row.LineWidth3==0?null:scope.row.LineWidth3}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽4" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth4Verify?'success':'danger'">{{scope.row.LineWidth4==0?null:scope.row.LineWidth4}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽5" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth5Verify?'success':'danger'">{{scope.row.LineWidth5==0?null:scope.row.LineWidth5}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽6" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth6Verify?'success':'danger'">{{scope.row.LineWidth6==0?null:scope.row.LineWidth6}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽7" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth7Verify?'success':'danger'">{{scope.row.LineWidth7==0?null:scope.row.LineWidth7}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽8" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth8Verify?'success':'danger'">{{scope.row.LineWidth8==0?null:scope.row.LineWidth8}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽9" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidth9Verify?'success':'danger'">{{scope.row.LineWidth9==0?null:scope.row.LineWidth9}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="线宽均值" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.LineWidthValueVerify?'success':'danger'">{{scope.row.LineWidthValue==0?null:scope.row.LineWidthValue}}</el-text>
			</template>
		</el-table-column>

<!-- 		<el-table-column prop="PT1" label="PT值1" width="120" :formatter="formatNum"/>
		<el-table-column prop="PT2" label="PT值2" width="120" :formatter="formatNum"/>
		<el-table-column prop="PT3" label="PT值3" width="120" :formatter="formatNum"/>
		<el-table-column prop="PT5" label="PT值4" width="120" :formatter="formatNum"/>
		<el-table-column prop="PT6" label="PT值5" width="120" :formatter="formatNum"/>
		<el-table-column prop="PTValue" label="PT均值" width="120" :formatter="formatNum"/> -->
		<!-- <el-table-column prop="PT6" label="PT值6" width="120" :formatter="formatNum"/> -->
		<el-table-column label="PT1" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.PT1Verify?'success':'danger'">{{scope.row.PT1==0?null:scope.row.PT1}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="PT2" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.PT2Verify?'success':'danger'">{{scope.row.PT2==0?null:scope.row.PT2}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="PT3" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.PT3Verify?'success':'danger'">{{scope.row.PT3==0?null:scope.row.PT3}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="PT4" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.PT5Verify?'success':'danger'">{{scope.row.PT5==0?null:scope.row.PT5}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="PT5" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.PT6Verify?'success':'danger'">{{scope.row.PT6==0?null:scope.row.PT6}}</el-text>
			</template>
		</el-table-column>
		<el-table-column label="PT均值" width="80" >
			<template #default="scope">
				<el-text class="mx-1" size="small" :type="scope.row.PTValueVerify?'success':'danger'">{{scope.row.PTValue==0?null:scope.row.PTValue}}</el-text>
			</template>
		</el-table-column>

		<!-- <el-table-column prop="DefectCount" label="缺陷总数" width="120" :formatter="formatNum"/> -->
		<el-table-column prop="DKCount" label="堵孔数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="ZWCount" label="脏污数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="GSYCCount" label="钢丝异常数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="XWSCount" label="纤维丝数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="QKCount" label="缺口数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="ZKCount" label="针孔数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="PPCount" label="泡泡数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="HSCount" label="划伤数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="YXCount" label="压线数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="XBCount" label="斜边数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="SXCount" label="栅线数量" width="120" :formatter="formatNum"/>
		<el-table-column prop="HistoryCount" label="修改次数" width="100" :formatter="formatNum"/>
		<el-table-column v-if="CustomerVer!='A'" fixed="right" align="center" label="" width="120">
			<template #default="scope">
				<el-button type="primary" link size="small"  @click="editDetail(scope.row)">修改</el-button>
				<el-divider  direction="vertical" /> <!-- v-if="scope.row.HistoryCount>0" -->
				<el-badge is-dot class="item" :hidden="scope.row.HistoryCount<1">
					<el-button :disabled="scope.row.HistoryCount<1" type="success" link size="small" @click="openHistoryView(scope.row.Id)">
							历史{{scope.row.HistoryCount>0?`(${scope.row.HistoryCount})`:''}}
					</el-button>
				</el-badge>
			</template>
		</el-table-column>
	</el-table>
	<div class="paging">
    <el-pagination
      v-model:current-page="paging.currentPage"
      v-model:page-size="paging.pageSize"
      :page-sizes="[10, 15, 20, 30, 50, 100]"
      :small="true"
      :background="true"
      layout="total, sizes, prev, pager, next, jumper"
      :total="paging.totalCount"
			@size-change="handleSizeChange"
			@current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup lang="ts">
import { useRouter} from 'vue-router'
const { isDark, toggleDark } = useDarks()
const { formatTableDateTime,formatTableDate,formatDateTime,formatDate,formatNum,show_loading,close_loading,objCompare }= utils()
import { exportJsonToExcel } from "../utils/exportExcel.js";
import XLSX from "xlsx"
import {query_table,update_table,delete_table} from '../api/api.ts'

const router = useRouter();
const CustomerVer=ref('')//客户版本 A/B

const queryDate=ref([])
const productIdList=ref([])
const stepId=ref('')
const compareResult = ref('')
const qualifiedValue = ref('')
const repairfiedValue = ref('')

const dataList = ref([])
const orderHistoryList=ref([])
const productList=ref([])
const stepList=ref([])

const selIds=ref([])
const paging=reactive({
	currentPage:1,//当前页
	pageSize:10,//每页条目数
	totalCount:0,//总条目数
})

const CompareResultOptions = [
  {
    value: 1,
    label: '通过',
  },{
    value: 2,
    label: '未通过',
  }
]
const QualifiedOptions = [
	{
    value: 1,
    label: '合格',
  },{
    value: 2,
    label: '不合格',
  }
]
const RepairfiedOptions = [
	{
    value: 0,
    label: '未修复',
  },{
    value: 5,
    label: '已修复',
  },{
    value: 10,
    label: '异常',
  }
]

const dialogFormVisible = ref(false)
const dialogOrderHistoryVisible = ref(false)
const editRowData=ref(false)
let editPreRowData={}
//
onMounted(async () => {
	document.body.style.overflow = 'hidden';//禁止滚动
		console.log("onMounted - DOM挂载完毕");
		console.log('参数',router.currentRoute.value.query,router.query,router.params)
		const params=router.currentRoute.value.query
		if(params.hasOwnProperty('CustomerVer'))
			CustomerVer.value=params.CustomerVer.trim()

		queryDate.value[0]=queryDate.value[1]=new Date()
		await getFiltersData()
		loadData()
})
const handleSelectionChange = (vals) => {
	selIds.value.length=0
	vals.forEach(row=>{
		console.log(row.Id)
		selIds.value.push(row.Id)
	})
	console.log(selIds.value)
  // multipleSelection.value = val
}
const handleSizeChange=(val) => {
	console.log(`每页 ${val} 条`);
	loadData()
}
const handleCurrentChange=(val) => {
	console.log(`当前页: ${val}`);
	loadData()
}
const delSelList=()=>{
	const req={
		model:'order',
		domain:[],
	}
	//0-等于 3-大于等于  5-小于等于 6-IN(1,2,3,不是数组[]) "CSharpTypeName":"int"
	req.domain.push({"FieldName": "Id","FieldValue": selIds.value+'',"ConditionalType": 6})
	delete_table(req).then(res=>{
		console.log('delSelList',res)
		if(res.code===200) {
			ElMessage({ message: `删除成功，删除${res.data}条记录！`, type: 'success', showClose:true, duration: 2000})

			//删除历史子表
			delete_table({model:'OrderHistory',domain:[{"FieldName": "Pid","FieldValue": selIds.value+'',"ConditionalType": 6}]})
			selIds.value.length=0
			loadData()
		}
		else
			ElMessage({ message: `删除失败:${res.data}`, type: 'success', showClose:true, duration: 2000})
	})
}
const getFiltersData =async () => {
	await query_table({ model:'product', fields:'*',order:'Name'}).then(res=>{
		console.log('getProductList',res)
		if(res.code===200) productList.value.push(...res.data)
	})
	await query_table({ model:'step', fields:'*',order:'Name'}).then(res=>{
		console.log('getStepList',res)
		if(res.code===200) stepList.value.push(...res.data)
	})
}
const loadData = (isExport=false) => {
	show_loading()
	const req={
		model:'order',
		fields:'*',
		domain:[],
		order:'id desc',
		pageNum:isExport?0:paging.currentPage,
		pageSize:isExport?0:paging.pageSize,
	}
	//单天
	// if(queryDate.value){//0-等于 3-大于等于  5-小于等于 6-IN(1,2,3,不是数组[]) "CSharpTypeName":"int"
	// 	req.domain.push({"FieldName": "CreateTime","FieldValue": formatDate(queryDate.value),"ConditionalType": 3})
	// 	req.domain.push({"FieldName": "CreateTime","FieldValue": formatDate(queryDate.value)+' 23:59:59',"ConditionalType": 5})
	// }
	//日期段
	if(queryDate.value && queryDate.value.length>0){//0-等于 3-大于等于  5-小于等于 6-IN "CSharpTypeName":"int"
		console.log(queryDate.value)
		req.domain.push({"FieldName": "CreateTime","FieldValue": formatDate(queryDate.value[0]),"ConditionalType": 3})
		req.domain.push({"FieldName": "CreateTime","FieldValue": formatDate(queryDate.value[1])+' 23:59:59',"ConditionalType": 5})
	}
	if(productIdList.value.length>0){
		var values=''
		for (let key in productIdList.value)
		  values+=productIdList.value[key]+','
		req.domain.push({"FieldName": "ProductId","FieldValue": values,"ConditionalType": 6})
	}

	if(stepId.value)
		req.domain.push({"FieldName": "StepId","FieldValue": stepId.value,"ConditionalType": 0})

	if(compareResult.value)
		req.domain.push({"FieldName": "CompareResult", "FieldValue": compareResult.value,"ConditionalType": 0})
	if(qualifiedValue.value)
		req.domain.push({"FieldName": "Qualified", "FieldValue": (qualifiedValue.value===1?qualifiedValue.value:0), "ConditionalType": 0})
	if(repairfiedValue.value)
		req.domain.push({"FieldName": "State", "FieldValue": repairfiedValue.value, "ConditionalType": 0})

	console.log('req',stepId.value,productIdList.value,req)
	//
	query_table(req).then(res=>{
		console.log('getOrderList',res)
		if(res.code!==200){
			close_loading()
			ElMessage({
				message: res.data,
				type: 'error',
				showClose:true,
				duration: 2000,//自动关闭时间
			})
			return
		}

		//
		const resDataList=res.data
		var rowIndex
		for(rowIndex=0;rowIndex<resDataList.length;rowIndex++){
			var info=productList.value.find(m=>m.Id===resDataList[rowIndex].ProductId)
			if(info) {
				resDataList[rowIndex].ProductName = info.Name
				resDataList[rowIndex].ProductCode = info.Code

				//标红与合格计算
				reCheckQualified(info,resDataList[rowIndex])
			}

			info=stepList.value.find(m=>m.Id===resDataList[rowIndex].StepId)
			if(info) resDataList[rowIndex].StepName = info.Name
		}

		console.log('isExport=',isExport)
		if(!isExport){
			dataList.value=resDataList
			paging.totalCount=res.totalCount
			close_loading()
		}
		else
			exExcel(resDataList)
	})
}
const onClickQuery=()=>{
	paging.currentPage=1
	loadData()
}
const exExcel = (datas) => {
	if(datas.length<1){
		close_loading()
		return
	}
	datas.forEach(data=>{
		data.CreateTime=formatDateTime(data.CreateTime)
		data.CompareResult=formatCompareResult(data)
		data.State=formatRepairfied(data)
		if(CustomerVer.value!='A')
			data.Qualified=formatQualified(data)
	})
	let tableField = [
		"CreateTime","ProductName","ProductCode","StepName","SN","BatchId","Qualified",
		"State","Abnormalities","RepairCode",
		"CompareResult",
		"Tension1","Tension2","Tension3","Tension4","Tension5","TensionValue",
		"Height1","Height2","Height3","Height4","Height5","HeightValue",
		"LineWidth1","LineWidth2","LineWidth3","LineWidth4","LineWidth5","LineWidth6","LineWidth7","LineWidth8","LineWidth9","LineWidthValue",
		"PT1","PT2","PT3","PT5","PT6","PTValue",
		"DefectCount","DKCount","ZWCount","GSYCCount","XWSCount","QKCount","ZKCount","PPCount","HSCount","YXCount","XBCount","SXCount"
	]
	let tableHeader = {
		CreateTime: "日期",
		ProductName: "产品名称",
		ProductCode: "料号",
		StepName: "所用流程",
		SN: "网版编码",
		BatchId: "批次",
		Qualified:"合格",
		State:"修复",
		Abnormalities:"异常情况",
		RepairCode:"修复人员",
		CompareResult:"比对",
		Tension1: "张力1",
		Tension2: "张力2",
		Tension3: "张力3",
		Tension4: "张力4",
		Tension5: "张力5",
		TensionValue: "张力均值",
		Height1: "厚度1",
		Height2: "厚度2",
		Height3: "厚度3",
		Height4: "厚度4",
		Height5: "厚度5",
		HeightValue: "厚度均值",
		LineWidth1: "线宽1",
		LineWidth2: "线宽2",
		LineWidth3: "线宽3",
		LineWidth4: "线宽4",
		LineWidth5: "线宽5",
		LineWidth6: "线宽6",
		LineWidth7: "线宽7",
		LineWidth8: "线宽8",
		LineWidth9: "线宽9",
		LineWidthValue: "线宽均值",
		PT1: "PT1",
		PT2: "PT2",
		PT3: "PT3",
		PT5: "PT4",
		PT6: "PT5",
		PTValue: "PT均值",
		DefectCount: "缺陷数",
		DKCount:"堵孔",
		ZWCount:"脏污",
		GSYCCount:"钢丝异常",
		XWSCount:"纤维丝",
		QKCount:"缺口",
		ZKCount:"针孔",
		PPCount:"泡泡",
		HSCount:"划伤",
		YXCount:"压线",
		XBCount:"斜边",
		SXCount:"栅线"
	}
	if(CustomerVer.value=='A'){
		tableField = tableField.filter(item=>{ return item !== "Qualified" })
		delete tableHeader.Qualified
	}
	//
	exportJsonToExcel({
		header: tableHeader,
		keys: tableField,
		data: datas,
		title: "",
		filename: queryDate.value[0]?formatDate(queryDate.value[0]): "生产报表",
		autoWidth: true,
	});
	ElMessage({ message: "生成中，请稍等...", type: 'success', showClose:true, duration: 2000})
	close_loading()
}
const editDetail=(row)=>{
	console.log(row)
	editRowData.value=row
	editPreRowData = JSON.parse(JSON.stringify(row))//深度copy
	// formData.CompareResult=1
	dialogFormVisible.value=true
}
const save=()=>{
	console.log('save...',editRowData.value,editPreRowData)
	if(objCompare(editRowData.value,editPreRowData)){
		ElMessage({ message: "未做修改，无需保存！", type: 'warning', showClose:true, duration: 2000})
		dialogFormVisible.value=false
		return
	}
	// await query_table({ model:'OrderHistory', fields:'*',order:'Name'}).then(res=>{
	show_loading()
	//标红与合格计算
	var info=productList.value.find(m=>m.Id===editRowData.value.ProductId)
	console.log(info)
	if(info) reCheckQualified(info,editRowData.value)
	editRowData.value.HistoryCount++//修改次
	editRowData.value.ModifyUserCode='admin'
	// editRowData.value.Qualified=true //需重新计算是否合格
	const req={
		model:'Order',
		columns:['CompareResult','TensionValue','HeightValue','LineWidthValue','PTValue','DKCount','ZWCount','GSYCCount',
			'XWSCount','QKCount','ZKCount','PPCount','HSCount','YXCount','XBCount','SXCount','Qualified','HistoryCount','ModifyUserCode'],
		datas:[editRowData.value],
	}
	console.log('req',req)
	//
	update_table(req).then(res=>{
		console.log('save',res)
		close_loading()
		if(res.code!==200){
			ElMessage({
				message: res.data,
				type: 'error',
				showClose:true,
				duration: 1000,//自动关闭时间
			})
			return
		}

		//
		ElMessage({ message: "保存成功！", type: 'success', showClose:true, duration: 1000})
		dialogFormVisible.value=false
	})

}
const openHistoryView=(id)=>{
	console.log('showHistoryView Id',id)
	// await query_table({ model:'OrderHistory', fields:'*',order:'Name'}).then(res=>{
	show_loading()
	const req={
		model:'OrderHistory',
		fields:'*',
		domain:[],
		order:'id desc',
		pageNum:0,//0-全部
		pageSize:0,//0-全部
	}
	req.domain.push({"FieldName": "Pid","FieldValue": id,"ConditionalType": 0})
  console.log('req',stepId.value,productIdList.value,req)
	//
	query_table(req).then(res=>{
		console.log('getOrderHistory',res)
		if(res.code!==200){
			close_loading()
			ElMessage({
				message: res.data,
				type: 'error',
				showClose:true,
				duration: 1000,//自动关闭时间
			})
			return
		}

		//
		dialogOrderHistoryVisible.value=true
		orderHistoryList.value.length=0
		orderHistoryList.value.push(...res.data)
		close_loading()
	})
}
//重新计算合格指标
const reCheckQualified=(pInfo,orderRow)=> {
	let upperLimit, lowerLimit
	console.log('reCheckQualified start...')
	orderRow.Qualified&=(orderRow.CompareResult!==2)
	//Tension 1-5
	upperLimit = pInfo.TensionBaseValue + pInfo.TensionUpFloatValue
	lowerLimit = pInfo.TensionBaseValue - pInfo.TensionDownFloatValue
	if(upperLimit + lowerLimit > 0){
		orderRow.Tension1Verify=(orderRow.Tension1 <= upperLimit && orderRow.Tension1 >= lowerLimit)
		orderRow.Tension2Verify=(orderRow.Tension2 <= upperLimit && orderRow.Tension2  >= lowerLimit)
		orderRow.Tension3Verify=(orderRow.Tension3 <= upperLimit && orderRow.Tension3  >= lowerLimit)
		orderRow.Tension4Verify=(orderRow.Tension4 <= upperLimit && orderRow.Tension4  >= lowerLimit)
		orderRow.Tension5Verify=(orderRow.Tension5 <= upperLimit && orderRow.Tension5  >= lowerLimit)
		orderRow.TensionValueVerify=(orderRow.TensionValue <= upperLimit && orderRow.TensionValue  >= lowerLimit)
	} else
		orderRow.Tension1Verify=orderRow.Tension2Verify=orderRow.Tension3Verify=orderRow.Tension4Verify=orderRow.Tension5Verify=orderRow.TensionValueVerify=true

	//Height 1-5
	upperLimit = pInfo.HeightBaseValue + pInfo.HeightUpFloatValue
	lowerLimit = pInfo.HeightBaseValue - pInfo.HeightDownFloatValue
	if(upperLimit + lowerLimit > 0){
		orderRow.Height1Verify=(orderRow.Height1 <= upperLimit && orderRow.Height1  >= lowerLimit)
		orderRow.Height2Verify=(orderRow.Height2 <= upperLimit && orderRow.Height2  >= lowerLimit)
		orderRow.Height3Verify=(orderRow.Height3 <= upperLimit && orderRow.Height3  >= lowerLimit)
		orderRow.Height4Verify=(orderRow.Height4 <= upperLimit && orderRow.Height4  >= lowerLimit)
		orderRow.Height5Verify=(orderRow.Height5 <= upperLimit && orderRow.Height5  >= lowerLimit)
		orderRow.HeightValueVerify=(orderRow.HeightValue <= upperLimit && orderRow.HeightValue  >= lowerLimit)
	} else
		orderRow.Height1Verify=orderRow.Height2Verify=orderRow.Height3Verify=orderRow.Height4Verify=orderRow.Height5Verify=orderRow.HeightValueVerify=true

	//LineWidth 1-5
	upperLimit = pInfo.LineWidthBaseValue + pInfo.LineWidthUpFloatValue
	lowerLimit = pInfo.LineWidthBaseValue - pInfo.LineWidthDownFloatValue
	if(upperLimit + lowerLimit > 0){
		orderRow.LineWidth1Verify=(orderRow.LineWidth1 <= upperLimit && orderRow.LineWidth1  >= lowerLimit)
		orderRow.LineWidth2Verify=(orderRow.LineWidth2 <= upperLimit && orderRow.LineWidth2  >= lowerLimit)
		orderRow.LineWidth3Verify=(orderRow.LineWidth3 <= upperLimit && orderRow.LineWidth3  >= lowerLimit)
		orderRow.LineWidth4Verify=(orderRow.LineWidth4 <= upperLimit && orderRow.LineWidth4  >= lowerLimit)
		orderRow.LineWidth5Verify=(orderRow.LineWidth5 <= upperLimit && orderRow.LineWidth5  >= lowerLimit)
		orderRow.LineWidth6Verify=(orderRow.LineWidth6 <= upperLimit && orderRow.LineWidth6  >= lowerLimit)
		orderRow.LineWidth7Verify=(orderRow.LineWidth7 <= upperLimit && orderRow.LineWidth7  >= lowerLimit)
		orderRow.LineWidth8Verify=(orderRow.LineWidth8 <= upperLimit && orderRow.LineWidth8  >= lowerLimit)
		orderRow.LineWidth9Verify=(orderRow.LineWidth9 <= upperLimit && orderRow.LineWidth9  >= lowerLimit)
		orderRow.LineWidthValueVerify=(orderRow.LineWidthValue <= upperLimit && orderRow.LineWidthValue  >= lowerLimit)
	}	else
		orderRow.LineWidth1Verify=orderRow.LineWidth2Verify=orderRow.LineWidth3Verify=orderRow.LineWidth4Verify=orderRow.LineWidth5Verify=
			orderRow.LineWidth6Verify=orderRow.LineWidth7Verify=orderRow.LineWidth8Verify=orderRow.LineWidth9Verify=orderRow.LineWidthValueVerify=true

	//PT 1-5
	upperLimit = pInfo.PTBaseValue + pInfo.PTUpFloatValue
	lowerLimit = pInfo.PTBaseValue - pInfo.PTDownFloatValue
	console.log('reCheckQualified PT ',upperLimit,lowerLimit,orderRow)
	if(upperLimit + lowerLimit > 0){
		orderRow.PT1Verify=(orderRow.PT1 <= upperLimit && orderRow.PT1  >= lowerLimit)
		orderRow.PT2Verify=(orderRow.PT2 <= upperLimit && orderRow.PT2  >= lowerLimit)
		orderRow.PT3Verify=(orderRow.PT3 <= upperLimit && orderRow.PT3  >= lowerLimit)
		orderRow.PT4Verify=(orderRow.PT4 <= upperLimit && orderRow.PT4  >= lowerLimit)
		orderRow.PT5Verify=(orderRow.PT5 <= upperLimit && orderRow.PT5  >= lowerLimit)
		orderRow.PT6Verify=(orderRow.PT6 <= upperLimit && orderRow.PT6  >= lowerLimit)
		orderRow.PTValueVerify=(orderRow.PTValue <= upperLimit && orderRow.PTValue  >= lowerLimit)
	}else
		orderRow.PT1Verify=orderRow.PT2Verify=orderRow.PT3Verify=orderRow.PT4Verify =orderRow.PT5Verify=orderRow.PT6Verify=orderRow.PTValueVerify=true
// console.log('reCheckQualified PT ',upperLimit,lowerLimit,orderRow.PT5,orderRow.PT5Verify)
	//
	orderRow.Qualified&=(orderRow.TensionValueVerify && orderRow.HeightValueVerify && orderRow.LineWidthValueVerify && orderRow.PTValueVerify)
}
const formatCompareResult=(row)=> {
	return row.CompareResult===1?'通过':(row.CompareResult===2?'未通过':'未比对')
}
const formatQualified=(row)=> {
	return row.Qualified==1?'合格':'不合格'
}
const formatRepairfied=(row)=> {
	return row.State==5?'修复':( row.State==10?'异常':'未修复')
}

</script>

<style scoped>
	.filterDiv{
		/* background-color: azure; */
		border-bottom:1px solid #CDD0D6;
		margin: 0px;
		padding-bottom: 10px;
		width: 100%;
		display: flex;
		justify-content:space-around;
	}
	.filterButtonDiv{
		  display: flex;
			align-items:center;
	}
	.paging{
		margin: 10px;
		width: 100%;
/* 		display: flex;
		justify-content: flex-end; */
	}
	.editNum{
		margin-left: 5px;
		margin-right: 15px;
	}
</style>
