Newer
Older
xc-business-system / src / views / equipement / standard / book / components / config / thirteenth / config.vue
dutingting on 16 Mar 2024 39 KB 示波器核查项完成
<!-- 标准装置台账信息详情 配置核查项 第13套:示波器检定装置 -->
<script name="StandardBookEquipmentConfig" lang="ts" setup>
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { IList } from './thirteenth-interface'
import TemplateTable from './templateTable.vue'
import type { dictType } from '@/global'
import { useCheckList } from '@/commonMethods/useCheckList'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { config, getCheckItemDetail } from '@/api/equipment/standard/book'
import { calc } from '@/utils/useCalc'
import { getDictByCode } from '@/api/system/dict'
import { differenceArray } from '@/utils/Array'
import { useArrayDataUnique } from '@/commonMethods/useArrayDataUnique'

const textMap: { [key: string]: string } = {
  edit: '编辑',
  detail: '详情',
}// 页面类型字典
const form = ref({ // 表单
  equipmentNo: '', // 统一编号
  equipmentName: '', // 设备名称
  model: '', // 型号规格
  manufactureNo: '', // 出厂编号
  measureRange: '', // 测量范围
  uncertainty: '', // 不确定度或允许误差极限或准确度等级
  itemCategoryName: '', // 核查项分类名称
  itemCategoryId: '', // 核查项分类id
  remark: '', // 核查项备注
  belongStandardEquipment: '', // 检校标准装置
  belongStandardEquipmentName: '', // 检校标准装置名称
})
const pageType = ref('detail') // 页面类型: add, edit, detail
const infoId = ref('') // id
const $router = useRouter() // 路由实例
const loading = ref(false) // loading
const equipmentId = ref('') // 设备id
// -----------------------------------路由参数------------------------------------------------------
// 从路由中获取页面类型参数
const $route = useRoute()
if ($route.params && $route.params.type) {
  pageType.value = $route.params.type as string
  if ($route.params.id) {
    infoId.value = $route.params.id as string
  }
  console.log('pageType.value', pageType.value)
}
// -------------------------------------------核查项-----------------------------------------------
const listTimeMark = ref<IList[]>([]) // 时标
const listSquareWaveVoltage50Ω = ref<IList[]>([]) // 方波电压(50Ω)
const listSquareWaveVoltage1MΩ = ref<IList[]>([]) // 方波电压(1MΩ)
const listDirectVoltage50Ω = ref<IList[]>([]) // 直流电压(50Ω)
const listDirectVoltage1MΩ = ref<IList[]>([]) // 直流电压(1MΩ)
const listInputImpedance = ref<IList[]>([]) // 输入阻抗
const listVoltageFlatness = ref<IList[]>([]) // 稳幅正弦信号电压平坦度
const listRisetime = ref<IList[]>([]) // 上升时间

const checkoutTimeMarkList = ref<IList[]>([]) // 时标选中数据
const checkoutSquareWaveVoltage50ΩList = ref<IList[]>([]) // 方波电压(50Ω)选中
const checkoutSquareWaveVoltage1MΩList = ref<IList[]>([]) // 方波电压(1MΩ)选中
const checkoutDirectVoltage50ΩList = ref<IList[]>([]) // 直流电压(50Ω)选中
const checkoutDirectVoltage1MΩList = ref<IList[]>([]) // 直流电压(1MΩ)选中
const checkoutInputImpedanceList = ref<IList[]>([]) // 输入阻抗选中
const checkoutVoltageFlatnessList = ref<IList[]>([]) // 稳幅正弦信号电压平坦度选中
const checkoutRisetimeList = ref<IList[]>([]) // 上升时间选中

const timeMark = ref(true) // 是否显示时标
const squareWaveVoltage50Ω = ref(true) // 方波电压(50Ω)
const squareWaveVoltage1MΩ = ref(true) // 方波电压(1MΩ)
const directVoltage50Ω = ref(true) // 直流电压(50Ω)
const directVoltage1MΩ = ref(true) // 直流电压(1MΩ)
const inputImpedance = ref(true) // 输入阻抗
const voltageFlatness = ref(true) // 稳幅正弦信号电压平坦度
const risetime = ref(true) // 上升时间

