<!-- 第11套:微波衰减标准库 --> <script lang="ts" setup name="TemplateDetailEleventh"> 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 form = ref({ appearanceFunctionCheck: 1, // 外观及功能性检查 attenuationAmount: 1, // 衰减量 }) watch(() => props.form, (newVal) => { form.value = newVal }) const dataList = ref<IList[]>([]) // ----------------------------------------表头------------------------------------------------ const columns = ref<TableColumn[]>([ // 衰减量 { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' }, { text: '频率', value: 'frequency', align: 'center', required: true, type: 'number' }, { text: '频率单位', value: 'frequencyUnit', align: 'center', required: true, type: 'select' }, { text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'number' }, { text: '标称值单位', value: 'nominalValueUnit', align: 'center', required: true, type: 'select' }, { text: '组合方式', value: 'composition', align: 'center', required: false, type: 'select' }, { text: 'U(k=2)', value: 'urel', align: 'center', required: false, type: 'number' }, { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'number' }, ]) watch(() => props.pageType, (newVal) => { if (newVal === 'detail') { columns.value = columns.value.map((item: TableColumn) => ({ ...item, typeBak: item.type, type: 'text' })) } else { columns.value = columns.value.map((item: TableColumn) => ({ ...item, type: item.typeBak ? item.typeBak : item.type })) } }, { immediate: true, }) // --------------------------------表格操作--------------------------------------------------- const addRow = (list1: IList[], title: string, index: string) => { if (useCheckList(list1, columns.value, `${title}表格`)) { let data = {} as any switch (title) { case '衰减量': // 衰减量 data = { params: '衰减量', dataType: '1', composition: '', // 组合方式 frequency: '', // 频率 frequencyUnit: '', // 频率单位 nominalValue: '', // 标称值 nominalValueUnit: '', // 标称值单位 urel: '', // U(k=2) technicalIndex: '', // 技术指标 technicalIndexSymbol: '±', // 技术指标符号 technicalIndexUnit: 'dB', // 技术指标单位 id: `custom-${new Date().getTime()}`, } dataList.value.length ? dataList.value.push(JSON.parse(JSON.stringify({ ...dataList.value[dataList.value.length - 1], id: `custom-${new Date().getTime()}` }))) : dataList.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 '衰减量': // 衰减量 dataList.value = data break } } } // ---------------------------------------------校验--------------------------------------------------- // 校验表格(点击保存的时候用、生成标准器示值) function checkList(list: any[], columns: any[], title: string) { if (form.value.attenuationAmount) { if (!dataList.value.length) { ElMessage.warning('衰减量列表不能为空') return false } return useCheckList(list, columns, title) } else { return true } } function checkAllList() { // if (!dataList.value.length) { // ElMessage.warning('鉴定项列表不能为空') // return false // } return checkList(dataList.value, columns.value, '衰减量') } watch(() => props.list, (newVal) => { // 检定项表格 if (newVal) { dataList.value = JSON.parse(JSON.stringify(newVal)).map((item: any) => ({ ...item, params: '衰减量' })) // dataList.value = dataList.value } }) const frequencyUnit = ref<{ value: string;name: string;id: string }[]>([]) // 频率单位 const nominalValueUnit = ref<{ value: string;name: string;id: string }[]>([]) // 标称值单位 const composition = ref<{ value: string;name: string;id: string }[]>([]) // 组合方式 // 每个table对应的下拉框内容 字典 const tableDict = ref<{ [key: string]: { value: string;name: string;id: string }[] }>({}) const fecthDict = async () => { // 频率单位 const res1 = await getDictByCode('standardFrequencyUnit') frequencyUnit.value = res1.data // 标称值单位 const res2 = await getDictByCode('standardAmplitudeUnit') nominalValueUnit.value = res2.data // 组合方式 const res3 = await getDictByCode('levelComposition') composition.value = res3.data tableDict.value = { 频率单位: frequencyUnit.value, 标称值单位: nominalValueUnit.value, 组合方式: composition.value, } } const getList = () => { if (form.value.attenuationAmount) { return JSON.parse(JSON.stringify(dataList.value)) } else { return [] } } fecthDict() defineExpose({ dataList, checkAllList, form, getList }) </script> <template> <div style="padding: 0 10px;"> <el-checkbox v-model="form.appearanceFunctionCheck" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'"> 外观及功能性检查 </el-checkbox> </div> <!-- 电源电压调整率 --> <template-table :show="Boolean(form.attenuationAmount)" :data="dataList" :columns="columns" :page-type="pageType" title="衰减量" index="1" :show-btn="pageType !== 'detail'" :select-all-list="tableDict" @add-row="addRow" @del-row="delRow" > <template #custom-check> <el-checkbox v-model="form.attenuationAmount" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'"> 衰减量 </el-checkbox> </template> <!-- 符号 --> <template #pre-content="{ scope, column }"> <div v-if="column.text === '技术指标'" style="line-height: 30px;margin-left: 10px;"> {{ scope.technicalIndexSymbol }} </div> </template> <template #next-content="{ scope, column }"> <template v-if="column.text === '技术指标'"> <span v-for="item in scope?.technicalIndexUnit" :key="item" style="display: inline-block;">{{ item }}</span> </template> </template> </template-table> </template>