Newer
Older
xc-business-system / src / views / business / measure / item / components / second / templateDetail.vue
<!-- 第2套:直流稳压电源标准装置 -->
<script lang="ts" setup name="TemplateDetailSecond">
import { ElMessage } from 'element-plus'
import type { IList } from './templateDetail-interface'
import templateTable from './templateTable.vue'
import type { dictType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import { calc } from '@/utils/useCalc'
import { useCheckList } from '@/commonMethods/useCheckList'
import { calculate, recalculate } from '@/api/business/measure/caculate'
import type { TableColumn } from '@/components/NormalTable/table_interface'
const props = defineProps({
  pageType: {
    type: String,
    default: 'add',
  },
  itemCategoryName: {
    type: String,
    require: true,
  }, // 设备检定项分类名称
  belongStandardEquipment: { // 检校标准装置code
    type: String,
    require: true,
  },
  list: {
    type: Array as any,
  },
  form: { // 检定项表单
    type: Object as any,
  },
  itemId: { // 检定项id
    type: String,
    default: '',
  },
})

const form = ref({
  voltageRepresentationValueErrorType: '1', // 电压表示值误差类型:1数字式、2指针式
  ammeterDirectType: '1', // 电流表示值误差(直接测量)类型:1数字式、2指针式
  ammeterIndirectType: '1', // 电流表示值误差(间接测量)类型:1数字式、2指针式
  technicalIndexSymbol: '3', // 通用规则
  appearanceFunctionCheck: 1, // 外观及功能性检查
  voltageRegulation: 1, // 电源电压调整率
  loadRegulation: 1, // 负载调整率
  voltageRepresentError: 1, // 电压表示值误差
  currentRepresentErrorDirect: 1, // 电流表示值误差(直接测量)
  currentRepresentErrorIndirect: 1, // 电流表示值误差(间接测量)
  rippleVoltage: 1, // 纹波电压
  voltageOutputStability: 1, // 输出电压短期稳定性
})
const tableLoading = ref(false)
const lineVoltageRegulationList = ref<IList[]>([]) // 电源电压调整率
const loadRegulationList = ref<IList[]>([]) // 负载调整率
const voltageRepresentationValueErrorList = ref<IList[]>([]) // 电压表示值误差
const ammeterDirectList = ref<IList[]>([]) // 电流表示值误差(直接测量)
const ammeterIndirectList = ref<IList[]>([]) // 电流表示值误差(间接测量)
const rippleVoltageList = ref<IList[]>([]) // 纹波电压
const outputVoltageStabilityList = ref<IList[]>([]) // 输出电压短期稳定性

const lineVoltageRegulationCheckoutList = ref<IList[]>([]) // 电源电压调整率多选
const loadRegulationCheckoutList = ref<IList[]>([]) // 负载调整率多选
const voltageRepresentationValueErrorCheckoutList = ref<IList[]>([]) // 电压表示值误差多选
const ammeterDirectCheckoutList = ref<IList[]>([]) // 电流表示值误差(直接测量)多选
const ammeterIndirectCheckoutList = ref<IList[]>([]) // 电流表示值误差(间接测量)多选
const rippleVoltageCheckoutList = ref<IList[]>([]) // 纹波电压多选
const outputVoltageStabilityCheckoutList = ref<IList[]>([]) // 输出电压短期稳定性多选
// ----------------------------------------表头------------------------------------------------
const columns_line_voltage_regulation = ref<TableColumn[]>([ // 电源电压调整率
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '调压器输出值', value: 'voltageRegulatorOutputValue', align: 'center', required: true, type: 'select' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'input' },
])
const columns_load_regulation = ref<TableColumn[]>([ // 负载调整率
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '负载情况', value: 'loadSituation', align: 'center', required: true, type: 'select' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'input' },
])
// 电压表示值误差(数字式)、电流表示值误差(直接测量)--(数字式)
const columns_voltage_representation_value_error_number = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' },
  { text: '误差参数a', value: 'paramsa', align: 'center', required: true, type: 'input' },
  { text: '误差参数b', value: 'paramsb', align: 'center', required: true, type: 'input' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'select' },
  { text: '分辨力', value: 'resolution', align: 'center', required: true, type: 'input' },
])
// 电压表示值误差(数字式)
const columns_voltage_representation = ref(columns_voltage_representation_value_error_number.value)
// 电流表示值误差(直接测量)
const columns_ammeter_direct = ref(columns_voltage_representation_value_error_number.value)
// 电压表示值误差(指针式)、电流表示值误差(直接测量)--(指针式)
const columns_voltage_representation_value_error_pointer = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' },
  { text: '准确度a', value: 'paramsa', align: 'center', required: true, type: 'input' },
  { text: '指针式仪表满量程值', value: 'paramsb', align: 'center', required: true, type: 'input' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'select' },
])
// 电流表示值误差(间接测量)--数字式
const columns_ammeter_indirect_number = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' },
  { text: '标准电阻值', value: 'standardResistanceValue', align: 'center', required: true, type: 'input' },
  { text: '标准电阻值单位', value: 'standardResistanceValueUnit', align: 'center', required: true, type: 'select' },
  { text: '误差参数a', value: 'paramsa', align: 'center', required: true, type: 'input' },
  { text: '误差参数b', value: 'paramsb', align: 'center', required: true, type: 'input' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'select' },
  { text: '分辨力', value: 'resolution', align: 'center', required: true, type: 'input' },
])
// 电流表示值误差(间接测量)
const columns_ammeter_indirect = ref(columns_ammeter_indirect_number.value)
// 电流表示值误差(间接测量)--指针式
const columns_ammeter_indirect_pointer = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '被检表示值', value: 'measureIndicationValue', align: 'center', required: true, type: 'input' },
  { text: '标准电阻值', value: 'standardResistanceValue', align: 'center', required: true, type: 'input' },
  { text: '标准电阻值单位', value: 'standardResistanceValueUnit', align: 'center', required: true, type: 'select' },
  { text: '准确度a', value: 'paramsa', align: 'center', required: true, type: 'input' },
  { text: '指针式仪表满量程值', value: 'paramsb', align: 'center', required: true, type: 'input' },
  { text: '最大允许误差', value: 'maximumError', align: 'center', required: true, type: 'select' },
])
// 纹波电压
const columns_ripple_voltage = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '被检电源技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'number' },
])
// 输出电压短期稳定性
const columns_output_voltage_stability = ref<TableColumn[]>([
  { text: '检定项目', value: 'params', align: 'center', required: true, type: 'text' },
  { text: '输出通道', value: 'outputChannel', align: 'center', required: true, type: 'select' },
  { text: '单位', value: 'unit', align: 'center', required: true, type: 'select' },
  { text: '仪器技术指标', value: 'technicalIndex', align: 'center', required: true, type: 'input' },
])
// --------------------------------表格操作---------------------------------------------------
// 多选
const handleSelectionChange = (e: any, type: string) => {
  switch (type) {
    case '电源电压调整率': // 电源电压调整率
      lineVoltageRegulationCheckoutList.value = e
      break
    case '负载调整率': // 负载调整率
      loadRegulationCheckoutList.value = e
      break
    case '电压表示值误差': // 电压表示值误差
      voltageRepresentationValueErrorCheckoutList.value = e
      break
    case '电流表示值误差(直接测量)': // 电流表示值误差(直接测量)
      ammeterDirectCheckoutList.value = e
      break
    case '电流表示值误差(间接测量)': // 电流表示值误差(间接测量)
      ammeterIndirectCheckoutList.value = e
      break
    case '纹波电压': // 纹波电压
      rippleVoltageCheckoutList.value = e
      break
    case '输出电压短期稳定性': // 输出电压短期稳定性
      outputVoltageStabilityCheckoutList.value = e
      break
  }
}
// 表格对应 columns字典  1数字式、2指针式
const columnsDict = {
  '输出电压短期稳定性': columns_output_voltage_stability.value, // 7
  '纹波电压': columns_ripple_voltage.value, // 6
  '电流表示值误差(间接测量)': columns_ammeter_indirect.value, // 5
  '电流表示值误差(直接测量)': columns_ammeter_direct.value, // 4
  '电源电压调整率': columns_line_voltage_regulation.value, // 1
  '负载调整率': columns_load_regulation.value, // 2
  '电压表示值误差': columns_voltage_representation.value, // 3
} as { [key: string]: any }
const listDict = {
  '输出电压短期稳定性': lineVoltageRegulationList.value, // 7
  '纹波电压': rippleVoltageList.value, // 6
  '电流表示值误差(间接测量)': ammeterIndirectList.value, // 5
  '电流表示值误差(直接测量)': ammeterDirectList.value, // 4
  '电源电压调整率': columns_line_voltage_regulation.value, // 1
  '负载调整率': loadRegulationList.value, // 2
  '电压表示值误差': voltageRepresentationValueErrorList.value, // 3
} as { [key: string]: any }
/**
 * 增加行公共方法
 * @param list 要操作的数组
 * @param title 操作的表格
 */
