<!-- 溯源计划管理 基本信息 -->
<script name="SourcePlanApproveBasic" 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 { IEquipmentInfoList, IForm, ITechnicalTargetList } from '../plan-interface'
import selectSourceDialog from '../dialog/selectSourceDialog.vue'
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 { useDoubleClickTableRow, useSetAllRowReadable } from '@/commonMethods/useSetAllRowReadable'
import selectEquipmentDialog from '@/views/business/fieldTest/approve/dialog/selectEquipmentDialog.vue'
import { addSourcePlanList, failUpdateSourcePlanList, getInfo, submit, updateSourcePlanList } from '@/api/equipment/source/plan'
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: '', // 组别代码
  planNo: '', // 计划表编号
  planName: '', // 计划表名称
  createUserId: '', // 创建人id
  createUserName: '', // 创建人
  createTime: '', // 创建时间
  planGroup: '', // 计划表组别
  planYear: '', // 计划表年份
})
const equipmentInfoForm = ref<IEquipmentInfoList>({
  equipmentId: '', // 设备id
  equipmentNo: '', // 统一编号
  equipmentName: '', // 设备名称
  model: '', // 型号规格
  manufacturer: '', // 生产厂家
  standardNo: '', // 所属测量标准号
  standardName: '', // 所属测量标准名称
  standardSituation: '1', // 标准情况字典code
  standardSituationName: '', // 标准情况(字典value)
  equipmentCategory: '', // 所属类别(字典code)
  equipmentCategoryName: '', // 所属类别(字典value)

  meterIdentify: '', // 检定结果
  traceDate: '', // 测试、校准/检定日期
  traceWay: '', // 溯源方式(字典code)
  traceWayName: '', // 溯源方式(字典value)
  supplierId: '', // 溯源机构id
  supplierName: '', // 溯源机构名称
  planTraceTime: '', // 计划溯源时间
  remark: '', // 备注
})
const ruleFormRef = ref() // 表单ref
const loading = ref(false) // loading
const infoId = ref('') // id
const rules = ref<FormRules>({ // 校验规则
  // 表单验证规则
  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'] }],
  standardSituation: [{ required: true, message: '标准情况不能为空', trigger: ['blur', 'change'] }],
  equipmentCategory: [{ required: true, message: '所属类别不能为空', trigger: ['blur', 'change'] }],
  standardNo: [{ required: true, message: '所属测量标准号不能为空', trigger: ['blur', 'change'] }],
  standardName: [{ required: true, message: '所属测量标准名称不能为空', trigger: ['blur', 'change'] }],
  traceWay: [{ required: true, message: '溯源方式不能为空', trigger: ['blur', 'change'] }],
  supplierName: [{ required: true, message: '溯源机构名称不能为空', trigger: ['blur', 'change'] }],
  planTraceTime: [{ required: true, message: '计划溯源时间不能为空', trigger: ['blur', 'change'] }],
})

// -----------------------------------------字典--------------------------------------------------------------
const planGroupList = ref<dictType[]>([]) // 计划表组别
const labCodeList = ref<dictType[]>([]) // 实验室代码
const groupCodeList = ref<dictType[]>([]) // 组别代码
const meterIdentifyDict = ref<dictType[]>([]) // 计量标识

// 查询字典
const getDict = async () => {
  // 计量标识
  getDictByCode('bizMeterIdentify').then((response) => {
    meterIdentifyDict.value = response.data
  })
  getDictByCode('bizGroupCode').then((response) => {
    planGroupList.value = response.data
  })
  // 实验室代码
  getDictByCode('bizLabCode').then((response) => {
    labCodeList.value = response.data
  })
  // 组别代码
  getDictByCode('bizGroupCode').then((response) => {
    groupCodeList.value = response.data
  })
}

