<!-- 标准装置台账信息详情 配置核查项 第5套:二等铂电阻温度计标准装置 -->
<script name="StandardBookEquipmentConfig" lang="ts" setup>
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { IList } from './fifth-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'
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
}
}
// -------------------------------------------核查项-----------------------------------------------
const listTemperature = ref<IList[]>([]) // 温度值
const listRTP = ref<IList[]>([]) // RTP值
const listInsulationResistance = ref<IList[]>([]) // 绝缘电阻表校准
const listThermodetector = ref<IList[]>([]) // 测温仪电阻核查
const checkoutTemperatureList = ref<IList[]>([]) // 温度值选中数据
const checkoutRTPList = ref<IList[]>([]) // RTP值选中数据
const checkoutInsulationResistanceList = ref<IList[]>([]) // 绝缘电阻表校准选中数据
const checkoutThermodetectorList = ref<IList[]>([]) // 测温仪电阻核查选中数据
const temperature = ref(true) // 是否显示温度值
const RTP = ref(true) // 是否显示RTP值
const insulationResistance = ref(true) // 是否显示绝缘电阻表校准
const thermodetector = ref(true) // 测温仪电阻核查
const columns_temperature = ref<TableColumn[]>([ // 温度值表头
{ text: '核查项目', value: 'params', align: 'center', required: true },
{ text: '温度点', value: 'checkPoint', align: 'center', required: true },
{ text: '单位', value: 'unit', align: 'center', required: true },
{ text: '循环次数', value: 'cycleNumber', align: 'center', required: true },
{ text: '扩展不确定度U', value: 'urel', align: 'center', required: true },
{ text: '核查类型', value: 'checkType', align: 'center', required: true },
])
const columns_RTP = ref<TableColumn[]>([ // RTP值表头
{ text: '核查项目', value: 'params', align: 'center', required: true },
{ text: '水三相点', value: 'checkPoint', align: 'center', required: true },
{ text: '单位', value: 'unit', align: 'center', required: true },
{ text: '循环次数', value: 'cycleNumber', align: 'center', required: true },
{ text: '允许值', value: 'allowValue', align: 'center', required: true },
{ text: '核查类型', value: 'checkType', align: 'center', required: true },
])
const columns_insulation_resistance = ref<TableColumn[]>([ // 绝缘电阻表校准表头
{ text: '核查项目', value: 'params', align: 'center', required: true },
{ text: '确认点', value: 'checkPoint', align: 'center', required: true },
{ text: '单位', value: 'unit', align: 'center', required: true },
{ text: '最大允许误差', value: 'maximumError', align: 'center', required: true },
])
const columns_thermodetector = ref<TableColumn[]>([ // 测温仪电阻核查
{ text: '核查项目', value: 'params', align: 'center', required: true },
{ text: '核查点', value: 'checkPoint', align: 'center', required: true },
{ text: '单位', value: 'unit', align: 'center', required: true },
{ text: '最大允许误差绝对值|MPE|', value: 'maximumError', align: 'center', required: true },
])
// 温度值多选
const handleSelectionTemperatureChange = (e: any) => {
checkoutTemperatureList.value = e
}
// RTP值多选
const handleSelectionRTPChange = (e: any) => {
checkoutRTPList.value = e
}
// 绝缘电阻表校准多选
const handleSelectionInsulationResistanceChange = (e: any) => {
checkoutInsulationResistanceList.value = e
}
const handleSelectionThermodetectorChange = (e: any) => {
checkoutThermodetectorList.value = e
}
// 校验表格(点击保存的时候、增加行用)
const checkList = (list: any, title: string) => {
let columns = []
columns = title === '温度值' ? columns_temperature.value : title === 'RTP值' ? columns_RTP.value : columns_insulation_resistance.value
return useCheckList(list, columns, title)
}
/**
* 增加行公共方法
* @param list 要操作的数组
* @param title 操作的表格
*/
const addRow = (list: IList[], title: string) => {
if (!checkArrayDataUnique()) { return false }
if (checkList(list, `${title}`)) {
if (list.length) { // 增加行时默认上一行数据
list.push({
id: '',
params: title, // 核查项目
// checkPoint: list[list.length - 1].checkPoint, // 核查点(直接存字典value)
checkPoint: title === '测温仪电阻核查' ? list[list.length - 1].checkPoint : '', // 核查点(直接存字典value)
unit: list[list.length - 1].unit, // 单位(直接存字典value)
cycleNumber: list[list.length - 1].cycleNumber, // 循环次数
urel: list[list.length - 1].urel, // 测量标准相对扩展不确定度urel
checkType: list[list.length - 1].checkType, // 核查类型
equipmentId: list[list.length - 1].equipmentId, // 配套设备id
itemCategoryId: list[list.length - 1].itemCategoryId, // 核查项分类id(能够确定是哪个标准装置)
remark: list[list.length - 1].remark, // 核查项备注(每个数据存储的核查项备注相同,前端取列表中一个即可)
maximumError: list[list.length - 1].maximumError, // 最大允许误差
allowValue: list[list.length - 1].allowValue, // 允许值
})
}
else {
list.push({
id: '',
params: title, // 核查项目
checkPoint: '', // 核查点(直接存字典value)
unit: (title === '绝缘电阻表校准' || title === '测温仪电阻核查') ? 'MΩ' : '℃', // 单位(直接存字典value)
cycleNumber: 6, // 循环次数
urel: '', // 测量标准相对扩展不确定度urel
checkType: ['重复性', '稳定性'], // 核查类型
equipmentId: infoId.value, // 配套设备id
itemCategoryId: form.value.itemCategoryId, // 核查项分类id(能够确定是哪个标准装置)
remark: '', // 核查项备注(每个数据存储的核查项备注相同,前端取列表中一个即可)
maximumError: '', // 最大允许误差
allowValue: '', // 允许值
})
}
}
}
/**
* 删除行公共方法
* @param checkoutList 选中的数组
* @param list 操作的数组
* @param type 表格类型
*/
const delRow = (checkoutList: IList[], list: IList[], type: string) => {
if (!checkoutList.length) {
ElMessage.warning('请选中要删除的行')
}
else {
const resultList = list.filter((item: any) => {
return !checkoutList.includes(item)
})
if (type === '温度值') {
listTemperature.value = resultList
}
else if (type === 'RTP值') {
listRTP.value = resultList
}
else if (type === '绝缘电阻表校准') {
listInsulationResistance.value = resultList
}
else if (type === '测温仪电阻核查') {
listThermodetector.value = resultList
}
}
}
// ---------------------------------------按钮-----------------------------------------------------
// 点击关闭
const close = () => {
$router.back()
}
// 清空配置
const clear = () => {
ElMessageBox.confirm(
'确认清空配置项吗?',
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
)
.then(() => {
listTemperature.value = []// 温度值
listRTP.value = []// RTP值
listInsulationResistance.value = [] // 绝缘电阻表校准
form.value.remark = ''
})
}
// 点击保存
const save = () => {
if (temperature.value && !listTemperature.value.length) { ElMessage.warning('温度值不能为空'); return false }
if (RTP.value && !listRTP.value.length) { ElMessage.warning('RTP值不能为空'); return false }
if (insulationResistance.value && !listInsulationResistance.value.length) { ElMessage.warning('绝缘电阻表校准不能为空'); return false }
if (thermodetector.value && !listThermodetector.value.length) { ElMessage.warning('测温仪电阻核查不能为空'); return false }
if (!checkList(listTemperature.value, '温度值')) { return false }
if (!checkList(listRTP.value, 'RTP值')) { return false }
if (!checkList(listInsulationResistance.value, '绝缘电阻表校准')) { return false }
if (!checkList(listThermodetector.value, '测温仪电阻核查')) { return false }
if (!checkArrayDataUnique()) { return false }
let listParam = [] as any
if (temperature.value) {
listParam = listParam.concat(listTemperature.value)
}
if (RTP.value) {
listParam = listParam.concat(listRTP.value)
}
if (insulationResistance.value) {
listParam = listParam.concat(listInsulationResistance.value)
}
if (thermodetector.value) {
listParam = listParam.concat(listThermodetector.value)
}
if (!listParam.length) {
ElMessage.warning('请至少配置一个核查项')
return false
}
listParam = listParam.map((item: any) => {
return {
...item,
checkType: item.checkType.join(','), // 核查类型
remark: form.value.remark,
}
})
const params = {
itemCategoryId: form.value.itemCategoryId, // 核查项分类id
checkItemDataResistanceThermometerList: listParam,
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()
}).catch(() => { 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.checkItemDataResistanceThermometerList && res.data.checkItemDataResistanceThermometerList.length) {
const resList = res.data.checkItemDataResistanceThermometerList.map((item: { checkType: string }) => { return { ...item, checkType: item.checkType ? item.checkType.split(',') : [] } })
listTemperature.value = resList.filter((item: { params: string }) => item.params === '温度值')
listRTP.value = resList.filter((item: { params: string }) => item.params === 'RTP值')
listInsulationResistance.value = resList.filter((item: { params: string }) => item.params === '绝缘电阻表校准')
listThermodetector.value = resList.filter((item: { params: string }) => item.params === '测温仪电阻核查')
// 核查项备注
form.value.remark = listTemperature.value.length
? listTemperature.value[0].remark!
: listRTP.value.length
? listRTP.value[0].remark!
: listInsulationResistance.value.length
? listInsulationResistance.value[0].remark!
: listThermodetector.value.length ? listThermodetector.value[0].remark! : ''
temperature.value = listTemperature.value.length > 0 // 是否显示温度值
RTP.value = listRTP.value.length > 0 // 是否显示RTP值
insulationResistance.value = listInsulationResistance.value.length > 0 // 是否显示绝缘电阻表校准
thermodetector.value = listThermodetector.value.length > 0 // 测温仪电阻核查
}
loading.close()
})
}
// 校验4个表格中不能同时出现核查项目和核查点、单位两个属性同时相同的两条数据
function checkArrayDataUnique() {
const tempListTemperature = listTemperature.value.map((item: any, index: number) => { item.tempTitle = '温度值'; item.tempIndex = index; return item })
const tempListRTP = listRTP.value.map((item: any, index: number) => { item.tempTitle = 'RTP值'; item.tempIndex = index; return item })
const tempListInsulationResistance = listInsulationResistance.value.map((item: any, index: number) => { item.tempTitle = '绝缘电阻表校准'; item.tempIndex = index; return item })
const tempListThermodetector = listThermodetector.value.map((item: any, index: number) => { item.tempTitle = '测温仪电阻核查'; item.tempIndex = index; return item })
const list = tempListTemperature.concat(tempListRTP, tempListInsulationResistance, tempListThermodetector)
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 && (list[i].checkPoint + list[i].unit) === (list[j].checkPoint + list[j].unit)) {
if (list[i].tempTitle === list[j].tempTitle) {
ElMessage.warning(`${list[i].tempTitle} 第${list[i].tempIndex + 1}行第${list[j].tempIndex + 1}行的 核查项目和核查点和单位不能同时完全一样`)
}
else {
ElMessage.warning(`${list[i].tempTitle} 第${list[i].tempIndex + 1}行和${list[j].tempTitle}第${list[j].tempIndex + 1}行的 核查项目和核查点和单位不能同时完全一样`)
}
return false
}
}
}
return true
}
// ------------------------------------------钩子--------------------------------------------------
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="temperature" :disabled="pageType === 'detail'">
温度值
</el-checkbox>
<div v-if="temperature && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
<el-button type="primary" @click="addRow(listTemperature, '温度值')">
增加行
</el-button>
<el-button type="info" @click="delRow(checkoutTemperatureList, listTemperature, '温度值')">
删除行
</el-button>
</div>
</div>
<template-table v-if="temperature" table-type="温度值" :data="listTemperature" :columns="columns_temperature" :page-type="pageType" @selection-change="handleSelectionTemperatureChange" />
</detail-block>
<!-- RTP值 -->
<detail-block title="" style="padding-bottom: 20px;">
<div style="display: flex;justify-content: space-between;">
<el-checkbox v-model="RTP" :disabled="pageType === 'detail'">
RTP值
</el-checkbox>
<div v-if="RTP && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
<el-button type="primary" @click="addRow(listRTP, 'RTP值')">
增加行
</el-button>
<el-button type="info" @click="delRow(checkoutRTPList, listRTP, 'RTP值')">
删除行
</el-button>
</div>
</div>
<template-table v-if="RTP" table-type="RTP值" :data="listRTP" :columns="columns_RTP" :page-type="pageType" @selection-change="handleSelectionRTPChange" />
</detail-block>
<!-- 绝缘电阻表校准 -->
<detail-block title="" style="padding-bottom: 20px;">
<div style="display: flex;justify-content: space-between;">
<el-checkbox v-model="insulationResistance" :disabled="pageType === 'detail'">
绝缘电阻表校准
</el-checkbox>
<div v-if="insulationResistance && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
<el-button type="primary" @click="addRow(listInsulationResistance, '绝缘电阻表校准')">
增加行
</el-button>
<el-button type="info" @click="delRow(checkoutInsulationResistanceList, listInsulationResistance, '绝缘电阻表校准')">
删除行
</el-button>
</div>
</div>
<template-table v-if="insulationResistance" table-type="绝缘电阻表校准" :data="listInsulationResistance" :columns="columns_insulation_resistance" :page-type="pageType" @selection-change="handleSelectionInsulationResistanceChange" />
</detail-block>
<!-- 测温仪电阻核查 -->
<detail-block title="" style="padding-bottom: 20px;">
<div style="display: flex;justify-content: space-between;">
<el-checkbox v-model="thermodetector" :disabled="pageType === 'detail'">
测温仪电阻核查
</el-checkbox>
<div v-if="thermodetector && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
<el-button type="primary" @click="addRow(listThermodetector, '测温仪电阻核查')">
增加行
</el-button>
<el-button type="info" @click="delRow(checkoutThermodetectorList, listThermodetector, '测温仪电阻核查')">
删除行
</el-button>
</div>
</div>
<template-table v-if="thermodetector" table-type="测温仪电阻核查" :data="listThermodetector" :columns="columns_thermodetector" :page-type="pageType" @selection-change="handleSelectionThermodetectorChange" />
</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>