const addRow = (list: IList[], title: string) => {
  if (checkList(list, columnsDict[`${title}`], `${title}表格`)) {
    switch (title) {
      case '电源电压调整率': // 电源电压调整率
        lineVoltageRegulationList.value.push({
          params: '电源电压调整率',
          dataType: '1',
          technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
          technicalIndex: '', // 技术指标
          outputChannel: '', // 输出通道
          unit: '', // 单位
          voltageRegulatorOutputValue: '', // 调压器输出值
          editable: true,
        })
        break
      case '负载调整率': // 负载调整率
        if (loadRegulationList.value.length === 8) {
          ElMessage.warning('最多添加四项')
          return
        }
        loadRegulationList.value.push({
          params: '负载调整率',
          dataType: '2',
          technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
          technicalIndex: '', // 技术指标
          outputChannel: '', // 输出通道
          unit: '', // 单位
          editable: true,
          loadSituation: '1', // 负载情况  1 空载  2 满载
        },
        {
          params: '负载调整率',
          dataType: '2',
          technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
          technicalIndex: '', // 技术指标
          outputChannel: '', // 输出通道
          unit: '', // 单位
          editable: true,
          loadSituation: '2', // 负载情况  1 空载  2 满载
        })
        break
      case '电压表示值误差': // 电压表示值误差
        // voltageRepresentationValueErrorList 1数字式、2指针式
        if (form.value.ammeterDirectType === '1') {
          //  数字式
          voltageRepresentationValueErrorList.value.push({
            params: '电压表示值误差',
            dataType: '3',
            dataTypeType: '1',
            outputChannel: '', // 输出通道
            technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
            unit: '', // 单位
            measureIndicationValue: '', // 被检表示值
            paramsa: '', // 误差参数a    **目前缺少该参数
            paramsb: '', // 误差参数b    **目前缺少该参数
            maximumError: '', // 最大允许误差
            resolution: '0.0001', // 分辨力
            editable: true,
          })
        }
        else {
          // 指针式
          voltageRepresentationValueErrorList.value.push({
            params: '电压表示值误差',
            dataType: '3',
            dataTypeType: '2',
            outputChannel: '', // 输出通道
            technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
            unit: '', // 单位
            measureIndicationValue: '', // 被检表示值
            paramsa: '', // 准确度a    **目前缺少该参数
            paramsb: '', // 指针式仪表满量程值 **目前缺少该参数
            maximumError: '1', // 最大允许误差
            resolution: '0.0001', // 分辨力
            editable: true,
          })
        }
        break
      case '电流表示值误差(直接测量)': // 电流表示值误差(直接测量)
        // 1数字式、2指针式
        if (form.value.ammeterDirectType === '1') {
          //  数字式
          ammeterDirectList.value.push({
            params: '电流表示值误差(直接测量)',
            dataType: '4',
            dataTypeType: '1',
            outputChannel: '', // 输出通道
            technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
            unit: '', // 单位
            measureIndicationValue: '', // 被检表示值
            paramsa: '', // 误差参数a    **目前缺少该参数
            paramsb: '', // 误差参数b    **目前缺少该参数
            maximumError: '', // 最大允许误差
            resolution: '0.0001', // 分辨力
            editable: true,
          })
        }
        else {
          // 指针式
          ammeterDirectList.value.push({
            params: '电流表示值误差(直接测量)',
            dataType: '4',
            dataTypeType: '2',
            outputChannel: '', // 输出通道
            technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
            unit: '', // 单位
            measureIndicationValue: '', // 被检表示值
            paramsa: '', // 准确度a    **目前缺少该参数
            paramsb: '', // 指针式仪表满量程值 **目前缺少该参数
            maximumError: '1', // 最大允许误差
            resolution: '0.0001', // 分辨力
            editable: true,
          })
        }
        break
      case '电流表示值误差(间接测量)': // 电流表示值误差(间接测量)
        // 1数字式、2指针式
        if (form.value.ammeterIndirectType === '1') {
          //  数字式
          ammeterIndirectList.value.push({
            params: '电流表示值误差(间接测量)',
            dataType: '5',
            dataTypeType: '1',
            outputChannel: '', // 输出通道
            technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
            unit: '', // 单位
            measureIndicationValue: '', // 被检表示值
            paramsa: '', // 误差参数a    **目前缺少该参数
            paramsb: '', // 误差参数b    **目前缺少该参数
            maximumError: '', // 最大允许误差
            resolution: '0.0001', // 分辨力
            standardResistanceValue: '', // 标准电阻值
            standardResistanceValueUnit: '', // 标准电阻值单位
            editable: true,
          })
        }
        else {
          // 指针式
          ammeterIndirectList.value.push({
            params: '电流表示值误差(间接测量)',
            dataType: '5',
            dataTypeType: '2',
            outputChannel: '', // 输出通道
            technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
            unit: '', // 单位
            measureIndicationValue: '', // 被检表示值
            paramsa: '', // 准确度a    **目前缺少该参数
            paramsb: '', // 指针式仪表满量程值 **目前缺少该参数
            maximumError: '1', // 最大允许误差
            standardResistanceValue: '', // 标准电阻值
            standardResistanceValueUnit: '', // 标准电阻值单位
            editable: true,
          })
        }
        break
      case '纹波电压': // 纹波电压
        rippleVoltageList.value.push({
          params: '纹波电压',
          dataType: '6',
          technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
          technicalIndex: 0, // 技术指标
          outputChannel: '', // 输出通道
          unit: '', // 单位
          editable: true,
        })
        break
      case '输出电压短期稳定性': // 输出电压短期稳定性
        outputVoltageStabilityList.value.push({
          params: '输出电压短期稳定性',
          dataType: '7',
          technicalIndexSymbol: form.value.technicalIndexSymbol, // 技术指标前符号
          technicalIndex: '', // 技术指标
          outputChannel: '', // 输出通道
          unit: '', // 单位
          editable: true,
        })
        break
    }
  }
}
/**
 * 删除行公共方法
 * @param checkoutList 选中的数组
 * @param list 操作的数组
 */