// -------------------------------------------表格--------------------------------------------------
const traceWayMap: { [key: string]: string } = {
  1: '自检',
  2: '送检',
  3: '比对',
}
const list = ref([]) as any // 溯源计划
const isShowEquipmentInfo = ref(false) // 是否显示设备信息
const isMulti = ref(false) // 是否多选
const checkoutList = ref([]) as any // 选中的表格
const equipmentInfoFormRef = ref() // 溯源需求组件ref
const selectEquipmentDialogRef = ref() // 选择设备组件
const sourceNeedlist = ref<ITechnicalTargetList[]>([]) // 溯源需求列表
const checkoutSourceNeedList = ref([]) as any // 选中的表格
const editIndex = ref() // 要编辑的是第几行
const selectIndex = ref(0) // 点击选择是第几行
const columns = ref([
  { text: '统一编号', value: 'equipmentNo', align: 'center', width: '240', required: true },
  { text: '设备名称', value: 'equipmentName', align: 'center', required: true },
  { text: '型号规格', value: 'model', align: 'center', required: true },
  { text: '所属测量标准名称', value: 'standardName', align: 'center', required: true },
  { text: '溯源方式', value: 'traceWayName', align: 'center', required: true },
  { text: '溯源机构名称', value: 'supplierName', align: 'center', required: true },
  { text: '计划溯源时间', value: 'planTraceTime', align: 'center', width: '180', required: true },
])
const addObj = {
  id: '',
  equipmentNo: '', // 统一编号
  equipmentName: '', // 设备名称
  model: '', // 型号规格
  standardName: '', // 所属测量标准名称
  traceWayName: '', // 溯源方式
  supplierName: '', // 溯源机构名称
  planTraceTime: '', // 计划溯源时间
}
// 多选发生改变时
const handleSelectionChange = (e: any) => {
  checkoutList.value = e
}

// 批量增加
const multiAdd = () => {
  isMulti.value = true
  selectEquipmentDialogRef.value.initDialog()
}

// 增加行
const addRow = () => {
  if (useCheckList(list.value, columns.value, '溯源计划')) {
    list.value.push(addObj)
  }
}
// 点击选择
const chooseList = (row: any, index: number) => {
  selectIndex.value = index
  isMulti.value = false
  selectEquipmentDialogRef.value.initDialog(false)
}

// 删除行
const delRow = () => {
  if (!checkoutList.value.length) {
    ElMessage({
      message: '请选中要删除的行',
      type: 'warning',
    })
    return false
  }
  list.value = list.value.filter((item: any) => {
    return !checkoutList.value.includes(item)
  })
}

// 点击编辑
const handleClickEdit = (row: any, index: number) => {
  isShowEquipmentInfo.value = true
  editIndex.value = index
  equipmentInfoForm.value = {
    equipmentId: row.id, // 设备id
    equipmentNo: row.equipmentNo, // 统一编号
    equipmentName: row.equipmentName, // 设备名称
    model: row.model, // 型号规格
    manufacturer: row.manufacturer, // 生产厂家
    standardNo: row.standardNo, // 所属测量标准号
    standardName: row.standardName, // 所属测量标准名称
    standardSituation: props.pageType === 'add' ? '1' : row.standardSituation, // 标准情况字典code
    standardSituationName: props.pageType === 'add' ? '' : row.standardSituationName, // 标准情况(字典value)
    equipmentCategory: props.pageType === 'add' ? '' : row.equipmentCategory, // 所属类别(字典code)
    equipmentCategoryName: props.pageType === 'add' ? '' : row.equipmentCategoryName, // 所属类别(字典value)

    meterIdentify: row.meterIdentify, // 检定结果（计量标识）
    traceDate: row.traceDate, // 测试、校准/检定日期
    traceWay: props.pageType === 'add' ? '' : row.traceWay, // 溯源方式(字典code)
    traceWayName: props.pageType === 'add' ? '' : row.traceWayName, // 溯源方式(字典value)
    supplierId: row.supplierId, // 溯源机构id
    supplierName: row.supplierName, // 溯源机构名称
    planTraceTime: props.pageType === 'add' ? '' : row.planTraceTime, // 计划溯源时间
    remark: props.pageType === 'add' ? '' : row.remark, // 备注
  }
  sourceNeedlist.value = row.technicalTargetList || []
}

