Newer
Older
xc-business-system / src / views / equipement / standard / checkData / detail.vue
<!-- 核查数据管理详情 -->
<script lang="ts" setup name="checkDataDetail">
import { ref } from 'vue'
import { ElLoading, ElMessage } from 'element-plus'
import dayjs from 'dayjs'
import type { IDetailCheckData, IEquipmentList, IForm } from './checkData-interface'
import selectStandardEquipmentDialog from './dialog/selectStandardEquipmentDialog.vue'
import saveCheckRecord from './dialog/saveCheckRecord.vue'
import checkDataFirst from './components/first/checkDataCom.vue'
import checkDataSecond from './components/second/checkDataCom.vue'
import checkDataThird from './components/third/checkDataCom.vue'
import checkDataFourth from './components/fourth/checkDataCom.vue'
import checkDataFifth from './components/fifth/checkDataCom.vue'
import checkDataSeventh from './components/seventh/checkDataCom.vue'
import checkDataEighth from './components/eighth/checkDataCom.vue'
import checkDataNinth from './components/ninth/checkDataCom.vue'
import checkDataTenth from './components/tenth/checkDataCom.vue'
import checkDataEleventh from './components/eleventh/checkDataCom.vue'
import checkDataThirteenth from './components/thirteenth/checkDataCom.vue'
import checkDataFifteenth from './components/fifteenth/checkDataCom.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import useUserStore from '@/store/modules/user'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import multiTable from '@/components/MultiHeaderTable/index.vue'
import { getCheckItemDetail, getJobInstructionList } from '@/api/equipment/standard/book'
import SelectEquipmentDialog from '@/views/business/fieldTest/approve/dialog/selectEquipmentDialog.vue'
import { addCheckData, calculateHandle, getInfo, updateCheckData } from '@/api/equipment/standard/checkData'
import { getLocationList } from '@/api/business/taskMeasure/measureData'
import { addCheckRecord } from '@/api/equipment/standard/checkRecords'

const user = useUserStore() // 用户信息
const textMap: { [key: string]: string } = {
  edit: '编辑',
  add: '新建',
  detail: '详情',
}// 字典
const $router = useRouter() // 关闭页面使用
const $route = useRoute() // 路由参数
const pageType = ref('add') // 页面类型: add, edit, detail
const infoId = ref('') // 列表id
const ruleFormRef = ref() // 表单ref
const form = ref<IForm>({
  dataNo: '', // 核查数据编号
  checkDate: '', // 核查日期
  checkAddress: '', // 核查地点
  temperature: 20, // 环境温度
  humidity: 20, // 环境湿度
  checkAccord: '', // 核查依据(即标准装置的作业指导书文件minio文件名,多个分号分割)
  createUserName: '', // 核查员
  stabilityExamine: '', // 是否用于稳定性考核(1/0)
})
// 校验规则
const formRules = ref({
  checkDate: [{ required: true, message: '核查日期不能为空', trigger: ['blur', 'change'] }],
  checkAddress: [{ required: true, message: '核查地点不能为空', trigger: ['blur', 'change'] }],
  temperature: [{ required: true, message: '温度不能为空', trigger: ['blur', 'change'] },
    { pattern: /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/, message: '温度只能为数字', trigger: ['blur', 'change'] }],
  humidity: [{ required: true, message: '相对湿度不能为空', trigger: ['blur', 'change'] },
    { pattern: /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/, message: '相对湿度只能为数字', trigger: ['blur', 'change'] }],
  createUserName: [{ required: true, message: '核查员不能为空', trigger: ['blur', 'change'] }],
  stabilityExamine: [{ required: true, message: '是否用于稳定性考核不能为空', trigger: ['blur', 'change'] }],
})

const saveCheckRecordRef = ref() // 保存核查记录dialog组件ref
const checkDataRef = ref() // 第一套多功能校准源标准装置组件ref
// -------------------------------------------字典------------------------------------------
const deviceTypeList = ref<dictType[]>([])// 设备分类
const standardList = ref<dictType[]>([])// 检校标准装置
const positionList = ref([]) as any // 核查地点
const stabilityExamineList = [ // 是否用于稳定性考核
  {
    id: 1,
    name: '是',
  },
  {
    id: 0,
    name: '否',
  },
]