const delRow = (checkoutList: IList[], list: IList[], title: string) => {
  if (!checkoutList.length) {
    ElMessage.warning('请选中要删除的行')
  }
  else {
    let data = [] as any[]
    data = list.filter((item: any) => {
      return !checkoutList.includes(item)
    })
    switch (title) {
      case '电源电压调整率': // 电源电压调整率
        lineVoltageRegulationList.value = data
        break
      case '负载调整率': // 负载调整率
        loadRegulationList.value = loadRegulationList.value.filter((item: any) => {
          const needDelte = [...new Set(checkoutList.map(item => item.outputChannel))]
          return !needDelte.includes(item.outputChannel)
        })
        break
      case '电压表示值误差': // 电压表示值误差
        voltageRepresentationValueErrorList.value = data
        break
      case '电流表示值误差(直接测量)': // 电流表示值误差(直接测量)
        ammeterDirectList.value = data
        break
      case '电流表示值误差(间接测量)': // 电流表示值误差(间接测量)
        ammeterIndirectList.value = data
        break
      case '纹波电压': // 纹波电压
        rippleVoltageList.value = data
        break
      case '输出电压短期稳定性': // 输出电压短期稳定性
        outputVoltageStabilityList.value = data
        break
    }
  }
}
// ---------------------------------------------校验---------------------------------------------------
// 校验表格(点击保存的时候用、生成标准器示值)
function checkList(list: any[], columns: any[], title: string) {
  return useCheckList(list, columns, title)
}
// 校验所有表格
function checkAllList() {
  const reultArr = []
  for (const i in columnsDict) {
    reultArr.push(useCheckList(listDict[i], columnsDict[i], i))
  }
  return reultArr.map((item: boolean) => item)
}
// ------------------------------------------------------------------------------------------------
const calculateResult = (title: string) => {

}
// 点击计算结果--上方表格计算
const calculateDataTop = () => {

}
// 点击生成辅助接地电阻--下面表格计算
const calculateDataBottom = () => {

}
// -----------------------------------------------------------------------------------------------------
// watch(() => props.list, (newVal) => { // 检定项表格
//   if (newVal) {
//     list.value = [...newVal]
//   }
// })
// 电压表示值误差、监听电流表示值误差(直接测量)
watch(() => [form.value.voltageRepresentationValueErrorType, form.value.ammeterDirectType], (newValue) => {
  console.log(newValue, 'newValue')
  switch (newValue[0]) { // 电压表示值误差
    case '2': // 指针式
      columns_voltage_representation.value = columns_voltage_representation_value_error_pointer.value
      voltageRepresentationValueErrorList.value = []
      break
    default:// 数字式
      columns_voltage_representation.value = columns_voltage_representation_value_error_number.value
      voltageRepresentationValueErrorList.value = []
  }
  switch (newValue[1]) { // 监听电流表示值误差(直接测量)
    case '2': // 指针式
      columns_ammeter_direct.value = columns_voltage_representation_value_error_pointer.value
      ammeterDirectList.value = []
      break
    default:// 数字式
      columns_ammeter_direct.value = columns_voltage_representation_value_error_number.value
      ammeterDirectList.value = []
  }
  console.log(columns_ammeter_direct.value, 'columns_ammeter_direct.value')
})
// 监听电流表示值误差(间接测量)
watch(() => form.value.ammeterIndirectType, (newValue) => {
  if (newValue === '2') { // 指针式
    columns_ammeter_indirect.value = columns_ammeter_indirect_pointer.value
  }
  else { // 数字式
    columns_ammeter_indirect.value = columns_ammeter_indirect_number.value
  }
  ammeterIndirectList.value = []
})