const columns_timeMark = ref<TableColumn[]>([ // 时标
  { text: '核查项目', value: 'params', align: 'center', required: true },
  { text: '核查点', value: 'checkPoint', align: 'center', required: true },
  { text: '核查点单位', value: 'unit', align: 'center', required: true },
  { text: '循环次数', value: 'cycleNumber', align: 'center', required: true, width: '90' },
  { text: '核查类型', value: 'checkType', align: 'center', required: true, width: '120' },
  { text: '最大允许误差的绝对值', value: 'maximumErrorAbsolute', align: 'center', required: true, width: '340' },
])

const columns_voltageFlatness = ref<TableColumn[]>([ // 稳幅正弦信号电压平坦度
  { text: '核查项目', value: 'params', align: 'center', required: true },
  { text: '类型', value: 'typeValue', align: 'center', required: true, width: '180' },
  { text: '核查点', value: 'checkPoint', align: 'center', required: true, width: '180' },
  { text: '核查点单位', value: 'unit', align: 'center', required: true, width: '100' },
  { text: '是否为参考点', value: 'referencePoint', align: 'center', required: true, width: '180' },
  { text: '循环次数', value: 'cycleNumber', align: 'center', required: true, width: '90' },
  { text: '核查类型', value: 'checkType', align: 'center', required: true, width: '120' },
  { text: '最大允许误差的绝对值', value: 'maximumErrorAbsolute', align: 'center', required: true, width: '340' },
])

const columns_risetime = ref<TableColumn[]>([ // 上升时间
  { text: '核查项目', value: 'params', align: 'center', required: true, width: '90' },
  { text: '快沿', value: 'checkPoint', align: 'center', required: true, width: '180' },
  { text: '快沿单位', value: 'unit', align: 'center', required: true, width: '100' },
  { text: '探头出厂编号', value: 'manufactureNo', align: 'center', required: true, width: '220' },
  { text: '探头设备名称', value: 'equipmentName', align: 'center', required: false },
  { text: '探头规格型号', value: 'model', align: 'center', required: false },
  { text: '技术指标', value: 'technicalIndex', align: 'center', required: true, width: '340' },
])

// 多选
const handleSelectionChange = (e: any, type: string) => {
  switch (type) {
    case '时标':
      checkoutTimeMarkList.value = e
      break
    case '方波电压(50Ω)':
      checkoutSquareWaveVoltage50ΩList.value = e
      break
    case '方波电压(1MΩ)':
      checkoutSquareWaveVoltage1MΩList.value = e
      break
    case '直流电压(50Ω)':
      checkoutDirectVoltage50ΩList.value = e
      break
    case '直流电压(1Ω)':
      checkoutDirectVoltage1MΩList.value = e
      break
    case '输入阻抗':
      checkoutInputImpedanceList.value = e
      break
    case '稳幅正弦信号电压平坦度':
      checkoutVoltageFlatnessList.value = e
      break
    case '上升时间':
      checkoutRisetimeList.value = e
      break
  }
}

// 校验表格(点击保存的时候、增加行用)
const checkList = (list: any, getTitle: string) => {
  let title = ''
  if (getTitle.slice(getTitle.length - 2) === '表格') {
    title = getTitle.slice(0, getTitle.length - 2)
  }
  else {
    title = getTitle
  }
  let columns
  switch (title) {
    case '时标':
      columns = columns_timeMark.value
      break
    case '方波电压(50Ω)':
      columns = columns_timeMark.value
      break
    case '方波电压(1MΩ)':
      columns = columns_timeMark.value
      break
    case '直流电压(50Ω)':
      columns = columns_timeMark.value
      break
    case '直流电压(1MΩ)':
      columns = columns_timeMark.value
      break
    case '输入阻抗':
      columns = columns_timeMark.value
      break
    case '稳幅正弦信号电压平坦度':
      columns = columns_voltageFlatness.value
      break
    case '上升时间':
      columns = columns_risetime.value
      break
  }
  return useCheckList(list, columns, `${title}表格`)
}

/**
 * 增加行公共方法
 * @param list 要操作的数组
 * @param title 操作的表格
 */