// 确认选好设备
const confirmSelectedEquipment = (val: any) => {
  if (isMulti.value) { // 多选
    val.forEach((item: { id: string }) => {
      // 只添加列表里不存在的
      const index = list.value.findIndex((i: { id: string }) => item.id === i.id)
      if (index === -1) {
        list.value.push(item)
      }
    })
  }
  else { // 单选
    const index = list.value.findIndex((i: { id: string }) => val[0].id === i.id)
    if (index === -1) {
      list.value.splice(list.value[index + 1], 1, val[0])
    }
    else {
      ElMessage.warning('此设备已添加过')
    }
  }
}

// 确认编辑
const conformEquipmentInfo = () => {
  if (!sourceNeedlist.value.length) {
    ElMessage.warning('溯源需求不能为空')
    return false
  }
  equipmentInfoFormRef.value.validate((valid: boolean) => {
    if (valid) {
      list.value[editIndex.value] = equipmentInfoForm.value
      list.value[editIndex.value].traceWayName = traceWayMap[`${equipmentInfoForm.value.traceWay}`]
      list.value[editIndex.value].technicalTargetList = sourceNeedlist.value // 溯源需求
      isShowEquipmentInfo.value = false // 隐藏编辑模块
    }
  })
}

// --------------------------------------------选择溯源机构---------------------------------------
const selectSourceDialogRef = ref() // 选择溯源机构组件ref
// 点击选择溯源机构
const selectsupplier = () => {
  selectSourceDialogRef.value.initDialog()
}

// 确定选择溯源机构
const confirmSelectedSource = (val: any) => {
  equipmentInfoForm.value.supplierId = val[0].id // 溯源机构id
  equipmentInfoForm.value.supplierName = val[0].supplierName // 溯源机构名称
}

// ----------------------------------------------溯源需求----------------------------------------

const sourceNeedColumns = ref([
  { text: '参数', value: 'measureParam', align: 'center', required: true },
  { text: '测量范围', value: 'measureRange', align: 'center', required: true },
])

// 点击增加行
const addSourceNeedRow = () => {
  const checkResult = useCheckList(sourceNeedlist.value, sourceNeedColumns.value, '溯源需求') // 检查表格
  if (checkResult) {
    useSetAllRowReadable(sourceNeedlist.value)
    sourceNeedlist.value.push({
      id: '',
      measureParam: '', // 参数
      measureRange: '', // 测量范围
      editable: true,
    })
  }
}

// 多选发生改变时
const handleSelectionSourceNeedChange = (e: any) => {
  console.log(e)
  checkoutSourceNeedList.value = e
}

// 删除行
const delSourceNeedRow = () => {
  console.log(checkoutSourceNeedList.value.length)
  if (!checkoutSourceNeedList.value.length) {
    ElMessage({
      message: '请选中要删除的行',
      type: 'warning',
    })
    return false
  }
  sourceNeedlist.value = sourceNeedlist.value.filter((item: any) => {
    return !checkoutSourceNeedList.value.includes(item)
  })
}

// 双击行
const rowDbClick = (row: any) => {
  if (props.pageType !== 'detail') {
    useDoubleClickTableRow(row, sourceNeedlist.value)
  }
}

// -----------------------------------------------保存----------------------------------------------
/**
 * 点击保存
 * @param formEl 基本信息表单ref
 */
