Newer
Older
xc-business-system / src / views / business / taskMeasure / measureData / components / second / templateDetail.vue
dutingting on 22 Apr 40 KB bug修复
<!-- 第2套:直流稳压电源标准装置 -->
<!-- 检定数据管理详情模板 -->
<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 categoryNameDict from '/public/config/categoryNameDict.json'
import { useSolveFormData } from '../useSolveFormData'
import useCaculate from './caculate'
import type { IDetailMeasureList, itemFormDataType } from './second-interface'
import templateTable1 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 templateTable from '@/views/business/measure/item/components/second/templateTable.vue'
import { initTableLastRow, initTableRow } from '@/commonMethods/useMergeTableRow'
import { differenceArray } from '@/utils/Array'
import { transformDecimal } from '@/utils/String'
const props = defineProps({
  infoId: String, // id
  dataNo: String, // 检定数据编号
})
const emits = defineEmits(['giveInfoId', 'changeMeterIdentify'])
const user = useUserStore() // 用户信息
const $router = useRouter() // 关闭页面使用
const $route = useRoute() // 路由参数
const ruleFormRef = ref() // 表单ref
const list = ref([]) // 总数据
const templateFormAndTableRef = ref() // 表单和被检设备、测量设备表格公共组件ref
const itemFormData = ref<itemFormDataType>({ // 有关于检定项的数据
  itemId: '', // 检定项id
  itemCategoryName: '', // 设备检定项分类名称
  itemCategoryId: '', // 设备检定项分类名称id
  belongStandardEquipment: '', // 标准装置code
  belongStandardEquipmentName: '', // 标准装置名称
  appearanceRemark: '外观完好,工作正常', // 外观(1/0)
  appearanceFunctionCheck: 0, // 外观
  voltageRegulation: 0, // 电源电压调整率
  loadRegulation: 0, // 负载调整率
  voltageRepresentError: 0, // 电压示值误差
  currentRepresentErrorDirect: 0, // 电流示值误差(直接测量)
  currentRepresentErrorIndirect: 0, // 电流示值误差(间接测量)
  rippleVoltage: 0, // 纹波电压
  voltageOutputStability: 0, // 输出电压短期稳定性
  remark: '无', // 情况说明
  conclusion: '1', // 检验结论
})
// -------------------------------------------路由参数------------------------------------------
const pageType = ref('add') // 页面类型: add, edit, detail
const isFirstPage = ref(true)
const infoId1 = ref('') // 列表id
if ($route.params && $route.params.type) {
  pageType.value = $route.params.type as string
  if ($route.params.id) {
    infoId1.value = $route.params.id as string
  }
}

// ------------------------------------------标签----------------------------------------------------------
const radioMenus = ref([ // 标签内容
  { name: '检定数据', value: 'measure-data' },
  { name: '历史修改记录', value: 'change-record' },
])
const current = ref('measure-data') // 选择的tab 默认基本信息