const addRow = (list: IList[], title: string) => {
  if (checkList(list, `${title}表格`)) {
    if (list.length) { // 增加行时默认上一行数据
      if (title === '稳幅正弦信号电压平坦度') { // 处理参考点
        const tempList = listVoltageFlatness.value.filter(item => item.typeValue === list[list.length - 1].typeValue)
        if (tempList.every(item => item.referencePoint === 0)) {
          list.push({ ...list[list.length - 1], referencePoint: 1 })
        }
        else {
          list.push({ ...list[list.length - 1], referencePoint: 0 })
        }
      }
      else {
        list.push({ ...list[list.length - 1] })
      }
    }
    else {
      switch (title) {
        case '时标':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            checkPoint: '', //	核查点
            unit: 's', // 核查点单位
            cycleNumber: 10, //	循环次数
            checkType: '重复性, 稳定性', //	核查类型(直接存字典value,多个逗号分隔)
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
            maximumErrorAbsolute: '', //	最大允许误差的绝对值
            maximumErrorAbsoluteUnit: 's', //	最大允许误差的绝对值单位
          })
          break
        case '方波电压(50Ω)':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            checkPoint: '', //	核查点
            unit: 'mV', // 核查点单位
            cycleNumber: 10, //	循环次数
            checkType: '重复性, 稳定性', //	核查类型(直接存字典value,多个逗号分隔)
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
            maximumErrorAbsolute: '', //	最大允许误差的绝对值
            maximumErrorAbsoluteUnit: 'mV', //	最大允许误差的绝对值单位
          })
          break
        case '方波电压(1MΩ)':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            checkPoint: '', //	核查点
            unit: 'mV', // 核查点单位
            cycleNumber: 10, //	循环次数
            checkType: '重复性, 稳定性', //	核查类型(直接存字典value,多个逗号分隔)
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
            maximumErrorAbsolute: '', //	最大允许误差的绝对值
            maximumErrorAbsoluteUnit: 'mV', //	最大允许误差的绝对值单位
          })
          break
        case '直流电压(50Ω)':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            checkPoint: '', //	核查点
            unit: 'mV', // 核查点单位
            cycleNumber: 10, //	循环次数
            checkType: '重复性, 稳定性', //	核查类型(直接存字典value,多个逗号分隔)
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
            maximumErrorAbsolute: '', //	最大允许误差的绝对值
            maximumErrorAbsoluteUnit: 'mV', //	最大允许误差的绝对值单位
          })
          break
        case '直流电压(1MΩ)':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            checkPoint: '', //	核查点
            unit: 'mV', // 核查点单位
            cycleNumber: 10, //	循环次数
            checkType: '重复性, 稳定性', //	核查类型(直接存字典value,多个逗号分隔)
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
            maximumErrorAbsolute: '', //	最大允许误差的绝对值
            maximumErrorAbsoluteUnit: 'mV', //	最大允许误差的绝对值单位
          })
          break
        case '输入阻抗':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            checkPoint: '', //	核查点
            unit: 'Ω', // 核查点单位
            cycleNumber: 10, //	循环次数
            checkType: '重复性, 稳定性', //	核查类型(直接存字典value,多个逗号分隔)
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
            maximumErrorAbsolute: '', //	最大允许误差的绝对值
            maximumErrorAbsoluteUnit: 'Ω', //	最大允许误差的绝对值单位
          })
          break
        case '稳幅正弦信号电压平坦度':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            typeValue: '5Vp-p', // 类型
            checkPoint: '', //	核查点
            unit: 'kHz', // 核查点单位
            referencePoint: 1, // 是否为参考点
            cycleNumber: 10, //	循环次数
            checkType: '重复性, 稳定性', //	核查类型(直接存字典value,多个逗号分隔)
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
            maximumErrorAbsolute: '', //	最大允许误差的绝对值
            maximumErrorAbsoluteUnit: '%', //	最大允许误差的绝对值单位
          })
          break
        case '上升时间':
          list.push({
            equipmentId: infoId.value, //	配套设备id
            id: '',
            params: title, // 核查项目
            checkPoint: '', // 快沿
            unit: 'ps', // 快沿单位
            manufactureNo: '', //	探头出厂编号
            equipmentName: '', //	探头设备名称
            model: '', //	探头规格型号
            technicalIndex: '', //	技术指标
            technicalIndexSymbol: '≤', //	技术指标前符号
            technicalIndexUnit: 'ps', //	技术指标单位
            itemCategoryId: form.value.itemCategoryId, //	核查项分类id(能够确定是哪个标准装置)
            remark: '', //	核查项备注
          })
          break
        default:
          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 '时标':
        listTimeMark.value = data
        break
      case '方波电压(50Ω)':
        listSquareWaveVoltage50Ω.value = data
        break
      case '方波电压(1MΩ)':
        listSquareWaveVoltage1MΩ.value = data
        break
      case '直流电压(50Ω)':
        listDirectVoltage50Ω.value = data
        break
      case '直流电压(1MΩ)':
        listDirectVoltage1MΩ.value = data
        break
      case '输入阻抗':
        listInputImpedance.value = data
        break
      case '稳幅正弦信号电压平坦度':
        listVoltageFlatness.value = data
        break
      case '上升时间':
        listRisetime.value = data
        break
    }
  }
}

