<!-- 点击配置检定项弹框 --> <script lang="ts" setup name="SelectStaffDialog"> import { ref } from 'vue' import { ElLoading, ElMessageBox } from 'element-plus' import type { dictType } from '@/global' import { getDictByCode } from '@/api/system/dict' import { getClassificationList } from '@/api/business/measure/classification' const emits = defineEmits(['confirm']) const dialogFormVisible = ref(false) const form = ref({ deviceType: '', // 设备分类(字典code) deviceTypeName: '', // 设备分类(value) belongStandardEquipment: '', // 检校标准装置(字典code) belongStandardEquipmentName: '', // 检校标准装置(字典value) itemCategoryId: '', // 设备检定项分类表id itemCategoryName: '', // 设备检定项分类名字 configType: '', // 检定项类型 }) const loading = ref(false) const originForm = ref({ deviceType: '', // 设备分类(字典code) belongStandardEquipment: '', // 检校标准装置(字典code) itemCategoryId: '', // 设备检定项分类表id }) // 校验规则 const rules = ref({ deviceType: [{ required: true, message: '设备分类不能为空', trigger: ['blur', 'change'] }], belongStandardEquipment: [{ required: true, message: '检校标准装置不能为空', trigger: ['blur', 'change'] }], itemCategoryId: [{ required: true, message: '设备检定项分类不能为空', trigger: ['blur', 'change'] }], }) const ruleFormRef = ref() const disabledItemCategoryId = ref('') // 检定项分类禁用选项 // -------------------------------------------字典------------------------------------------ const deviceTypeList = ref<dictType[]>([])// 设备分类 const standardList = ref<dictType[]>([])// 检校标准装置 const standardMapList = ref<dictType[]>([])// 检校标准装置 async function getDict() { // 检校标准装置 const response = await getDictByCode('bizStandardEquipmentType') standardList.value = response.data // 设备分类 const res = await getDictByCode('eqptDeviceType') deviceTypeList.value = res.data } // -------------------------------------------获取检定项分类------------------------------------------------ const itemList = ref<{ id: string; name: string; disabled?: boolean }[]>([]) // 检定项分类列表 // 获取检定项分类 const fetchItemList = (deviceType = '', belongStandardEquipment = '') => { loading.value = true const requestParams = { belongStandardEquipment, // 检校标准装置 categoryName: '', // 检定项分类名称 categoryNo: '', // 检定项分类编号 deviceType, // 设备分类 measureCategory: '', // 检校类别 limit: 999999, offset: 1, } getClassificationList(requestParams).then((response) => { itemList.value = response.data.rows.map((item: { categoryName: string; id: string }) => { return { name: item.categoryName, // 检定项分类名称 id: item.id, disabled: disabledItemCategoryId.value === item.id, } }) loading.value = false }) } // -------------------------------------------------------------------------------------------------------- // 点击确定 const confirmSelect = () => { ruleFormRef.value!.validate((valid: boolean) => { if (valid) { if (form.value.configType === 'edit' && (form.value.belongStandardEquipment !== originForm.value.belongStandardEquipment || form.value.itemCategoryId !== originForm.value.itemCategoryId || form.value.deviceType !== originForm.value.deviceType)) { ElMessageBox.confirm( '您将会更新之前所有配置项,无法撤销!', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { form.value.itemCategoryName = itemList.value.find(item => item.id === form.value.itemCategoryId)!.name form.value.belongStandardEquipmentName = standardList.value.find(item => item.value === form.value.belongStandardEquipment)!.name emits('confirm', form.value) dialogFormVisible.value = false }) .catch(() => { // dialogFormVisible.value = false }) } else { form.value.itemCategoryName = itemList.value.find(item => item.id === form.value.itemCategoryId)!.name form.value.belongStandardEquipmentName = standardList.value.find(item => item.value === form.value.belongStandardEquipment)!.name emits('confirm', form.value) dialogFormVisible.value = false } } }) } // 取消 const cancle = () => { dialogFormVisible.value = false form.value = { // 清空数据 deviceType: '', // 设备分类(字典code) deviceTypeName: '', // 设备分类(value) belongStandardEquipment: '', // 检校标准装置(字典code) belongStandardEquipmentName: '', // 检校标准装置(字典value) itemCategoryId: '', // 设备检定项分类表id itemCategoryName: '', // 设备检定项分类名字 configType: '', } } // 初始化 const initDialog = (configTypeParam = 'edit', deviceType: string, belongStandardEquipment: string, itemCategoryId: string) => { loading.value = true getDict().then(() => { form.value.configType = configTypeParam // 配置类型 edit修改原有配置、add新增配置 form.value.deviceType = deviceType // 设备分类 form.value.belongStandardEquipment = belongStandardEquipment // 检校标准装置 originForm.value.deviceType = deviceType // 设备分类 originForm.value.belongStandardEquipment = belongStandardEquipment // 检校标准装置 originForm.value.itemCategoryId = itemCategoryId // 检定项分类id nextTick(() => { fetchItemList(deviceType, belongStandardEquipment) // 获取检定项分类 disabledItemCategoryId.value = itemCategoryId form.value.itemCategoryId = configTypeParam === 'add' ? '' : itemCategoryId // 设备检定项分类表id }) dialogFormVisible.value = true // 显示对话框 loading.value = false }) } watch(() => form.value.belongStandardEquipment, (newValue) => { // 监听到检校标准装置变化 form.value.itemCategoryId = '' // 清空检定项分类 form.value.itemCategoryName = '' if (form.value.deviceType) { fetchItemList(form.value.deviceType, newValue) } }, { immediate: true }) watch(() => form.value.deviceType, (newValue) => { // 监听到设备分类变化 form.value.itemCategoryId = '' // 清空检定项分类 form.value.itemCategoryName = '' if (newValue === '1') { // 电学 standardMapList.value = standardList.value.slice(0, 3) } else if (newValue === '2') { // 压力 standardMapList.value = standardList.value.slice(3, 8) } else if (newValue === '0') { // 无线电 standardMapList.value = standardList.value.slice(8, 18) } else { standardMapList.value = standardList.value.slice(18) } const index = standardMapList.value.findIndex(item => item.value === form.value.belongStandardEquipment) if (index === -1) { form.value.belongStandardEquipment = '' // 清空检校标准装置 } }) defineExpose({ initDialog }) </script> <template> <el-dialog v-if="dialogFormVisible" v-model="dialogFormVisible" v-loading="loading" class="confirm-config" title="确认操作"> <el-form ref="ruleFormRef" v-loading="loading" :model="form" label-width="140" label-position="right" :rules="rules" > <el-form-item label="设备分类:" prop="deviceType"> <el-select v-model="form.deviceType" placeholder="设备分类" filterable style="width: 400px;" > <el-option v-for="item in deviceTypeList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </el-form-item> <el-form-item label="检校标准装置:" prop="belongStandardEquipment"> <el-select v-model="form.belongStandardEquipment" placeholder="请选择检校标准装置" filterable style="width: 400px;" :disabled="!form.deviceType" > <el-option v-for="item in standardMapList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </el-form-item> <el-form-item label="设备检定项分类:" prop="itemCategoryId"> <el-select v-model="form.itemCategoryId" placeholder="请选择设备检定项分类" filterable style="width: 400px;" :disabled="!form.belongStandardEquipment" > <el-option v-for="item in itemList" :key="item.id" :disabled="item.disabled" :label="item.name" :value="item.id" /> </el-select> </el-form-item> </el-form> <template #footer> <span class="dialog-footer"> <el-button type="primary" @click="confirmSelect">确认</el-button> <el-button @click="cancle"> 取消 </el-button> </span> </template> </el-dialog> </template> <style lang="scss" scoped> :deep(.el-radio__label) { display: none; } :deep(.el-dialog__body) { display: flex; flex-direction: column; justify-content: center; align-items: center; } </style> <style lang="scss"> .confirm-config { .el-dialog__body { display: flex; flex-direction: column; justify-content: center; align-items: center; } } </style>