// 监听 输出通道 修改下拉框内容
const changeLoadSituationa = (value: any, index: number, title: string, type: string, list: IList[], item: string) => {
  if (title !== '输出通道') { return }
  if (type === 'change' && item === '负载调整率') {
    // 1.判断奇偶修改对应的 输出通道
    if (Number(index) % 2 === 0) {
      loadRegulationList.value[index + 1].outputChannel = value
    }
    else {
      loadRegulationList.value[index - 1].outputChannel = value
    }
  }
  // 2.限制下拉框内容
  setLoadSituation(typeof value === 'string' ? value : list[index].outputChannel as string, list)
}
// ---------------------------------------------获取字典---------------------------------------------------
const TechnicalIndexSymbolList = ref<{ value: string;name: string;id: string }[]>([]) // 技术指标前符号
const OutputChannelList = ref<{ value: string;name: string;id: string }[]>([]) // 输出通道
const unitList = ref<{ value: string;name: string;id: string }[]>([]) // 单位
const unitList1 = ref<{ value: string;name: string;id: string }[]>([]) // 单位 (直接测量/间接测量)
const RegulatorOutputValue = ref<{ value: string;name: string;id: string }[]>([]) // 调压器输出值
const loadSituationList = ref<{ value: string;name: string;id: string }[]>([
  {
    name: '空载',
    value: '1',
    id: '1',
  },
  {
    name: '满载',
    value: '2',
    id: '2',
  },
]) // 负载情况
const OutputChannelAllList = ref<{ value: string;name: string;id: string }[]>([]) // 所有输出通道
const standardMaximumError = ref<{ value: string;name: string;id: string }[]>([]) // 最大允许误差公式
const typeList = [{
  value: '1',
  name: '数字式',
},
{
  value: '2',
  name: '指针式',
}]
// 每个table对应的下拉框内容 字典
const tableDict = ref<{ [key: string]: { value: string;name: string;id: string }[] }>({})
// 修改输出通道
function setLoadSituation(current: string, list: IList[]) {
  // 1. 已经选择的输出通道
  const selectLoadSituation = [...new Set(list.map((item: any) => item.outputChannel))].filter((item: string) => item !== current)
  // 2. 修改下拉框内容
  tableDict.value['输出通道'] = OutputChannelAllList.value.filter((item) => { return !selectLoadSituation.includes(item.value) })
}