// 上升时间选好设备
const confirmSelectedEquipment = (equipmentInfo: any, index: number) => {
  listRisetime.value[index].equipmentName = equipmentInfo.equipmentName // 探头设备名称
  listRisetime.value[index].manufactureNo = equipmentInfo.manufactureNo // 探头出厂编号
  listRisetime.value[index].model = equipmentInfo.model // 探头规格型号
}

// 参考点改变
const selectReferencePoint = (val: number, row: any, getIndex: number) => {
  if (val === 1) {
    listVoltageFlatness.value = listVoltageFlatness.value.map((item, index: number) => {
      return {
        ...item,
        referencePoint: item.typeValue === row.typeValue ? 0 : item.referencePoint,
      }
    })
    listVoltageFlatness.value[getIndex].referencePoint = 1
  }
}

// 类型改变
const changeSelectTypeValue = (val: string, row: any) => {
  const length = listVoltageFlatness.value.filter(item => item.typeValue === val).length
  if (length === 1) {
    row.referencePoint = 1
  }
  else {
    row.referencePoint = 0
  }
}
// ---------------------------------------按钮-----------------------------------------------------
// 点击关闭
const close = () => {
  $router.back()
}
// 清空配置
const clear = () => {
  ElMessageBox.confirm(
    '确认清空配置项吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  )
    .then(() => {
      listTimeMark.value = []// 时标
      listSquareWaveVoltage50Ω.value = [] // 方波电压(50Ω)
      listSquareWaveVoltage1MΩ.value = [] // 方波电压(1MΩ)
      listDirectVoltage50Ω.value = [] // 直流电压(50Ω)
      listDirectVoltage1MΩ.value = [] // 直流电压(1MΩ)
      listInputImpedance.value = [] // 输入阻抗
      listVoltageFlatness.value = [] // 稳幅正弦信号电压平坦度
      listRisetime.value = [] // 上升时间
      form.value.remark = ''
    })
}
// 保存之前校验
const checkListBeforeSave = () => {
  console.log('保存之前校验')
  // 验空
  if (timeMark.value && !listTimeMark.value.length) { //	时标
    ElMessage.warning('时标 不能为空')
    return false
  }
  if (squareWaveVoltage50Ω.value && !listSquareWaveVoltage50Ω.value.length) { // 方波电压(50Ω)
    ElMessage.warning('方波电压(50Ω) 不能为空')
    return false
  }
  if (squareWaveVoltage1MΩ.value && !listSquareWaveVoltage1MΩ.value.length) { // 方波电压(1MΩ)
    ElMessage.warning('方波电压(1MΩ) 不能为空')
    return false
  }
  if (directVoltage50Ω.value && !listDirectVoltage50Ω.value.length) { // 直流电压(50Ω)
    ElMessage.warning('直流电压(50Ω) 不能为空')
    return false
  }
  if (directVoltage1MΩ.value && !listDirectVoltage1MΩ.value.length) { // 直流电压(1MΩ)
    ElMessage.warning('直流电压(1MΩ) 不能为空')
    return false
  }
  if (inputImpedance.value && !listInputImpedance.value.length) { // 输入阻抗
    ElMessage.warning('输入阻抗 不能为空')
    return false
  }
  if (voltageFlatness.value && !listVoltageFlatness.value.length) { // 稳幅正弦信号电压平坦度
    ElMessage.warning('稳幅正弦信号电压平坦度 不能为空')
    return false
  }
  if (risetime.value && !listRisetime.value.length) { // 上升时间
    ElMessage.warning('上升时间 不能为空')
    return false
  }
  let timeMarkResult = true // 时标
  let squareWaveVoltage50ΩResult = true // 方波电压(50Ω)
  let squareWaveVoltage1MΩResult = true // 方波电压(1MΩ)
  let directVoltage50ΩResult = true // 直流电压(50Ω)
  let directVoltage1MΩResult = true // 直流电压(1MΩ)
  let inputImpedanceResult = true // 输入阻抗
  let voltageFlatnessResult = true // 稳幅正弦信号电压平坦度
  let risetimeResult = true // 上升时间
  if (timeMark.value) {
    timeMarkResult = checkList(listTimeMark.value, '时标')
  }
  if (squareWaveVoltage50Ω.value) {
    squareWaveVoltage50ΩResult = checkList(listSquareWaveVoltage50Ω.value, '方波电压(50Ω)')
  }
  if (squareWaveVoltage1MΩ.value) {
    squareWaveVoltage1MΩResult = checkList(listSquareWaveVoltage1MΩ.value, '方波电压(1MΩ)')
  }
  if (directVoltage50Ω.value) {
    directVoltage50ΩResult = checkList(listDirectVoltage50Ω.value, '直流电压(50Ω)')
  }
  if (directVoltage1MΩ.value) {
    directVoltage1MΩResult = checkList(listDirectVoltage1MΩ.value, '直流电压(1MΩ)')
  }
  if (inputImpedance.value) {
    inputImpedanceResult = checkList(listInputImpedance.value, '输入阻抗')
  }
  if (voltageFlatness.value) {
    voltageFlatnessResult = checkList(listVoltageFlatness.value, '稳幅正弦信号电压平坦度')
  }
  if (risetime.value) {
    risetimeResult = checkList(listRisetime.value, '上升时间')
  }
  if (timeMarkResult && squareWaveVoltage50ΩResult && squareWaveVoltage1MΩResult && directVoltage50ΩResult && directVoltage1MΩResult && inputImpedanceResult && voltageFlatnessResult && risetimeResult) {
    // return true
    console.log('checkList校验通过')
  }
  else {
    console.log('checkList校验不通过')
    return false
  }

  // 检查核查点和核查点单位不能同时完全一样
  const listTimeMarkCheckPointResult = checkArrayDataUnique(listTimeMark.value)
  const listSquareWaveVoltage50ΩCheckPointResult = checkArrayDataUnique(listSquareWaveVoltage50Ω.value)
  const listSquareWaveVoltage1MΩCheckPointResult = checkArrayDataUnique(listSquareWaveVoltage1MΩ.value)
  const listDirectVoltage50ΩCheckPointResult = checkArrayDataUnique(listDirectVoltage50Ω.value)
  const listDirectVoltage1MΩCheckPointResult = checkArrayDataUnique(listDirectVoltage1MΩ.value)
  const listInputImpedanceCheckPointResult = checkArrayDataUnique(listInputImpedance.value)
  const listVoltageFlatnessCheckPointResult = checkArrayDataUnique(listVoltageFlatness.value)
  const listRisetimeCheckPointResult = checkArrayDataUnique(listRisetime.value)
  if (listTimeMarkCheckPointResult
    && listSquareWaveVoltage50ΩCheckPointResult
    && listSquareWaveVoltage1MΩCheckPointResult
    && listDirectVoltage50ΩCheckPointResult
    && listDirectVoltage1MΩCheckPointResult
    && listInputImpedanceCheckPointResult
    && listVoltageFlatnessCheckPointResult
    && listRisetimeCheckPointResult
  ) {
    return true
  }
  else {
    return false
  }
}

// 校验4个表格中不能同时出现核查项目和核查点、单位两个属性同时相同的两条数据
function checkArrayDataUnique(list: any) {
  for (let i = 0; i < list.length; i++) {
    const j = i + 1
    for (let j = 0; j < list.length; j++) {
      if (i !== j && list[i].params === list[j].params && (list[i].checkPoint + list[i].unit) === (list[j].checkPoint + list[j].unit)) {
        if (list[i].params === '上升时间') {
          ElMessage.warning(`${list[i].params} 第${i + 1}行第${j + 1}行的 快沿和单位不能同时完全一样`)
          return false
        }
        else {
          ElMessage.warning(`${list[i].params} 第${i + 1}行第${j + 1}行的 核查点和单位不能同时完全一样`)
          return false
        }
      }
    }
  }
  return true
}

// 校验参考点
const checkReferencePoint = () => {
  for (let i = 0; i < listVoltageFlatness.value.length; i++) {
    const tempList = listVoltageFlatness.value.filter(item => item.typeValue === listVoltageFlatness.value[i].typeValue)
    if (tempList.length && tempList.every(item => item.referencePoint === 0)) {
      ElMessage.warning(`稳幅正弦信号电压平坦度 ${tempList[0].typeValue}类型需至少一个参考点`)
      return false
    }
  }
  return true
}

// 保存之前处理数据
const solveDataBeforeSave = () => {
  // 数据处理
  let tempList = [] as any
  if (timeMark.value) { //	时标
    tempList = tempList.concat(listTimeMark.value)
  }
  if (squareWaveVoltage50Ω.value) { // 方波电压(50Ω)
    tempList = tempList.concat(listSquareWaveVoltage50Ω.value)
  }
  if (squareWaveVoltage1MΩ.value) { // 方波电压(1MΩ)
    tempList = tempList.concat(listSquareWaveVoltage1MΩ.value)
  }
  if (directVoltage50Ω.value) { // 直流电压(50Ω)
    tempList = tempList.concat(listDirectVoltage50Ω.value)
  }
  if (directVoltage1MΩ.value) { // 直流电压(1MΩ)
    tempList = tempList.concat(listDirectVoltage1MΩ.value)
  }
  if (inputImpedance.value) { // 输入阻抗
    tempList = tempList.concat(listInputImpedance.value)
  }
  if (voltageFlatness.value) { // 稳幅正弦信号电压平坦度
    tempList = tempList.concat(listVoltageFlatness.value)
  }
  if (risetime.value) { // 上升时间
    tempList = tempList.concat(listRisetime.value)
  }

  tempList = tempList.map((item: { id: string }) => {
    return {
      ...item,
      id: '',
      remark: form.value.remark,
    }
  })
  return tempList
}

// 点击保存
const save = () => {
  if (!checkReferencePoint()) { return false }
  if (!checkListBeforeSave()) { return false }
  const list = solveDataBeforeSave()
  const params = {
    itemCategoryId: form.value.itemCategoryId, // 核查项分类id
    checkItemDataOscilloscopeList: list,
    equipmentId: equipmentId.value,
  }
  const loading = ElLoading.service({
    lock: true,
    text: '加载中',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  config(params).then((res) => {
    ElMessage.success('已保存')
    pageType.value = 'detail'
    loading.close()
  })
}

// 获取详情
const getInfo = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '加载中',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  const params = {
    equipmentId: equipmentId.value, // 设备id
    belongStandardEquipment: form.value.belongStandardEquipment, // 检校标准装置code
    itemCategoryId: form.value.itemCategoryId, // 核查项分类id
    itemCategoryName: form.value.itemCategoryName, // 核查项分类名称
  }
  getCheckItemDetail(params).then((res) => {
    if (res.data && res.data.checkItemDataOscilloscopeList && res.data.checkItemDataOscilloscopeList.length) {
      listTimeMark.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '时标')
      listSquareWaveVoltage50Ω.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '方波电压(50Ω)')
      listSquareWaveVoltage1MΩ.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '方波电压(1MΩ)')
      listDirectVoltage50Ω.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '直流电压(50Ω)')
      listDirectVoltage1MΩ.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '直流电压(1MΩ)')
      listInputImpedance.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '输入阻抗')
      listVoltageFlatness.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '稳幅正弦信号电压平坦度')
      listRisetime.value = res.data.checkItemDataOscilloscopeList.filter((item: { params: string }) => item.params === '上升时间')
    }
    loading.close()
  })
}

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

