<!-- 第一套标准装置多功能校准源 -->
<!-- 第二种表格--生成检定项模式 -->
<!-- 交流电压表、交流电流表、直流电压表、直流电流表、75mV电流表 使用 -->
<script lang="ts" setup name="TemplateDetailCreatePattern">
import { ElMessage } from 'element-plus'
import type { IFormCreatePattern, ITemplateDetailCreatePattern } from './first-interface'
import { calc } from '@/utils/useCalc'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { mergeTableRow, useMergeTableRow } from '@/commonMethods/useMergeTableRow'
const props = defineProps({
pageType: {
type: String,
default: 'add',
},
itemCategoryName: {
type: String,
require: true,
}, // 设备检定项分类名称
list: {
type: Array as any,
},
form: { // 检定项表单
type: Object as any,
},
})
const list = ref<ITemplateDetailCreatePattern[]>([]) // 表格数据
const checkoutList = ref<ITemplateDetailCreatePattern[]>([]) // 选中数据
const columns = ref([
{ text: '参数', value: 'params', align: 'center', required: true },
{ text: '量', value: 'capacity', align: 'center', width: '120', required: true },
{ text: '单位', value: 'unit', align: 'center', width: '120', required: true },
{ text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true },
{ text: '标准值', value: 'standardValue', align: 'center', required: true },
{ text: '分辨力', value: 'resolution', align: 'center', required: true, reg: (resolution: string | number) => { return Number(resolution) <= 1 } },
{ text: '准确度等级', value: 'accuracyLevel', align: 'center', required: true },
{ text: '最大允许误差', value: 'maximumError', align: 'center', required: true },
{ text: '频率', value: 'frequency', align: 'center' },
{ text: '频率单位', value: 'frequencyUnit', align: 'center' },
])
const ruleFormRef = ref() // 表单ref
const form = ref<IFormCreatePattern>({
fullScaleValue: 0, // 表满量程值
fullScaleValueUnit: '', // 表满量程值单位
standardValueUpper: 0, // 标准值上限
standardValueUpperUnit: '', // 标准值上限单位
points: 0, // 检定点个数
frequency: 0, // 频率
frequencyUnit: '', // 频率单位
accuracyLevel: 0, // 准确度等级
resolution: 0.0001, // 分辨力
itemId: '', // 检定项id
id: '',
})
// 校验规则
const rules = ref({
fullScaleValue: [{ required: true, message: '表满量程值不能为空', trigger: ['blur', 'change'] }],
fullScaleValueUnit: [{ required: true, message: '表满量程值单位不能为空', trigger: ['blur', 'change'] }],
standardValueUpper: [{ required: true, message: '标准值上限不能为空', trigger: ['blur', 'change'] }],
standardValueUpperUnit: [{ required: true, message: '标准值上限单位不能为空', trigger: ['blur', 'change'] }],
points: [{ required: true, message: '检定点个数不能为空', trigger: ['blur', 'change'] }],
frequency: [{ required: true, message: '频率不能为空', trigger: ['blur', 'change'] }],
frequencyUnit: [{ required: true, message: '频率单位不能为空', trigger: ['blur', 'change'] }],
accuracyLevel: [{ required: true, message: '准确度等级不能为空', trigger: ['blur', 'change'] }],
resolution: [{ required: true, message: '分辨力不能为空', trigger: ['blur', 'change'] }],
})
// ------------------------------------------字典----------------------------------------------
const frequencyUnitList = ref<dictType[]>([]) // 频率
const fullScaleValueUnitList = ref<dictType[]>([]) // 指针式仪表满量程值单位
const unitIList = ref<dictType[]>([]) // 指针式仪表满量程值I单位
/**
* 获取字典
*/
function getDict() {
// 频率单位
getDictByCode('bizFirstStandardFrequencyUnit').then((response) => {
frequencyUnitList.value = response.data
})
// 表满量程值单位
getDictByCode('bizFirstStandardFullScaleValueCreate').then((response) => {
fullScaleValueUnitList.value = response.data
})
// I单位
getDictByCode('bizFirstStandardFullScaleValueCreateI').then((response) => {
unitIList.value = response.data
})
}
getDict()
// ------------------------------------------------------------------------------------------------
const paramsMap: { [key: string]: string | undefined } = { // 参数
'交流电压表': 'ACV',
'交流电流表': 'ACI',
'直流电压表': 'DCV',
'直流电流表': 'DCI',
'75mV电流表': 'DCV',
}
const capacityMap: { [key: string]: string | undefined } = { // 量
'交流电压表': 'U',
'交流电流表': 'I',
'直流电压表': 'U',
'直流电流表': 'I',
'75mV电流表': 'U',
}
// const measureIndicationValueMap: { [key: string]: string | undefined } = { // 被检表示值
// '交流电压表': 'V',
// '交流电流表': 'A',
// '直流电压表': 'V',
// '直流电流表': 'A',
// '75mV电流表': 'V',
// }
// 点击生成检定点
const createCheckPoint = () => {
ruleFormRef.value!.validate((valid: boolean) => {
if (valid) {
list.value = []
const tempMaximumError = calc(calc(Number(form.value.accuracyLevel), Number(form.value.standardValueUpper), '*'), 100, '/')
for (let i = 0; i < form.value.points; i++) {
list.value.push({
id: '', // 主键
params: paramsMap[props.itemCategoryName! as string]!, // 参数
capacity: capacityMap[props.itemCategoryName! as string]!, // 量
unit: form.value.standardValueUpperUnit, // 单位
measureIndicationValue: calc(Number(calc(form.value.fullScaleValue as number, form.value.points, '/')), (i + 1), '*') + form.value.fullScaleValueUnit, // 被检表示值
standardValue: `${calc(Number(calc(form.value.standardValueUpper, form.value.points, '/')), (i + 1), '*')}`, // 标准值
frequency: form.value.frequency, // 频率
frequencyUnit: form.value.frequencyUnit, // 频率单位
resolution: form.value.resolution, // 分辨力
accuracyLevel: Number(form.value.accuracyLevel), // 准确度等级
maximumError: `±${tempMaximumError}${form.value.standardValueUpperUnit}`, // 最大允许误差
})
}
}
})
}
// 多选
const handleSelectionChange = (e: any) => {
checkoutList.value = e
}
// -----------------------------------分辨力多0少0--------------------------------------------
// 点击减号
const clickSub = () => {
if (Number(calc(form.value.resolution, 10, '*')) > 1) {
ElMessage.warning('要求分辨力不能大于1')
}
else {
form.value.resolution = Number(calc(form.value.resolution, 10, '*'))
}
}
// 点击加号
const clickAdd = () => {
form.value.resolution = Number(calc(form.value.resolution, 10, '/'))
}
// ----------------------------------------检验表单--------------------------------------------
const checkForm = () => {
ruleFormRef.value.clearValidate()
if (`${form.value.fullScaleValue}` === '' || `${form.value.fullScaleValue}` === 'null') {
ElMessage.warning('表满量程值不能为空')
return false
}
if (`${form.value.fullScaleValueUnit}` === '' || `${form.value.fullScaleValueUnit}` === 'null') {
ElMessage.warning('表满量程值单位不能为空')
return false
}
if (`${form.value.standardValueUpper}` === '' || `${form.value.standardValueUpper}` === 'null') {
ElMessage.warning('标准值上限不能为空')
return false
}
if (`${form.value.standardValueUpperUnit}` === '' || `${form.value.standardValueUpperUnit}` === 'null') {
ElMessage.warning('标准值上限单位不能为空')
return false
}
if (`${form.value.points}` === '' || `${form.value.points}` === 'null') {
ElMessage.warning('检定点个数不能为空')
return false
}
if (props.itemCategoryName === '交流电压表' || props.itemCategoryName === '交流电流表') {
if (`${form.value.frequency}` === '' || `${form.value.frequency}` === 'null') {
ElMessage.warning('频率不能为空')
return false
}
if (`${form.value.frequencyUnit}` === '' || `${form.value.frequencyUnit}` === 'null') {
ElMessage.warning('频率单位不能为空')
return false
}
}
if (`${form.value.accuracyLevel}` === '' || `${form.value.accuracyLevel}` === 'null') {
ElMessage.warning('准确度等级不能为空')
return false
}
if (`${form.value.resolution}` === '' || `${form.value.resolution}` === 'null') {
ElMessage.warning('分辨力不能为空')
return false
}
return true
}
// --------------------------------------------------------------------------------------------
// 监听表满量程值,修改标准值上限
watch(() => form.value.fullScaleValue, (newValue) => {
if (props.itemCategoryName !== '75mV电流表') {
form.value.standardValueUpper = newValue
if (!form.value.standardValueUpper) {
form.value.fullScaleValueUnit = form.value.standardValueUpperUnit
}
}
})
watch(() => props.list, (newVal) => {
if (newVal) {
list.value = [...newVal]
list.value = list.value.map((item: ITemplateDetailCreatePattern) => {
return {
...item,
resolution: Number(item.resolution), // 分辨力去掉末尾的0
}
})
if (props.pageType === 'detail') {
useMergeTableRow(list.value, ['params', 'capacity', 'unit'])
}
}
}, { immediate: true, deep: true })
watch(() => props.form, (newVal) => { // 检定项表单
if (newVal) {
form.value.fullScaleValue = newVal.fullScaleValue // 表满量程值
form.value.fullScaleValueUnit = newVal.fullScaleValueUnit // 表满量程值单位
form.value.standardValueUpper = newVal.standardValueUpper// 标准值上限
form.value.standardValueUpperUnit = newVal.standardValueUpperUnit // 标准值上限单位
form.value.points = newVal.points// 检定点个数
form.value.frequency = newVal.frequency // 频率
form.value.frequencyUnit = newVal.frequencyUnit // 频率单位
form.value.accuracyLevel = newVal.accuracyLevel // 准确度等级
if (newVal.fromTemplate !== 'true') {
form.value.id = newVal.id
form.value.itemId = newVal.itemId
}
form.value.resolution = `${newVal.resolution}` !== 'undefined' ? Number(newVal.resolution) : 0.0001 // 分辨力去掉末尾的0
if (props.itemCategoryName === '75mV电流表') { // 75mV电流表 标准值上限固定
form.value.standardValueUpper = 75
form.value.standardValueUpperUnit = 'mV'
}
}
}, { deep: true, immediate: true })
onMounted(() => {
// if (!form.value.standardValueUpper && !form.value.standardValueUpperUnit && props.itemCategoryName === '75mV电流表') {
// form.value.standardValueUpper = 75
// form.value.standardValueUpperUnit = 'mV'
// }
if (props.itemCategoryName === '75mV电流表') {
form.value.standardValueUpper = 75
form.value.standardValueUpperUnit = 'mV'
}
})
defineExpose({ list, form, checkForm })
</script>
<template>
<el-form
ref="ruleFormRef"
:model="form"
label-width="120"
label-position="right"
:rules="rules"
>
<el-row :gutter="24">
<el-col :span="8" style="display: flex;justify-content: flex-start;">
<el-form-item label="表满量程值:" prop="fullScaleValue">
<precision-input-number
v-model="form.fullScaleValue"
:placeholder="pageType === 'detail' ? '' : '请输入表满量程值'"
:disabled="pageType === 'detail'"
style="flex: 1;"
/>
</el-form-item>
<el-form-item label-width="10" prop="fullScaleValueUnit">
<!-- 电压单位 -->
<el-select
v-if="props.itemCategoryName === '交流电压表' || props.itemCategoryName === '直流电压表'"
v-model="form.fullScaleValueUnit"
placeholder="单位"
:disabled="props.pageType === 'detail'"
filterable
style="width: 100px;"
>
<el-option v-for="item in fullScaleValueUnitList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
<!-- 电流单位 -->
<el-select
v-else
v-model="form.fullScaleValueUnit"
placeholder="单位"
:disabled="props.pageType === 'detail'"
filterable
style="width: 100px;"
>
<el-option v-for="item in unitIList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="8" style="display: flex;justify-content: flex-start;">
<el-form-item label="标准值上限:" prop="standardValueUpper">
<precision-input-number
v-model="form.standardValueUpper"
:placeholder="pageType === 'detail' ? '' : '请输入标准值上限'"
:disabled="pageType === 'detail' || props.itemCategoryName === '75mV电流表'"
/>
</el-form-item>
<el-form-item label-width="10" prop="standardValueUpperUnit">
<!-- 电压单位 -->
<el-select
v-if="props.itemCategoryName === '交流电压表' || props.itemCategoryName === '直流电压表'"
v-model="form.standardValueUpperUnit"
placeholder="单位"
:disabled="props.pageType === 'detail'"
filterable
style="width: 100px;"
>
<el-option v-for="item in fullScaleValueUnitList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
<!-- 75mv电流表电压单位 -->
<el-select
v-if="props.itemCategoryName === '75mV电流表'"
v-model="form.standardValueUpperUnit"
placeholder="单位"
disabled
filterable
style="width: 100px;"
>
<el-option v-for="item in ['mV']" :key="item" :label="item" :value="item" />
</el-select>
<!-- 电流单位 -->
<el-select
v-if="props.itemCategoryName === '交流电流表' || props.itemCategoryName === '直流电流表'"
v-model="form.standardValueUpperUnit"
placeholder="单位"
:disabled="props.pageType === 'detail'"
filterable
style="width: 100px;"
>
<el-option v-for="item in unitIList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="8" style="display: flex;justify-content: flex-start;">
<el-form-item label="检定点个数:" prop="points">
<precision-input-number
v-model="form.points"
:placeholder="pageType === 'detail' ? '' : '请输入检定点个数'"
:disabled="pageType === 'detail'"
:step="1"
:min="1"
:precision="0"
/>
</el-form-item>
</el-col>
<el-col v-if="props.itemCategoryName === '交流电压表' || props.itemCategoryName === '交流电流表'" :span="8" style="display: flex;justify-content: flex-start;">
<el-form-item label="频率:" prop="frequency">
<precision-input-number
v-model="form.frequency"
:placeholder="pageType === 'detail' ? '' : '请输入频率'"
:disabled="pageType === 'detail'"
/>
</el-form-item>
<el-form-item label-width="10" prop="frequencyUnit">
<!-- 单位 -->
<el-select
v-model="form.frequencyUnit"
placeholder="单位"
:disabled="props.pageType === 'detail'"
filterable
style="width: 100px;"
>
<el-option v-for="item in frequencyUnitList" :key="item.id" :label="item.name" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="准确度等级:" prop="accuracyLevel">
<precision-input-number
v-model="form.accuracyLevel"
:placeholder="pageType === 'detail' ? '' : '请输入准确度等级'"
:disabled="pageType === 'detail'"
/>
<!-- <el-input v-model="form.accuracyLevel" :placeholder="pageType === 'detail' ? '' : '请输入准确度等级'" class="input" /> -->
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label="分辨力:" prop="resolution">
<!-- <el-input-number
v-model="form.resolution"
:placeholder="pageType === 'detail' ? '' : '请输入分辨力'"
:disabled="pageType === 'detail'"
:min="0"
/> -->
<!-- 分辨力 -->
<div style="display: flex;">
<icon-button v-if="pageType !== 'detail'" style="margin-right: 10px;" size="20" icon="icon-reduce-circle" title="扩大10倍" type="primary" @click="clickSub" />
<el-input
v-model="form.resolution"
:placeholder="pageType === 'detail' ? '' : '请输入分辨力'"
:disabled="pageType === 'detail'"
class="input"
/>
<icon-button v-if="pageType !== 'detail'" style="margin-left: 10px;" size="20" icon="icon-add-circle" title="缩小10倍" type="primary" @click="clickAdd" />
</div>
</el-form-item>
</el-col>
</el-row>
</el-form>
<detail-block :title="props.pageType === 'detail' ? '' : ' '">
<template v-if="props.pageType !== 'detail'" #btns>
<el-button type="primary" @click="createCheckPoint">
生成检定点
</el-button>
</template>
<el-table
ref="tableRef"
:data="list"
border
style="width: 100%;"
:span-method="mergeTableRow"
@selection-change="handleSelectionChange"
>
<el-table-column align="center" label="序号" width="80" type="index" />
<el-table-column
v-for="item in columns"
:key="item.value"
:prop="item.value"
:label="item.text"
:width="item.width"
align="center"
>
<template #header>
<span v-show="item.required" style="color: red;">*</span><span>{{ item.text }}</span>
</template>
<template #default="scope">
<el-input
v-if="props.pageType !== 'detail' && (item.value === 'measureIndicationValue' || item.value === 'standardValue' || item.value === 'errorParamA' || item.value === 'errorParamB' || item.value === 'standardValue')" v-model="scope.row[item.value]" :autofocus="true" :placeholder="`${item.text}`" class="input"
/>
<!-- 频率 -->
<el-input v-if="props.pageType !== 'detail' && item.value === 'frequency' && (scope.row.params === 'ACV' || scope.row.params === 'ACI')" v-model="scope.row[item.value]" style="display: flex;" :autofocus="true" :placeholder="`${item.text}`" class="input" />
<span
v-if="(item.value === 'frequency' && (scope.row.params !== 'ACV' && scope.row.params !== 'ACI'))
|| (item.value === 'frequencyUnit' && (scope.row.params !== 'ACV' && scope.row.params !== 'ACI'))
"
>/</span>
</template>
</el-table-column>
</el-table>
</detail-block>
</template>