<!-- 第7套:精密露点仪标准装置标准装置 --> <script lang="ts" setup name="TemplateDetailSeventh"> import { ElMessage } from 'element-plus' import type { IList } from './templateDetail-interface' import type { dictType } from '@/global' import { getDictByCode } from '@/api/system/dict' import { calc } from '@/utils/useCalc' import { useCheckList } from '@/commonMethods/useCheckList' import { calculate, recalculate } from '@/api/business/measure/caculate' import type { TableColumn } from '@/components/NormalTable/table_interface' import templateTable from '@/views/business/measure/item/components/second/templateTable.vue' import { differenceArray, setSelectList } from '@/utils/Array' const props = defineProps({ pageType: { type: String, default: 'add', }, itemCategoryName: { type: String, require: true, }, // 设备检定项分类名称 belongStandardEquipment: { // 检校标准装置code type: String, require: true, }, list: { type: Array as any, }, form: { // 检定项表单 type: Object as any, }, itemId: { // 检定项id type: String, default: '', }, }) const list = ref<IList[]>([]) const checkoutList = ref<IList[]>([]) // 多选 // ------------------------------------------表头------------------------------------------------------------- const columns = ref([]) as any // 表头数据 const columns_mechanical = ref<TableColumn[]>([ // 机械式温湿度仪表 1 { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' }, { text: '类型', value: 'typeDesc', align: 'center', required: true, type: 'select' }, { text: '温度点/湿度点', value: 'dimensionPoint', align: 'center', required: true, type: 'number' }, { text: '单位', value: 'dimensionPointUnit', align: 'center', required: false, type: 'text' }, { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'number' }, ]) const columns_digital = ref<TableColumn[]>([ // 数字式/外置探头式温湿度仪表2 { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' }, { text: '类型', value: 'typeDesc', align: 'center', required: true, type: 'select' }, { text: '温度点/湿度点', value: 'dimensionPoint', align: 'center', required: true, type: 'number' }, { text: '单位', value: 'dimensionPointUnit', align: 'center', required: false, type: 'text' }, { text: '不确定度', value: 'urel', align: 'center', required: true, type: 'number' }, { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'number' }, ]) const form = ref({ indicationError: 1, appearanceFunctionCheck: 1, }) watch(() => props.form, (newVal) => { if (newVal) { form.value = newVal } }, { deep: true, }) // --------------------------------------------钩子---------------------------------------------------- watch(() => props.itemCategoryName, (newValue) => { if (newValue) { switch (newValue) { case '机械式温湿度仪表': columns.value = columns_mechanical.value break case '数字式/外置探头式温湿度仪表': columns.value = columns_digital.value break } } }, { immediate: true }) watch(() => props.list, (newVal) => { // 检定项表格 if (newVal) { list.value = [] list.value = [...newVal].map((item: any) => ({ ...item, params: '示值测试', })).filter((item: any) => item.dataType === (props.itemCategoryName === '机械式温湿度仪表' ? '1' : '2')) } }) // defineExpose({ list }) // --------------------------------表格操作--------------------------------------------------- const addRow = (list1: IList[], title: string, index: string) => { if (useCheckList(list1, columns.value, `${title}表格`)) { let data = {} as any switch (title) { case '示值测试': // 示值测试 data = { // id: '', params: '示值测试', editable: true, dataType: props.itemCategoryName === '机械式温湿度仪表' ? '1' : '2', typeDesc: '', dimensionPoint: '', dimensionPointUnit: '', urel: '', maximumError: '', id: `custom-${new Date().getTime()}`, } list.value.length ? list.value.push(JSON.parse(JSON.stringify({ ...list.value[list.value.length - 1], id: `custom-${new Date().getTime()}` }))) : list.value.push(data) break } } } /** * 删除行公共方法 * @param checkoutList 选中的数组 * @param list 操作的数组 */ const delRow = (checkoutList: IList[], list1: IList[], title: string) => { if (!checkoutList.length) { ElMessage.warning('请选中要删除的行') } else { let data = [] as any[] data = differenceArray(list1, checkoutList) switch (title) { case '示值测试': // 衰减量 list.value = data break } } } // ---------------------------------------------校验--------------------------------------------------- // 校验表格(点击保存的时候用、生成标准器示值) function checkList() { if (!Number(form.value.indicationError) && !Number(form.value.appearanceFunctionCheck)) { ElMessage.warning('检定项不能为空') return false } if (Number(form.value.indicationError)) { if (!list.value.length) { ElMessage.warning('示值测试列表不能为空') return false } return useCheckList(list.value, columns.value, '示值测试') } else { return true } } // 每个table对应的下拉框内容 字典 const tableDict = ref<{ [key: string]: { value: string; name: string; id: string }[] }>({}) tableDict.value = { 类型: [ { name: '温度示值', value: '1', id: '1', }, { name: '湿度示值', value: '2', id: '2', }, ], } const changeLoadSituationa = (value: any, index: number, text: string, type: string, list: any[], item: string) => { if (item === '示值测试') { if (text === '类型') { if (typeof value === 'string') { list[index].dimensionPointUnit = value === '温度示值' ? '℃' : value === '湿度示值' ? '%RH' : '' } } } } watch(() => props.pageType, (newVal) => { // 检定项表格 if (newVal === 'detail') { list.value.forEach((item: any) => { item.editable = false }) } else { list.value.forEach((item: any) => { item.editable = true }) } }) // 表格下拉框等内容是否禁用 const disabled = ({ scope, column }, fun) => { fun(props.pageType === 'detail') } // 清空配置 const clearConfig = () => { list.value = [] } defineExpose({ list, checkList, form, clearConfig }) </script> <template> <div style="padding: 0 10px;"> <el-checkbox v-model="form.appearanceFunctionCheck" :true-label="1" :false-label="0" :checked="true" :disabled="pageType === 'detail'" > 外观检查 </el-checkbox> </div> <!-- 示值测试 --> <template-table :show="Boolean(form.indicationError)" :data="list" :columns="columns" :page-type="pageType" title="示值测试" index="1" :show-btn="pageType !== 'detail'" :select-all-list="tableDict" @disabled="disabled" @add-row="addRow" @del-row="delRow" @change-load-situationa="changeLoadSituationa" > <template #custom-check> <el-checkbox v-model="form.indicationError" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'" > 示值测试 </el-checkbox> </template> <template #pre-content="{ column }"> <div v-if="column.text === '最大允许误差'" style="line-height: 30px;margin-left: 10px;"> ± </div> </template> </template-table> </template>