Newer
Older
xc-business-system / src / views / business / measure / item / components / fourteen / components / universalCounter.vue
lyg on 10 May 2024 49 KB 数据看板基础页面
<!-- 第14套:铯原子频率标准装置标准装置 -- 通用计数器 || 频率计数器 -->
<script lang="ts" setup name="TemplateDetailFourteenUniversalCount">
import { ElMessage } from 'element-plus'
import type { IList } from '../templateDetail-interface'
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'
import templateTable from '@/views/business/measure/item/components/second/templateTable.vue'
import { differenceArray, setSelectList } from '@/utils/Array'
import { clearSymbol, clearSymbolStart } from '@/utils/String'
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: '',
  },
})
// 通用计数器对应form
const currencyFomr = {
  appearanceFunctionCheck: 1, // 外观及功能性检查
  crystalOscillatorStartupCharacter: 1, // 晶振开机特性
  crystalOscillatorStability: 1, // 晶振1s频率稳定度
  crystalOscillatorDeviation: 1, // 晶振相对频率偏差
  crystalOscillatorReproducibility: 1, // 晶振频率复现性
  crystalOscillatorDailyAgingRate: 1, // 晶振日老化率
  frequencyMeasureRange: 1, // 频率测量范围、输入灵敏度
  frequencyMeasureError: 1, // 频率测量误差
  periodicMeasureRange: 1, // 周期测量范围、输入灵敏度
  periodicMeasureError: 1, // 周期测量误差
  timeIntervalMeasureRange: 1, // 时间间隔测量范围及测量误差
}
// 微波计数器对应form
const rippleForm = {
  appearanceFunctionCheck: 1, // 外观及功能性检查
  crystalOscillatorStartupCharacter: 1, // 晶振开机特性
  crystalOscillatorStability: 1, // 晶振1s频率稳定度
  crystalOscillatorDeviation: 1, // 晶振相对频率偏差
  crystalOscillatorReproducibility: 1, // 晶振频率复现性
  crystalOscillatorDailyAgingRate: 1, // 晶振日老化率
  frequencyMeasureRange: 1, // 频率测量范围、输入灵敏度
  frequencyMeasureError: 1, // 频率测量误差
}
const form = ref(props.itemCategoryName === '通用计数器' ? currencyFomr : rippleForm)
watch(() => props.form, (newVal) => {
  form.value = JSON.parse(JSON.stringify(newVal))
})
const list = ref<IList[]>([]) // 全部数据
const crystalOscillatorStartupCharacterList = ref<IList[]>([]) // 晶振开机特性
const crystalOscillatorStabilityList = ref<IList[]>([]) // 晶振1s频率稳定度
const crystalOscillatorDeviationList = ref<IList[]>([]) // 晶振相对频率偏差
const crystalOscillatorReproducibilityList = ref<IList[]>([]) // 晶振频率复现性
const crystalOscillatorDailyAgingRateList = ref<IList[]>([]) // 晶振日老化率
const frequencyMeasureRangeList = ref<IList[]>([]) // 频率测量范围、输入灵敏度
const frequencyMeasureErrorList = ref<IList[]>([]) // 频率测量误差
const periodicMeasureRangeList = ref<IList[]>([]) // 周期测量范围、输入灵敏度
const periodicMeasureErrorList = ref<IList[]>([]) //  周期测量误差
const timeIntervalMeasureRangeList = ref<IList[]>([]) // 时间间隔测量范围及测量误差