onMounted(() => {
  form.value.equipmentNo = $route.query.equipmentNo as string // 统一编号
  form.value.equipmentName = $route.query.equipmentName as string // 设备名称
  form.value.model = $route.query.model as string // 型号规格
  form.value.manufactureNo = $route.query.manufactureNo as string // 出厂编号
  form.value.measureRange = $route.query.measureRange as string // 测量范围
  form.value.uncertainty = $route.query.uncertainty as string // 不确定度或允许误差极限或准确度等级
  form.value.itemCategoryName = $route.query.itemCategoryName as string // 核查项分类名称
  form.value.itemCategoryId = $route.query.itemCategoryId as string // 核查项分类id
  form.value.belongStandardEquipment = $route.query.belongStandardEquipment as string // 核查项标准装置id
  form.value.belongStandardEquipmentName = $route.query.belongStandardEquipmentName as string // 核查项标准装置id
  equipmentId.value = $route.query.equipmentId as string // 设备id
  getInfo()
})
</script>

<template>
  <app-container class="config-13">
    <detail-page v-loading="loading" :title="`配置核查项(${textMap[pageType]})`">
      <template #btns>
        <el-button v-if="pageType === 'edit'" type="warning" @click="clear">
          清空配置
        </el-button>
        <el-button v-if="pageType === 'edit'" type="primary" @click="save">
          保存
        </el-button>
        <el-button type="info" @click="close">
          关闭
        </el-button>
      </template>
      <el-form
        ref="ruleFormRef"
        :model="form"
        :label-width="130"
        label-position="right"
      >
        <el-row :gutter="24" class="marg">
          <el-col :span="6">
            <el-form-item label="统一编号:" prop="equipmentNo">
              <el-input
                v-model="form.equipmentNo"
                disabled
                :placeholder="pageType === 'detail' ? '' : '统一编号'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="设备名称:" prop="equipmentName">
              <el-input
                v-model="form.equipmentName"
                disabled
                :placeholder="pageType === 'detail' ? '' : '设备名称'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="型号规格:" prop="model">
              <el-input
                v-model="form.model"
                disabled
                :placeholder="pageType === 'detail' ? '' : '型号规格'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出厂编号:" prop="manufactureNo">
              <el-input
                v-model="form.manufactureNo"
                disabled
                :placeholder="pageType === 'detail' ? '' : '出厂编号'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="测量范围:" prop="measureRange">
              <el-input
                v-model="form.measureRange"
                disabled
                type="textarea"
                autosize
                :placeholder="pageType === 'detail' ? '' : '测量范围'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="260" label="不确定度或允许误差极限或准确度等级:" prop="uncertainty">
              <el-input
                v-model="form.uncertainty"
                type="textarea"
                autosize
                disabled
                :placeholder="pageType === 'detail' ? '' : '不确定度或允许误差极限或准确度等级'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="核查项分类名称:" prop="itemCategoryName">
              <el-input
                v-model="form.itemCategoryName"
                disabled
                :placeholder="pageType === 'detail' ? '' : '核查项分类名称'"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </detail-page>

    <!-- 时标 -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="timeMark" :disabled="pageType === 'detail'">
          时标
        </el-checkbox>
        <div v-if="timeMark && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listTimeMark, '时标')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutTimeMarkList, listTimeMark, '时标')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table v-if="timeMark" type="时标" :data="listTimeMark" :columns="columns_timeMark" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '时标')" />
    </detail-block>

    <!-- 方波电压(50Ω) -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="squareWaveVoltage50Ω" :disabled="pageType === 'detail'">
          方波电压(50Ω)
        </el-checkbox>
        <div v-if="squareWaveVoltage50Ω && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listSquareWaveVoltage50Ω, '方波电压(50Ω)')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutSquareWaveVoltage50ΩList, listSquareWaveVoltage50Ω, '方波电压(50Ω)')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table v-if="squareWaveVoltage50Ω" type="方波电压(50Ω)" :data="listSquareWaveVoltage50Ω" :columns="columns_timeMark" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '方波电压(50Ω)')" />
    </detail-block>

    <!-- 方波电压(1MΩ) -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="squareWaveVoltage1MΩ" :disabled="pageType === 'detail'">
          方波电压(1MΩ)
        </el-checkbox>
        <div v-if="squareWaveVoltage1MΩ && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listSquareWaveVoltage1MΩ, '方波电压(1MΩ)')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutSquareWaveVoltage1MΩList, listSquareWaveVoltage1MΩ, '方波电压(1MΩ)')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table v-if="squareWaveVoltage1MΩ" type="方波电压(1MΩ)" :data="listSquareWaveVoltage1MΩ" :columns="columns_timeMark" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '方波电压(1MΩ)')" />
    </detail-block>

    <!-- 直流电压(50Ω) -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="directVoltage50Ω" :disabled="pageType === 'detail'">
          直流电压(50Ω)
        </el-checkbox>
        <div v-if="directVoltage50Ω && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listDirectVoltage50Ω, '直流电压(50Ω)')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutDirectVoltage50ΩList, listDirectVoltage50Ω, '直流电压(50Ω)')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table v-if="directVoltage50Ω" type="直流电压(50Ω)" :data="listDirectVoltage50Ω" :columns="columns_timeMark" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '直流电压(50Ω)')" />
    </detail-block>

    <!-- 直流电压(1MΩ) -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="directVoltage1MΩ" :disabled="pageType === 'detail'">
          直流电压(1MΩ)
        </el-checkbox>
        <div v-if="directVoltage1MΩ && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listDirectVoltage1MΩ, '直流电压(1MΩ)')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutDirectVoltage1MΩList, listDirectVoltage1MΩ, '直流电压(1MΩ)')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table v-if="directVoltage1MΩ" type="直流电压(1MΩ)" :data="listDirectVoltage1MΩ" :columns="columns_timeMark" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '直流电压(1MΩ)')" />
    </detail-block>

    <!-- 输入阻抗 -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="inputImpedance" :disabled="pageType === 'detail'">
          输入阻抗
        </el-checkbox>
        <div v-if="inputImpedance && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listInputImpedance, '输入阻抗')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutInputImpedanceList, listInputImpedance, '输入阻抗')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table v-if="inputImpedance" type="输入阻抗" :data="listInputImpedance" :columns="columns_timeMark" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '输入阻抗')" />
    </detail-block>

    <!-- 稳幅正弦信号电压平坦度 -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="voltageFlatness" :disabled="pageType === 'detail'">
          稳幅正弦信号电压平坦度
        </el-checkbox>
        <div v-if="voltageFlatness && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listVoltageFlatness, '稳幅正弦信号电压平坦度')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutVoltageFlatnessList, listVoltageFlatness, '稳幅正弦信号电压平坦度')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table
        v-if="voltageFlatness"
        type="稳幅正弦信号电压平坦度"
        :data="listVoltageFlatness"
        :columns="columns_voltageFlatness"
        :page-type="pageType"
        @selection-change="(e) => handleSelectionChange(e, '稳幅正弦信号电压平坦度')"
        @selectReferencePoint="selectReferencePoint"
        @changeSelectTypeValue="changeSelectTypeValue"
      />
    </detail-block>

    <!-- 上升时间 -->
    <detail-block title="" style="padding-bottom: 20px;">
      <div style="display: flex;justify-content: space-between;">
        <el-checkbox v-model="risetime" :disabled="pageType === 'detail'">
          上升时间
        </el-checkbox>
        <div v-if="risetime && pageType !== 'detail'" style="padding: 0 10px;padding-bottom: 10px;">
          <el-button type="primary" @click="addRow(listRisetime, '上升时间')">
            增加行
          </el-button>
          <el-button type="info" @click="delRow(checkoutRisetimeList, listRisetime, '上升时间')">
            删除行
          </el-button>
        </div>
      </div>
      <template-table v-if="risetime" type="上升时间" :data="listRisetime" :columns="columns_risetime" :page-type="pageType" @selection-change="(e) => handleSelectionChange(e, '上升时间')" @confirmSelectedEquipment="confirmSelectedEquipment" />
    </detail-block>

    <!-- 核查项备注 -->
    <el-form
      :model="form"
      label-width="120"
      label-position="right"
      style="margin-top: 20px;"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="核查项备注:" prop="remark">
            <el-input
              v-model="form.remark"
              class="full-width-input"
              autosize
              type="textarea"
              :disabled="pageType === 'detail'"
              :placeholder="pageType === 'detail' ? ' ' : '请输入核查项备注'"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </app-container>
</template>

<style lang="scss">
.config-13 {
  .el-radio__label {
    display: block !important;
  }
}
</style>