const fecthDict = async () => {
  // 技术指标前符号
  const res1 = await getDictByCode('standardTechnicalIndexSymbol')
  TechnicalIndexSymbolList.value = res1.data
  // 输出通道
  const res2 = await getDictByCode('standardOutputChannel')
  OutputChannelList.value = res2.data
  OutputChannelAllList.value = JSON.parse(JSON.stringify(res2.data))
  // 单位
  const res3 = await getDictByCode('unitElectricalSignalV')
  unitList.value = res3.data
  //  调压器输出值
  const res4 = await getDictByCode('voltageRegulatorOutputValue')
  RegulatorOutputValue.value = res4.data
  // 最大允许误差公式
  const res5 = await getDictByCode('standardMaximumError')
  standardMaximumError.value = res5.data
  // 单位 (直接测量/间接测量)
  const res6 = await getDictByCode('unitElectricalSignalA')
  unitList1.value = res6.data
  // table字典
  tableDict.value = {
    输出通道: OutputChannelList.value,
    单位: unitList.value,
    调压器输出值: RegulatorOutputValue.value,
    负载情况: loadSituationList.value,
    最大允许误差: standardMaximumError.value,
  }
}
fecthDict()
// 获取技术指标前符号name
const getSymbolName = (value: string) => {
  return TechnicalIndexSymbolList.value.filter(item => item.value === value)[0].name || ''
}
// 获取任意下拉框
const getAnySelect = (text: string, title: string) => {
  if (text === '单位' && title.includes('测量')) {
    return unitList1.value
  }
  return tableDict.value[text]
}
// defineExpose({ list })
</script>