const saveForm = async () => {
  if (!useCheckList(list.value, columns.value, '溯源计划')) {
    return false
  }
  if (!list.value.length) {
    ElMessage.warning('溯源计划不能为空')
    return false
  }
  await ruleFormRef.value.validate((valid: boolean) => {
    if (valid) { // 基本信息表单通过校验
      ElMessageBox.confirm(
        '确认保存吗？',
        '提示',
        {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning',
        },
      ).then(() => {
        const loading = ElLoading.service({
          lock: true,
          text: '加载中...',
          background: 'rgba(255, 255, 255, 0.8)',
        })
        console.log('props.processId', props.processId)

        const params = {
          ...form.value,
          id: infoId.value,
          planName: `${form.value.planYear}年${form.value.planGroup}组测量设备溯源计划`,
          tracePlanEquipmentList: list.value,
          processId: props.processId,
        }
        if (props.pageType === 'add') { // 新建
          addSourcePlanList(params).then((res) => {
            loading.close()
            form.value.planNo = res.data.planNo // 计划表编号
            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 === '全部') {
            updateSourcePlanList(params).then((res) => {
              loading.close()
              emits('addSuccess', infoId.value)
              ElMessage.success('已保存')
            }).catch(() => {
              loading.close()
            })
          }
          else { // '未通过' || '已取消'
            failUpdateSourcePlanList(params).then((res) => {
              loading.close()
              emits('submitSuccess')
              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_PALN_APPROVAL }).then((res) => {
    ElMessage.success('已提交')
    emits('submitSuccess')
    loading.close()
  })
}
// -----------------------------------------获取详情------------------------------------------
// 获取详情
const fetchInfo = () => {
  loading.value = true
  getInfo({ id: infoId.value }).then((res) => {
    loading.value = false
    form.value = res.data
    form.value.planYear = `${res.data.planYear}`
    list.value = res.data.tracePlanEquipmentList // 设备列表
  })
}
// ---------------------------------------------钩子----------------------------------------------
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="applyNo">
            <el-input v-model="form.planNo" 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="溯源计划">
    <template v-if="pageType !== 'detail'" #btns>
      <el-button type="primary" @click="multiAdd">
        批量增加
      </el-button>
      <el-button type="primary" @click="addRow">
        增加行
      </el-button>
      <el-button type="info" @click="delRow">
        删除行
      </el-button>
    </template>
    <el-table
      :data="list"
      border
      style="width: 100%;"
      max-height="600"
      @selection-change="handleSelectionChange"
    >
      <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 columns"
        :key="item.value"
        :prop="item.value"
        :label="item.text"
        :width="item.width"
        align="center"
      >
        <template #header>
          <span v-show="item.required" style="color: red;">*</span><span>{{ item.text }}</span>
        </template>
        <template
          v-if="item.value === 'equipmentNo' && pageType !== 'detail'"
          #default="scope"
        >
          <el-input
            v-model="scope.row[item.value]"
            :placeholder="`${item.text}`"
            class="input"
            disabled
          >
            <template v-if="pageType !== 'detail'" #append>
              <el-button
                size="small"
                @click="chooseList(scope.row, scope.$index)"
              >
                选择
              </el-button>
            </template>
          </el-input>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" width="90">
        <template #default="scope">
          <el-button v-if="pageType !== 'detail'" type="text" size="small" @click="handleClickEdit(scope.row, scope.$index)">
            编辑
          </el-button>
          <el-button v-if="pageType === 'detail'" type="text" size="small" @click="handleClickEdit(scope.row, scope.$index)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </detail-block>
  <!-- 编辑设备 -->
  <detail-block v-if="isShowEquipmentInfo" v-loading="loading" title=" ">
    <template #btns>
      <el-button v-if="pageType !== 'detail'" size="small" type="primary" @click="conformEquipmentInfo">
        确认编辑
      </el-button>
      <el-button size="small" type="info" @click="isShowEquipmentInfo = false">
        关闭
      </el-button>
    </template>
    <el-form
      ref="equipmentInfoFormRef"
      :model="equipmentInfoForm"
      :label-width="130"
      label-position="right"
      :rules="rules"
    >
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="统一编号:" prop="equipmentNo">
            <el-input v-model="equipmentInfoForm.equipmentNo" disabled placeholder="统一编号" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="设备名称:" prop="equipmentName">
            <el-input v-model="equipmentInfoForm.equipmentName" disabled placeholder="设备名称" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="型号规格" prop="model">
            <el-input
              v-model.trim="equipmentInfoForm.model"
              placeholder="型号规格"
              disabled
              class="full-width-input"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="生产厂家:" prop="manufacturer">
            <el-input
              v-model.trim="equipmentInfoForm.manufacturer"
              placeholder="生产厂家"
              class="detail-input"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所属测量标准编号:" prop="standardNo">
            <el-input
              v-model.trim="equipmentInfoForm.standardNo"
              placeholder="请输入所属测量标准编号"
              class="detail-input"
              :disabled="equipmentInfoForm.standardNo === '' || pageType === 'detail'"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所属测量标准名称:" prop="standardName">
            <el-input
              v-model.trim="equipmentInfoForm.standardName"
              placeholder="请输入所属测量标准名称"
              class="detail-input"
              :disabled="equipmentInfoForm.standardName === '' || pageType === 'detail'"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="标准情况:" prop="standardSituation">
            <el-radio-group v-model="equipmentInfoForm.standardSituation" :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="6">
          <el-form-item label="所属类别:" prop="equipmentCategory">
            <el-radio-group v-model="equipmentInfoForm.equipmentCategory" :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-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="上一年度溯源情况" />
        </el-col>
        <el-col :span="6">
          <el-form-item label="检定结果:" prop="meterIdentify">
            <el-select
              v-model="equipmentInfoForm.meterIdentify"
              :placeholder="pageType === 'detail' ? ' ' : '检定结果'"
              disabled
              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-col :span="6">
          <el-form-item label="测试、校准/检定日期:" label-width="150px" prop="traceDate">
            <el-date-picker
              v-model="equipmentInfoForm.traceDate"
              type="datetime"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              disabled
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="6">
          <el-form-item label="本年溯源计划" />
        </el-col>
        <el-col :span="6">
          <el-form-item label="溯源方式:" prop="traceWay">
            <el-radio-group v-model="equipmentInfoForm.traceWay" :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="6">
          <el-form-item label="溯源机构名称:" prop="supplierName">
            <el-input
              v-model="equipmentInfoForm.supplierName"
              placeholder="请选择溯源机构名称"
              class="input"
              disabled
            >
              <template v-if="pageType !== 'detail'" #append>
                <el-button
                  size="small"
                  @click="selectsupplier"
                >
                  选择
                </el-button>
              </template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="计划溯源时间:" prop="planTraceTime">
            <el-date-picker
              v-model="equipmentInfoForm.planTraceTime"
              type="datetime"
              :placeholder="pageType === 'detail' ? ' ' : '计划溯源时间'"
              class="full-width-input"
              :class="{ 'detail-input': pageType === 'detail' }"
              :disabled="pageType === 'detail'"
              format="YYYY-MM-DD HH:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24" class="marg">
        <el-col :span="12">
          <el-form-item label="备注:">
            <el-input
              v-model="equipmentInfoForm.remark"
              type="textarea"
              autosize
              :placeholder="pageType === 'detail' ? '' : '请输入备注'"
              :disabled="pageType === 'detail'"
              :class="{ 'detail-input': pageType === 'detail' }"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 溯源需求 -->
    <detail-block v-loading="loading" title="溯源需求">
      <template v-if="pageType !== 'detail'" #btns>
        <el-button type="primary" @click="addSourceNeedRow">
          增加行
        </el-button>
        <el-button type="info" @click="delSourceNeedRow">
          删除行
        </el-button>
      </template>
      <el-table
        :data="sourceNeedlist"
        border
        style="width: 100%;"
        max-height="600"
        @row-dblclick="rowDbClick"
        @selection-change="handleSelectionSourceNeedChange"
      >
        <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 sourceNeedColumns"
          :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
            v-if="pageType !== 'detail'"
            #default="scope"
          >
            <el-input
              v-if="scope.row.editable"
              v-model="scope.row[item.value]"
              :placeholder="`${item.text}`"
              class="input"
            />
            <span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
          </template>
        </el-table-column>
      </el-table>
    </detail-block>
  </detail-block>
  <!-- 选择设备台账 -->
  <select-equipment-dialog ref="selectEquipmentDialogRef" :is-multi="isMulti" @confirm="confirmSelectedEquipment" />
  <!-- 选择溯源供方 -->
  <select-source-dialog ref="selectSourceDialogRef" @confirm="confirmSelectedSource" />
</template>
