<!-- 标准装置台账信息详情 配置核查项 第17套:S参数 --> <script name="StandardBookEquipmentConfig" lang="ts" setup> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { IList } from './seventeenth-interface' import TemplateTable from './templateTable.vue' import type { dictType } from '@/global' import { useCheckList } from '@/commonMethods/useCheckList' import type { TableColumn } from '@/components/NormalTable/table_interface' import { config, getCheckItemDetail } from '@/api/equipment/standard/book' import { calc } from '@/utils/useCalc' import { getDictByCode } from '@/api/system/dict' import { differenceArray } from '@/utils/Array' const textMap: { [key: string]: string } = { edit: '编辑', detail: '详情', }// 页面类型字典 const form = ref({ // 表单 equipmentNo: '', // 统一编号 equipmentName: '', // 设备名称 model: '', // 规格型号 manufactureNo: '', // 出厂编号 measureRange: '', // 测量范围 uncertainty: '', // 不确定度或允许误差极限或准确度等级 itemCategoryName: '', // 核查项分类名称 itemCategoryId: '', // 核查项分类id remark: '', // 核查项备注 belongStandardEquipment: '', // 检校标准装置 belongStandardEquipmentName: '', // 检校标准装置名称 }) const pageType = ref('detail') // 页面类型: add, edit, detail const infoId = ref('') // id const $router = useRouter() // 路由实例 const loading = ref(false) // loading const equipmentId = ref('') // 设备id // -----------------------------------路由参数------------------------------------------------------ // 从路由中获取页面类型参数 const $route = useRoute() if ($route.params && $route.params.type) { pageType.value = $route.params.type as string if ($route.params.id) { infoId.value = $route.params.id as string } console.log('pageType.value', pageType.value) } // -------------------------------------------核查项----------------------------------------------- const listMismatch = ref<IList[]>([]) // 失配测量 const listAttenuation = ref<IList[]>([]) // 衰减测量 const listPhase = ref<IList[]>([]) // 相移测量 const checkoutMismatchList = ref<IList[]>([]) // 失配测量多选 const checkoutAttenuationList = ref<IList[]>([]) // 衰减测量多选 const checkoutPhaseList = ref<IList[]>([]) // 相移测量多选 const mismatch = ref(true) // 失配测量 const attenuation = ref(true) // 衰减测量 const phase = ref(true) // 相移测量 const columns_mismatch = ref<TableColumn[]>([ // 失配测量 { text: '核查项目', value: 'params', align: 'center', required: true }, { text: '类型', value: 'typeValue', align: 'center', required: true, width: '100' }, { text: 'VSMR', value: 'vswr', align: 'center', required: true, width: '100' }, { text: '频率', value: 'frequency', align: 'center', required: true, width: '180' }, { text: '频率单位', value: 'frequencyUnit', align: 'center', required: true, width: '100' }, { text: 'U(k=2)', value: 'urel', align: 'center', required: true, width: '180' }, { text: '循环次数', value: 'cycleNumber', align: 'center', required: true }, { text: '核查类型', value: 'checkType', align: 'center', required: true, width: '180' }, ]) const columns_attenuation = ref<TableColumn[]>([ // 衰减测量 { text: '核查项目', value: 'params', align: 'center', required: true }, { text: '类型', value: 'typeValue', align: 'center', required: true, width: '100' }, { text: '幅度', value: 'amplitude', align: 'center', required: true, width: '180' }, { text: '幅度单位', value: 'amplitudeUnit', align: 'center', required: true, width: '100' }, { text: '频率', value: 'frequency', align: 'center', required: true, width: '180' }, { text: '频率单位', value: 'frequencyUnit', align: 'center', required: true, width: '100' }, { text: 'U(k=2)', value: 'urel', align: 'center', required: true, width: '180' }, { text: '循环次数', value: 'cycleNumber', align: 'center', required: true }, { text: '核查类型', value: 'checkType', align: 'center', required: true, width: '180' }, ]) const columns_phase = ref<TableColumn[]>([ // 相移测量 { text: '核查项目', value: 'params', align: 'center', required: true }, { text: '类型', value: 'typeValue', align: 'center', required: true, width: '100' }, { text: '频率', value: 'frequency', align: 'center', required: true, width: '180' }, { text: '频率单位', value: 'frequencyUnit', align: 'center', required: true, width: '100' }, { text: '相位', value: 'phase', align: 'center', required: true, width: '180' }, { text: '相位单位', value: 'phaseUnit', align: 'center', required: true, width: '100' }, { text: 'U(k=2)', value: 'urel', align: 'center', required: true, width: '180' }, { text: '循环次数', value: 'cycleNumber', align: 'center', required: true }, { text: '核查类型', value: 'checkType', align: 'center', required: true, width: '180' }, ]) // 多选 const handleSelectionChange = (e: any, type: string) => { switch (type) { case '失配测量': checkoutMismatchList.value = e break case '衰减测量': checkoutAttenuationList.value = e break case '相移测量': checkoutPhaseList.value = e break } } // 校验表格(点击保存的时候、增加行用) const checkList = (list: any, getTitle: string) => { let title = '' if (getTitle.slice(getTitle.length - 2) === '表格') { title = getTitle.slice(0, getTitle.length - 2) } else { title = getTitle } let columns switch (title) { case '失配测量': columns = columns_mismatch.value break case '衰减测量': columns = columns_attenuation.value break case '相移测量': columns = columns_phase.value break } return useCheckList(list, columns, `${title}表格`) } /** * 增加行公共方法 * @param list 要操作的数组 * @param title 操作的表格 */ const addRow = (list: IList[], title: string) => { if (checkList(list, `${title}表格`)) { if (list.length) { // 增加行时默认上一行数据 list.push({ ...list[list.length - 1] }) } else { switch (title) { case '失配测量': list.push({ equipmentId: infoId.value, // 配套设备id itemCategoryId: form.value.itemCategoryId, // 核查项分类id(能够确定是哪个标准装置) id: '', params: title, // 核查项目 typeValue: 'S11', // 类型 vswr: '1.2', // VSWR frequency: undefined, // 频率 frequencyUnit: 'MHz', // 频率单位 cycleNumber: 10, // 循环次数 checkType: '重复性, 稳定性', // 核查类型(直接存字典value,多个逗号分隔) remark: '', // 核查项备注 urel: undefined, // U(k=2) }) break case '衰减测量': list.push({ equipmentId: infoId.value, // 配套设备id itemCategoryId: form.value.itemCategoryId, // 核查项分类id(能够确定是哪个标准装置) id: '', params: title, // 核查项目 typeValue: 'S11', // 类型 frequency: undefined, // 频率 frequencyUnit: 'MHz', // 频率单位 amplitude: undefined, // 幅度 amplitudeUnit: 'dB', // 幅度单位 cycleNumber: 10, // 循环次数 checkType: '重复性, 稳定性', // 核查类型(直接存字典value,多个逗号分隔) remark: '', // 核查项备注 urel: undefined, // U(k=2) }) break case '相移测量': list.push({ equipmentId: infoId.value, // 配套设备id itemCategoryId: form.value.itemCategoryId, // 核查项分类id(能够确定是哪个标准装置) id: '', params: title, // 核查项目 typeValue: 'S11', // 类型 frequency: undefined, // 频率 frequencyUnit: 'MHz', // 频率单位 phase: undefined, // 相位 phaseUnit: '°', // 相位单位 cycleNumber: 10, // 循环次数 checkType: '重复性, 稳定性', // 核查类型(直接存字典value,多个逗号分隔) remark: '', // 核查项备注 urel: undefined, // U(k=2) }) break } } } } /** * 删除行公共方法 * @param checkoutList 选中的数组 * @param list 操作的数组 */ const delRow = (checkoutList: IList[], list: IList[], title: string) => { if (!checkoutList.length) { ElMessage.warning('请选中要删除的行') } else { let data = [] as any[] data = differenceArray(list, checkoutList) switch (title) { case '失配测量': listMismatch.value = data break case '衰减测量': listAttenuation.value = data break case '相移测量': listPhase.value = data break } } } // ---------------------------------------按钮----------------------------------------------------- // 点击关闭 const close = () => { $router.back() } // 清空配置 const clear = () => { ElMessageBox.confirm( '确认清空配置项吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { listMismatch.value = [] // 失配测量 listAttenuation.value = [] // 衰减测量 listPhase.value = [] // 相移测量 form.value.remark = '' }) } // 保存之前校验 const checkListBeforeSave = () => { console.log('保存之前校验') // 验空 if (mismatch.value && !listMismatch.value.length) { // 失配测量 ElMessage.warning('失配测量 不能为空') return false } if (attenuation.value && !listAttenuation.value.length) { // 衰减测量 ElMessage.warning('衰减测量 不能为空') return false } if (phase.value && !listPhase.value.length) { // 相移测量 ElMessage.warning('相移测量 不能为空') return false } let mismatchResult = true // 失配测量 let attenuationResult = true // 衰减测量 let phaseResult = true // 相移测量 if (mismatch.value) { mismatchResult = checkList(listMismatch.value, '失配测量') } if (attenuation.value) { attenuationResult = checkList(listAttenuation.value, '衰减测量') } if (phase.value) { phaseResult = checkList(listPhase.value, '相移测量') } if (mismatchResult && attenuationResult && phaseResult) { // return true console.log('checkList校验通过') } else { console.log('checkList校验不通过') return false } // 检查表格数据 /** S参数 * 失配测量:类型、频率(数值+单位) * 衰减测量:类型、频率(数值+单位)、幅度(数值+单位) * 相移测量:类型、幅度(数值+单位)、相位(数值+单位) */ const listMismatchResult = checkArrayDataUnique(listMismatch.value) const listAttenuationResult = checkArrayDataUnique(listAttenuation.value) const listPhaseResult = checkArrayDataUnique(listPhase.value) if (listMismatchResult && listAttenuationResult && listPhaseResult) { return true } else { return false } } // 校验表格中不能同时相同的两条数据 /** S参数 * 失配测量:类型、频率(数值+单位) * 衰减测量:类型、频率(数值+单位)、幅度(数值+单位) * 相移测量:类型、幅度(数值+单位)、相位(数值+单位) */ function checkArrayDataUnique(list: any) { for (let i = 0; i < list.length; i++) { const j = i + 1 for (let j = 0; j < list.length; j++) { if (i !== j && list[i].params === list[j].params) { if (list[i].params === '失配测量' && list[i].typeValue === list[j].typeValue && (list[i].frequency + list[i].frequencyUnit) === (list[j].frequency + list[j].frequencyUnit)) { ElMessage.warning(`${list[i].params} 第${i + 1}行第${j + 1}行的 类型、频率和单位不能同时完全一样`) return false } if (list[i].params === '衰减测量' && list[i].typeValue === list[j].typeValue && (list[i].frequency + list[i].frequencyUnit) === (list[j].frequency + list[j].frequencyUnit) && (list[i].amplitude + list[i].amplitudeUnit) === (list[j].amplitude + list[j].amplitudeUnit)) { ElMessage.warning(`${list[i].params} 第${i + 1}行第${j + 1}行的 类型、频率、单位、幅度和单位不能同时完全一样`) return false } if (list[i].params === '相移测量' && list[i].typeValue === list[j].typeValue && (list[i].phase + list[i].phaseUnit) === (list[j].phase + list[j].phaseUnit) && (list[i].frequency + list[i].frequencyUnit) === (list[j].frequency + list[j].frequencyUnit)) { ElMessage.warning(`${list[i].params} 第${i + 1}行第${j + 1}行的 类型、相位、单位、幅度和单位不能同时完全一样`) return false } } } } return true } // 保存之前处理数据 const solveDataBeforeSave = () => { // 数据处理 let tempList = [] as any if (mismatch.value) { // 失配测量 tempList = tempList.concat(listMismatch.value) } if (attenuation.value) { // 衰减测量 tempList = tempList.concat(listAttenuation.value) } if (phase.value) { // 相移测量 tempList = tempList.concat(listPhase.value) } tempList = tempList.map((item: { id: string }) => { return { ...item, id: '', remark: form.value.remark, } }) return tempList } // 点击保存 const save = () => { if (!checkListBeforeSave()) { return false } const list = solveDataBeforeSave() const params = { itemCategoryId: form.value.itemCategoryId, // 核查项分类id checkItemDataSParamList: list, equipmentId: equipmentId.value, standardId: $route.query.standardId, } const loading = ElLoading.service({ lock: true, text: '加载中', background: 'rgba(255, 255, 255, 0.6)', }) config(params).then((res) => { ElMessage.success('已保存') pageType.value = 'detail' loading.close() }) } // 获取详情 const getInfo = () => { const loading = ElLoading.service({ lock: true, text: '加载中', background: 'rgba(255, 255, 255, 0.6)', }) const params = { equipmentId: equipmentId.value, // 设备id belongStandardEquipment: form.value.belongStandardEquipment, // 检校标准装置code itemCategoryId: form.value.itemCategoryId, // 核查项分类id itemCategoryName: form.value.itemCategoryName, // 核查项分类名称 } getCheckItemDetail(params).then((res) => { if (res.data && res.data.checkItemDataSParamList && res.data.checkItemDataSParamList.length) { listMismatch.value = res.data.checkItemDataSParamList.filter((item: { params: string }) => item.params === '失配测量') listAttenuation.value = res.data.checkItemDataSParamList.filter((item: { params: string }) => item.params === '衰减测量') listPhase.value = res.data.checkItemDataSParamList.filter((item: { params: string }) => item.params === '相移测量') form.value.remark = res.data.checkItemDataSParamList[0].remark mismatch.value = listMismatch.value.length > 0 // 失配测量 attenuation.value = listAttenuation.value.length > 0 // 衰减测量 phase.value = listPhase.value.length > 0 // 相移测量 } loading.close() }) } // ------------------------------------------钩子-------------------------------------------------- onMounted(() => { form.value.equipmentNo = $route.query.equipmentNo as string // 统一编号 form.value.equipmentName = $route.query.equipmentName as string // 设备名称 form.value.model = $route.query.model as string // 规格型号 form.value.manufactureNo = $route.query.manufactureNo as string // 出厂编号 form.value.measureRange = $route.query.measureRange as string // 测量范围 form.value.uncertainty = $route.query.uncertainty as string // 不确定度或允许误差极限或准确度等级 form.value.itemCategoryName = $route.query.itemCategoryName as string // 核查项分类名称 form.value.itemCategoryId = $route.query.itemCategoryId as string // 核查项分类id form.value.belongStandardEquipment = $route.query.belongStandardEquipment as string // 核查项标准装置id form.value.belongStandardEquipmentName = $route.query.belongStandardEquipmentName as string // 核查项标准装置id equipmentId.value = $route.query.equipmentId as string // 设备id getInfo() }) </script> <template> <app-container> <detail-page v-loading="loading" :title="`配置核查项(${textMap[pageType]})`"> <template #btns> <el-button v-if="pageType === 'edit'" type="warning" @click="clear"> 清空配置 </el-button> <el-button v-if="pageType === 'edit'" type="primary" @click="save"> 保存 </el-button> <el-button type="info" @click="close"> 关闭 </el-button> </template> <el-form ref="ruleFormRef" :model="form" :label-width="130" label-position="right" > <el-row :gutter="24" class="marg"> <el-col :span="6"> <el-form-item label="统一编号:" prop="equipmentNo"> <el-input v-model="form.equipmentNo" disabled :placeholder="pageType === 'detail' ? '' : '统一编号'" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="设备名称:" prop="equipmentName"> <el-input v-model="form.equipmentName" disabled :placeholder="pageType === 'detail' ? '' : '设备名称'" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="规格型号:" prop="model"> <el-input v-model="form.model" disabled :placeholder="pageType === 'detail' ? '' : '规格型号'" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="出厂编号:" prop="manufactureNo"> <el-input v-model="form.manufactureNo" disabled :placeholder="pageType === 'detail' ? '' : '出厂编号'" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="测量范围:" prop="measureRange"> <el-input v-model="form.measureRange" disabled type="textarea" autosize :placeholder="pageType === 'detail' ? '' : '测量范围'" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label-width="260" label="不确定度或允许误差极限或准确度等级:" prop="uncertainty"> <el-input v-model="form.uncertainty" type="textarea" autosize disabled :placeholder="pageType === 'detail' ? '' : '不确定度或允许误差极限或准确度等级'" /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="核查项分类名称:" prop="itemCategoryName"> <el-input v-model="form.itemCategoryName" disabled :placeholder="pageType === 'detail' ? '' : '核查项分类名称'" /> </el-form-item> </el-col> </el-row> </el-form> </detail-page> <!-- 失配测量 --> <detail-block title="" style="padding-bottom: 20px;"> <div style="display: flex;justify-content: space-between;"> <el-checkbox v-model="mismatch" :disabled="pageType === 'detail'"> 失配测量 </el-checkbox> <div v-if="mismatch && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;"> <el-button type="primary" @click="addRow(listMismatch, '失配测量')"> 增加行 </el-button> <el-button type="info" @click="delRow(checkoutMismatchList, listMismatch, '失配测量')"> 删除行 </el-button> </div> </div> <template-table v-if="mismatch" :data="listMismatch" :columns="columns_mismatch" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '失配测量')" /> </detail-block> <!-- 衰减测量 --> <detail-block title="" style="padding-bottom: 20px;"> <div style="display: flex;justify-content: space-between;"> <el-checkbox v-model="attenuation" :disabled="pageType === 'detail'"> 衰减测量 </el-checkbox> <div v-if="attenuation && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;"> <el-button type="primary" @click="addRow(listAttenuation, '衰减测量')"> 增加行 </el-button> <el-button type="info" @click="delRow(checkoutAttenuationList, listAttenuation, '衰减测量')"> 删除行 </el-button> </div> </div> <template-table v-if="attenuation" :data="listAttenuation" :columns="columns_attenuation" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '衰减测量')" /> </detail-block> <!-- 相移测量 --> <detail-block title="" style="padding-bottom: 20px;"> <div style="display: flex;justify-content: space-between;"> <el-checkbox v-model="phase" :disabled="pageType === 'detail'"> 相移测量 </el-checkbox> <div v-if="phase && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;"> <el-button type="primary" @click="addRow(listPhase, '相移测量')"> 增加行 </el-button> <el-button type="info" @click="delRow(checkoutPhaseList, listPhase, '相移测量')"> 删除行 </el-button> </div> </div> <template-table v-if="phase" :data="listPhase" :columns="columns_phase" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '相移测量')" /> </detail-block> <!-- 核查项备注 --> <el-form :model="form" label-width="120" label-position="right" style="margin-top: 20px;" > <el-row> <el-col :span="12"> <el-form-item label="核查项备注:" prop="remark"> <el-input v-model="form.remark" class="full-width-input" autosize type="textarea" :disabled="pageType === 'detail'" :placeholder="pageType === 'detail' ? ' ' : '请输入核查项备注'" /> </el-form-item> </el-col> </el-row> </el-form> </app-container> </template>