<template>
  <div style="padding: 0 10px;display: flex;justify-content: space-between;">
    <el-checkbox v-model="form.appearanceFunctionCheck" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
      外观及功能性检查
    </el-checkbox>
    <div style="display: flex;">
      <div style="width: 70px;margin-right: 10px;white-space: nowrap;line-height: 30px;">
        通用规则:
      </div>
      <el-select
        v-model="form.technicalIndexSymbol"
        placeholder="请选择"
        :disabled="pageType === 'detail'"
        class="full-width-input"
        style="margin-right: 10px;"
      >
        <el-option v-for="item of TechnicalIndexSymbolList" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </div>
  </div>
  <!-- 电源电压调整率 -->
  <detail-block title="">
    <div style="display: flex;justify-content: space-between;">
      <el-checkbox v-model="form.voltageRegulation" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
        电源电压调整率
      </el-checkbox>
      <div v-if="pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
        <el-button type="primary" @click="addRow(lineVoltageRegulationList, '电源电压调整率')">
          增加行
        </el-button>
        <el-button type="info" @click="delRow(lineVoltageRegulationCheckoutList, lineVoltageRegulationList, '电源电压调整率')">
          删除行
        </el-button>
      </div>
    </div>
    <template-table :data="lineVoltageRegulationList" :columns="columns_line_voltage_regulation" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '电源电压调整率')">
      <template #custom-column>
        <el-table-column
          v-for="item in columns_line_voltage_regulation"
          :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">
            <div style="display: flex;">
              <!-- 默认文字 -->
              <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
              <span v-if="scope.row.editable && item.type === 'text'">{{ scope.row[item.value] }}</span>
              <!-- 技术指标规则 -->
              <div v-if="item.text === '被检电源技术指标'" style="line-height: 30px;margin-right: 10px;">
                {{ getSymbolName(scope.row.technicalIndexSymbol) }}
              </div>
              <!-- {{ scope.row }} -->
              <el-select
                v-if="scope.row.editable && item.type === 'select'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
                @change="(value) => changeLoadSituationa(value, scope.$index, item.text, 'change', lineVoltageRegulationList, '电源电压调整率')"
                @focus="(value) => changeLoadSituationa(value, scope.$index, item.text, 'focus', lineVoltageRegulationList, '电源电压调整率')"
              >
                <el-option
                  v-for="citem in getAnySelect(item.text, '电源电压调整率')"
                  :key="citem.id"
                  :label="citem.name"
                  :value="citem.value"
                />
              </el-select>
              <el-input
                v-if="scope.row.editable && item.type === 'input'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
              />
              <div v-if="item.text === '被检电源技术指标'" style="line-height: 30px;margin-left: 10px;">
                %
              </div>
            </div>
          </template>
        </el-table-column>
      </template>
    </template-table>
  </detail-block>
  <!-- 负载调整率 -->
  <detail-block title="">
    <div style="display: flex;justify-content: space-between;">
      <el-checkbox v-model="form.loadRegulation" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
        负载调整率
      </el-checkbox>
      <div v-if="pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
        <el-button type="primary" @click="addRow(loadRegulationList, '负载调整率')">
          增加行
        </el-button>
        <el-button type="info" @click="delRow(loadRegulationCheckoutList, loadRegulationList, '负载调整率')">
          删除行
        </el-button>
      </div>
    </div>
    <template-table :data="loadRegulationList" :columns="columns_load_regulation" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '负载调整率')">
      <template #custom-column>
        <el-table-column
          v-for="item in columns_load_regulation"
          :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">
            <div style="display: flex;">
              <!-- 默认文字 -->
              <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
              <span v-if="scope.row.editable && item.type === 'text'">{{ scope.row[item.value] }}</span>
              <!-- 技术指标规则 -->
              <div v-if="item.text === '被检电源技术指标'" style="line-height: 30px;margin-right: 10px;">
                {{ getSymbolName(scope.row.technicalIndexSymbol) }}
              </div>
              <!-- {{ scope.row }} -->
              <el-select
                v-if="scope.row.editable && item.type === 'select'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
                :disabled="item.text === '负载情况'"
                @change="(value) => changeLoadSituationa(value, scope.$index, item.text, 'change', loadRegulationList, '负载调整率')"
                @focus="(value) => changeLoadSituationa(value, scope.$index, item.text, 'focus', loadRegulationList, '负载调整率')"
              >
                <el-option
                  v-for="citem in getAnySelect(item.text, '负载调整率')"
                  :key="citem.id"
                  :label="citem.name"
                  :value="citem.value"
                />
              </el-select>
              <el-input
                v-if="scope.row.editable && item.type === 'input'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
              />
              <div v-if="item.text === '被检电源技术指标'" style="line-height: 30px;margin-left: 10px;">
                %
              </div>
            </div>
          </template>
        </el-table-column>
      </template>
    </template-table>
  </detail-block>

  <!--  电压表示值误差 -->
  <detail-block title="">
    <div style="display: flex;justify-content: space-between;">
      <el-checkbox v-model="form.voltageRepresentError" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
        电压表示值误差
      </el-checkbox>
      <div v-if="pageType !== 'detail'" style="display: flex;padding: 0 10px;padding-bottom: 10px;">
        <!-- 选择类型:1数字式、2指针式 -->
        <el-select
          v-model="form.voltageRepresentationValueErrorType"
          placeholder="请选择"
          :disabled="pageType === 'detail'"
          class="full-width-input"
          style="margin-right: 10px;"
        >
          <el-option v-for="item of typeList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
        <el-button type="primary" @click="addRow(voltageRepresentationValueErrorList, '电压表示值误差')">
          增加行
        </el-button>
        <el-button type="info" @click="delRow(voltageRepresentationValueErrorCheckoutList, voltageRepresentationValueErrorList, '电压表示值误差')">
          删除行
        </el-button>
        <el-button type="primary" @click="calculateResult('电压表示值误差')">
          计算结果
        </el-button>
      </div>
    </div>
    <template-table :data="voltageRepresentationValueErrorList" :columns="columns_voltage_representation" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '电压表示值误差')">
      <template #custom-column>
        <el-table-column
          v-for="item in columns_voltage_representation"
          :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">
            <div style="display: flex;">
              <!-- 默认文字 -->
              <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
              <span v-if="scope.row.editable && item.type === 'text'">{{ scope.row[item.value] }}</span>
              <el-select
                v-if="scope.row.editable && item.type === 'select'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
                @change="(value) => changeLoadSituationa(value, scope.$index, item.text, 'change', voltageRepresentationValueErrorList, '电压表示值误差')"
                @focus="(value) => changeLoadSituationa(value, scope.$index, item.text, 'focus', voltageRepresentationValueErrorList, '电压表示值误差')"
              >
                <el-option
                  v-for="citem in getAnySelect(item.text, '电压表示值误差')"
                  :key="citem.id"
                  :label="citem.name"
                  :value="citem.value"
                />
              </el-select>
              <el-input
                v-if="scope.row.editable && item.type === 'input'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
              />
            </div>
          </template>
        </el-table-column>
      </template>
    </template-table>
  </detail-block>

  <!--  电流表示值误差(直接测量) -->
  <detail-block title="">
    <div style="display: flex;justify-content: space-between;">
      <el-checkbox v-model="form.currentRepresentErrorDirect" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
        电流表示值误差(直接测量)
      </el-checkbox>
      <div v-if="pageType !== 'detail'" style="display: flex;padding: 0 10px;padding-bottom: 10px;">
        <!-- 选择类型:1数字式、2指针式 -->
        <el-select
          v-model="form.ammeterDirectType"
          placeholder="请选择"
          :disabled="pageType === 'detail'"
          class="full-width-input"
          style="margin-right: 10px;"
        >
          <el-option v-for="item of typeList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
        <el-button type="primary" @click="addRow(ammeterDirectList, '电流表示值误差(直接测量)')">
          增加行
        </el-button>
        <el-button type="info" @click="delRow(ammeterDirectCheckoutList, ammeterDirectList, '电流表示值误差(直接测量)')">
          删除行
        </el-button>
        <el-button type="primary" @click="calculateResult('电流表示值误差(直接测量)')">
          计算结果
        </el-button>
      </div>
    </div>
    <template-table :data="ammeterDirectList" :columns="columns_ammeter_direct" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '电流表示值误差(直接测量)')">
      <template #custom-column>
        <el-table-column
          v-for="item in columns_ammeter_direct"
          :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">
            <div style="display: flex;">
              <!-- 默认文字 -->
              <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
              <span v-if="scope.row.editable && item.type === 'text'">{{ scope.row[item.value] }}</span>
              <el-select
                v-if="scope.row.editable && item.type === 'select'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
                @change="(value) => changeLoadSituationa(value, scope.$index, item.text, 'change', ammeterDirectList, '电流表示值误差(直接测量)')"
                @focus="(value) => changeLoadSituationa(value, scope.$index, item.text, 'focus', ammeterDirectList, '电流表示值误差(直接测量)')"
              >
                <el-option
                  v-for="citem in getAnySelect(item.text, '电流表示值误差(直接测量)')"
                  :key="citem.id"
                  :label="citem.name"
                  :value="citem.value"
                />
              </el-select>
              <el-input
                v-if="scope.row.editable && item.type === 'input'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
              />
            </div>
          </template>
        </el-table-column>
      </template>
    </template-table>
  </detail-block>

  <!--  电流表示值误差(间接测量) -->
  <detail-block title="">
    <div style="display: flex;justify-content: space-between;">
      <el-checkbox v-model="form.currentRepresentErrorIndirect" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
        电流表示值误差(间接测量)
      </el-checkbox>
      <div v-if="pageType !== 'detail'" style="display: flex;padding: 0 10px;padding-bottom: 10px;">
        <!-- 选择类型:1数字式、2指针式 -->
        <el-select
          v-model="form.ammeterIndirectType"
          placeholder="请选择"

          :disabled="pageType === 'detail'"
          class="full-width-input"
          style="margin-right: 10px;"
        >
          <el-option v-for="item of typeList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
        <el-button type="primary" @click="addRow(ammeterIndirectList, '电流表示值误差(间接测量)')">
          增加行
        </el-button>
        <el-button type="info" @click="delRow(ammeterIndirectCheckoutList, ammeterIndirectList, '电流表示值误差(间接测量)')">
          删除行
        </el-button>
        <el-button type="primary" @click="calculateResult('电流表示值误差(间接测量)')">
          计算结果
        </el-button>
      </div>
    </div>
    <template-table :data="ammeterIndirectList" :columns="columns_ammeter_indirect" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '电流表示值误差(间接测量)')">
      <template #custom-column>
        <el-table-column
          v-for="item in columns_ammeter_indirect"
          :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">
            <div style="display: flex;">
              <!-- 默认文字 -->
              <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
              <span v-if="scope.row.editable && item.type === 'text'">{{ scope.row[item.value] }}</span>
              <el-select
                v-if="scope.row.editable && item.type === 'select'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
                @change="(value) => changeLoadSituationa(value, scope.$index, item.text, 'change', ammeterIndirectList, '电流表示值误差(间接测量)')"
                @focus="(value) => changeLoadSituationa(value, scope.$index, item.text, 'focus', ammeterIndirectList, '电流表示值误差(间接测量)')"
              >
                <el-option
                  v-for="citem in getAnySelect(item.text, '电流表示值误差(间接测量)')"
                  :key="citem.id"
                  :label="citem.name"
                  :value="citem.value"
                />
              </el-select>
              <el-input
                v-if="scope.row.editable && item.type === 'input'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
              />
            </div>
          </template>
        </el-table-column>
      </template>
    </template-table>
  </detail-block>

  <!-- 纹波电压 -->
  <detail-block title="">
    <div style="display: flex;justify-content: space-between;">
      <el-checkbox v-model="form.rippleVoltage" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
        纹波电压
      </el-checkbox>
      <div v-if="pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
        <el-button type="primary" @click="addRow(rippleVoltageList, '纹波电压')">
          增加行
        </el-button>
        <el-button type="info" @click="delRow(rippleVoltageCheckoutList, rippleVoltageList, '纹波电压')">
          删除行
        </el-button>
      </div>
    </div>
    <template-table :data="rippleVoltageList" :columns="columns_ripple_voltage" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '纹波电压')">
      <template #custom-column>
        <el-table-column
          v-for="item in columns_ripple_voltage"
          :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">
            <div style="display: flex;">
              <!-- 默认文字 -->
              <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
              <span v-if="scope.row.editable && item.type === 'text'">{{ scope.row[item.value] }}</span>
              <!-- 技术指标规则 -->
              <div v-if="item.text === '被检电源技术指标'" style="line-height: 30px;margin-right: 10px;">
                {{ getSymbolName(scope.row.technicalIndexSymbol) }}
              </div>
              <el-select
                v-if="scope.row.editable && item.type === 'select'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
                @change="(value) => changeLoadSituationa(value, scope.$index, item.text, 'change', rippleVoltageList, '纹波电压')"
                @focus="(value) => changeLoadSituationa(value, scope.$index, item.text, 'focus', rippleVoltageList, '纹波电压')"
              >
                <el-option
                  v-for="citem in getAnySelect(item.text, '纹波电压')"
                  :key="citem.id"
                  :label="citem.name"
                  :value="citem.value"
                />
              </el-select>
              <el-input
                v-if="scope.row.editable && item.type === 'input'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
              />
              <el-input-number
                v-if="scope.row.editable && item.type === 'number'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;" controls-position="right"
              />
            </div>
          </template>
        </el-table-column>
      </template>
    </template-table>
  </detail-block>

  <!--  输出电压短期稳定性 -->
  <detail-block title="">
    <div style="display: flex;justify-content: space-between;">
      <el-checkbox v-model="form.voltageOutputStability" :checked="true" :true-label="1" :false-label="0" :disabled="pageType === 'detail'">
        输出电压短期稳定性
      </el-checkbox>
      <div v-if="pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
        <el-button type="primary" @click="addRow(outputVoltageStabilityList, '输出电压短期稳定性')">
          增加行
        </el-button>
        <el-button type="info" @click="delRow(outputVoltageStabilityCheckoutList, outputVoltageStabilityList, '输出电压短期稳定性')">
          删除行
        </el-button>
      </div>
    </div>
    <template-table :data="outputVoltageStabilityList" :columns="columns_output_voltage_stability" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '输出电压短期稳定性')">
      <template #custom-column>
        <el-table-column
          v-for="item in columns_output_voltage_stability"
          :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">
            <div style="display: flex;">
              <!-- 默认文字 -->
              <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
              <span v-if="scope.row.editable && item.type === 'text'">{{ scope.row[item.value] }}</span>
              <!-- 技术指标规则 -->
              <div v-if="item.text === '仪器技术指标'" style="line-height: 30px;margin-right: 10px;">
                {{ getSymbolName(scope.row.technicalIndexSymbol) }}
              </div>
              <el-select
                v-if="scope.row.editable && item.type === 'select'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
                @change="(value) => changeLoadSituationa(value, scope.$index, item.text, 'change', outputVoltageStabilityList, '输出电压短期稳定性')"
                @focus="(value) => changeLoadSituationa(value, scope.$index, item.text, 'focus', outputVoltageStabilityList, '输出电压短期稳定性')"
              >
                <el-option
                  v-for="citem in getAnySelect(item.text, '输出电压短期稳定性')"
                  :key="citem.id"
                  :label="citem.name"
                  :value="citem.value"
                />
              </el-select>
              <el-input
                v-if="scope.row.editable && item.type === 'input'" v-model="scope.row[item.value]"
                :placeholder="`${item.text}`" style="width: 100%;"
              />
              <div v-if="item.text === '仪器技术指标'" style="line-height: 30px;margin-left: 10px;">
                %
              </div>
            </div>
          </template>
        </el-table-column>
      </template>
    </template-table>
  </detail-block>
</template>