// 表格数据对应 list 字典
const listDict = ref<{ [key: string]: any }>()
watch(() => [crystalOscillatorStartupCharacterList.value, crystalOscillatorStabilityList.value, crystalOscillatorDeviationList.value, crystalOscillatorReproducibilityList.value, crystalOscillatorDailyAgingRateList.value, frequencyMeasureRangeList.value, frequencyMeasureErrorList.value, periodicMeasureRangeList.value, periodicMeasureErrorList.value, timeIntervalMeasureRangeList.value], () => {
  listDict.value = {
    '1-晶振开机特性': crystalOscillatorStartupCharacterList.value,
    '2-晶振1s频率稳定度': crystalOscillatorStabilityList.value,
    '3-晶振相对频率偏差': crystalOscillatorDeviationList.value,
    '4-晶振频率复现性': crystalOscillatorReproducibilityList.value,
    '5-晶振日老化率': crystalOscillatorDailyAgingRateList.value,
    '6-频率测量范围、输入灵敏度': frequencyMeasureRangeList.value,
    '6-频率测量范围、输入灵敏度及最大输入电平': frequencyMeasureRangeList.value,
    '7-频率测量误差': frequencyMeasureErrorList.value,
    '8-周期测量范围、输入灵敏度': periodicMeasureRangeList.value,
    '9-周期测量误差': periodicMeasureErrorList.value,
    '10-时间间隔测量范围及测量误差': timeIntervalMeasureRangeList.value,
  }
  list.value = []
  for (const i in listDict.value) {
    list.value = [...list.value, ...listDict.value[i]]
  }
}, {
  deep: true,
})
// 表格对应的 选择状态
let chekedDict = {} as { [key: string]: any }
watch(() => [props.form, form.value], () => {
  chekedDict = {
    '1-晶振开机特性': form.value.crystalOscillatorStartupCharacter,
    '2-晶振1s频率稳定度': form.value.crystalOscillatorStability,
    '3-晶振相对频率偏差': form.value.crystalOscillatorDeviation,
    '4-晶振频率复现性': form.value.crystalOscillatorReproducibility,
    '5-晶振日老化率': form.value.crystalOscillatorDailyAgingRate,
    '6-频率测量范围、输入灵敏度': form.value.frequencyMeasureRange,
    '6-频率测量范围、输入灵敏度及最大输入电平': form.value.frequencyMeasureRange,
    '7-频率测量误差': form.value.frequencyMeasureError,
    '8-周期测量范围、输入灵敏度': form.value.periodicMeasureRange,
    '9-周期测量误差': form.value.periodicMeasureError,
    '10-时间间隔测量范围及测量误差': form.value.timeIntervalMeasureRange,
  }
  if (props.itemCategoryName === '通用计数器') {
    delete chekedDict['6-频率测量范围、输入灵敏度及最大输入电平']
  }
  else {
    delete chekedDict['6-频率测量范围、输入灵敏度']
  }
}, {
  deep: true,
})
// ----------------------------------------表头------------------------------------------------
const columns_crystal_oscillator_startup_character = ref<TableColumn[]>([ // 晶振开机特性
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '闸门时间', value: 'gateTime', align: 'center', required: true, type: 'select', bind: 'value' },
  { text: '倍增次数', value: 'multiplyFrequency', align: 'center', required: false, type: 'number' },
  { text: '组数', value: 'sampleGroupNumber', align: 'center', required: true, type: 'number' },
  { text: '测量间隔', value: 'measureInterval', align: 'center', required: true, type: 'number' },
  { text: '测量间隔单位', value: 'measureIntervalUnit', align: 'center', required: true, type: 'select' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_crystal_oscillator_stability = ref<TableColumn[]>([ // 晶振1s频率稳定度
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '闸门时间', value: 'gateTime', align: 'center', required: true, type: 'select', bind: 'value' },
  { text: '倍增次数', value: 'multiplyFrequency', align: 'center', required: false, type: 'number' },
  { text: '组数', value: 'sampleGroupNumber', align: 'center', required: true, type: 'number' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度uc', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_crystal_oscillator_deviation = ref<TableColumn[]>([ // 晶振相对频率偏差
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '闸门时间', value: 'gateTime', align: 'center', required: true, type: 'select', bind: 'value' },
  { text: '倍增次数', value: 'multiplyFrequency', align: 'center', required: false, type: 'number' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_crystal_oscillator_reproducibility = ref<TableColumn[]>([ // 晶振频率复现性
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '闸门时间', value: 'gateTime', align: 'center', required: true, type: 'select', bind: 'value' },
  { text: '倍增次数', value: 'multiplyFrequency', align: 'center', required: false, type: 'number' },
  { text: 'T1/T3', value: 'tOne', align: 'center', required: true, type: 'number' },
  { text: 'T1/T3单位', value: 'tOneUnit', align: 'center', required: true, type: 'select' },
  { text: 'T2', value: 'tTwo', align: 'center', required: true, type: 'number' },
  { text: 'T2单位', value: 'tTwoUnit', align: 'center', required: true, type: 'select' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_crystal_oscillator_dailyAging_rate = ref<TableColumn[]>([ // 晶振日老化率
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '被测信号频率', value: 'testedSignalFrequency', align: 'center', required: true, type: 'select' },
  { text: '闸门时间', value: 'gateTime', align: 'center', required: true, type: 'select', bind: 'value' },
  { text: '取样时间', value: 'sampleTime', align: 'center', required: true, type: 'number' },
  { text: '取样时间单位', value: 'sampleTimeUnit', align: 'center', required: true, type: 'select' },
  { text: '采样组数', value: 'sampleGroupNumber', align: 'center', required: true, type: 'number' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_frequency_measure_range = ref<TableColumn[]>( // 频率测量范围、输入灵敏度
  props.itemCategoryName === '通用计数器'
    ? [
        { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
        { text: '通道', value: 'thoroughfare', align: 'center', required: true, type: 'select' },
        { text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'number' },
        { text: '标称值单位', value: 'nominalValueUnit', align: 'center', required: true, type: 'select' },
        { text: '信号源输出幅度', value: 'signalSourceOutputAmplitude', align: 'center', required: true, type: 'number' },
        { text: '信号源输出幅度单位', value: 'signalSourceOutputAmplitudeUnit', align: 'center', required: true, type: 'select' },
        { text: '输入灵敏度技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'number' },
        { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
      ]
    : [
        { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
        { text: '通道', value: 'thoroughfare', align: 'center', required: true, type: 'select' },
        { text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'number' },
        { text: '标称值单位', value: 'nominalValueUnit', align: 'center', required: true, type: 'select' },
        { text: '信号源输出幅度', value: 'signalSourceOutputAmplitude', align: 'center', required: true, type: 'number' },
        { text: '信号源输出幅度单位', value: 'signalSourceOutputAmplitudeUnit', align: 'center', required: true, type: 'select' },
        { text: '信号源最大输入电平', value: 'signalSourceMaxInputLevel', align: 'center', required: true, type: 'number' },
        { text: '信号源最大输入电平单位', value: 'signalSourceMaxInputLevelUnit', align: 'center', required: true, type: 'select' },
        { text: '输入灵敏度技术指标', value: 'technicalIndex', align: 'center', width: '200', required: false, type: 'number' },
        { text: '最大输入电平技术指标', value: 'otherTechnicalIndex', align: 'center', width: '200', required: false, type: 'number' },
        { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
      ])

const columns_frequency_measure_error = ref<TableColumn[]>([ // 频率测量误差
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '通道', value: 'thoroughfare', align: 'center', required: true, type: 'select' },
  { text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'number' },
  { text: '标称值单位', value: 'nominalValueUnit', align: 'center', required: true, type: 'select' },
  { text: '闸门时间', value: 'gateTime', align: 'center', required: true, type: 'select', bind: 'value' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_periodic_measure_range = ref<TableColumn[]>([ // 周期测量范围、输入灵敏度
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '通道', value: 'thoroughfare', align: 'center', required: true, type: 'select' },
  { text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'number' },
  { text: '标称值单位', value: 'nominalValueUnit', align: 'center', required: true, type: 'select' },
  { text: '信号源输出幅度', value: 'signalSourceOutputAmplitude', align: 'center', required: true, type: 'number' },
  { text: '信号源输出幅度单位', value: 'signalSourceOutputAmplitudeUnit', align: 'center', required: true, type: 'select' },
  { text: '输入灵敏度技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'number' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_periodic_measure_error = ref<TableColumn[]>([ // 周期测量误差
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '通道', value: 'thoroughfare', align: 'center', required: true, type: 'select' },
  { text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'number' },
  { text: '标称值单位', value: 'nominalValueUnit', align: 'center', required: true, type: 'select' },
  { text: '闸门时间', value: 'gateTime', align: 'center', required: true, type: 'select', bind: 'value' },
  { text: '信号源输出幅度', value: 'signalSourceOutputAmplitudeUnit', align: 'center', required: true, type: 'number' },
  { text: '信号源输出幅度单位', value: 'signalSourceMaxInputLevelUnit', align: 'center', required: true, type: 'select' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
const columns_time_interval_measure_range = ref<TableColumn[]>([ // 时间间隔测量范围及测量误差
  { text: '检定项目', value: 'params', align: 'center', required: false, type: 'text' },
  { text: '标称值', value: 'nominalValue', align: 'center', required: true, type: 'number' },
  { text: '标称值单位', value: 'nominalValueUnit', align: 'center', required: true, type: 'select' },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: false, type: 'notation' },
  { text: '不确定度U(k=2)', value: 'urel', align: 'center', required: false, type: 'notation' },
])
// --------------------------------表格操作---------------------------------------------------
// 表格对应 columns字典
const columnsDict = ref<{ [key: string]: any }>(
  {
    '1-晶振开机特性': columns_crystal_oscillator_startup_character.value,
    '2-晶振1s频率稳定度': columns_crystal_oscillator_stability.value,
    '3-晶振相对频率偏差': columns_crystal_oscillator_deviation.value,
    '4-晶振频率复现性': columns_crystal_oscillator_reproducibility.value,
    '5-晶振日老化率': columns_crystal_oscillator_dailyAging_rate.value,
    '6-频率测量范围、输入灵敏度': columns_frequency_measure_range.value,
    '6-频率测量范围、输入灵敏度及最大输入电平': columns_frequency_measure_range.value,
    '7-频率测量误差': columns_frequency_measure_error.value,
    '8-周期测量范围、输入灵敏度': columns_periodic_measure_range.value,
    '9-周期测量误差': columns_periodic_measure_error.value,
    '10-时间间隔测量范围及测量误差': columns_time_interval_measure_range.value,
  },
)
/**
 * 增加行公共方法
 * @param list 要操作的数组
 * @param title 操作的表格
 */
const addRow = (list: IList[], title: string, index: string) => {
  if (checkList(list, columnsDict.value[`${index}-${title}`], `${title}表格`)) {
    const params = {
      gateTime: '10', // 闸门时间
      gateTimeUnit: 's', // 闸门时间
      multiplyFrequency: '', // 倍增次数
      // sampleGroupNumber: '', // 组数
      measureInterval: '', // 测量间隔
      measureIntervalUnit: '', // 测量间隔单位
      technicalIndex: '', // 上升时间技术指标
      technicalIndexSymbol: '±', // 上升时间技术指标符号
      urel: '', // 不确定度U(k=2)
      tOne: '1',
      tOneUnit: '',
      tTwo: '24',
      tTwoUnit: '',
      tThree: '',
      tThreeUnit: '',
      sampleGroupNumber: '', // 采样组数
      sampleTime: '', // 取样时间
      sampleTimeUnit: '', // 取样时间单位
      testedSignalFrequency: '', // 被测信号频率
      testedSignalFrequencyUnit: 'MHz', // 被测信号频率单位
      nominalValue: '',
      unit: '',
      signalSourceOutputAmplitude: '',
      signalSourceOutputAmplitudeUnit: '',
      signalSourceMaxInputLevel: '',
      signalSourceMaxInputLevelUnit: '',
      otherTechnicalIndex: '',
      otherTechnicalIndexSymbol: '±',
    }
    switch (title) {
      case '晶振开机特性': // 晶振开机特性
        crystalOscillatorStartupCharacterList.value.length
          ? crystalOscillatorStartupCharacterList.value.push(JSON.parse(JSON.stringify(crystalOscillatorStartupCharacterList.value[crystalOscillatorStartupCharacterList.value.length - 1])))
          : crystalOscillatorStartupCharacterList.value.push({
            dataType: '1',
            params: '晶振开机特性',
            ...params,
            technicalIndexSymbol: '<', // 上升时间技术指标符号
            sampleGroupNumber: '8',
            editable: true,
          } as any)
        break
      case '晶振1s频率稳定度': // 晶振1s频率稳定度
        crystalOscillatorStabilityList.value.length
          ? crystalOscillatorStabilityList.value.push(JSON.parse(JSON.stringify(crystalOscillatorStabilityList.value[crystalOscillatorStabilityList.value.length - 1])))
          : crystalOscillatorStabilityList.value.push({
            dataType: '2',
            params: '晶振1s频率稳定度',
            ...params,
            technicalIndexSymbol: '<', // 上升时间技术指标符号
            sampleGroupNumber: '101',
            editable: true,
          } as any)
        break
      case '晶振相对频率偏差': // 晶振相对频率偏差
        crystalOscillatorDeviationList.value.length
          ? crystalOscillatorDeviationList.value.push(JSON.parse(JSON.stringify(crystalOscillatorDeviationList.value[crystalOscillatorDeviationList.value.length - 1])))
          : crystalOscillatorDeviationList.value.push({
            dataType: '3',
            params: '晶振相对频率偏差',
            ...params,
            technicalIndexSymbol: '<', // 上升时间技术指标符号
            editable: true,
          } as any)
        break
      case '晶振频率复现性': // 晶振频率复现性
        crystalOscillatorReproducibilityList.value.length
          ? crystalOscillatorReproducibilityList.value.push(JSON.parse(JSON.stringify(crystalOscillatorReproducibilityList.value[crystalOscillatorReproducibilityList.value.length - 1])))
          : crystalOscillatorReproducibilityList.value.push({
            dataType: '4',
            params: '晶振频率复现性',
            ...params,
            technicalIndexSymbol: '<', // 上升时间技术指标符号
            editable: true,
          } as any)
        break
      case '晶振日老化率': // 晶振日老化率
        crystalOscillatorDailyAgingRateList.value.length
          ? crystalOscillatorDailyAgingRateList.value.push(JSON.parse(JSON.stringify(crystalOscillatorDailyAgingRateList.value[crystalOscillatorDailyAgingRateList.value.length - 1])))
          : crystalOscillatorDailyAgingRateList.value.push({
            dataType: '5',
            params: '晶振日老化率',
            ...params,
            sampleTime: '12',
            sampleGroupNumber: '15',
            editable: true,
          } as any)
        break
      case '频率测量范围、输入灵敏度': // 频率测量范围、输入灵敏度
        frequencyMeasureRangeList.value.length
          ? frequencyMeasureRangeList.value.push(JSON.parse(JSON.stringify(frequencyMeasureRangeList.value[frequencyMeasureRangeList.value.length - 1])))
          : frequencyMeasureRangeList.value.push({
            dataType: '6',
            params: '频率测量范围、输入灵敏度',
            ...params,
            technicalIndexSymbol: '<', // 上升时间技术指标符号
            editable: true,
          } as any)
        break
      case '频率测量范围、输入灵敏度及最大输入电平': // 频率测量范围、输入灵敏度及最大输入电平
        frequencyMeasureRangeList.value.length
          ? frequencyMeasureRangeList.value.push(JSON.parse(JSON.stringify(frequencyMeasureRangeList.value[frequencyMeasureRangeList.value.length - 1])))
          : frequencyMeasureRangeList.value.push({
            dataType: '6',
            params: '频率测量范围、输入灵敏度及最大输入电平',
            ...params,
            technicalIndexSymbol: '<', // 上升时间技术指标符号
            editable: true,
          } as any)
        break
      case '频率测量误差': // 频率测量误差
        frequencyMeasureErrorList.value.length
          ? frequencyMeasureErrorList.value.push(JSON.parse(JSON.stringify(frequencyMeasureErrorList.value[frequencyMeasureErrorList.value.length - 1])))
          : frequencyMeasureErrorList.value.push({
            dataType: '7',
            params: '频率测量误差',
            ...params,
            technicalIndexSymbol: '<', // 上升时间技术指标符号
            editable: true,
          } as any)
        break
      case '周期测量范围、输入灵敏度': // 周期测量范围、输入灵敏度
        periodicMeasureRangeList.value.length
          ? periodicMeasureRangeList.value.push(JSON.parse(JSON.stringify(periodicMeasureRangeList.value[periodicMeasureRangeList.value.length - 1])))
          : periodicMeasureRangeList.value.push({
            dataType: '8',
            params: '周期测量范围、输入灵敏度',
            ...params,
            editable: true,
          } as any)
        break
      case '周期测量误差': // 周期测量误差
        periodicMeasureErrorList.value.length
          ? periodicMeasureErrorList.value.push(JSON.parse(JSON.stringify(periodicMeasureErrorList.value[periodicMeasureErrorList.value.length - 1])))
          : periodicMeasureErrorList.value.push({
            dataType: '9',
            params: '周期测量误差',
            ...params,
            editable: true,
          } as any)
        break
      case '时间间隔测量范围及测量误差': // 时间间隔测量范围及测量误差
        timeIntervalMeasureRangeList.value.length
          ? timeIntervalMeasureRangeList.value.push(JSON.parse(JSON.stringify(timeIntervalMeasureRangeList.value[timeIntervalMeasureRangeList.value.length - 1])))
          : timeIntervalMeasureRangeList.value.push({
            dataType: '10',
            params: '时间间隔测量范围及测量误差',
            ...params,
            editable: true,
          } as any)
        break
    }
  }
}
/**
 * 删除行公共方法
 * @param checkoutList 选中的数组
 * @param list 操作的数组
 */
const delRow = (checkoutList: IList[], list: IList[], title: string) => {
  if (!checkoutList.length) {
    ElMessage.warning('请选中要删除的行')
  }
  else {
    let data = [] as any[]
    data = differenceArray(list, checkoutList)
    switch (title) {
      case '晶振开机特性': // 频率显示
        crystalOscillatorStartupCharacterList.value = data
        break
      case '晶振1s频率稳定度': // 晶振1s频率稳定度
        crystalOscillatorStabilityList.value = data
        break
      case '晶振相对频率偏差': // 晶振相对频率偏差
        crystalOscillatorDeviationList.value = data
        break
      case '晶振频率复现性': // 晶振频率复现性
        crystalOscillatorReproducibilityList.value = data
        break
      case '晶振日老化率': // 晶振日老化率
        crystalOscillatorDailyAgingRateList.value = data
        break
      case '频率测量范围、输入灵敏度': // 频率测量范围、输入灵敏度
        frequencyMeasureRangeList.value = data
        break
      case '频率测量误差': // 频率测量误差
        frequencyMeasureErrorList.value = data
        break
      case '周期测量范围、输入灵敏度': // 周期测量范围、输入灵敏度
        periodicMeasureRangeList.value = data
        break
      case '周期测量误差': // 周期测量误差
        periodicMeasureErrorList.value = data
        break
      case '时间间隔测量范围及测量误差': // 时间间隔测量范围及测量误差
        timeIntervalMeasureRangeList.value = data
        break
    }
  }
}
// ---------------------------------------------校验---------------------------------------------------
// 校验表格(点击保存的时候用、生成标准器示值)
function checkList(list: any[], columns: any[], title: string) {
  return useCheckList(list, columns, title)
}
// 校验所有表格
function checkAllList() {
  let result = true
  for (const i in columnsDict.value) {
    if (!Number(chekedDict[i])) {
      result = true
    }
    else {
      const requireLength = !!((chekedDict[i] === '1' || chekedDict[i] === 1) && chekedDict[i])
      if (!useCheckList(listDict.value[i], columnsDict.value[i], i.substring(2), '', '', '', requireLength)) {
        result = false
        break
      }
    }
  }
  return result
}
// -----------------------------------------------------------------------------------------------------
const clearAllList = () => {
  list.value = []
  crystalOscillatorStartupCharacterList.value = []
  crystalOscillatorStabilityList.value = []
  crystalOscillatorDeviationList.value = []
  crystalOscillatorReproducibilityList.value = []
  crystalOscillatorDailyAgingRateList.value = []
  frequencyMeasureRangeList.value = []
  frequencyMeasureErrorList.value = []
  periodicMeasureRangeList.value = []
  periodicMeasureErrorList.value = []
  timeIntervalMeasureRangeList.value = []
  for (const i in listDict.value) {
    listDict.value[i] = []
  }
}
watch(() => props.list, (newVal) => { // 检定项表格
  if (newVal) {
    clearAllList()
    newVal.forEach((item: any) => {
      switch (item.dataType) {
        case '1':
          // 晶振开机特性
          crystalOscillatorStartupCharacterList.value.push({ ...item, params: '晶振开机特性', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '2':
          // 晶振1s频率稳定度
          crystalOscillatorStabilityList.value.push({ ...item, params: '晶振1s频率稳定度', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '3':
          // 晶振相对频率偏差
          crystalOscillatorDeviationList.value.push({ ...item, params: '晶振相对频率偏差', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '4':
          // 晶振频率复现性
          crystalOscillatorReproducibilityList.value.push({ ...item, params: '晶振频率复现性', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '5':
          // 晶振日老化率
          crystalOscillatorDailyAgingRateList.value.push({ ...item, params: '晶振日老化率', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '6':
          if (props.itemCategoryName === '通用计数器') {
            // 频率测量范围、输入灵敏度
            frequencyMeasureRangeList.value.push({ ...item, params: '频率测量范围、输入灵敏度', technicalIndex: clearSymbol(item.technicalIndex) })
          }
          else {
            // 频率测量范围、输入灵敏度及最大输入电平
            frequencyMeasureRangeList.value.push({ ...item, params: '频率测量范围、输入灵敏度及最大输入电平', technicalIndex: clearSymbol(item.technicalIndex) })
          }
          break
        case '7':
          // 频率测量误差
          frequencyMeasureErrorList.value.push({ ...item, params: '频率测量误差', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '8':
          // 周期测量范围、输入灵敏度
          periodicMeasureRangeList.value.push({ ...item, params: '周期测量范围、输入灵敏度', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '9':
          // 周期测量误差
          periodicMeasureErrorList.value.push({ ...item, params: '周期测量误差', technicalIndex: clearSymbol(item.technicalIndex) })
          break
        case '10':
          // 时间间隔测量范围及测量误差
          timeIntervalMeasureRangeList.value.push({ ...item, params: '时间间隔测量范围及测量误差', technicalIndex: clearSymbol(item.technicalIndex) })
          break
      }
    })
    if (props.pageType !== 'detail') {
      if (!newVal.filter((item: { dataType: string }) => item.dataType === '1').length) {
        addRow([], '晶振开机特性', '1')
      }
      if (!newVal.filter((item: { dataType: string }) => item.dataType === '2').length) {
        addRow([], '晶振1s频率稳定度', '2')
      }
      if (!newVal.filter((item: { dataType: string }) => item.dataType === '3').length) {
        addRow([], '晶振相对频率偏差', '3')
      }
      if (!newVal.filter((item: { dataType: string }) => item.dataType === '4').length) {
        addRow([], '晶振频率复现性', '4')
      }
      if (!newVal.filter((item: { dataType: string }) => item.dataType === '5').length) {
        addRow([], '晶振日老化率', '5')
      }
    }
  }
  else {
    if (props.pageType !== 'detail') {
      setTimeout(() => {
        addRow([], '晶振开机特性', '1')
        addRow([], '晶振1s频率稳定度', '2')
        addRow([], '晶振相对频率偏差', '3')
        addRow([], '晶振频率复现性', '4')
        addRow([], '晶振日老化率', '5')
      })
    }
  }
})
const getList = () => {
  let result = [] as any[]
  for (const i in chekedDict) {
    if ((chekedDict[i] === '1' || chekedDict[i] === 1) && chekedDict[i]) {
      const data = listDict.value[i].map((item: any) => ({
        ...item,
        // technicalIndex: item.technicalIndex ? `${item.technicalIndexSymbol || ''}${item.technicalIndex}` : '/',
        technicalIndex: item.technicalIndex === 0 ? '0' : clearSymbol(item.technicalIndex || '/') ? clearSymbol(item.technicalIndex || '/') : '/',
        urel: item.urel ? item.urel : '/',
        multiplyFrequency: item.multiplyFrequency ? item.multiplyFrequency : '/',
        otherTechnicalIndex: item.otherTechnicalIndex ? item.otherTechnicalIndex : '/',
      }))
      result = [...result, ...data]
    }
  }
  return result
}
defineExpose({ list, checkAllList, form, getList })
// 表格下拉框等内容是否禁用
const disabled = ({ scope, column }, fun) => {
  fun(props.pageType === 'detail')
}

// 每个table对应的下拉框内容 字典
const tableDict = ref<{ [key: string]: { value: string; name: string; id: string }[] }>({})
const changeLoadSituationa = (value: any, index: number, text: string, type: string, list: any[], item: string) => {
  // if (item === '频率显示') {
  //   if (text === '标称值') {
  //     list[index].frequency = value
  //   }
  //   if (text === '标称值单位') {
  //     list[index].frequencyUnit = typeof value === 'string' ? value : ''
  //   }
  // }
}

// 获取字典
const gateTimeValue = ref<{ value: string; name: string; id: string }[]>([]) // 闸门时间
const timeList = ref<{ value: string; name: string; id: string }[]>([]) // 时间
const standardTechnicalIndexSymbol = ref<{ value: string; name: string; id: string }[]>([]) // 技术指标符号
const testedSignalFrequency = ref<{ value: string; name: string; id: string }[]>([]) // 被测信号频率
const nominalValueUnit = ref<{ value: string; name: string; id: string }[]>([]) // 标称值单位
const standardAmplitudeUnit = ref<{ value: string; name: string; id: string }[]>([]) // 信号源输出幅度
const thoroughfare = ref<{ value: string; name: string; id: string }[]>([]) // 通道
const fetchDict = async () => {
  // 标称值单位
  const res1 = await getDictByCode('gateTimeValue')
  gateTimeValue.value = res1.data
  // 时间
  const res2 = await getDictByCode('standardTimeUnit')
  timeList.value = res2.data
  // 技术指标符号
  const res3 = await getDictByCode('standardTechnicalIndexSymbol')
  standardTechnicalIndexSymbol.value = res3.data
  // 被测信号频率
  const res4 = await getDictByCode('cesiumAtomTestedSignalFrequency')
  testedSignalFrequency.value = res4.data
  // 标称值单位
  const res5 = await getDictByCode('standardFrequencyUnit')
  nominalValueUnit.value = res5.data
  // 信号源输出幅度
  const res6 = await getDictByCode('standardAmplitudeUnit')
  standardAmplitudeUnit.value = res6.data
  // 通道
  const res7 = await getDictByCode('cesiumAtomThoroughfare')
  thoroughfare.value = res7.data

  tableDict.value = {
    '闸门时间': gateTimeValue.value,
    '取样时间单位': gateTimeValue.value,
    '测量间隔单位': timeList.value,
    'T1/T3单位': timeList.value,
    'T2单位': timeList.value,
    '被测信号频率': testedSignalFrequency.value,
    '标称值单位': nominalValueUnit.value,
    '信号源输出幅度单位': standardAmplitudeUnit.value,
    '信号源最大输入电平单位': standardAmplitudeUnit.value,
    '通道': thoroughfare.value,
  }
}
fetchDict()

// 自定义下拉框内容
const customSelect = (data: any, fun: any) => {
  if ((data.title === '时间间隔测量范围及测量误差' || data.title === '周期测量误差' || data.title === '周期测量范围、输入灵敏度') && data.text === '标称值单位') {
    fun(timeList.value)
  }
  else {
    fun(tableDict.value[data.text])
  }
}
</script>

<template>
  <div style="padding: 0 10px;">
    <el-checkbox
      v-model="form.appearanceFunctionCheck" :checked="true" :true-label="1" :false-label="0"
      :disabled="pageType === 'detail'"
    >
      外观及功能性检查
    </el-checkbox>
  </div>

  <!-- 晶振开机特性 -->
  <template-table
    :show="Boolean(form.crystalOscillatorStartupCharacter)"
    :data="crystalOscillatorStartupCharacterList" :columns="columns_crystal_oscillator_startup_character"
    :page-type="pageType" title="晶振开机特性" index="1" :show-btn="false" :select-all-list="tableDict" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.crystalOscillatorStartupCharacter" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        晶振开机特性
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>

  <!-- 晶振1s频率稳定度 -->
  <template-table
    :show="Boolean(form.crystalOscillatorStability)"
    :data="crystalOscillatorStabilityList" :columns="columns_crystal_oscillator_stability"
    :page-type="pageType" title="晶振1s频率稳定度" index="2" :show-btn="false" :select-all-list="tableDict"
    @disabled="disabled" @add-row="addRow" @del-row="delRow" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.crystalOscillatorStability" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        晶振1s频率稳定度
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>

  <!-- 晶振相对频率偏差 -->
  <template-table
    :show="Boolean(form.crystalOscillatorDeviation)"
    :data="crystalOscillatorDeviationList" :columns="columns_crystal_oscillator_deviation"
    :page-type="pageType" title="晶振相对频率偏差" index="3" :show-btn="false" :select-all-list="tableDict" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.crystalOscillatorDeviation" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        晶振相对频率偏差
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>

  <!-- 晶振频率复现性 -->
  <template-table
    :show="Boolean(form.crystalOscillatorReproducibility)"
    :data="crystalOscillatorReproducibilityList" :columns="columns_crystal_oscillator_reproducibility"
    :page-type="pageType" title="晶振频率复现性" index="4" :show-btn="false" :select-all-list="tableDict" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.crystalOscillatorReproducibility" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        晶振频率复现性
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>

  <!-- 晶振日老化率 -->
  <template-table
    :show="Boolean(form.crystalOscillatorDailyAgingRate)"
    :data="crystalOscillatorDailyAgingRateList" :columns="columns_crystal_oscillator_dailyAging_rate"
    :page-type="pageType" title="晶振日老化率" index="5" :show-btn="false" :select-all-list="tableDict" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.crystalOscillatorDailyAgingRate" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        晶振日老化率
      </el-checkbox>
    </template>
    <template #next-content="{ column, scope }">
      <template v-if="column.text === '被测信号频率'">
        <span v-for="item in scope?.testedSignalFrequencyUnit" :key="item" style="display: inline-block;">{{ item
        }}</span>
      </template>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>
  <!-- 频率测量范围、输入灵敏度 ||  频率测量范围、输入灵敏度及最大输入电平 -->
  <template-table
    :show="Boolean(form.frequencyMeasureRange)"
    :data="frequencyMeasureRangeList" :columns="columns_frequency_measure_range" :page-type="pageType"
    :title="props.itemCategoryName === '通用计数器' ? '频率测量范围、输入灵敏度' : '频率测量范围、输入灵敏度及最大输入电平'" index="6"
    :show-btn="pageType !== 'detail'" :select-all-list="tableDict" @disabled="disabled" @add-row="addRow"
    @del-row="delRow" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.frequencyMeasureRange" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        {{ props.itemCategoryName === '通用计数器' ? '频率测量范围、输入灵敏度' : '频率测量范围、输入灵敏度及最大输入电平' }}
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '输入灵敏度技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
      <template v-if="props.itemCategoryName !== '通用计数器' && column.text === '最大输入电平技术指标'">
        <el-select
          v-model="scope.otherTechnicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
    <template #next-content="{ column, scope }">
      <template v-if="column.text === '输入灵敏度技术指标'">
        <span v-for="item in scope?.signalSourceOutputAmplitudeUnit" :key="item" style="display: inline-block;">{{ item }}</span>
      </template>
      <template v-if="column.text === '最大输入电平技术指标'">
        <span v-for="item in scope?.signalSourceMaxInputLevelUnit" :key="item" style="display: inline-block;">{{ item }}</span>
      </template>
    </template>
  </template-table>

  <!-- 频率测量误差 -->
  <template-table
    :show="Boolean(form.frequencyMeasureError)"
    :data="frequencyMeasureErrorList" :columns="columns_frequency_measure_error" :page-type="pageType"
    title="频率测量误差" index="7" :show-btn="pageType !== 'detail'" :select-all-list="tableDict" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.frequencyMeasureError" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        频率测量误差
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>

  <!-- 周期测量范围、输入灵敏度 -->
  <template-table
    v-if="props.itemCategoryName === '通用计数器'"
    :show="Boolean(form.periodicMeasureRange)" :data="periodicMeasureRangeList"
    :columns="columns_periodic_measure_range" :page-type="pageType" title="周期测量范围、输入灵敏度" index="8"
    :show-btn="pageType !== 'detail'" :select-all-list="tableDict" :custom-select="true" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @customSelect="customSelect" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.periodicMeasureRange" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        周期测量范围、输入灵敏度
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '输入灵敏度技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
    <template #next-content="{ column, scope }">
      <template v-if="column.text === '输入灵敏度技术指标'">
        <span v-for="item in scope?.signalSourceOutputAmplitudeUnit" :key="item" style="display: inline-block;">{{ item }}</span>
      </template>
    </template>
  </template-table>

  <!-- 周期测量误差 -->
  <template-table
    v-if="props.itemCategoryName === '通用计数器'"
    :show="Boolean(form.periodicMeasureError)" :data="periodicMeasureErrorList"
    :columns="columns_periodic_measure_error" :page-type="pageType" title="周期测量误差" index="9"
    :show-btn="pageType !== 'detail'" :select-all-list="tableDict" :custom-select="true" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @customSelect="customSelect" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.periodicMeasureError" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        周期测量误差
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>

  <!-- 时间间隔测量范围及测量误差 -->
  <template-table
    v-if="props.itemCategoryName === '通用计数器'"
    :show="Boolean(form.timeIntervalMeasureRange)" :data="timeIntervalMeasureRangeList"
    :columns="columns_time_interval_measure_range" :page-type="pageType" title="时间间隔测量范围及测量误差" index="10"
    :show-btn="pageType !== 'detail'" :select-all-list="tableDict" :custom-select="true" @disabled="disabled"
    @add-row="addRow" @del-row="delRow" @customSelect="customSelect" @change-load-situationa="changeLoadSituationa"
  >
    <template #custom-check>
      <el-checkbox
        v-model="form.timeIntervalMeasureRange" :checked="true" :true-label="1" :false-label="0"
        :disabled="pageType === 'detail'"
      >
        时间间隔测量范围及测量误差
      </el-checkbox>
    </template>
    <template #pre-content="{ column, scope }">
      <template v-if="column.text === '技术指标'">
        <el-select
          v-model="scope.technicalIndexSymbol" :disabled="pageType === 'detail'" placeholder=" "
          style="width: 100px;"
        >
          <el-option
            v-for="citem in standardTechnicalIndexSymbol" :key="citem.id" :label="citem.name"
            :value="citem.name"
          />
        </el-select>
      </template>
    </template>
  </template-table>
</template>