function getDict() {
  // 设备分类
  getDictByCode('bizEquipmentCategory').then((response) => {
    deviceTypeList.value = response.data
  })
  // 检校标准装置
  getDictByCode('bizStandardEquipmentType').then((response) => {
    standardList.value = response.data
  })
  // 地点
  getLocationList({
    locationName: '', // 地点名称
    locationNo: '', // 地点编号
    limit: 999999,
    offset: 1,
  }).then((res) => {
    positionList.value = res.data.rows.map((item: { id: string; locationName: string; temperature: string; humidity: string }) => {
      return {
        id: item.id,
        name: item.locationName, // 地点名称
        temperature: item.temperature || '', // 温度
        humidity: item.temperature || '', // 湿度
      }
    })
  })
}
// ----------------------------------路由参数------------------------------------------------
if ($route.params && $route.params.type) {
  pageType.value = $route.params.type as string

  if ($route.params.id) {
    infoId.value = $route.params.id as string
  }
}

// --------------------------------核查标准设备-----------------------------------------------
const equipmentColumns = [ // 表头
  { text: '设备名称', value: 'equipmentName', align: 'center', width: '240' },
  { text: '型号规格', value: 'model', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  // { text: '准确度等级', value: 'accuracyLevel', align: 'center' },
  // { text: '测量范围', value: 'measureRange', align: 'center' },
  { text: '制造厂家', value: 'manufacturer', align: 'center' },
  { text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' },
  { text: '备注', value: 'remark', align: 'center' },
]
const equipmentList = ref<IEquipmentList[]>([])// 表格数据
const checkoutEquipmentList = ref([]) as any // 选中数据
const selectEquipmentDialogRef = ref() // 选择设备组件ref
// 选中
const handleSelectionEquipmentChange = (e: any) => {
  checkoutEquipmentList.value = e
}
// 批量添加
const multiAddEquipment = () => {
  selectEquipmentDialogRef.value.initDialog()
}

// 确定选择设备
const confirmSelectEquipment = (list = []) => {
  list.forEach((item: IEquipmentList) => {
    // 只添加列表里不存在的
    const index = equipmentList.value.findIndex((i: { id: string }) => item.id === i.id)
    if (index === -1) {
      item.measureValidDate = item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate
      equipmentList.value.push(item)
    }
  })
}
// 删除
const delEquipmentRow = () => {
  if (!checkoutEquipmentList.value.length) {
    ElMessage.warning('请选中要删除的行')
  }
  else {
    equipmentList.value = equipmentList.value.filter((item: any) => {
      return !checkoutEquipmentList.value.includes(item)
    })
  }
}
// ------------------------------------------被核查设备---------------------------------------
const selectStandardId = ref('') // 被核查设备选择的标准装置id
const selectStandardName = ref('') // 被核查设备选择的标准装置名称
const belongStandardEquipment = ref('') // 检校标准装置code
const itemCategoryId = ref('') // 核查项分类id
const itemCategoryName = ref('') // 核查项分类名称
const chekedEquipmentList = ref<IEquipmentList[]>([{
  id: '',
  equipmentNo: '', // 设备编号
  equipmentName: '', // 设备名称
  model: '', // 型号规格
  manufactureNo: '', // 出厂编号
  accuracyLevel: '', // 准确度等级
  measureRange: '', // 测量范围
  manufacturer: '', // 制造厂(生产厂家)
  measureValidDate: '', // 检定有效期
  remark: '', // 备注
}])// 表格数据
const selectStandardEquipmentDialogRef = ref() // 选择标准装置组件ref

// 点击选择被核查设备
const selectStandardEquipment = () => {
  selectStandardEquipmentDialogRef.value.initDialog()
}

// 选好配套设备
const confirmSelectedStandardEquipmentDialog = (val: any, standardId: string, standardName: string, belongStandardEquipmentParams: string) => {
  selectStandardId.value = standardId // 被核查设备选择的标准装置id
  selectStandardName.value = standardName // 被核查设备选择的标准装置name
  belongStandardEquipment.value = belongStandardEquipmentParams // 检校标准装置code
  itemCategoryId.value = val[0].itemCategoryId // 核查项分类id
  itemCategoryName.value = val[0].itemCategoryName // 核查项分类名称
  let measureRange = '' // 测量范围
  let accuracyLevel = '' // 准确度等级
  if (val[0].technicalTargetList.length) {
    val[0].technicalTargetList.forEach((i: any, index: number) => {
      if (index === val[0].technicalTargetList.length - 1) {
        measureRange = `${measureRange}${i.measureRange} `
        accuracyLevel = `${accuracyLevel}${i.uncertainty} `
      }
      else {
        measureRange = `${measureRange}${i.measureRange}; `
        accuracyLevel = `${accuracyLevel}${i.uncertainty}; `
      }
    })
  }

  chekedEquipmentList.value = [{
    id: val[0].id,
    equipmentId: val[0].id,
    equipmentNo: val[0].equipmentNo, // 设备编号
    equipmentName: val[0].equipmentName, // 设备名称
    model: val[0].model, // 型号规格
    manufactureNo: val[0].manufactureNo, // 出厂编号
    accuracyLevel, // 准确度等级
    measureRange, // 测量范围
    manufacturer: val[0].manufacturer, // 制造厂(生产厂家)
    measureValidDate: val[0].measureValidDate, // 检定有效期
    remark: val[0].remark, // 备注
    itemCategoryId: val[0].itemCategoryId, // 核查项分类id
    itemCategoryName: val[0].itemCategoryName, // 核查项分类名称
  }]
  nextTick(() => {
    checkDataRef.value.fetchCheckItemDetail(val[0].id, belongStandardEquipment.value, itemCategoryId.value, itemCategoryName.value) // 获取核查数据
  })
}

// -------------------------------------------表单--请求核查依据(作业指导书)----------------------------------------
const technologyFile = ref([]) // 核查依据
// 查询条件(作业指导书列表)
const listQueryJobInstruction = ref({
  id: '',
  offset: 1,
  limit: 999999,
})
// // 请求作业指导书列表
function fetchJobInstruction(isNowPage = false, StandardId = '') {
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQueryJobInstruction.value.offset = 1
  }
  listQueryJobInstruction.value.id = StandardId // 标准装置id
  getJobInstructionList(listQueryJobInstruction.value).then((response) => {
    technologyFile.value = response.data.rows.map((item: { file: string }) => item.file)
  })
}

// ------------------------------------------------------------------------------------------
// 关闭新增页面的回调
const close = () => {
  $router.back()
}

// 处理保存数据
const solveSaveParams = () => {
  let params
  if (belongStandardEquipment.value === '1') {
    if (!checkDataRef.value.checkList()) { params = '未通过校验'; return params }
    const tempCheckDataCalibratorList = checkDataRef.value.bestList.concat(checkDataRef.value.bestListStability, checkDataRef.value.worstList, checkDataRef.value.worstListStability, checkDataRef.value.modelList, checkDataRef.value.modelListStability)
    params = {
      ...form.value,
      checkAccord: technologyFile.value.length ? technologyFile.value.join(',') : '', // 核查依据
      checkDataCalibratorList: tempCheckDataCalibratorList.map((item: any) => {
        return {
          ...item,
          qualified: checkDataRef.value.form.bestQualified === '合格'
                      && checkDataRef.value.form.worstQualified === '合格'
                      && checkDataRef.value.form.modelQualified === '合格'
            ? '1'
            : '0',
          lessThan: item.lessThan === '是' ? '1' : item.lessThan === '否' ? '0' : '', // 是否小于相对扩展不确定度Urel(0/1)
        }
      }), // 核查数据
      conclusion: checkDataRef.value.form.bestQualified === '合格' && checkDataRef.value.form.worstQualified === '合格' && checkDataRef.value.form.modelQualified === '合格' ? '合格' : '不合格', // 结论,与稳定性考核相同,后端需要这个字段差稳定性历史数据
      checkEquipmentIdList: equipmentList.value.map(item => item.id), // 核查标准设备
      equipmentId: chekedEquipmentList.value[0].equipmentId, // 被核查标准设备id
      equipmentName: chekedEquipmentList.value[0].equipmentName, // 被核查标准设备名称
      createUserId: user.id, //	核查员id
      createUserName: user.name, //	核查员
      itemCategoryId: chekedEquipmentList.value[0].itemCategoryId, // 核查项分类id
      itemCategoryName: itemCategoryName.value, // 核查项分类name
      standardEquipmentId: selectStandardId.value, // 被核查标准装置id
      id: infoId.value,
      belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置
    }
  }
  else if (belongStandardEquipment.value === '2') {
    if (!checkDataRef.value.checkList()) { params = '未通过校验'; return params }
    const checkDataDcPowerList = checkDataRef.value.getList()
    params = {
      ...form.value,
      checkAccord: technologyFile.value.join(','), // 核查依据
      checkDataDcPowerList: checkDataDcPowerList.map((item: any) => {
        return {
          ...item,
          qualified: checkDataRef.value.form['1-flit'] === '合格'
                      && checkDataRef.value.form['2-flit'] === '合格'
                      && checkDataRef.value.form['3-flit'] === '合格'
                      && checkDataRef.value.form['4-flit'] === '合格'
                      && checkDataRef.value.form['5-flit'] === '合格'
            ? '1'
            : '0',
          lessThan: item.lessThan === '是' ? '1' : item.lessThan === '否' ? '0' : '', // 是否小于相对扩展不确定度Urel(0/1)
        }
      }), // 核查数据
      conclusion: checkDataRef.value.form['1-flit'] === '合格' && checkDataRef.value.form['2-flit'] === '合格' && checkDataRef.value.form['3-flit'] && checkDataRef.value.form['4-flit'] && checkDataRef.value.form['5-flit'] === '合格' ? '合格' : '不合格', // 结论,与稳定性考核相同,后端需要这个字段差稳定性历史数据
      checkEquipmentIdList: equipmentList.value.map(item => item.id), // 核查标准设备
      equipmentId: chekedEquipmentList.value[0].equipmentId, // 被核查标准设备id
      createUserId: user.id, //	核查员id
      createUserName: user.name, //	核查员
      itemCategoryId: chekedEquipmentList.value[0].itemCategoryId, // 核查项分类id
      itemCategoryName: itemCategoryName.value, // 核查项分类name
      standardEquipmentId: selectStandardId.value, // 被核查标准装置id
      id: infoId.value,
      belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置
    }
  }
  else if (belongStandardEquipment.value === '3') { // 多功能电气安全校准器
    if (!checkDataRef.value.checkList()) { params = '未通过校验'; return params }
    const tempCheckDataElectricalSafetyList = checkDataRef.value.voltageList.concat(checkDataRef.value.voltageListStability, checkDataRef.value.resistanceList, checkDataRef.value.resistanceListStability)
    params = {
      ...form.value,
      checkAccord: technologyFile.value.join(','), // 核查依据
      checkDataElectricalSafetyList: tempCheckDataElectricalSafetyList.map((item: any) => {
        return {
          ...item,
          qualified: checkDataRef.value.form.voltageQualified === '合格' && checkDataRef.value.form.resistanceQualified === '合格' ? '1' : '0',
          lessThan: item.lessThan === '是' ? '1' : item.lessThan === '否' ? '0' : '', // 是否小于相对扩展不确定度Urel(0/1)
        }
      }), // 核查数据
      conclusion: checkDataRef.value.form.voltageQualified === '合格' && checkDataRef.value.form.resistanceQualified === '合格' ? '合格' : '不合格', // 结论,与稳定性考核相同,后端需要这个字段差稳定性历史数据
      checkEquipmentIdList: equipmentList.value.map(item => item.id), // 核查标准设备
      equipmentName: chekedEquipmentList.value[0].equipmentName, // 被核查标准设备名称
      equipmentId: chekedEquipmentList.value[0].equipmentId, // 被核查标准设备id
      createUserId: user.id, //	核查员id
      createUserName: user.name, //	核查员
      itemCategoryId: chekedEquipmentList.value[0].itemCategoryId, // 核查项分类id
      itemCategoryName: itemCategoryName.value, // 核查项分类name
      standardEquipmentId: selectStandardId.value, // 被核查标准装置id
      id: infoId.value,
      belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置
    }
  }
  else if (belongStandardEquipment.value === '4') { // 0.02
    params = {
      ...form.value,
      ...checkDataRef.value.form,
      checkAccord: technologyFile.value.join(','), // 核查依据
      checkDataPistonGaugeList: checkDataRef.value.list.map((item: { id: string }) => {
        return {
          ...item,
          id: pageType.value === 'add' ? '' : item.id,
        }
      }), // 核查数据
      checkEquipmentIdList: equipmentList.value.map(item => item.id), // 核查标准设备
      equipmentName: chekedEquipmentList.value[0].equipmentName, // 被核查标准设备名称
      equipmentId: chekedEquipmentList.value[0].equipmentId, // 被核查标准设备id
      createUserId: user.id, //	核查员id
      createUserName: user.name, //	核查员
      // temperature: Number(form.value.temperature), // 环境温度
      // humidity: Number(form.value.humidity), // 环境湿度
      itemCategoryId: chekedEquipmentList.value[0].itemCategoryId, // 核查项分类id
      itemCategoryName: itemCategoryName.value, // 核查项分类name
      standardEquipmentId: selectStandardId.value, // 被核查标准装置id
      id: infoId.value,
      belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置
    }
  }
  else if (belongStandardEquipment.value === '5') { // 二等铂
    if (!checkDataRef.value.checkList()) { params = '未通过校验'; return params }
    let tempCheckDataResistanceThermometerList = [] as any
    // 是否进行温度核查
    if (`${checkDataRef.value.form.isCheckTemperature}` === '1') { // 温度值
      tempCheckDataResistanceThermometerList = tempCheckDataResistanceThermometerList.concat(checkDataRef.value.temperatureListRepeatability, checkDataRef.value.temperatureListStability)
    }
    // 是否进行RTP核查
    if (`${checkDataRef.value.form.isCheckRTP}` === '1') { // RTP值
      tempCheckDataResistanceThermometerList = tempCheckDataResistanceThermometerList.concat(checkDataRef.value.RTPListRepeatability, checkDataRef.value.RTPListStability)
    }
    // 绝缘电阻表校准\测温仪电阻核查
    tempCheckDataResistanceThermometerList = tempCheckDataResistanceThermometerList.concat(checkDataRef.value.listinsulationResistance, checkDataRef.value.listThermodetector)
    params = {
      ...form.value,
      ...checkDataRef.value.form,
      checkAccord: technologyFile.value.join(','), // 核查依据
      checkDataResistanceThermometerList: tempCheckDataResistanceThermometerList.map((item: { id: string }) => {
        return {
          ...item,
          id: pageType.value === 'add' ? '' : item.id,
        }
      }), // 核查数据
      checkEquipmentIdList: equipmentList.value.map(item => item.id), // 核查标准设备
      equipmentName: chekedEquipmentList.value[0].equipmentName, // 被核查标准设备名称
      equipmentId: chekedEquipmentList.value[0].equipmentId, // 被核查标准设备id
      createUserId: user.id, //	核查员id
      createUserName: user.name, //	核查员
      itemCategoryId: chekedEquipmentList.value[0].itemCategoryId, // 核查项分类id
      itemCategoryName: itemCategoryName.value, // 核查项分类name
      standardEquipmentId: selectStandardId.value, // 被核查标准装置id
      id: infoId.value,
      belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置
    }
  }
  else if (belongStandardEquipment.value === '8') { // E2等砝码
    if (!checkDataRef.value.checkList()) { params = '未通过校验'; return params }
    const list = checkDataRef.value.listRepeatability.concat(checkDataRef.value.listStability)
    params = {
      ...form.value,
      ...checkDataRef.value.form,
      checkAccord: technologyFile.value.join(','), // 核查依据
      checkDataETwoList: list.map((item: { id: string }) => {
        return {
          ...item,
          id: pageType.value === 'add' ? '' : item.id,
        }
      }), // 核查数据
      checkEquipmentIdList: equipmentList.value.map(item => item.id), // 核查标准设备
      equipmentName: chekedEquipmentList.value[0].equipmentName, // 被核查标准设备名称
      equipmentId: chekedEquipmentList.value[0].equipmentId, // 被核查标准设备id
      createUserId: user.id, //	核查员id
      createUserName: user.name, //	核查员
      itemCategoryId: chekedEquipmentList.value[0].itemCategoryId, // 核查项分类id
      itemCategoryName: itemCategoryName.value, // 核查项分类name
      standardEquipmentId: selectStandardId.value, // 被核查标准装置id
      id: infoId.value,
      belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置
    }
  }
  else if (belongStandardEquipment.value === '9') { // 频谱分析仪
    if (!checkDataRef.value.checkList()) { params = '未通过校验'; return params }
    const list = checkDataRef.value.getList()
    params = {
      ...form.value,
      checkDataSpectrumAnalyzerList: list.map((item: { id: string }) => {
        return {
          ...item,
          id: pageType.value === 'add' ? '' : item.id,
        }
      }), // 核查数据
      checkEquipmentIdList: equipmentList.value.map(item => item.id), // 核查标准设备
      equipmentName: chekedEquipmentList.value[0].equipmentName, // 被核查标准设备名称
      equipmentId: chekedEquipmentList.value[0].equipmentId, // 被核查标准设备id
      createUserId: user.id, //	核查员id
      createUserName: user.name, //	核查员
      itemCategoryId: chekedEquipmentList.value[0].itemCategoryId, // 核查项分类id
      itemCategoryName: itemCategoryName.value, // 核查项分类name
      standardEquipmentId: selectStandardId.value, // 被核查标准装置id
      id: infoId.value,
      belongStandardEquipment: belongStandardEquipment.value, // 检校标准装置
    }
  }
  return params
}

// 保存
const save = () => {
  if (!equipmentList.value.length) {
    ElMessage.warning('核查标准设备不能为空')
    return false
  }
  if (!chekedEquipmentList.value[0].equipmentNo) {
    ElMessage.warning('被核查设备不能为空')
    return false
  }
  ruleFormRef.value!.validate((valid: boolean) => {
    if (valid) {
      const params = solveSaveParams()// 处理保存入参
      console.log('保存的入参', params)
      if (params === '未通过校验') { return false }
      const loading = ElLoading.service({
        lock: true,
        background: 'rgba(255, 255, 255, 0.8)',
      })
      if (pageType.value === 'add') { // 新建
        addCheckData(params).then((res) => {
          ElMessage.success('保存成功')
          // form.value.dataNo = res.data.dataNo // 核查数据编号
          infoId.value = res.data
          pageType.value = 'detail'
          fetchInfo()
          loading.close()
        }).catch(() => {
          loading.close()
        })
      }
      // 保存
      else if (pageType.value === 'edit') { // 编辑
        updateCheckData(params).then((res) => {
          ElMessage.success('保存成功')
          pageType.value = 'detail'
          loading.close()
        }).catch(() => {
          loading.close()
        })
      }
    }
    else {
      console.log('表单校验不通过')
    }
  })
}
// 点击编辑
const edit = () => {
  pageType.value = 'edit'
}

// 获取详情
function fetchInfo() {
  const loading = ElLoading.service({
    lock: true,
    background: 'rgba(255, 255, 255, 0.8)',
  })
  getInfo({ id: infoId.value }).then((res) => {
    form.value = { ...res.data }
    // =========================================================
    chekedEquipmentList.value = [{ // 被检设备
      id: '',
      equipmentId: res.data.equipmentInfo.id, // 设备id
      equipmentNo: res.data.equipmentInfo.equipmentNo, // 设备编号
      equipmentName: res.data.equipmentInfo.equipmentName, // 设备名称
      model: res.data.equipmentInfo.model, // 型号规格
      manufactureNo: res.data.equipmentInfo.manufactureNo, // 出厂编号
      accuracyLevel: res.data.accuracyLevel, // 准确度等级
      measureRange: res.data.measureRange, // 测量范围
      manufacturer: res.data.equipmentInfo.manufacturer, // 制造厂(生产厂家)
      measureValidDate: res.data.equipmentInfo.measureValidDate, // 证书有效期
      remark: res.data.equipmentInfo.remark, // 备注
      itemCategoryId: res.data.itemCategoryId, // 核查项分类id
      itemCategoryName: res.data.itemCategoryName, // 核查项分类名称
    }]
    technologyFile.value = res.data.checkAccord ? res.data.checkAccord.split(',') : [] // 核查依据
    equipmentList.value = res.data.checkEquipmentList // 核查标准设备
    selectStandardId.value = res.data.standardEquipmentId // 被核查标准装置id
    itemCategoryName.value = $route.query.itemCategoryName as string // 核查项分类名称
    loading.close()
  })
}

// 点击生成核查记录
const createCheckRecord = () => {
  const solvedParams = solveSaveParams()
  // saveCheckRecordRef.value.initDialog(params)
  if (user.bizLabCode === '') {
    ElMessage.warning('此用户没有实验室代码,不允许生成证书')
    return false
  }
  if (user.groupNo === '') {
    ElMessage.warning('此用户没有组别代码,不允许生成证书')
    return false
  }
  // saveMeasureCertificateRef.value.initDialog(params) 弹窗输入组别代码、实验室代码、名称
  const loading = ElLoading.service({
    lock: true,
    text: '正在生成证书、请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  console.log('实验室代码', user.bizLabCode)
  console.log('组别代码', user.groupNo)

  const params = {
    ...solvedParams,
    labCode: user.bizLabCode, // 实验室代码
    groupCode: user.groupNo, // 组别代码
    recordName: `${solvedParams.equipmentInfo.equipmentName}-${solvedParams.checkDate}`, // 核查记录报告名称
    dataId: solvedParams.id, // 核查记录id
    checkDateId: solvedParams.id, // 核查记录id
    id: '',
  }
  addCheckRecord(params).then((res) => {
    ElMessage.success('生成证书成功')
    $router.push({
      path: `/equipmentCheckRecord/detail/${res.data.id}`,
      query: {
        certNo: res.data.certNo, // 检定证书报告
        sampleName: solvedParams.sampleName, // 被检设备名称
        model: solvedParams.sampleModel, // 被检设备名称
        manufacturingNo: solvedParams.manufactureNo, // 被检设备名称
        approvalStatusName: '草稿箱',
        dataId: solvedParams.id, // 检定数据管理基础信息表id
        checkDateId: solvedParams.id,
      },
    })
    loading.close()
  }).catch(() => {
    loading.close()
  })
}

// -------------------------------------组件change事件--------------------------------------------
// 地点变化事件
const handleChangeAddress = (name: string) => {
  console.log('地点变化事件', name)
  if (`${name}` !== '') {
    const index = positionList.value.findIndex((item: { name: string }) => item.name === name)
    if (index !== -1) {
      form.value.temperature = positionList.value[index].temperature
      form.value.humidity = positionList.value[index].humidity
    }
  }
}

// -------------------------------------钩子-----------------------------------------------------
watch(() => selectStandardId.value, (newValue) => {
  if (newValue) {
    fetchJobInstruction(false, newValue) // 请求作业指导书
  }
})
onMounted(async () => {
  belongStandardEquipment.value = $route.query.belongStandardEquipment as string // 检校标准装置
  itemCategoryId.value = $route.query.itemCategoryId as string // 核查项分类id
  itemCategoryName.value = $route.query.itemCategoryName as string // 核查项分类名称
  console.log('itemCategoryIddetail', itemCategoryId.value)
  console.log('itemCategoryNamedetai', itemCategoryName.value)
  getDict()
  if (pageType.value === 'add') {
    form.value.createUserName = user.name // 核查员
    form.value.checkDate = dayjs().format('YYYY-MM-DD')
  }
  else {
    fetchInfo()
  }
})
</script>

<template>
  <app-container>
    <detail-page :title="`核查数据管理-${textMap[pageType]}`">
      <template #btns>
        <el-button v-if="pageType === 'detail'" type="primary" @click="createCheckRecord">
          生成核查记录
        </el-button>
        <!-- <el-button v-if="pageType === 'detail'" type="primary" @click="edit">
          编辑
        </el-button> -->
        <el-button v-if="pageType !== 'detail'" 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"
        :rules="formRules"
      >
        <el-row :gutter="24">
          <el-col :span="6">
            <el-form-item label="核查数据编号:" prop="dataNo">
              <el-input v-model="form.dataNo" class="full-width-input" disabled placeholder="系统自动生成" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="核查日期:" prop="checkDate">
              <el-date-picker
                v-model="form.checkDate"
                type="date"
                format="YYYY-MM-DD"
                value-format="YYYY-MM-DD"
                :placeholder="pageType === 'detail' ? ' ' : '请选择核查日期'"
                :disabled="pageType === 'detail'"
                class="full-width-input"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="核查地点:" prop="checkAddress">
              <el-select
                v-model="form.checkAddress"
                placeholder="核查地点"
                filterable
                :disabled="pageType === 'detail'"
                @change="handleChangeAddress"
              >
                <el-option v-for="item in positionList" :key="item.id" :label="item.name" :value="item.name" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="温度(℃):" prop="temperature">
              <el-input-number
                v-model="form.temperature"
                :disabled="pageType === 'detail'"
                :placeholder="pageType === 'detail' ? ' ' : '请输入温度'"
                :max="99.99"
                :precision="2"
              />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="相对湿度(%RH):" prop="humidity">
              <el-input-number
                v-model="form.humidity"
                :disabled="pageType === 'detail'"
                :placeholder="pageType === 'detail' ? ' ' : '请输入相对湿度'"
                :max="99.99"
                :precision="2"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="核查员:" prop="dacreateUserNametaNo">
              <el-input v-model="form.createUserName" disabled placeholder="检定员" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否用于稳定性考核:" label-width="160" prop="stabilityExamine">
              <el-select
                v-model="form.stabilityExamine"
                placeholder="请选择"
                class="short-input"
                filterable
                :disabled="pageType === 'detail'"
              >
                <el-option v-for="item in stabilityExamineList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" class="marg">
          <el-col :span="24">
            <el-form-item label="核查依据:" prop="technologyFile">
              <div v-for="(item, index) in technologyFile" :key="index" style="display: flex;">
                <show-photo v-if="technologyFile.length" :minio-file-name="item" style="margin-right: 10px;" />
              </div>
              <span v-if="pageType === 'detail' && !technologyFile.length">无</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </detail-page>
    <detail-block title="核查标准设备">
      <template v-if="pageType !== 'detail'" #btns>
        <el-button type="primary" @click="multiAddEquipment">
          批量添加
        </el-button>
        <el-button type="info" @click="delEquipmentRow">
          删除行
        </el-button>
      </template>
      <el-table
        :data="equipmentList"
        border
        style="width: 100%;"
        @selection-change="handleSelectionEquipmentChange"
      >
        <el-table-column v-if="pageType !== 'detail'" type="selection" width="55" />
        <el-table-column align="center" label="序号" width="80" type="index" />
        <el-table-column
          v-for="item in equipmentColumns"
          :key="item.value"
          :prop="item.value"
          :label="item.text"
          :width="item.width"
          align="center"
        />
      </el-table>
    </detail-block>
    <detail-block title="被核查设备">
      <el-table
        :data="chekedEquipmentList"
        border
        style="width: 100%;"
      >
        <el-table-column align="center" label="序号" width="80" type="index" />
        <el-table-column
          v-for="item in equipmentColumns"
          :key="item.value"
          :prop="item.value"
          :label="item.text"
          :width="item.width"
          align="center"
        >
          <template #default="scope">
            <el-input
              v-if="pageType !== 'detail' && item.value === 'equipmentName'"
              v-model="scope.row[item.value]"
              placeholder="请选择"
              disabled
            >
              <template #append>
                <el-button size="small" @click="selectStandardEquipment">
                  选择
                </el-button>
              </template>
            </el-input>
          </template>
        </el-table-column>
      </el-table>
    </detail-block>
    <!-- 第1套:多功能校准源标准装置 -->
    <check-data-first v-if="belongStandardEquipment === '1'" ref="checkDataRef" :check-date="form.checkDate" :page-type="pageType" :select-standard-id="selectStandardId" />
    <!-- 第2套:直流稳压电源 -->
    <check-data-second v-if="belongStandardEquipment === '2'" ref="checkDataRef" :check-date="form.checkDate" :page-type="pageType" :select-standard-id="selectStandardId" />
    <!-- 第3套:多功能电器安全校准器 -->
    <check-data-third v-if="belongStandardEquipment === '3'" ref="checkDataRef" :check-date="form.checkDate" :page-type="pageType" :select-standard-id="selectStandardId" />
    <!-- 第4套:0.02级活塞式压力计 -->
    <check-data-fourth v-if="belongStandardEquipment === '4'" ref="checkDataRef" />
    <!-- 第5套:二等铂电阻温度计标准装置 -->
    <check-data-fifth v-if="belongStandardEquipment === '5'" ref="checkDataRef" :check-date="form.checkDate" :page-type="pageType" :select-standard-id="selectStandardId" />
    <!-- 第7套:精密露点仪标准装置  -->
    <check-data-seventh v-if="belongStandardEquipment === '7'" ref="checkDataRef" />
    <!-- 第8套:E2等砝码标准装置  -->
    <check-data-eighth v-if="belongStandardEquipment === '8'" ref="checkDataRef" :check-date="form.checkDate" :page-type="pageType" :select-standard-id="selectStandardId" />
    <!-- 第9套: 频谱分析仪 -->
    <check-data-ninth v-if="belongStandardEquipment === '9'" ref="checkDataRef" :check-date="form.checkDate" :page-type="pageType" :select-standard-id="selectStandardId" />
    <!-- 第10套: 信号发生器 -->
    <check-data-tenth v-if="belongStandardEquipment === '10'" ref="checkDataRef" />
    <!-- 第11套: 微波衰减器 -->
    <check-data-eleventh v-if="belongStandardEquipment === '11'" ref="checkDataRef" />
    <!-- 第13套:示波器标准装置 -->
    <check-data-thirteenth v-if="belongStandardEquipment === '13'" ref="checkDataRef" />
    <!-- 第15套:小功率标准装置 -->
    <check-data-fifteenth v-if="belongStandardEquipment === '15'" ref="checkDataRef" />

    <!-- 选择设备台账 -->
    <select-equipment-dialog ref="selectEquipmentDialogRef" :is-multi="true" @confirm="confirmSelectEquipment" />
    <!-- 选择标准装置设备 -->
    <select-standard-equipment-dialog ref="selectStandardEquipmentDialogRef" @confirm="confirmSelectedStandardEquipmentDialog" />
    <!-- 保存核查记录  -->
    <save-check-record ref="saveCheckRecordRef" />
  </app-container>
</template>

<style lang="scss" scoped>
.link {
  text-decoration: underline;
  color: #3d7eff;
  cursor: pointer;
}

.file-area {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #60627f;
  margin-bottom: 10px;
  margin-left: 40px;
  white-space: nowrap;

  .tech-file {
    display: flex;
    align-items: center;
    margin-left: 20px;

    .file-text {
      margin-right: 10px;
    }
  }
}
</style>