<!-- 第16套:低频信号源标准装置 -->
<!-- 检定数据管理详情模板 -->
<script lang="ts" setup name="MeasureDataTemplateDetail">
import { ref } from 'vue'
import { ElLoading, ElMessage } from 'element-plus'
import dayjs from 'dayjs'
import changeRecord from '../changeRecord.vue'
import selectStandard from '../../dialog/selectStandardDialog.vue'
import TemplateFormAndTable from '../templateFormAndTable.vue'
import { useSolveFormData } from '../useSolveFormData'
import type { IDetailMeasureList } from './sixteen-interface'
import templateTable from './templateTable.vue'
import useUserStore from '@/store/modules/user'
import type { dictType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { calculateHandle, getInfo } from '@/api/business/taskMeasure/measureData'
import { getInfo as getItemInfo } from '@/api/business/measure/item'
import { useCheckList } from '@/commonMethods/useCheckList'
import { calc } from '@/utils/useCalc'
import templateTable1 from '@/views/business/measure/item/components/second/templateTable.vue'
import { clearSymbol } from '@/utils/String'
const props = defineProps({
infoId: String, // id
dataNo: String, // 检定数据编号
})
const emits = defineEmits(['giveInfoId'])
const user = useUserStore() // 用户信息
const $router = useRouter() // 关闭页面使用
const $route = useRoute() // 路由参数
const ruleFormRef = ref() // 表单ref
const templateFormAndTableRef = ref() // 表单和被检设备、测量设备表格公共组件ref
const itemFormData = ref({ // 有关于检定项的数据
itemId: '', // 检定项id
itemCategoryName: '', // 设备检定项分类名称
itemCategoryId: '', // 设备检定项分类名称id
belongStandardEquipment: '', // 标准装置code
belongStandardEquipmentName: '', // 标准装置名称
appearanceRemark: '正常',
appearanceFunctionCheck: 1 as any, // 外观(1/0)
})
// -------------------------------------------路由参数------------------------------------------
const pageType = ref('add') // 页面类型: add, edit, detail
const infoId = ref('') // 列表id
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 radioMenus = ref([ // 标签内容
{ name: '检定数据', value: 'measure-data' },
{ name: '历史修改记录', value: 'change-record' },
])
const current = ref('measure-data') // 选择的tab 默认基本信息
// ---------------------------------------检定项数据表格----------------------------------------------------
const frequencyList = ref<IDetailMeasureList[]>([]) // 频率
const acVoltageList = ref<IDetailMeasureList[]>([]) // 交流电压
const dcVoltageList = ref<IDetailMeasureList[]>([]) // 直流电压
const riseTimeList = ref<IDetailMeasureList[]>([]) // 上升时间
const sinusoidFlatnessList = ref<IDetailMeasureList[]>([]) // 正弦信号平坦度
const harmonicDistortionList = ref<IDetailMeasureList[]>([]) // 总谐波失真
const listDict = ref<{ [key: string]: IDetailMeasureList[] }>({})
const setListDict = () => {
listDict.value = {
'1-频率': frequencyList.value,
'2-交流电压': acVoltageList.value,
'3-直流电压': dcVoltageList.value,
'4-上升时间': riseTimeList.value,
'5-正弦信号平坦度': sinusoidFlatnessList.value,
'6-总谐波失真': harmonicDistortionList.value,
}
}
const columns_frequency = ref<TableColumn[]>([ // 频率
{ text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
{ text: '标称值', value: 'nominalValue', align: 'center', required: false, type: 'text' },
{ text: '指标下限', value: 'lowerIndex', align: 'center', required: false, type: 'text' },
{ text: '测量值', value: 'measureValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
{ text: '指标上限', value: 'upperIndex', align: 'center', required: false, type: 'text' },
{ text: '结论', value: 'conclusion', align: 'center', required: false, type: 'text' },
])
const columns_ac_voltage = ref<TableColumn[]>([ // 交流电压
{ text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
{ text: '标称值', value: 'nominalValue', align: 'center', required: false, type: 'text' },
{ text: '交流频率', value: 'acFrequency', align: 'center', required: false, type: 'text' },
{ text: '指标下限', value: 'lowerIndex', align: 'center', required: false, type: 'text' },
{ text: '测量值', value: 'measureValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
{ text: '指标上限', value: 'upperIndex', align: 'center', required: false, type: 'text' },
{ text: '结论', value: 'conclusion', align: 'center', required: false, type: 'text' },
])
const columns_dc_voltage = ref(columns_frequency.value)
const columns_rise_time = ref<TableColumn[]>([ // 上升时间
{ text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
{ text: '频率', value: 'frequency', align: 'center', required: false, type: 'text' },
{ text: '幅度', value: 'amplitude', align: 'center', required: false, type: 'text' },
{ text: '上升时间', value: 'riseTime', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
{ text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'text' },
{ text: '结论', value: 'conclusion', align: 'center', required: false, type: 'text' },
])
const columns_sinusoid_flatness = ref<TableColumn[]>([ // 正弦信号平坦度
{ text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
{ text: '电压', value: 'voltage', align: 'center', required: false, type: 'text' },
{ text: '频率点', value: 'frequency', align: 'center', required: false, type: 'text' },
{ text: '测量值', value: 'measureValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
{ text: '平坦度', value: 'flatness', align: 'center', required: false, type: 'text' },
{ text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'text' },
{ text: '结论', value: 'conclusion', align: 'center', required: false, type: 'text' },
])
const columns_harmonic_distortion = ref<TableColumn[]>([ // 总谐波失真
{ text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
{ text: '频率', value: 'frequency', align: 'center', required: false, type: 'text' },
{ text: '测量值', value: 'measureValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
{ text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'text' },
{ text: '结论', value: 'conclusion', align: 'center', required: false, type: 'text' },
])
const columnsDict = ref<{ [key: string]: any[] | TableColumn[] }>({
'1-频率': columns_frequency.value,
'2-交流电压': columns_ac_voltage.value,
'3-直流电压': columns_dc_voltage.value,
'4-上升时间': columns_rise_time.value,
'5-正弦信号平坦度': columns_sinusoid_flatness.value,
'6-总谐波失真': columns_harmonic_distortion.value,
})
watch(() => pageType.value, (newValue) => {
if (newValue) {
if (newValue === 'detail') {
for (const i in columnsDict.value) {
columnsDict.value[i].forEach((item: TableColumn | any) => {
item.type = 'text'
})
}
}
}
})
// -------------------------------------------获取详情信息--------------------------------------------------
// 获取页面详情信息
const fetchInfo = () => {
const loading = ElLoading.service({
lock: true,
background: 'rgba(255, 255, 255, 0.8)',
})
getInfo({
id: infoId.value,
belongStandardEquipment: itemFormData.value.belongStandardEquipment,
// 我的任务跳转过来如果已经配置过检定项了,到编辑页面,且用一下三个字段替代传id请求详情
itemId: $route.query.itemId, // 检定项id
orderId: $route.query.orderId, // 任务单id
sampleId: $route.query.sampleId, // 被检设备id
}).then((res) => {
// 有关于检定项的数据
itemFormData.value.itemId = res.data.itemId // 检定项id
itemFormData.value.itemCategoryName = res.data.itemCategoryName // 设备检定项分类名称
itemFormData.value.itemCategoryId = res.data.itemCategoryId ? res.data.itemCategoryId : itemFormData.value.itemCategoryId // 设备检定项分类名称id
itemFormData.value.appearanceFunctionCheck = Number(res.data.appearanceFunctionCheck)// 外观及功能检查
itemFormData.value.appearanceRemark = res.data.appearanceRemark // 外观及功能检查
console.log(res, 'res')
initInputData(res.data.measureDataLowFrequencySignalList)
// =======================================表单公共组件数据处理=======================================================
useSolveFormData(res, templateFormAndTableRef.value)
// ==================================检定数据========================================================================
infoId.value = res.data.id
emits('giveInfoId', infoId.value)
loading.close()
// 处理有效位数
const params = {
id: $route.query.itemId! as string,
itemCategoryName: $route.query.itemCategoryName! as string, // 检定项分类名字
belongStandardEquipment: $route.query.belongStandardEquipment as string, // 检校标准装置字典code
}
getItemInfo(params).then((res) => {
const data = res.data.measureItemDataLowFrequencySignalList.filter((item: { dataType: string }) => item.dataType === '1')
frequencyList.value.forEach((item: any, index: number) => {
frequencyList.value[index].validDigit = data[index].validDigit
})
})
})
}
// 初始化数据
function initAllData() {
for (const i in listDict.value) {
listDict.value[i] = []
}
frequencyList.value = []
acVoltageList.value = []
dcVoltageList.value = []
riseTimeList.value = []
sinusoidFlatnessList.value = []
harmonicDistortionList.value = []
}
// 初始化输入数据
function initInputData(data: any) {
initAllData()
data.forEach((item: any) => {
const params = {
measureValue: item.measureValue || '', // 测量值
riseTime: item.riseTime || '', // 上升时间
technicalIndex: item.technicalIndex ? clearSymbol(item.technicalIndex) : '',
}
switch (item.dataType) {
case '1':
// 频率
frequencyList.value.push({ ...item, params: '频率', ...params, measureValueUnit: item.unit })
break
case '2':
// 交流电压
acVoltageList.value.push({ ...item, params: '交流电压', ...params, measureValueUnit: item.unit })
break
case '3':
// 直流电压
dcVoltageList.value.push({ ...item, params: '直流电压', ...params, measureValueUnit: item.unit })
break
case '4':
// 上升时间
riseTimeList.value.push({ ...item, params: '上升时间', ...params, measureValueUnit: item.unit })
break
case '5':
// 正弦信号平坦度
sinusoidFlatnessList.value.push({ ...item, params: '正弦信号平坦度', ...params, measureValueUnit: item.unit })
break
case '6':
// 总谐波失真
harmonicDistortionList.value.push({ ...item, params: '总谐波失真', ...params, measureValueUnit: item.unit })
break
}
})
setListDict()
}
/**
* 新增的时候获取检定项输入数据(获取检定项分类详情)
* @param itemId 检定项id
* @param itemCategoryName 检定项分类名字
* @param belongStandardEquipment 检校标准装置字典
*/
const fetchItemInfo = (itemId: string, itemCategoryName: string, belongStandardEquipment = '') => {
const params = {
id: itemId,
itemCategoryName, // 检定项分类名字
belongStandardEquipment, // 检校标准装置字典code
}
getItemInfo(params).then((res) => {
itemFormData.value.appearanceFunctionCheck = res.data.appearanceFunctionCheck // 外观及功能检查 1有外观,2没有外观
initInputData(res.data.measureItemDataLowFrequencySignalList || [])
})
}
// ----------------------------------------点击保存时校验---------------------------------------
// 校验
const checkout = () => {
}
function checkList(list: IDetailMeasureList[], columns: TableColumn[] | any[], title: string) {
return useCheckList(list, columns, title)
}
// -----------------------------------------生成结果处理----------------------------------------
// 点击计算结果
// 计算
const calculateFun = async (list: IDetailMeasureList[]) => {
let result = [] as any[]
const params = {
belongStandardEquipment: itemFormData.value.belongStandardEquipment, // 检校标准装置
itemCategoryName: itemFormData.value.itemCategoryName, // 检定项分类名称
measureDataLowFrequencySignalList: list,
}
const res = await calculateHandle(params)
result = res.data
return result
}
// 计算单独鉴定项
const caclItem = async (list: IDetailMeasureList[], columns: TableColumn[] | any[], title: string) => {
if (!checkList(list, columns, title)) { return }
const res = await calculateFun(list)
return res.map(item => ({ ...item, params: title }))
}
// 点击计算结果
const calculate = async (title: string, index: string) => {
const result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
switch (title) {
case '频率':
frequencyList.value = result || frequencyList.value
break
case '交流电压':
acVoltageList.value = result || acVoltageList.value
break
case '直流电压':
dcVoltageList.value = result || dcVoltageList.value
break
case '上升时间':
riseTimeList.value = result || riseTimeList.value
break
case '正弦信号平坦度':
sinusoidFlatnessList.value = result || sinusoidFlatnessList.value
break
case '总谐波失真':
harmonicDistortionList.value = result || harmonicDistortionList.value
break
}
setListDict()
}
// 列表
const getList = () => {
let arr = [] as IDetailMeasureList[]
for (const i in listDict.value) {
arr = [...arr, ...listDict.value[i]]
}
return arr
}
// ------------------------------------------钩子----------------------------------------------
watch(() => props.infoId, (newValue) => {
if (newValue) {
infoId.value = newValue
}
}, { immediate: true })
onMounted(() => {
if (pageType.value === 'add') { // 从我的任务跳转过来(新增)
itemFormData.value.itemId = $route.query.itemId as string// 检定项id
itemFormData.value.itemCategoryName = $route.query.itemCategoryName as string// 设备检定项分类名称
itemFormData.value.itemCategoryId = $route.query.itemCategoryId as string// 设备检定项分类名称id
itemFormData.value.belongStandardEquipment = $route.query.belongStandardEquipment as string// 标准装置code
itemFormData.value.belongStandardEquipmentName = $route.query.belongStandardEquipmentName as string// 标准装置名称
// 查输入值(查检定项管理的详情)
fetchItemInfo($route.query.itemId! as string, $route.query.itemCategoryName! as string, $route.query.belongStandardEquipment as string)
}
else {
itemFormData.value.itemCategoryName = $route.query.itemCategoryName as string // 设备检定项分类名称
itemFormData.value.itemCategoryId = $route.query.itemCategoryId as string// 设备检定项分类名称id
itemFormData.value.belongStandardEquipment = $route.query.belongStandardEquipment as string// 标准装置code
itemFormData.value.belongStandardEquipmentName = $route.query.belongStandardEquipmentName as string// 标准装置名称
fetchInfo()
}
})
defineExpose({ checkout, itemFormData, templateFormAndTableRef, pageType, getList })
// watch(() => sinusoidFlatnessList.value, (newVal) => {
// if (newVal) {
// // 计算
// }
// }, {
// deep: true,
// })
</script>
<template>
<div class="measure-data-template-detail">
<template-form-and-table ref="templateFormAndTableRef" :page-type="pageType" />
<!-- 标签 -->
<detail-block :title="pageType !== 'detail' ? '检定数据' : ''" :class="pageType === 'detail' ? 'setBottom' : ''">
<el-radio-group v-if="pageType === 'detail'" v-model="current">
<el-radio-button v-for="item in radioMenus" :key="item.value" :label="item.value">
{{ item.name }}
</el-radio-button>
</el-radio-group>
<el-form
v-if="current === 'measure-data'" ref="formRef" :model="itemFormData" label-width="140"
label-position="right" style="margin-top: 20px;"
>
<!-- 外观 -->
<el-row v-if="itemFormData.appearanceFunctionCheck === 1">
<el-col :span="12">
<el-form-item label="外观及功能性检查:" prop="appearanceRemark">
<el-input
v-model="itemFormData.appearanceRemark" class="full-width-input" autosize type="textarea"
:disabled="pageType === 'detail'"
/>
</el-form-item>
</el-col>
</el-row>
<!-- 频率 -->
<template-table1
v-if="frequencyList.length" title="频率" :data="frequencyList" :columns="columns_frequency"
:disabled="pageType === 'detail'" index="1" :show-btn="false" :calc-btn="pageType !== 'detail'"
:show-title="true" :is-multi="false" :need-merge-cells="[]" @calculate-result="calculate"
>
<template #next-content="{ scope, column }">
<!-- 单位 -->
<template
v-if="column.text === '标称值' || column.text === '测量值' || (column.text === '指标上限' && scope.upperIndex) || (column.text === '指标下限' && scope.lowerIndex)"
>
<span v-for="item in scope.unit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<!-- 标* -->
<span
v-if="scope.conclusion === '不符合指标' && column.text === '测量值'"
style="display: inline-block; color: red;"
>*</span>
</template>
</template-table1>
<!-- 交流电压 -->
<template-table1
v-if="acVoltageList.length" title="交流电压" :data="acVoltageList" :columns="columns_ac_voltage"
:disabled="pageType === 'detail'" index="2" :show-btn="false" :calc-btn="pageType !== 'detail'"
:show-title="true" :is-multi="false" :need-merge-cells="[]" @calculate-result="calculate"
>
<template #next-content="{ scope, column }">
<!-- 单位 -->
<template
v-if="column.text === '标称值' || column.text === '测量值' || (column.text === '指标上限' && scope.upperIndex) || (column.text === '指标下限' && scope.lowerIndex)"
>
<span v-for="item in scope.unit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<template v-if="column.text === '交流频率'">
<span v-for="item in scope.acFrequencyUnit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<!-- 标* -->
<span
v-if="scope.conclusion === '不符合指标' && column.text === '测量值'"
style="display: inline-block; color: red;"
>*</span>
</template>
</template-table1>
<!-- 直流电压 -->
<template-table1
v-if="dcVoltageList.length" title="直流电压" :data="dcVoltageList" :columns="columns_dc_voltage"
:disabled="pageType === 'detail'" index="3" :show-btn="false" :calc-btn="pageType !== 'detail'"
:show-title="true" :is-multi="false" :need-merge-cells="[]" @calculate-result="calculate"
>
<template #next-content="{ scope, column }">
<!-- 单位 -->
<template
v-if="column.text === '标称值' || column.text === '测量值' || (column.text === '指标上限' && scope.upperIndex) || (column.text === '指标下限' && scope.lowerIndex)"
>
<span v-for="item in scope.unit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<!-- 标* -->
<span
v-if="scope.conclusion === '不符合指标' && column.text === '测量值'"
style="display: inline-block; color: red;"
>*</span>
</template>
</template-table1>
<!-- 上升时间 -->
<template-table1
v-if="riseTimeList.length" title="上升时间" :data="riseTimeList" :columns="columns_rise_time"
:disabled="pageType === 'detail'" index="4" :show-btn="false" :calc-btn="pageType !== 'detail'"
:show-title="true" :is-multi="false" :need-merge-cells="[]" @calculate-result="calculate"
>
<!-- 符号 -->
<template #pre-content="{ scope, column }">
<template v-if="column.text === '技术指标'">
<span v-for="item in scope.technicalIndexSymbol" :key="item" style="display: inline-block;">{{ item
}}</span>
</template>
</template>
<template #next-content="{ scope, column }">
<!-- 单位 -->
<template v-if="column.text === '频率'">
<span v-for="item in scope.frequencyUnit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<template v-if="column.text === '幅度'">
<span v-for="item in scope.amplitudeUnit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<template v-if="column.text === '技术指标' || column.text === '上升时间'">
<span v-for="item in scope.technicalIndexUnit" :key="item" style="display: inline-block;">{{ item
}}</span>
</template>
<!-- 标* -->
<span
v-if="scope.conclusion === '不符合指标' && column.text === '上升时间'"
style="display: inline-block; color: red;"
>*</span>
</template>
</template-table1>
<!-- 正弦信号平坦度 -->
<template-table1
v-if="sinusoidFlatnessList.length" title="正弦信号平坦度" :data="sinusoidFlatnessList"
:columns="columns_sinusoid_flatness" :disabled="pageType === 'detail'" index="5" :show-btn="false"
:calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false" :need-merge-cells="[]"
@calculate-result="calculate"
>
<!-- 符号 -->
<template #pre-content="{ scope, column }">
<template v-if="column.text === '技术指标'">
<span v-for="item in scope.technicalIndexSymbol" :key="item" style="display: inline-block;">{{ item
}}</span>
</template>
</template>
<template #next-content="{ scope, column }">
<!-- 单位 -->
<template v-if="column.text === '电压' || column.text === '测量值'">
<span v-for="item in scope.voltageUnit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<template v-if="column.text === '频率点'">
<span v-for="item in scope.frequencyUnit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<template v-if="column.text === '技术指标'">
<span v-for="item in scope.technicalIndexUnit" :key="item" style="display: inline-block;">{{ item
}}</span>
</template>
<!-- 标* -->
<span
v-if="scope.conclusion === '不符合指标' && column.text === '平坦度'"
style="display: inline-block; color: red;"
>*</span>
</template>
</template-table1>
<!-- 总谐波失真 -->
<template-table1
v-if="harmonicDistortionList.length" title="总谐波失真" :data="harmonicDistortionList"
:columns="columns_harmonic_distortion" :disabled="pageType === 'detail'" index="6" :show-btn="false"
:calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false" :need-merge-cells="[]"
@calculate-result="calculate"
>
<!-- 符号 -->
<template #pre-content="{ scope, column }">
<template v-if="column.text === '技术指标'">
<span v-for="item in scope.technicalIndexSymbol" :key="item" style="display: inline-block;">{{ item
}}</span>
</template>
</template>
<template #next-content="{ scope, column }">
<!-- 单位 -->
<template v-if="column.text === '测量值' || column.text === '技术指标'">
<span style="display: inline-block;">%</span>
</template>
<template v-if="column.text === '频率'">
<span v-for="item in scope.frequencyUnit" :key="item" style="display: inline-block;">{{ item }}</span>
</template>
<!-- 标* -->
<span
v-if="scope.conclusion === '不符合指标' && column.text === '测量值'"
style="display: inline-block; color: red;"
>*</span>
</template>
</template-table1>
</el-form>
<!-- 历史修改记录 -->
<change-record v-if="pageType === 'detail' && current === 'change-record'" :info-id="infoId" />
</detail-block>
</div>
</template>
<style lang="scss">
.measure-data-template-detail {
.el-radio__label {
display: block !important;
}
}
</style>