<!-- 溯源计划管理 基本信息 -->
<script name="ResultConfirmApproveBasic" lang="ts" setup>
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import dayjs from 'dayjs'
import type { IForm, IQuantityTarget } from '../resultConfirm-interface'
import type { dictType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import { SCHEDULE } from '@/utils/scheduleDict'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import useUserStore from '@/store/modules/user'
import { useCheckList } from '@/commonMethods/useCheckList'
import { UploadFile } from '@/api/file'
import SelectEquipmentDialog from '@/views/business/fieldTest/approve/dialog/selectEquipmentDialog.vue'
import { useDoubleClickTableRow, useSetAllRowReadable } from '@/commonMethods/useSetAllRowReadable'
import { addResultConfirmList, failUpdateResultConfirmList, getInfo, submit, updateResultConfirmList } from '@/api/equipment/source/resultConfirm'
const props = defineProps({
  pageType: { // 页面类型 add新建 edit编辑 detail详情
    type: String,
    requre: true,
    default: 'detail',
  },
  id: {
    type: String,
    requre: true,
  },
  approvalStatusName: { // 审批状态名称
    type: String,
    requre: true,
  },
  processId: {
    type: String,
  },
})
const emits = defineEmits(['addSuccess', 'submitSuccess'])
const user = useUserStore() // 用户信息
const form = ref<IForm>({
  id: '', // 列表id
  labCode: '', // 实验室代码
  groupCode: '', // 组别代码
  confirmNo: '', // 登记表编号
  confirmName: '', // 登记表名称
  createUserId: '', // 创建人id
  createUserName: '', // 创建人
  createTime: '', // 创建时间
  planGroup: '', // 计划表组别
  planYear: '', // 计划表年份

  equipmentId: '', // 设备id
  equipmentNo: '', // 统一编号
  equipmentName: '', // 设备名称
  model: '', // 型号规格
  standardNo: '', // 所属测量标准号
  standardName: '', // 所属测量标准名称

  measureCategory: '', // 证书类型
  measureCategoryName: '', // 证书类型名称
  labelConsistent: undefined, // 是否与粘贴标识一致
  certificateNo: '', // 证书编号
  traceCompany: '', // 溯源机构名称
  supplierConsistent: undefined, // 是否与合格供方名录一致
  diagramConsistent: undefined, // 是否与溯源等级关系图一致
  customerMatch: undefined, // 委托方名称是否与实际相符
  customerAddressMatch: undefined, // 委托方地址是否与实际相符
  equipmentCorrect: undefined, // 被检件名称是否正确
  equipmentModelCorrect: undefined, // 被检件型号是否正确
  equipmentNoCorrect: undefined, // 被检件编号是否正确
  equipmentManufacturerCorrect: undefined, // 被检件生产厂家是否正确
  onValid: undefined, // 测量设备开展检定工作时是否在有效期内
  denyInfo: '', // 否则列出
  fileCorrect: undefined, // 依据文件是否正确
  fileNoOne: '', // 依据文件编号1
  fileNoNameOne: '', // 依据文件名称1
  fileNoTwo: '', // 依据文件编号2
  fileNoNameTwo: '', // 依据文件名称2
  fileNoThree: '', // 依据文件编号3
  fileNoNameThree: '', // 依据文件名称3
  fileNoFour: '', // 依据文件编号4
  fileNoNameFour: '', // 依据文件名称4
  conclusion: '', // 结论
  traceDate: '', // 测试、校准或检定日期
  dateCorrect: undefined, // 日期是否与粘贴标识一致
  validDate: '', // 有效期
  validDateCorrect: undefined, // 有效期是否正确
  signComplete: undefined, // 签名信息是否齐全
  sealComplete: undefined, // 是否盖有有效印章

  meterIdentify: '', // 结果确认结论(计量标识字典code)
  meterIdentifyName: '', // 结果确认结论(计量标识字典value)
  certificateFile: '', // 检定证书
  remark: '', // 备注

  quantityTargetItem: '', // 量传指标检定项目
  notQuantityTargetItem: '', // 非量传指标检定项目

})

const ruleFormRef = ref() // 表单ref
const certFormRef = ref() // 证书要素确认ref
const resultRulesRef = ref() // 结果确认ref
const equipmentRef = ref() // 设备ref
const loading = ref(false) // loading
const infoId = ref('') // id
const rules = ref<FormRules>({ // 校验规则
  equipmentNo: [{ required: true, message: '统一编号不能为空', trigger: ['blur', 'change'] }],
  denyInfo: [{ required: true, message: '否则列出不能为空', trigger: ['blur', 'change'] }],
  labCode: [{ required: true, message: '实验室代码不能为空', trigger: ['blur', 'change'] }],
  groupCode: [{ required: true, message: '组别代码不能为空', trigger: ['blur', 'change'] }],
  planYear: [{ required: true, message: '年不能为空', trigger: ['blur', 'change'] }],
  planGroup: [{ required: true, message: '组不能为空', trigger: ['blur', 'change'] }],
  measureCategory: [{ required: true, message: '证书类型不能为空', trigger: ['blur', 'change'] }],
  labelConsistent: [{ required: true, message: '是否与粘贴标识一致不能为空', trigger: ['blur', 'change'] }],
  certificateNo: [{ required: true, message: '证书编号不能为空', trigger: ['blur', 'change'] }],
  traceCompany: [{ required: true, message: '溯源机构名称不能为空', trigger: ['blur', 'change'] }],
  supplierConsistent: [{ required: true, message: '是否与合格供方名录一致不能为空', trigger: ['blur', 'change'] }],
  diagramConsistent: [{ required: true, message: '是否与溯源等级关系图一致不能为空', trigger: ['blur', 'change'] }],
  customerMatch: [{ required: true, message: '委托方名称是否与实际相符不能为空', trigger: ['blur', 'change'] }],
  customerAddressMatch: [{ required: true, message: '委托方地址是否与实际相符不能为空', trigger: ['blur', 'change'] }],
  equipmentCorrect: [{ required: true, message: '被检件名称是否正确不能为空', trigger: ['blur', 'change'] }],
  equipmentModelCorrect: [{ required: true, message: '被检件型号是否正确不能为空', trigger: ['blur', 'change'] }],
  equipmentNoCorrect: [{ required: true, message: '被检件编号是否正确不能为空', trigger: ['blur', 'change'] }],
  equipmentManufacturerCorrect: [{ required: true, message: '被检件生产厂家是否正确不能为空', trigger: ['blur', 'change'] }],
  onValid: [{ required: true, message: '测量设备开展检定工作时是否在有效期内不能为空', trigger: ['blur', 'change'] }],
  fileCorrect: [{ required: true, message: '依据文件是否正确不能为空', trigger: ['blur', 'change'] }],
  fileNoOne: [{ required: true, message: '依据文件编号1不能为空', trigger: ['blur', 'change'] }],
  fileNoNameOne: [{ required: true, message: '依据文件名称1不能为空', trigger: ['blur', 'change'] }],
  fileNoTwo: [{ required: true, message: '依据文件编号2不能为空', trigger: ['blur', 'change'] }],
  fileNoNameTwo: [{ required: true, message: '依据文件名称2不能为空', trigger: ['blur', 'change'] }],
  fileNoThree: [{ required: true, message: '依据文件编号3不能为空', trigger: ['blur', 'change'] }],
  fileNoNameThree: [{ required: true, message: '依据文件名称3不能为空', trigger: ['blur', 'change'] }],
  fileNoFour: [{ required: true, message: '依据文件编号4不能为空', trigger: ['blur', 'change'] }],
  fileNoNameFour: [{ required: true, message: '依据文件名称4不能为空', trigger: ['blur', 'change'] }],
  conclusion: [{ required: true, message: '结论不能为空', trigger: ['blur', 'change'] }],
  traceDate: [{ required: true, message: '测试、校准或检定日期不能为空', trigger: ['blur', 'change'] }],
  dateCorrect: [{ required: true, message: '日期是否与粘贴标识一致不能为空', trigger: ['blur', 'change'] }],
  validDate: [{ required: true, message: '有效期不能为空', trigger: ['blur', 'change'] }],
  validDateCorrect: [{ required: true, message: '有效期是否正确不能为空', trigger: ['blur', 'change'] }],
  signComplete: [{ required: true, message: '签名信息是否齐全不能为空', trigger: ['blur', 'change'] }],
  sealComplete: [{ required: true, message: '是否盖有有效印章不能为空', trigger: ['blur', 'change'] }],
  meterIdentify: [{ required: true, message: '结果确认结论不能为空', trigger: ['blur', 'change'] }],
  certificateFile: [{ required: true, message: '检定证书不能为空', trigger: ['blur', 'change'] }],
})

// -----------------------------------------字典--------------------------------------------------------------
const labCodeList = ref<dictType[]>([]) // 实验室代码
const groupCodeList = ref<dictType[]>([]) // 组别代码
const meterIdentifyDict = ref<dictType[]>([]) // 计量标识
const measureCategoryList = ref<dictType[]>([]) // 证书类型(即检校类别)

// 查询字典
const getDict = async () => {
  // 计量标识
  getDictByCode('bizMeterIdentify').then((response) => {
    meterIdentifyDict.value = response.data
  })
  // 实验室代码
  getDictByCode('bizLabCode').then((response) => {
    labCodeList.value = response.data
  })
  // 组别代码
  getDictByCode('bizGroupCode').then((response) => {
    groupCodeList.value = response.data
  })
  // 证书类型(即检校类别)
  getDictByCode('measureCategory').then((response) => {
    measureCategoryList.value = response.data
  })
}
// --------------------------------------选择设备编号-------------------------------------------------
const selectEquipmentDialogRef = ref() // 选择设备编号组件ref
// 批量添加
const selectEquipment = () => {
  selectEquipmentDialogRef.value.initDialog()
}

// 确定选择设备
const confirmSelectEquipment = (val: any) => {
  console.log(val[0])

  if (val.length) {
    form.value.equipmentId = val[0].id // 设备id
    form.value.equipmentNo = val[0].equipmentNo // 统一编号
    form.value.equipmentName = val[0].equipmentName // 设备名称
    form.value.model = val[0].model // 型号规格
    form.value.standardNo = val[0].standardNo // 所属测量标准号
    form.value.standardName = val[0].standardName // 所属测量标准名称
  }
}

// ----------------------------------------------依据文件-------------------------------------------
const showFileTree = ref(false) // 是否显示第三个依据文件
const showFileFour = ref(false) // 是否显示第四个依据文件
// 点击增加依据文件
const addFile = () => {
  if (!showFileTree.value) {
    showFileTree.value = true
  }
  else {
    showFileFour.value = true
  }
}

// ------------------------------------------量传指标------------------------------------------------
const quantityTargetColumns = ref([ // 表头
  { text: '测量范围', value: 'measureRange', align: 'center', required: true },
  { text: '使用要求', value: 'useRequire', align: 'center', required: true },
  { text: '测试、校准或检定数据是否满足使用要求', value: 'meetRequire', align: 'center', required: true },
  { text: '如不满足，请写明范围', value: 'reason', align: 'center' },
])
const quantityTargetList = ref<IQuantityTarget[]>([]) // 量传指标列表
const checkoutQuantityTargetList = ref<IQuantityTarget[]>([]) // 量传指标选中
const notQuantityTargetList = ref<IQuantityTarget[]>([]) // 非量传指标列表
const checkoutNotQuantityTargetList = ref<IQuantityTarget[]>([]) // 非量传指标选中

// 量传指标选中
const handleTechSelectionQuantityTargetChange = (e: any) => {
  checkoutQuantityTargetList.value = e
}

// 非量传指标选中
const handleTechSelectionNotQuantityTargetChange = (e: any) => {
  checkoutNotQuantityTargetList.value = e
}

// 点击增加行
const addRow = (type: string) => {
  if (type === 'quantityTarget') { // 量传指标
    const checkResult = useCheckList(quantityTargetList.value, quantityTargetColumns.value, '量传指标', 'reason', 'meetRequire', 0) // 检查表格
    if (checkResult) {
      useSetAllRowReadable(quantityTargetList.value)
      quantityTargetList.value.push({
        id: '',
        measureRange: '', // 测量范围
        useRequire: '', // 使用要求
        meetRequire: '', // 测试、校准或检定数据是否满足使用要求
        reason: '', // 如不满足，请写明范围
        editable: props.pageType === 'edit',
      })
    }
  }
  else {
    const checkResult = useCheckList(notQuantityTargetList.value, quantityTargetColumns.value, '非量传指标', 'reason', 'meetRequire', 0) // 检查表格
    if (checkResult) {
      useSetAllRowReadable(notQuantityTargetList.value)
      notQuantityTargetList.value.push({
        id: '',
        measureRange: '', // 测量范围
        useRequire: '', // 使用要求
        meetRequire: '', // 测试、校准或检定数据是否满足使用要求
        reason: '', // 如不满足，请写明范围
        editable: props.pageType === 'edit',
      })
    }
  }
}

// 删除行
const deleteRow = (type: string) => {
  if (type === 'quantityTarget') { // 量传指标
    if (!checkoutQuantityTargetList.value.length) {
      ElMessage({
        message: '请选中要删除的行',
        type: 'warning',
      })
      return false
    }
    quantityTargetList.value = quantityTargetList.value.filter((item: any) => {
      return !checkoutQuantityTargetList.value.includes(item)
    })
  }
  else { // 非量传指标
    if (!checkoutNotQuantityTargetList.value.length) {
      ElMessage({
        message: '请选中要删除的行',
        type: 'warning',
      })
      return false
    }
    notQuantityTargetList.value = notQuantityTargetList.value.filter((item: any) => {
      return !checkoutNotQuantityTargetList.value.includes(item)
    })
  }
}

// 双击行--量传指标
const rowDblclickQuantityTarget = (row: any) => {
  if (props.pageType !== 'detail') {
    useDoubleClickTableRow(row, checkoutQuantityTargetList.value)
  }
}

// 双击行--非量传指标
const rowDblclickNotQuantityTarget = (row: any) => {
  if (props.pageType !== 'detail') {
    useDoubleClickTableRow(row, checkoutNotQuantityTargetList.value)
  }
}

// -------------------------------------------文件上传--------------------------------------
const fileRef = ref() // 文件上传input
const onFileChange = (event: any) => {
  if (event.target.files?.length !== 0) {
    // 创建formdata对象
    const fd = new FormData()
    fd.append('multipartFile', event.target.files[0])
    const loading = ElLoading.service({
      lock: true,
      background: 'rgba(255, 255, 255, 0.8)',
    })
    UploadFile(fd).then((res) => {
      if (res.code === 200) {
        form.value.certificateFile = res.data[0]
        // 重置当前验证
        ElMessage.success('文件上传成功')
        loading.close()
      }
      else {
        ElMessage.error(res.message)
        loading.close()
      }
    })
  }
}
const upload = () => {
  fileRef.value.click()
}

// -----------------------------------------------保存----------------------------------------------
/**
 * 点击保存
 * @param formEl 基本信息表单ref
 */
const saveForm = () => {
  if (!useCheckList(quantityTargetList.value, quantityTargetColumns.value, '量传指标', 'reason', 'meetRequire', 0)) {
    return false
  }
  if (!quantityTargetList.value.length) {
    ElMessage.warning('量传指标不能为空')
    return false
  }
  if (!useCheckList(notQuantityTargetList.value, quantityTargetColumns.value, '非量传指标', 'reason', 'meetRequire', 0)) {
    return false
  }
  if (!notQuantityTargetList.value.length) {
    ElMessage.warning('非量传指标不能为空')
    return false
  }
  if (!form.value.quantityTargetItem) {
    ElMessage.warning('量传指标检定项目不能为空')
    return false
  }
  if (!form.value.notQuantityTargetItem) {
    ElMessage.warning('非量传指标检定项目不能为空')
    return false
  }

  if (!ruleFormRef || !certFormRef || !resultRulesRef) { return }
  Promise.all([ruleFormRef.value.validate(), certFormRef.value.validate(), resultRulesRef.value.validate(), equipmentRef.value.validate()]).then(() => {
    ElMessageBox.confirm(
      '确认保存吗？',
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    ).then(() => {
      const loading = ElLoading.service({
        lock: true,
        text: '加载中...',
        background: 'rgba(255, 255, 255, 0.8)',
      })
      const quantityTargetListParam = quantityTargetList.value.map((item) => {
        return {
          ...item,
          quantityTarget: '1',
          item: form.value.quantityTargetItem,
        }
      })
      const notQuantityTargetListParam = notQuantityTargetList.value.map((item) => {
        return {
          ...item,
          quantityTarget: '2',
          item: form.value.notQuantityTargetItem,
        }
      })
      const list = quantityTargetListParam.concat(notQuantityTargetListParam)

      const params = {
        ...form.value,
        id: infoId.value,
        confirmName: `${form.value.planYear}年${form.value.planGroup}组测量设备测试、校准或检定结果确认登记表`,
        quantityList: list,
        processId: props.processId,
      }
      if (props.pageType === 'add') { // 新建
        addResultConfirmList(params).then((res) => {
          loading.close()
          form.value.confirmNo = res.data.confirmNo // 计划表编号
          infoId.value = res.data.id // id
          emits('addSuccess', infoId.value)
          ElMessage.success('已保存')
        }).catch(() => {
          loading.close()
        })
      }
      else if (props.pageType === 'edit') { // 编辑
        console.log(props.approvalStatusName)
        if (props.approvalStatusName === '草稿箱' || props.approvalStatusName === '全部') {
          updateResultConfirmList(params).then((res) => {
            loading.close()
            emits('addSuccess', infoId.value)
            ElMessage.success('已保存')
          }).catch(() => {
            loading.close()
          })
        }
        else { // '未通过' || '已取消'
          failUpdateResultConfirmList(params).then((res) => {
            loading.close()
            emits('submitSuccess')
            fetchInfo()
            ElMessage.success('已保存')
          }).catch(() => {
            loading.close()
          })
        }
      }
    })
  })
}

// ----------------------------------------------提交--------------------------------------------
// 提交
/**
 *
 * @param processId 流程实例id
 * @param id
 */
const submitForm = (processId: string, id: string) => {
  const loading = ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  submit({ id, formId: SCHEDULE.TRACE_RESULT_VERIFICATION_APPROVAL }).then((res) => {
    ElMessage.success('已提交')
    emits('submitSuccess')
    loading.close()
  })
}
// -----------------------------------------获取详情------------------------------------------
// 获取详情
function fetchInfo() {
  loading.value = true
  getInfo({ id: infoId.value }).then((res) => {
    loading.value = false
    form.value = res.data
    form.value.planYear = `${res.data.planYear}`
    quantityTargetList.value = res.data.quantityList.filter((item: { quantityTarget: string }) => item.quantityTarget === '1') // 量传指标
    notQuantityTargetList.value = res.data.quantityList.filter((item: { quantityTarget: string }) => item.quantityTarget === '2') // 非量传指标
    if (props.pageType === 'detail') {
      quantityTargetList.value = quantityTargetList.value.map((item) => {
        return {
          ...item,
          editable: false,
        }
      })
      notQuantityTargetList.value = notQuantityTargetList.value.map((item) => {
        return {
          ...item,
          editable: false,
        }
      })
    }
    else {
      quantityTargetList.value = quantityTargetList.value.map((item) => {
        return {
          ...item,
          editable: true,
        }
      })
      notQuantityTargetList.value = notQuantityTargetList.value.map((item) => {
        return {
          ...item,
          editable: true,
        }
      })
      console.log(quantityTargetList.value)
    }
    form.value.quantityTargetItem = quantityTargetList.value[0].item // 量传指标检定项目
    form.value.notQuantityTargetItem = notQuantityTargetList.value[0].item // 非量传指标检定项目
  })
}
// ---------------------------------------------钩子----------------------------------------------
watch(() => props.id, (newValue) => {
  infoId.value = newValue!
  if (infoId.value) {
    fetchInfo() // 获取详情信息
  }
}, { immediate: true })

onMounted(() => {
  getDict()
  form.value.createUserId = user.id// 创建人id
  form.value.createUserName = user.name // 创建人名字
  form.value.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss')// 创建时间
  if (props.pageType !== 'add' && infoId.value) {
    fetchInfo() // 获取详情信息
  }
})

defineExpose({ saveForm, submitForm, fetchInfo })
</script>

<template>
  <detail-block v-loading="loading" title="">
    <el-form
      ref="ruleFormRef"
      :model="form"
      :label-width="120"
      label-position="right"
      :rules="rules"
    >
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="登记表编号:" prop="confirmNo">
            <el-input v-model="form.confirmNo" disabled placeholder="系统自动生成" />
          </el-form-item>
        </el-col>
        <el-col :span="12" style="display: flex;line-height: 32px;">
          <el-form-item label="登记表名称:" />
          <el-form-item label-width="0" prop="planYear" style="width: 90px;">
            <el-date-picker
              v-model="form.planYear"
              type="year"
              placeholder="选择年"
              format="YYYY"
              value-format="YYYY"
              :disabled="pageType === 'detail'"
            />
          </el-form-item>
          <span style="margin: 0 8px;font-size: 14px;color: #606266;">年</span>
          <el-form-item label-width="0" prop="planGroup" style="width: 90px;">
            <!-- <el-select v-model="form.planGroup" placeholder="选择组">
              <el-option
                v-for="item in planGroupList"
                :key="item.value"
                :value="item.value"
                :label="item.name"
              />
            </el-select> -->
            <el-input v-model="form.planGroup" :disabled="pageType === 'detail'" placeholder="输入组" />
          </el-form-item>
          <span style="margin: 0 8px;font-size: 14px;color: #606266;">组测量设备测试、校准或检定结果确认登记表</span>
        </el-col>
        <el-col :span="6">
          <el-form-item label="实验室代码" prop="labCode">
            <el-select
              v-model="form.labCode"
              :placeholder="pageType === 'detail' ? ' ' : '请选择实验室代码'"
              :disabled="pageType === 'detail'"
              class="full-width-input"
            >
              <el-option
                v-for="item in labCodeList"
                :key="item.id"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="组别代码" prop="groupCode">
            <el-select
              v-model="form.groupCode"
              :placeholder="pageType === 'detail' ? ' ' : '请选择组别代码'"
              :disabled="pageType === 'detail'"
              class="full-width-input"
            >
              <el-option
                v-for="item in groupCodeList"
                :key="item.id"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="创建人:">
            <el-input
              v-model="form.createUserName" disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="创建时间:" prop="createTime">
            <el-date-picker
              v-model="form.createTime"
              type="datetime"
              format="YYYY-MM-DD HH:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
              disabled
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </detail-block>
  <detail-block v-loading="loading" title="测量设备基本信息">
    <el-form
      ref="equipmentRef"
      :model="form"
      :label-width="120"
      label-position="right"
      :rules="rules"
    >
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="统一编号:" prop="equipmentNo">
            <el-input
              v-model="form.equipmentNo"
              :placeholder="pageType === 'detail' ? '' : '请选择统一编号'"
              :class="{ 'detail-input': pageType === 'detail' }"
              disabled
            >
              <template v-if="pageType !== 'detail'" #append>
                <el-button size="small" @click="selectEquipment">
                  选择
                </el-button>
              </template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备名称:" prop="equipmentName">
            <el-input v-model="form.equipmentName" disabled placeholder="设备名称" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="型号规格" prop="model">
            <el-input
              v-model.trim="form.model"
              placeholder="型号规格"
              disabled
              class="full-width-input"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所属测量标准名称:" prop="standardName" label-width="140px">
            <el-input
              v-model.trim="form.standardName"
              placeholder="所属测量标准名称"
              class="detail-input"
              disabled
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </detail-block>
  <detail-block v-loading="loading" title="证书相关要素确认">
    <el-form
      ref="certFormRef"
      :model="form"
      :label-width="200"
      label-position="right"
      :rules="rules"
    >
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="证书类型:" prop="measureCategory">
            <el-radio-group v-model="form.measureCategory" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                测试
              </el-radio>
              <el-radio label="2">
                校准
              </el-radio>
              <el-radio label="3">
                检定
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否与粘贴标识一致:" prop="labelConsistent">
            <el-radio-group v-model="form.labelConsistent" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="证书编号:" prop="certificateNo">
            <el-input
              v-model="form.certificateNo"
              :placeholder="pageType === 'detail' ? '' : '请输入证书编号'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="溯源机构名称:" prop="traceCompany">
            <el-input
              v-model="form.traceCompany"
              :placeholder="pageType === 'detail' ? '' : '请输入溯源机构名称'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否与合格供方名录一致:" prop="supplierConsistent">
            <el-radio-group v-model="form.supplierConsistent" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否与溯源等级关系图一致:" prop="diagramConsistent">
            <el-radio-group v-model="form.diagramConsistent" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="委托方名称是否与实际相符:" prop="customerMatch">
            <el-radio-group v-model="form.customerMatch" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="委托方地址是否与实际相符:" prop="customerAddressMatch">
            <el-radio-group v-model="form.customerAddressMatch" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="被检件名称是否正确:" prop="equipmentCorrect">
            <el-radio-group v-model="form.equipmentCorrect" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="被检件型号是否正确:" prop="equipmentModelCorrect">
            <el-radio-group v-model="form.equipmentModelCorrect" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="被检件编号是否正确:" prop="equipmentNoCorrect">
            <el-radio-group v-model="form.equipmentNoCorrect" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="被检件生产厂家是否正确:" prop="equipmentManufacturerCorrect">
            <el-radio-group v-model="form.equipmentManufacturerCorrect" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="测量设备开展检定工作时是否在有效期内:" prop="onValid">
            <el-radio-group v-model="form.onValid" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col v-if="form.onValid === 0" :span="16">
          <el-form-item label="否则列出:" prop="denyInfo">
            <el-input
              v-model="form.denyInfo"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="依据文件" style="font-weight: 600;" />
        </el-col>
        <el-col :span="8">
          <el-form-item label="依据文件是否正确:" prop="fileCorrect">
            <el-radio-group v-model="form.fileCorrect" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="编号1:" prop="fileNoOne">
            <el-input
              v-model="form.fileNoOne"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入编号'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="名称1:" prop="fileNoNameOne">
            <el-input
              v-model="form.fileNoNameOne"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入名称'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="编号2:" prop="fileNoTwo">
            <el-input
              v-model="form.fileNoTwo"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入编号'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="名称2:" prop="fileNoNameTwo">
            <div style="display: flex;flex-wrap: nowrap;">
              <el-input
                v-model="form.fileNoNameTwo"
                type="textarea"
                autosize
                :placeholder="pageType === 'detail' ? '' : '请输入名称'"
                :disabled="pageType === 'detail'"
                :class="{ 'detail-input': pageType === 'detail' }"
                style="flex: 1;"
              />
              <icon-button v-if="!showFileTree && pageType !== 'detail'" style="margin-left: 10px;" size="20" icon="icon-add" title="新建" type="primary" @click="addFile" />
            </div>
          </el-form-item>
        </el-col>
        <el-col v-if="showFileTree" :span="8">
          <el-form-item label="编号3:" prop="fileNoThree">
            <el-input
              v-model="form.fileNoThree"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入编号'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="showFileTree" :span="8">
          <el-form-item label="名称3:" prop="fileNoNameThree">
            <div style="display: flex;flex-wrap: nowrap;">
              <el-input
                v-model="form.fileNoNameThree"
                type="textarea"
                autosize
                :placeholder="pageType === 'detail' ? '' : '请输入名称'"
                :disabled="pageType === 'detail'"
                :class="{ 'detail-input': pageType === 'detail' }"
              />
              <icon-button v-if="!showFileFour && pageType !== 'detail'" style="margin-left: 10px;" size="20" icon="icon-add" title="新建" type="primary" @click="addFile" />
            </div>
          </el-form-item>
        </el-col>
        <el-col v-if="showFileFour" :span="8">
          <el-form-item label="编号4:" prop="fileNoFour">
            <el-input
              v-model="form.fileNoFour"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入编号'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col v-if="showFileFour" :span="8">
          <el-form-item label="名称4:" prop="fileNoNameFour">
            <el-input
              v-model="form.fileNoNameFour"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入名称'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-form-item label="结论:" prop="conclusion">
            <el-input
              v-model="form.conclusion"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入结论'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="测试、校准或检定日期:" prop="traceDate">
            <el-date-picker
              v-model="form.traceDate"
              type="date"
              :placeholder="pageType === 'detail' ? ' ' : '测试、校准或检定日期'"
              class="full-width-input"
              :class="{ 'detail-input': pageType === 'detail' }"
              :disabled="pageType === 'detail'"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="日期是否与粘贴标识一致:" prop="dateCorrect">
            <el-radio-group v-model="form.dateCorrect" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="有效期:" prop="validDate">
            <el-date-picker
              v-model="form.validDate"
              type="datetime"
              :placeholder="pageType === 'detail' ? ' ' : '有效期'"
              class="full-width-input"
              :class="{ 'detail-input': pageType === 'detail' }"
              :disabled="pageType === 'detail'"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="有效期是否正确:" prop="validDateCorrect">
            <el-radio-group v-model="form.validDateCorrect" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="签名信息是否齐全:" prop="signComplete">
            <el-radio-group v-model="form.signComplete" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否盖有有效印章:" prop="sealComplete">
            <el-radio-group v-model="form.sealComplete" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                是
              </el-radio>
              <el-radio :label="0">
                否
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </detail-block>

  <detail-block v-loading="loading" title="相关数据信息确认">
    <detail-block title="量传指标">
      <div>
        <div class="tech-file">
          <span class="file-text">检定项目:  {{ form.quantityTargetItem }}</span>
          <el-input
            v-if="pageType !== 'detail'"
            v-model.trim="form.quantityTargetItem"
            type="textarea"
            autosize
            :placeholder="pageType === 'detail' ? '' : '请输入检定项目'"
            :disabled="pageType === 'detail'"
            style="width: 50%;"
          />
        </div>
      </div>
      <template v-if="pageType !== 'detail'" #btns>
        <el-button type="primary" @click="addRow('quantityTarget')">
          增加行
        </el-button>
        <el-button type="info" @click="deleteRow('quantityTarget')">
          删除行
        </el-button>
      </template>
      <el-table
        ref="techRef"
        :data="quantityTargetList"
        border
        style="width: 100%;"
        @selection-change="handleTechSelectionQuantityTargetChange"
        @row-dblclick="rowDblclickQuantityTarget"
      >
        <el-table-column v-if="pageType !== 'detail'" type="selection" width="38" />
        <el-table-column align="center" label="序号" width="80" type="index" />
        <el-table-column
          v-for="item in quantityTargetColumns"
          :key="item.value"
          :prop="item.value"
          :label="item.text"
          align="center"
        >
          <template #header>
            <span v-show="item.required" style="color: red;">*</span><span>{{ item.text }}</span>
          </template>
          <template #default="scope">
            <span v-if="!scope.row.editable && item.value !== 'meetRequire'">{{ scope.row[item.value] }}</span>
            <span v-if="!scope.row.editable && item.value === 'meetRequire'">{{ scope.row[item.value] === 0 ? '不满足' : scope.row[item.value] === 1 ? '满足' : '未知' }}</span>
            <el-input v-if="scope.row.editable && item.value !== 'meetRequire'" v-model="scope.row[item.value]" :autofocus="true" :placeholder="`${item.text}`" class="input" />
            <el-radio-group v-if="scope.row.editable && item.value === 'meetRequire'" v-model="scope.row[item.value]" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                满足
              </el-radio>
              <el-radio :label="0">
                不满足
              </el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
      </el-table>
    </detail-block>

    <detail-block title="非量传指标">
      <div class="tech-file">
        <span class="file-text">检定项目:  {{ form.notQuantityTargetItem }}</span>
        <el-input
          v-if="pageType !== 'detail'"
          v-model.trim="form.notQuantityTargetItem"
          type="textarea"
          autosize
          :placeholder="pageType === 'detail' ? '' : '请输入检定项目'"
          :disabled="pageType === 'detail'"
          style="width: 50%;"
        />
      </div>
      <template v-if="pageType !== 'detail'" #btns>
        <el-button type="primary" @click="addRow('notQuantityTarget')">
          增加行
        </el-button>
        <el-button type="info" @click="deleteRow('notQuantityTarget')">
          删除行
        </el-button>
      </template>
      <el-table
        ref="techRef"
        :data="notQuantityTargetList"
        border
        style="width: 100%;"
        @selection-change="handleTechSelectionNotQuantityTargetChange"
        @row-dblclick="rowDblclickNotQuantityTarget"
      >
        <el-table-column v-if="pageType !== 'detail'" type="selection" width="38" />
        <el-table-column align="center" label="序号" width="80" type="index" />
        <el-table-column
          v-for="item in quantityTargetColumns"
          :key="item.value"
          :prop="item.value"
          :label="item.text"
          align="center"
        >
          <template #header>
            <span v-show="item.required" style="color: red;">*</span><span>{{ item.text }}</span>
          </template>
          <template #default="scope">
            <span v-if="!scope.row.editable && item.value !== 'meetRequire'">{{ scope.row[item.value] }}</span>
            <span v-if="!scope.row.editable && item.value === 'meetRequire'">{{ scope.row[item.value] === 0 ? '不满足' : scope.row[item.value] === 1 ? '满足' : '未知' }}</span>
            <el-input v-if="scope.row.editable && item.value !== 'meetRequire'" v-model="scope.row[item.value]" :autofocus="true" :placeholder="`${item.text}`" class="input" />
            <el-radio-group v-if="scope.row.editable && item.value === 'meetRequire'" v-model="scope.row[item.value]" :disabled="pageType === 'detail'">
              <el-radio :label="1">
                满足
              </el-radio>
              <el-radio :label="0">
                不满足
              </el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
      </el-table>
    </detail-block>
  </detail-block>
  <detail-block v-loading="loading" title="">
    <el-form
      ref="resultRulesRef"
      :model="form"
      :label-width="120"
      label-position="right"
      :rules="rules"
    >
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="结果确认结论:" prop="meterIdentify">
            <el-select
              v-model="form.meterIdentify"
              :placeholder="pageType === 'detail' ? ' ' : '请选择结果确认结论'"
              :disabled="pageType === 'detail'"
              class="full-width-input"
            >
              <el-option v-for="item of meterIdentifyDict" :key="item.value" :label="item.name" :value="item.value" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="14">
          <el-form-item label="备注:">
            <el-input
              v-model="form.remark"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入备注'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" class="marg">
        <el-col :span="24">
          <el-form-item label="检定证书:" prop="certificateFile">
            <show-photo v-if="form.certificateFile" :minio-file-name="form.certificateFile" />
            <span v-else-if="pageType === 'detail'">无</span>
            <input v-show="pageType === ''" ref="fileRef" type="file" @change="onFileChange">
            <el-button v-if="pageType !== 'detail'" id="file" type="primary" :disabled="pageType === 'detail'" :style="{ 'margin-left': form.certificateFile === '' ? '0px' : '20px' }" @click="upload">
              {{ form.certificateFile === '' ? '上传' : '更换附件' }}
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </detail-block>

  <!-- 选择设备台账 -->
  <select-equipment-dialog ref="selectEquipmentDialogRef" @confirm="confirmSelectEquipment" />
</template>

<style lang="scss" scoped>
.tech-file {
  display: flex;
  align-items: center;
  margin-left: 20px;
  margin-bottom: 10px;

  .file-text {
    white-space: nowrap;
    margin-right: 10px;
    font-size: 14px;
    color: #60627f;
  }
}
</style>