// ---------------------------------------检定项数据表格----------------------------------------------------
const lineVoltageRegulationList = ref<IDetailMeasureList[]>([]) // 电源电压调整率
const loadRegulationList = ref<IDetailMeasureList[]>([]) // 负载调整率
const voltageRepresentationValueErrorList = ref<IDetailMeasureList[]>([]) // 电压示值误差
const ammeterDirectList = ref<IDetailMeasureList[]>([]) // 电流示值误差(直接测量)
const ammeterIndirectList = ref<IDetailMeasureList[]>([]) // 电流示值误差(间接测量)
const rippleVoltageList = ref<IDetailMeasureList[]>([]) // 纹波电压
const outputVoltageStabilityList = ref<IDetailMeasureList[]>([]) // 输出电压短期稳定性
const listDict = ref<{ [key: string]: IDetailMeasureList[] }>({})
const measureItemData = ref<any[]>([])
const setListDict = () => {
  listDict.value = {
    '1-电源电压调整率': lineVoltageRegulationList.value, // 1
    '2-负载调整率': loadRegulationList.value, // 2
    '3-电压示值误差': voltageRepresentationValueErrorList.value, // 3
    '4-电流示值误差(直接测量)': ammeterDirectList.value, // 4
    '5-电流示值误差(间接测量)': ammeterIndirectList.value, // 5
    '6-纹波电压': rippleVoltageList.value, // 6
    '7-输出电压短期稳定性': outputVoltageStabilityList.value, // 7
  }
}
const columns_line_voltage_regulation = ref<TableColumn[]>([ // 电源电压调整率
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: false, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: false, type: 'text' },
  { text: '调压器输出值', value: 'voltageRegulatorOutputValue', align: 'center', required: false, type: 'text' },
  { text: '被检电源输出电压值', value: 'voltageOutputValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number', precision: 3 },
  { text: '被检电源输出电压最大差值', value: 'voltageMaxDifference', align: 'center', required: false, type: 'text' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'text' },
  { text: '电源电压调整率', value: 'voltageRegulation', align: 'center', required: false, type: 'text' },
])
const columns_load_regulation = ref<TableColumn[]>([ // 负载调整率
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: false, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: false, type: 'text' },
  { text: '负载情况', value: 'loadSituation', align: 'center', required: false, type: 'text' },
  { text: '被检电源输出电压值', value: 'voltageOutputValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number', precision: 3 },
  { text: '电压差值', value: 'voltageDifference', align: 'center', required: false, type: 'text' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'text' },
  { text: '负载调整率', value: 'loadRegulation', align: 'center', required: false, type: 'text' },
])
// 电压示值误差
const columns_voltage_representation_value_error = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: false, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: false, type: 'text' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
  { text: '标准值', value: 'standardValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: false, type: 'text' },
  { text: '绝对误差', value: 'absoluteError', align: 'center', required: false, type: 'text' },
])
const columns_voltage_representation_value_error_1 = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: false, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: false, type: 'text' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
  { text: '标准值', value: 'standardValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: false, type: 'text' },
  { text: '绝对误差', value: 'absoluteError', align: 'center', required: false, type: 'text' },
])
// 电流示值误差(间接测量)
const columns_ammeter_indirect = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: false, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: false, type: 'text' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
  { text: '标准电压值', value: 'standardVoltageValue', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number', width: '250', precision: 6 },
  { text: '标准电阻值', value: 'standardResistanceValue', align: 'center', required: false, type: 'text' },
  { text: '标准值', value: 'standardValue', align: 'center', required: false, type: 'text' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: false, type: 'text' },
  { text: '绝对误差', value: 'absoluteError', align: 'center', required: false, type: 'text' },
])
// 纹波电压
const columns_ripple_voltage = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: false, type: 'text' },
  { text: '单位', value: 'unit', align: 'center', required: false, type: 'text' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'text' },
  { text: '纹波电压', value: 'rippleVoltage', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'number' },
])
// 输出电压短期稳定性
const columns_output_voltage_stability = ref<any[]>([
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: pageType.value === 'detail' ? 'text' : 'select-dict', code: 'standardOutputChannel' },
  { text: '单位', value: 'unit', align: 'center', required: false, type: 'text' },
  { text: '被测电源输出电压', value: 'voltageOutputValueUpper', align: 'center', required: false, customContent: true, type: pageType.value === 'detail' ? 'text' : 'number' },
  { text: '输出电压最大变化值', value: 'outputVoltageMaxChange', align: 'center', required: false, type: 'text' },
  { text: '仪器技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'text' },
  { text: '短期稳定性', value: 'shortTermStability', align: 'center', required: false, type: 'text' },
])
const columnsDict = ref<{ [key: string]: any[] | TableColumn[] }>({
  '1-电源电压调整率': columns_line_voltage_regulation.value, // 1
  '2-负载调整率': columns_load_regulation.value, // 2
  '3-电压示值误差': columns_voltage_representation_value_error.value, // 3
  '4-电流示值误差(直接测量)': columns_voltage_representation_value_error_1.value, // 4
  '5-电流示值误差(间接测量)': columns_ammeter_indirect.value, // 5
  '6-纹波电压': columns_ripple_voltage.value, // 6
  '7-输出电压短期稳定性': columns_output_voltage_stability.value, // 7
})
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 addRow = () => {
  if (!checkList(outputVoltageStabilityList.value, columns_output_voltage_stability.value, '输出电压短期稳定性')) { return }
  // 增加行
  outputVoltageStabilityList.value.push({ ...outputVoltageStabilityList.value[outputVoltageStabilityList.value.length - 1] })
  // 初始化数据
  outputVoltageStabilityList.value = initTableRow(outputVoltageStabilityList.value)
}
// 删除行
const delRow = (checkList: any[]) => {
  if (!checkList.length) {
    ElMessage.warning('请选择需要删除的数据')
    return
  }
  // 每个输入通道,最少需要有二行数据
  if (checkList.every(item => outputVoltageStabilityList.value.filter(citem => citem.outputChannel === item.outputChannel).length < 2)) {
    ElMessage.warning('输出通道最少需要有两行数据')
    return
  }
  // 删除行
  outputVoltageStabilityList.value = differenceArray(outputVoltageStabilityList.value, checkList)
  // console.log(outputVoltageStabilityList.value, 'outputVoltageStabilityList.value')
  listDict.value['7-输出电压短期稳定性'] = outputVoltageStabilityList.value
  // 初始化数据
  outputVoltageStabilityList.value = initTableRow(outputVoltageStabilityList.value)
}
// -------------------------------------------获取详情信息--------------------------------------------------
// 获取页面详情信息
const fetchInfo = () => {
  const loading = ElLoading.service({
    lock: true,
    background: 'rgba(255, 255, 255, 0.8)',
  })
  getInfo({
    id: infoId1.value,
    belongStandardEquipment: itemFormData.value.belongStandardEquipment,
    // 我的任务跳转过来如果已经配置过检定项了,到编辑页面,且用一下三个字段替代传id请求详情
    itemId: $route.query.itemId, // 检定项id
    orderId: $route.query.orderId, // 任务单id
    sampleId: $route.query.sampleId, // 被检设备id
  }).then(async (res) => {
    // 获取检定项数据
    const params = {
      id: $route.query.itemId,
      itemCategoryName: itemFormData.value.itemCategoryName, // 检定项分类名字
      belongStandardEquipment: itemFormData.value.belongStandardEquipment, // 检校标准装置字典code
    }
    const response = await getItemInfo(params)
    measureItemData.value = JSON.parse(JSON.stringify(response.data.measureItemDataDcPowerList))

    console.log(res.data, '编辑 详情')
    // 有关于检定项的数据
    itemFormData.value.appearanceFunctionCheck = res.data.appearanceFunctionCheck // 外观及功能检查
    initInputData(res.data.measureDataDcPowerList)
    isFirstPage.value = false
    // =======================================表单公共组件数据处理=======================================================
    useSolveFormData(res, templateFormAndTableRef.value)
    // ==================================检定数据========================================================================
    infoId1.value = res.data.id
    emits('giveInfoId', infoId1.value)
    loading.close()
  })
}
// 最大允许误差 计算
const calcMaxError = (item: any, index: number, type: string) => {
  let initData = {} as any
  if (type === 'all') {
    initData = measureItemData.value[index]
  }
  else {
    initData = measureItemData.value.filter((citem: any) => citem.dataType === item.dataType)[index]
  }
  // 1数字式、2指针式
  if (item.dataTypeType === '1') {
    if (initData.maximumError === '2') {
      return (Number(initData.errorParamA) * Number(item.measureIndicationValue) + Number(initData.errorParamB) * Number(initData.resolution)) || 0
    }
    else if (initData.maximumError === '3') {
      return (Number(initData.errorParamA) * Number(item.measureIndicationValue) + Number(initData.errorParamB)) || 0
    }
    else if (initData.maximumError === '1') {
      return (Number(initData.accuracyA) * Number(initData.fullScaleValue)) || 0
    }
  }
  else if (item.dataTypeType === '2') {
    return (Number(initData.accuracyA) * Number(initData.fullScaleValue)) || 0
  }
}
// 保留小数位数
const InterceptDecimal = (item: any, index: number) => {
  // 1数字式、2指针式
  if (item.dataTypeType === '1') {
    const decimal = item.resolution.includes('.') ? item.resolution.substring(item.resolution.indexOf('.'), item.resolution.length - 1).length : 0
    item.standardValue = Number(item.standardValue || 0).toFixed(decimal + 1)
    const tempData = {
      accuracyA: item.accuracyA, // 准确度a
      fullScaleValue: item.fullScaleValue, // 指针式仪表满量程值
      errorParamA: item.errorParamA, // 误差参数a
      errorParamB: item.errorParamB, // 误差参数b
      measureIndicationValue: item.measureIndicationValue, // 被检表示值
      resolution: item.resolution, // 分辨力
    }
    item.maximumError = useCaculate(`${item.maximumError}`, tempData)
    item.maximumError = Number(item.maximumError || 0).toFixed(decimal + 1)
    if (pageType.value !== 'add' && !isFirstPage.value) {
      item.absoluteError = Number(calcMaxError(item, index, 'all') || 0).toFixed(decimal + 1)
    }
    switch (item.dataType) {
      case '3':
        // 标准值、最大允许误差、绝对误差,比分辨力配置的,小数点后多一位
        item.params = '电压示值误差'
        break
      case '4':
        // 标准值、最大允许误差、绝对误差,比分辨力配置的,小数点后多一位
        item.params = '电流示值误差(直接测量)'
        break
      case '5':
        // 标准值、最大允许误差、绝对误差,比分辨力配置的,小数点后多一位
        item.params = '电流示值误差(间接测量)'
        break
    }
  }
  else {
    const tempData = {
      accuracyA: item.accuracyA, // 准确度a
      fullScaleValue: item.fullScaleValue, // 指针式仪表满量程值
      errorParamA: item.errorParamA, // 误差参数a
      errorParamB: item.errorParamB, // 误差参数b
      measureIndicationValue: item.measureIndicationValue, // 被检表示值
      resolution: item.resolution, // 分辨力
    }
    item.maximumError = useCaculate(`${item.maximumError}`, tempData)
    switch (item.dataType) {
      case '3':
        // 标准值、最大允许误差、绝对误差,保留小数点后2位
        item.params = '电压示值误差'
        item.standardValue = Number(item.standardValue || 0).toFixed(2)
        item.maximumError = Number(item.maximumError || 0).toFixed(2)
        if (pageType.value !== 'add' && !isFirstPage.value) {
          item.absoluteError = Number(calcMaxError(item, index, 'all') || 0).toFixed(2)
        }
        break
      case '4':
        // 标准值、最大允许误差、绝对误差,保留小数点后3位
        item.params = '电流示值误差(直接测量)'
        item.standardValue = Number(item.standardValue || 0).toFixed(3)
        item.maximumError = Number(item.maximumError || 0).toFixed(3)
        if (pageType.value !== 'add' && !isFirstPage.value) {
          item.absoluteError = Number(calcMaxError(item, index, 'all') || 0).toFixed(3)
        }
        break
      case '5':
        // 标准值、最大允许误差、绝对误差,保留小数点后3位
        item.params = '电流示值误差(间接测量)'
        item.standardValue = Number(item.standardValue || 0).toFixed(3)
        item.maximumError = Number(item.maximumError || 0).toFixed(3)
        if (pageType.value !== 'add' && !isFirstPage.value) {
          item.absoluteError = Number(calcMaxError(item, index, 'all') || 0).toFixed(3)
        }

        break
    }
  }
  return {
    ...item,
  }
}
// 初始化数据
function initAllData() {
  for (const i in listDict.value) {
    listDict.value[i] = []
  }
  lineVoltageRegulationList.value = []
  loadRegulationList.value = []
  voltageRepresentationValueErrorList.value = []
  ammeterDirectList.value = []
  ammeterIndirectList.value = []
  rippleVoltageList.value = []
  outputVoltageStabilityList.value = []
}
// 初始化输入数据
function initInputData(data: any[]) {
  initAllData()
  data.forEach((item, index) => {
    switch (item.dataType) {
      case '1':
        // 电源电压调整率
        lineVoltageRegulationList.value.push({ ...item, params: '电源电压调整率', voltageOutputValue: transformDecimal(item.voltageOutputValue, 3) })
        break
      case '2':
        // 负载调整率
        loadRegulationList.value.push({ ...item, params: '负载调整率', voltageOutputValue: transformDecimal(item.voltageOutputValue, 3) })
        break
      case '3':
        // 电压示值误差
        if (pageType.value === 'add') {
          voltageRepresentationValueErrorList.value.push(InterceptDecimal(item, index))
        }
        else {
          voltageRepresentationValueErrorList.value.push({ ...item, params: '电压示值误差' })
        }
        break
      case '4':
        // 电流示值误差(直接测量)
        if (pageType.value === 'add') {
          ammeterDirectList.value.push(InterceptDecimal(item, index))
        }
        else {
          ammeterDirectList.value.push({ ...item, params: '电流示值误差(直接测量)' })
        }
        break
      case '5':
        // 电流示值误差(间接测量)
        if (pageType.value === 'add') {
          ammeterIndirectList.value.push(InterceptDecimal(item, index))
        }
        else {
          ammeterIndirectList.value.push({ ...item, params: '电流示值误差(间接测量)' })
        }

        break
      case '6':
        // 纹波电压
        rippleVoltageList.value.push({ ...item, params: '纹波电压' })
        break
      case '7':
        // 纹波电压
        outputVoltageStabilityList.value.push({ ...item, params: '输出电压短期稳定性' })
        break
    }
  })
  setListDict()
}
const getList = () => {
  let arr = [] as IDetailMeasureList[]
  for (const i in listDict.value) {
    arr = [...arr, ...listDict.value[i]]
  }
  return arr
}
/**
 * 新增的时候获取检定项输入数据(获取检定项分类详情)
 * @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 // 外观及功能检查
    itemFormData.value.voltageRegulation = res.data.voltageRegulation // 电源电压调整率
    itemFormData.value.loadRegulation = res.data.loadRegulation // 负载调整率
    itemFormData.value.voltageRepresentError = res.data.voltageRepresentError // 电压示值误差
    itemFormData.value.currentRepresentErrorDirect = res.data.currentRepresentErrorDirect // 电流示值误差(直接测量)
    itemFormData.value.currentRepresentErrorIndirect = res.data.currentRepresentErrorIndirect // 电流示值误差(间接测量)
    itemFormData.value.rippleVoltage = res.data.rippleVoltage // 纹波电压
    itemFormData.value.voltageOutputStability = res.data.voltageOutputStability // 输出电压短期稳定性
    measureItemData.value = JSON.parse(JSON.stringify(res.data.measureItemDataDcPowerList))
    initInputData(res.data.measureItemDataDcPowerList.map((item: IDetailMeasureList) => ({ ...item, id: '' })))
    isFirstPage.value = false
  })
}
// -----------------------------------------字典----------------------------------------
const RegulatorOutputValue = ref<{ value: string; name: string; id: string }[]>([]) // 调压器输出值
const fetchDict = async () => {
  const res1 = await getDictByCode('voltageRegulatorOutputValue')
  RegulatorOutputValue.value = res1.data
}
fetchDict()
// 调压器输出值
// ----------------------------------------点击保存时校验---------------------------------------
// 校验
// 检查数据
function checkList(list: IDetailMeasureList[], columns: TableColumn[] | any[], title: string) {
  return useCheckList(list, columns, title)
}
// 检查所有数据
function checkAllList() {
  let result = true
  for (const i in columnsDict.value) {
    const requireLength = listDict.value[i].length > 0
    if (!useCheckList(listDict.value[i], columnsDict.value[i], i.substring(2), '', '', '', requireLength)) {
      result = false
      break
    }
  }
  return result
}
// -----------------------------------------生成结果处理----------------------------------------
// 计算
const calculateFun = async (list: IDetailMeasureList[]) => {
  let result = [] as any[]
  const params = {
    belongStandardEquipment: itemFormData.value.belongStandardEquipment, // 检校标准装置
    itemCategoryName: itemFormData.value.itemCategoryName, // 检定项分类名称
    measureDataDcPowerList: list.map((item: any) => ({ ...item, exceedMark: 0 })).map((item: any, index: number) => {
      if (item.dataType === '3' || item.dataType === '4' || item.dataType === '5') {
        return {
          ...item,
          maximumError: item.dataTypeType === '1' ? Number(item.maximumError || 0).toFixed(item.resolution.includes('.') ? item.resolution.substring(item.resolution.indexOf('.'), item.resolution.length - 1).length : 0 + 1) : Number(item.maximumError || 0).toFixed(3),
        }
      }
      else {
        return item
      }
    }),
  }
  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) => {
  let result = [] as IDetailMeasureList[]
  switch (title) {
    case '电源电压调整率':
      result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
      lineVoltageRegulationList.value = result || lineVoltageRegulationList.value
      setListDict()
      break
    case '负载调整率':
      result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
      loadRegulationList.value = result || loadRegulationList.value
      setListDict()
      break
    case '电压示值误差':
      result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
      voltageRepresentationValueErrorList.value = result || voltageRepresentationValueErrorList.value
      setListDict()
      break
    case '电流示值误差(直接测量)':
      result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
      ammeterDirectList.value = result || ammeterDirectList.value
      setListDict()
      break
    case '电流示值误差(间接测量)':
      result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
      ammeterIndirectList.value = result || ammeterIndirectList.value
      setListDict()
      break
    case '纹波电压':
      result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
      rippleVoltageList.value = result || rippleVoltageList.value
      setListDict()
      break
    case '输出电压短期稳定性':
      result = await caclItem(listDict.value[`${index}-${title}`], columnsDict.value[`${index}-${title}`], title) as IDetailMeasureList[]
      outputVoltageStabilityList.value = result || outputVoltageStabilityList.value
      setListDict()
      break
    case '':
      if (!checkAllList()) { return }
      initInputData(await calculateFun(getList()))
  }
}
// -----------------------------------------------------------------------------------------
const isNeverDefineItemCategory = ref(false) // 检定项分类是否是从未定义过的
watch(() => itemFormData.value.itemCategoryName, (newValue) => {
  if (newValue) {
    // 判断是否是新增的检定项分类
    const index = categoryNameDict.findIndex((item: any) => item === newValue)
    if (index === -1) {
      isNeverDefineItemCategory.value = true
    }
    else {
      isNeverDefineItemCategory.value = false
    }
  }
})
// -----------------------------------------------------------------------------------------

// ------------------------------------------钩子----------------------------------------------

watch(() => props.infoId, (newValue) => {
  if (newValue) {
    infoId1.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({ checkList, itemFormData, templateFormAndTableRef, pageType, getList, checkAllList })
</script>

<template>
  <div class="measure-data-template-detail">
    <template-form-and-table
      ref="templateFormAndTableRef" :page-type="pageType"
      @change-meter-identify="emits('changeMeterIdentify')"
    />
    <!-- 标签 -->
    <detail-block
      v-if="!isNeverDefineItemCategory" :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' || 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-table
          v-if="lineVoltageRegulationList.length" title="电源电压调整率" :data="lineVoltageRegulationList"
          :columns="columns_line_voltage_regulation" :disabled="pageType === 'detail'" index="1" :show-btn="false"
          :calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false"
          :need-merge-cells="['outputChannel', 'voltageMaxDifference', 'technicalIndex', 'voltageRegulation']"
          @calculate-result="calculate"
        >
          <!-- 技术指标 -->
          <template #pre-content="{ scope, column }">
            <div
              v-if="column.text === '被检电源技术指标' && scope.technicalIndex !== '/'"
              style="line-height: 30px;margin-right: 10px;"
            >
              {{ scope.technicalIndexSymbol }}
            </div>
          </template>
          <template #next-content="{ scope, column }">
            <div
              v-if="column.text === '被检电源技术指标' && scope.technicalIndex !== '/'"
              style="line-height: 30px;margin-right: 10px;"
            >
              %
            </div>
            <template v-if="column.text === '电源电压调整率' && scope.exceedMark">
              <span style="color: red;">*</span>
            </template>
          </template>
        </template-table>
        <!-- 负载调整率 -->
        <template-table
          v-if="loadRegulationList.length" title="负载调整率" :data="loadRegulationList"
          :columns="columns_load_regulation" :disabled="pageType === 'detail'" index="2" :show-btn="false"
          :calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false"
          :need-merge-cells="['outputChannel', 'voltageDifference', 'technicalIndex', 'loadRegulation']"
          @calculate-result="calculate"
        >
          <!-- 技术指标 -->
          <template #pre-content="{ scope, column }">
            <div
              v-if="column.text === '被检电源技术指标' && scope.technicalIndex !== '/'"
              style="line-height: 30px;margin-right: 10px;"
            >
              {{ scope.technicalIndexSymbol }}
            </div>
          </template>
          <template #next-content="{ scope, column }">
            <div
              v-if="column.text === '被检电源技术指标' && scope.technicalIndex !== '/'"
              style="line-height: 30px;margin-right: 10px;"
            >
              %
            </div>
            <template v-if="column.text === '负载调整率' && scope.exceedMark">
              <span style="color: red;">*</span>
            </template>
          </template>
        </template-table>

        <!--  电压示值误差 -->
        <template-table
          v-if="voltageRepresentationValueErrorList.length" title="电压示值误差"
          :data="voltageRepresentationValueErrorList" :columns="columns_voltage_representation_value_error" index="3"
          :show-btn="false" :calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false"
          :need-merge-cells="['outputChannel']" :disabled="pageType === 'detail'" @calculate-result="calculate"
        >
          <!-- 符号 -->
          <template #pre-content="{ column }">
            <div v-if="column.text === '最大允许误差'" style="line-height: 30px;margin-right: 10px;">
              ±
            </div>
          </template>
          <template #next-content="{ scope, column }">
            <template v-if="column.text === '绝对误差' && scope.exceedMark">
              <span style="color: red;">*</span>
            </template>
          </template>
        </template-table>

        <!-- 电流示值误差(直接测量) -->
        <template-table
          v-if="ammeterDirectList.length" title="电流示值误差(直接测量)" :data="ammeterDirectList"
          :columns="columns_voltage_representation_value_error" :disabled="pageType === 'detail'" index="4"
          :show-btn="false" :calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false"
          :need-merge-cells="['outputChannel']" @calculate-result="calculate"
        >
          <!-- 符号 -->
          <template #pre-content="{ column }">
            <div v-if="column.text === '最大允许误差'" style="line-height: 30px;margin-right: 10px;">
              ±
            </div>
          </template>
          <template #next-content="{ scope, column }">
            <template v-if="column.text === '绝对误差' && scope.exceedMark">
              <span style="color: red;">*</span>
            </template>
          </template>
        </template-table>
        <!-- 电流示值误差(间接测量) -->
        <template-table
          v-if="ammeterIndirectList.length" title="电流示值误差(间接测量)" :data="ammeterIndirectList"
          :columns="columns_ammeter_indirect" :disabled="pageType === 'detail'" index="5" :show-btn="false"
          :calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel']"
          @calculate-result="calculate"
        >
          <!-- 符号 -->
          <template #pre-content="{ column }">
            <div v-if="column.text === '最大允许误差'" style="line-height: 30px;margin-right: 10px;">
              ±
            </div>
          </template>
          <template #next-content="{ scope, column }">
            <template v-if="column.text === '绝对误差' && scope.exceedMark">
              <span style="color: red;">*</span>
            </template>
            <template v-if="column.text === '标准电压值'">
              <!-- <span style="color: red;">*</span> -->
              <span v-if="pageType === 'detail'">{{ scope.standardVoltageValueUnit }}</span>
              <el-select v-else v-model="scope.standardVoltageValueUnit" style="width: 100px;" placeholder="单位">
                <el-option value="V" label="V" />
                <el-option value="mV" label="mV" />
              </el-select>
            </template>
          </template>
        </template-table>
        <!--  纹波电压 -->
        <template-table
          v-if="rippleVoltageList.length" title="纹波电压" :data="rippleVoltageList"
          :columns="columns_ripple_voltage" :disabled="pageType === 'detail'" index="6" :show-btn="false"
          :calc-btn="pageType !== 'detail'" :show-title="true" :is-multi="false" :need-merge-cells="['outputChannel']"
          @calculate-result="calculate"
        >
          <!-- 技术指标 -->
          <template #pre-content="{ scope, column }">
            <div
              v-if="column.text === '被检电源技术指标' && scope.technicalIndex !== '/'"
              style="line-height: 30px;margin-right: 10px;"
            >
              {{ scope.technicalIndexSymbol }}
            </div>
          </template>
          <template #next-content="{ scope, column }">
            <!-- <div v-if="column.text === '被检电源技术指标'" style="line-height: 30px;margin-right: 10px;">
              %
            </div> -->
            <template v-if="column.text === '纹波电压' && scope.exceedMark">
              <span style="color: red;">*</span>
            </template>
          </template>
        </template-table>
        <!--  输出电压短期稳定性 -->
        <template-table
          v-if="outputVoltageStabilityList.length" title="输出电压短期稳定性" :data="outputVoltageStabilityList"
          :columns="columns_output_voltage_stability" :disabled="pageType === 'detail'" index="7"
          :show-btn="pageType !== 'detail'" :calc-btn="pageType !== 'detail'" :show-title="true"
          :is-multi="pageType !== 'detail'"
          :need-merge-cells="['outputVoltageMaxChange', 'technicalIndex', 'shortTermStability']"
          @calculate-result="calculate" @add-row="addRow" @del-row="delRow"
        >
          <!-- 仪器技术指标 -->
          <template #pre-content="{ scope, column }">
            <div
              v-if="column.text === '仪器技术指标' && scope.technicalIndex !== '/'"
              style="line-height: 30px;margin-right: 10px;"
            >
              {{ scope.technicalIndexSymbol }}
            </div>
          </template>
          <template #custom-content="{ scope, column }">
            <!-- {{ scope.row }} -->
            <template v-if="column.text === '被测电源输出电压'">
              <!-- 数字输入框 -->
              <precision-input-number
                v-model="scope.voltageOutputValueLower"
                placeholder="被测电源输出电压下限" style="width: 45%;" controls-position="right"
                :disabled="pageType === 'detail'" :precision="0"
                :value-on-clear="0"
              />
              ~
              <precision-input-number
                v-model="scope.voltageOutputValueUpper"
                placeholder="被测电源输出电压上限" style="width: 45%;" controls-position="right"
                :disabled="pageType === 'detail'" :precision="0"
                :value-on-clear="0"
              />
            </template>
          </template>
          <template #next-content="{ scope, column }">
            <div
              v-if="column.text === '仪器技术指标' && scope.technicalIndex !== '/'"
              style="line-height: 30px;margin-right: 10px;"
            >
              %
            </div>
            <template v-if="column.text === '短期稳定性' && scope.exceedMark">
              <span style="color: red;">*</span>
            </template>
          </template>
        </template-table>
      </el-form>
      <!-- 历史修改记录 -->
      <change-record v-if="pageType === 'detail' && current === 'change-record'" :info-id="infoId1" />
    </detail-block>
  </div>
</template>

<style lang="scss">
.measure-data-template-detail {
  .el-radio__label {
    display: block !important;
  }
}
</style>