Newer
Older
xc-business-system / src / views / equipement / source / resultConfirm / list.vue
<!-- 溯源结果确认列表 -->
<script name="EquipmentResultConfirmList" lang="ts" setup>
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { IList, IListQuery } from './resultConfirm-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import type { deptType } from '@/global'
import { exportFile } from '@/utils/exportUtils'
import ButtonBox from '@/components/buttonBox/buttonBox.vue'
import useUserStore from '@/store/modules/user'
import { SCHEDULE } from '@/utils/scheduleDict'
import {
  approvalDelete,
  cancelApproval,
  deleteEquipment,
  draftDelete,
  exportResultConfirmList,
  getResultConfirmList,
  getResultToConfirmList,
  refuseApproval,
  rejectApproval,
} from '@/api/equipment/source/resultConfirm'
import useBridgeCount from '@/components/buttonBox/useBridgeCount'
const approvalDialog = ref() // 审批对话ref
const $route = useRoute()
const user = useUserStore() // 用户信息
const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const operateWidth = ref('180') // 操作栏的宽度
const buttonBoxActive = 'equipmentSourceResultConfirmApproval' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
const loadingTable = ref(false)
const menu = ref<IMenu[]>([]) // 审批状态按钮组合
const active = ref('') // 右上方按钮
// 查询条件
const listQuery: Ref<IListQuery> = ref({
  approvalStatus: active.value, //	审批状态类型code,导出接口不用传
  confirmName: '', //	登记表名字
  confirmNo: '', //	登记表编号
  createTimeEnd: '', //	创建时间结束
  createTimeStart: '', //	创建时间开始
  createUserName: '', //	创建人
  equipmentName: '', //	设备名称
  equipmentNo: '', //	设备编号
  formId: SCHEDULE.TRACE_RESULT_VERIFICATION_APPROVAL, //	表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
  groupCode: '', //	部门
  labCode: '', //	实验室
  manufactureNo: '', //	出厂编号
  manufacturer: '', //	生产厂家
  measureValidDateEnd: '', //	检定有效期结束
  measureValidDateStart: '', //	检定有效期开始
  meterIdentify: '', //	计量标识(字典code),即溯源检定结果
  model: '', //	规格型号
  planName: '', //	计划表名称
  planNo: '', //	计划表编号
  planTraceTimeEnd: '', //	计划溯源时间结束
  planTraceTimeStart: '', //	计划溯源时间开始
  standardName: '', //	所属标准名称
  standardNo: '', //	所属标准编号
  supplierName: '', //	溯源供方名字
  traceWay: '', //	溯源方式(字典code)
  limit: 20,
  offset: 1,
})

// 表头
const columnsToConfirm = ref<TableColumn[]>([
  { text: '设备名称', value: 'equipmentName', align: 'center' },
  { text: '规格型号', value: 'model', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  { text: '生产厂家', value: 'manufacturer', align: 'center' },
  { text: '计量标识', value: 'meterIdentifyName', align: 'center' },
  { text: '设备使用状态', value: 'useStatusName', align: 'center' },
  { text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' },
  { text: '所属测量标准名称', value: 'standardName', align: 'center' },
  { text: '溯源方式', value: 'traceWayName', align: 'center' },
  { text: '溯源机构名称', value: 'supplierName', align: 'center' },
  { text: '计划溯源时间', value: 'planTraceTime', align: 'center', width: '180' },
  { text: '实验室', value: 'labCodeName', align: 'center' },
  { text: '部门', value: 'groupCodeName', align: 'center' },
  { text: '文件编号', value: 'planNo_hide', align: 'center', width: '180', followLink: true },
  { text: '文件名称', value: 'planName', align: 'center' },
])

// 表头
const columns = ref<TableColumn[]>([
  { text: '文件编号', value: 'confirmNo', align: 'center' },
  { text: '文件名称', value: 'confirmName', align: 'center' },
  { text: '设备名称', value: 'equipmentName', align: 'center' },
  { text: '规格型号', value: 'model', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  { text: '生产厂家', value: 'manufacturer', align: 'center' },
  { text: '计量标识', value: 'meterIdentifyName', align: 'center' },
  { text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' },
  { text: '所属测量标准名称', value: 'standardName', align: 'center' },
  { text: '溯源方式', value: 'traceWayName', align: 'center' },
  { text: '溯源机构名称', value: 'supplierName', align: 'center' },
  { text: '计划溯源时间', value: 'planTraceTime', align: 'center', width: '180' },
  { text: '实验室', value: 'labCodeName', align: 'center' },
  { text: '部门', value: 'groupCodeName', align: 'center' },
  { text: '溯源计划文件编号', value: 'planNo_hide', align: 'center', width: '180', followLink: true },
  { text: '溯源计划文件名称', value: 'planName', align: 'center' },
])
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const planTraceTimeDateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const createDateRange = ref<[DateModelType, DateModelType]>(['', ''])// 创建时间数据

const list = ref<IList[]>([]) // 列表
const total = ref(0) // 数据总条数
const totalToApproval = ref(0) // 待审批数据条数
const totalApproval = ref(0) // 审批中数据条数
const totalRefuse = ref(0) // 未通过数据条数
// 选中的内容
const checkoutList = ref<string[]>([])
// -----------------------------------------字典--------------------------------------------------------------
const groupCodeList = ref<deptType[]>([]) // 部门
const groupCodeDict = ref([]) as any// 部门map
const labCodeList = ref<deptType[]>([]) // 实验室
const labCodeDict = ref([]) as any// 实验室map
const traceWayList = ref<deptType[]>([]) // 溯源方式
const traceWayDict = ref([]) as any // 溯源方式
const meterIdentifyList = ref<deptType[]>([]) // 计量标识
const meterIdentifyDict = ref([]) as any // 计量标识
const useStatusDict = ref([]) as any // 设备使用状态
// 查询字典
const getDict = async () => {
  loadingTable.value = true
  // 审批状态
  const res = await getDictByCode('approvalStatus')
  // 制作右上角的菜单
  const tempMenu = ['待确认', '全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消']
  tempMenu.forEach((item) => {
    const tempFindData = res.data.find((e: { name: string; value: string }) => e.name === item)
    if (tempFindData) {
      menu.value.push({
        name: tempFindData.name,
        id: `${tempFindData.value}`,
      })
    }
  })

  // 设备使用状态
  const resUseStatus = await getDictByCode('bizUsageStatus')
  resUseStatus.data.forEach((item: any) => {
    useStatusDict.value[`${item.value}`] = item.name
  })

  // 溯源方式
  const resTraceWay = await getDictByCode('bizTraceWay')
  traceWayList.value = resTraceWay.data
  resTraceWay.data.forEach((item: any) => {
    traceWayDict.value[`${item.value}`] = item.name
  })
  // 计量标识
  const resMeterIdentify = await getDictByCode('bizMeterIdentify')
  meterIdentifyList.value = resMeterIdentify.data
  resMeterIdentify.data.forEach((item: any) => {
    meterIdentifyDict.value[`${item.value}`] = item.name
  })
  // 实验室
  const resLabCode = await getDictByCode('bizGroupCodeEquipment')
  labCodeList.value = resLabCode.data
  resLabCode.data.forEach((item: any) => {
    labCodeDict.value[`${item.value}`] = item.name
  })
  // 部门
  const resGroupCode = await getDictByCode('bizGroupCode')
  groupCodeList.value = resGroupCode.data
  resGroupCode.data.forEach((item: any) => {
    groupCodeDict.value[`${item.value}`] = item.name
  })
}
// ----------------------------------------列表数据----------------------------------------------------
// 由非待确认的请求参数 制作 待确认请求参数
const solveRequestParam = () => {
  const params = {
    equipmentName: listQuery.value.equipmentName,
    equipmentNo: listQuery.value.equipmentNo,
    groupCode: listQuery.value.groupCode,
    labCode: listQuery.value.labCode,
    manufactureNo: listQuery.value.manufactureNo,
    manufacturer: listQuery.value.manufacturer,
    measureValidDateEnd: listQuery.value.measureValidDateEnd,
    measureValidDateStart: listQuery.value.measureValidDateStart,
    meterIdentify: listQuery.value.meterIdentify,
    model: listQuery.value.model,
    planName: listQuery.value.planName,
    planNo: listQuery.value.planNo,
    planTraceTimeEnd: listQuery.value.planTraceTimeEnd,
    planTraceTimeStart: listQuery.value.planTraceTimeStart,
    standardName: listQuery.value.standardName,
    standardNo: listQuery.value.standardNo,
    supplierName: listQuery.value.supplierName,
    traceWay: listQuery.value.traceWay,
    limit: listQuery.value.limit,
    offset: listQuery.value.offset,
  }
  console.log('待确认参数', params)

  return params
}

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  if (active.value === '12') {
    const params = solveRequestParam()
    getResultToConfirmList(params).then((response) => {
      list.value = response.data.rows.map((item: { usageStatus: string; planNo: string; meterIdentify: string; traceWay: string; labCode: string; groupCode: string }) => {
        return {
          ...item,
          followLinkArr: [item.planNo], // 溯源计划表编号
          meterIdentifyName: `${item.meterIdentify}` ? meterIdentifyDict.value[item.meterIdentify] : item.meterIdentify, // 计量标识
          traceWayName: `${item.traceWay}` ? traceWayDict.value[item.traceWay] : item.traceWay, // 溯源方式
          labCodeName: item.labCode ? labCodeDict.value[item.labCode] : item.labCode, // 实验室
          groupCodeName: item.groupCode ? groupCodeDict.value[item.groupCode] : item.groupCode, // 部门
          useStatusName: item.usageStatus ? useStatusDict.value[item.usageStatus] : item.usageStatus, // 使用状态
        }
      })
      total.value = parseInt(response.data.total)
      loadingTable.value = false
    })
    // 获取待审批,审批中,未通过数据数量
    useBridgeCount(listQuery.value).then((res: any) => {
      totalToApproval.value = res.totalToApproval // 待审批数据条数
      totalApproval.value = res.totalApproval // 审批中数据条数
      totalRefuse.value = res.totalRefuse // 未通过数据条数
    })
  }
  else {
    if (listQuery.value.approvalStatus === '10') { listQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传''
    getResultConfirmList(listQuery.value).then((response) => {
      list.value = response.data.rows.map((item: { planNo: string; meterIdentify: string; traceWay: string; labCode: string; groupCode: string }) => {
        return {
          ...item,
          followLinkArr: [item.planNo], // 溯源计划表编号
          meterIdentifyName: `${item.meterIdentify}` ? meterIdentifyDict.value[item.meterIdentify] : item.meterIdentify, // 计量标识
          traceWayName: `${item.traceWay}` ? traceWayDict.value[item.traceWay] : item.traceWay, // 溯源方式
          labCodeName: item.labCode ? labCodeDict.value[item.labCode] : item.labCode, // 实验室
          groupCodeName: item.groupCode ? groupCodeDict.value[item.groupCode] : item.groupCode, // 部门
        }
      })
      total.value = parseInt(response.data.total)
      loadingTable.value = false
    })
    // 获取待审批,审批中,未通过数据数量
    useBridgeCount(listQuery.value).then((res: any) => {
      totalToApproval.value = res.totalToApproval // 待审批数据条数
      totalApproval.value = res.totalApproval // 审批中数据条数
      totalRefuse.value = res.totalRefuse // 未通过数据条数
    })
  }
}

// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}

// 重置
const clearList = () => {
  listQuery.value = {
    approvalStatus: active.value, //	审批状态类型code,导出接口不用传
    confirmName: '', //	登记表名字
    confirmNo: '', //	登记表编号
    createTimeEnd: '', //	创建时间结束
    createTimeStart: '', //	创建时间开始
    createUserName: '', //	创建人
    equipmentName: '', //	设备名称
    equipmentNo: '', //	设备编号
    formId: SCHEDULE.TRACE_RESULT_VERIFICATION_APPROVAL, //	表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
    groupCode: '', //	部门
    labCode: '', //	实验室
    manufactureNo: '', //	出厂编号
    manufacturer: '', //	生产厂家
    measureValidDateEnd: '', //	检定有效期结束
    measureValidDateStart: '', //	检定有效期开始
    meterIdentify: '', //	计量标识(字典code),即溯源检定结果
    model: '', //	规格型号
    planName: '', //	计划表名称
    planNo: '', //	计划表编号
    planTraceTimeEnd: '', //	计划溯源时间结束
    planTraceTimeStart: '', //	计划溯源时间开始
    standardName: '', //	所属标准名称
    standardNo: '', //	所属标准编号
    supplierName: '', //	溯源供方名字
    traceWay: '', //	溯源方式(字典code)
    limit: 20,
    offset: 1,
  }
  dateRange.value = ['', '']
  planTraceTimeDateRange.value = ['', '']
  createDateRange.value = ['', '']
  fetchData()
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData(true)
}

// ----------------------------------------按钮-------------------------------------------------
// 导出
const exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  if (list.value.length > 0) {
    let params
    if (active.value !== '12') { // 非待确认
      params = {
        approvalStatus: listQuery.value.approvalStatus, //	审批状态类型code,导出接口不用传
        confirmName: listQuery.value.confirmName, //	登记表名字
        confirmNo: listQuery.value.confirmNo, //	登记表编号
        createTimeEnd: listQuery.value.createTimeEnd, //	创建时间结束
        createTimeStart: listQuery.value.createTimeStart, //	创建时间开始
        createUserName: listQuery.value.createUserName, //	创建人
        equipmentName: listQuery.value.equipmentName, //	设备名称
        equipmentNo: listQuery.value.equipmentNo, //	设备编号
        formId: listQuery.value.formId, //	表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
        groupCode: listQuery.value.groupCode, //	部门
        labCode: listQuery.value.labCode, //	实验室
        manufactureNo: listQuery.value.manufactureNo, //	出厂编号
        manufacturer: listQuery.value.manufacturer, //	生产厂家
        measureValidDateEnd: listQuery.value.measureValidDateEnd, //	检定有效期结束
        measureValidDateStart: listQuery.value.measureValidDateStart, //	检定有效期开始
        meterIdentify: listQuery.value.meterIdentify, //	计量标识(字典code),即溯源检定结果
        model: listQuery.value.model, //	规格型号
        planName: listQuery.value.planName, //	计划表名称
        planNo: listQuery.value.planNo, //	计划表编号
        planTraceTimeEnd: listQuery.value.planTraceTimeEnd, //	计划溯源时间结束
        planTraceTimeStart: listQuery.value.planTraceTimeStart, //	计划溯源时间开始
        standardName: listQuery.value.standardName, //	所属标准名称
        standardNo: listQuery.value.standardNo, //	所属标准编号
        supplierName: listQuery.value.supplierName, //	溯源供方名字
        traceWay: listQuery.value.traceWay, //	溯源方式(字典code)
        limit: 20,
        offset: 1,
        ids: checkoutList.value,
      }
    }
    else {
      params = {
        equipmentName: listQuery.value.equipmentName,
        equipmentNo: listQuery.value.equipmentNo,
        groupCode: listQuery.value.groupCode,
        labCode: listQuery.value.labCode,
        manufactureNo: listQuery.value.manufactureNo,
        manufacturer: listQuery.value.manufacturer,
        measureValidDateEnd: listQuery.value.measureValidDateEnd,
        measureValidDateStart: listQuery.value.measureValidDateStart,
        meterIdentify: listQuery.value.meterIdentify,
        model: listQuery.value.model,
        planName: listQuery.value.planName,
        planNo: listQuery.value.planNo,
        planTraceTimeEnd: listQuery.value.planTraceTimeEnd,
        planTraceTimeStart: listQuery.value.planTraceTimeStart,
        standardName: listQuery.value.standardName,
        standardNo: listQuery.value.standardNo,
        supplierName: listQuery.value.supplierName,
        traceWay: listQuery.value.traceWay,
        limit: listQuery.value.limit,
        offset: listQuery.value.offset,
        ids: checkoutList.value,
      }
    }

    exportResultConfirmList(params).then((res) => {
      const blob = new Blob([res.data])
      exportFile(blob, '溯源结果确认.xlsx')
      loading.close()
    })
  }
  else {
    loading.close()
    ElMessage.warning('无数据可导出数据')
  }
}
// ----------------------------------------------操作---------------------------------------------------
const handleEdit = (row: IList, type: string) => {
  if (type === 'edit' || type === 'detail') { // 编辑、详情
    if (active.value === '0' && type === 'detail') { // 全部查看文件
      $router.push({
        path: `resultConfirmDoc/${type}/${row.id}`,
        query: {
          approvalStatusName: '全部', // 审批状态名称
          processId: row.processId, // 流程实例id
          taskId: row.taskId, // 任务id
          decisionItem: row.decisionItem,
        },
      })
    }
    else if (active.value === '12' && type === 'detail') { // 跳转溯源计划的详情
      $router.push({
        path: `resultConfirmPlan/detail/${row.planId}`,
        query: {
          equipmentId: row.equipmentId, // 设备id
          directorName: row.directorName, // 负责人
          decisionItem: row.decisionItem,
        },
      })
    }
    else {
      $router.push({
        path: `resultConfirm/${type}/${row.id}`,
        query: {
          approvalStatusName: active.value === '0' ? '全部' : active.value === '7' ? '已审批' : row.approvalStatusName, // 审批状态名称
          processId: row.processId, // 流程实例id
          taskId: row.taskId, // 任务id
          labCode: row.labCode, // 实验室
          labCodeName: row.labCodeName, // 实验室名称
          groupCode: row.groupCode, // 部门
          groupCodeName: row.groupCodeName, // 部门名称
          planGroup: row.planGroup, // 计划表部门
          planYear: row.planYear, // 计划表年份
          equipmentId: row.equipmentId, // 设备id
          equipmentNo: row.equipmentNo, // 统一编号
          equipmentName: row.equipmentName, // 设备名称
          model: row.model, // 规格型号
          manufactureNo: row.manufactureNo, // 出厂编号
          manufacturer: row.manufacturer, // 生产厂家
          standardNo: row.standardNo, // 所属测量标准号
          standardName: row.standardName, // 所属测量标准名称
          directorName: row.directorName, // 负责人
          decisionItem: row.decisionItem,
        },
      })
    }
  }
  else if (type === '同意') {
    approvalDialog.value.initDialog('agree', row.taskId)
  }
  else if (type === '驳回') {
    approvalDialog.value.initDialog('reject', row.taskId, row.id)
  }
  else if (type === '拒绝') {
    approvalDialog.value.initDialog('refuse', row.taskId, row.id)
  }
  else if (type === '取消') {
    const params = {
      processInstanceId: row.processId!,
      comments: '',
      id: row.id,
    }
    ElMessageBox.confirm(
      '确认取消该审批吗?',
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    )
      .then(() => {
        cancelApproval(params).then((res) => {
          ElMessage({
            type: 'success',
            message: '已取消',
          })
          fetchData(true)
        })
      })
  }
  else if (type === '结果确认') {
    if (row.usageStatus === '2' || row.usageStatus === '3' || row.usageStatus === '4') {
      const title = row.usageStatus === '2' ? '禁用' : row.usageStatus === '3' ? '报废' : row.usageStatus === '4' ? '封存' : row.usageStatus
      ElMessageBox.confirm(
        `当前设备状态为${title},不能进行溯源结果确认,是否删除?`,
        '提示',
        {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning',
        },
      )
        .then(() => {
          deleteEquipment({ id: row.relationId! }).then((res) => {
            ElMessage.success('删除成功')
            fetchData(true)
          }).catch(() => {
            ElMessage.warning('删除失败')
          })
        })
    }
    else {
      // 带着设备信息跳转溯源结果确认新建页面
      $router.push({
        path: 'resultConfirm/add',
        query: {
          labCode: row.labCode, // 实验室
          labCodeName: row.labCodeName, // 实验室名称
          groupCode: row.groupCode, // 部门
          groupCodeName: row.groupCodeName, // 部门名称
          planGroup: row.planGroup, // 计划表部门
          planYear: row.planYear, // 计划表年份
          equipmentId: row.equipmentId, // 设备id
          equipmentNo: row.equipmentNo, // 统一编号
          equipmentName: row.equipmentName, // 设备名称
          model: row.model, // 规格型号
          manufactureNo: row.manufactureNo, // 出厂编号
          manufacturer: row.manufacturer, // 生产厂家
          standardNo: row.standardNo, // 所属测量标准号
          standardName: row.standardName, // 所属测量标准名称
          directorName: row.directorName, // 负责人
          planId: row.planId,
        },
      })
    }
  }
  else {
    ElMessageBox.confirm(
      `确认${type}吗?`,
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    ).then(() => {
      // 草稿箱删除
      if (type === '删除' && row.approvalStatusName === '草稿箱') {
        draftDelete({ id: row.id }).then(() => {
          ElMessage.success(`已${type}`)
          fetchData()
        })
      }
      // 审批删除--已取消、全部
      else if (type === '删除' && (row.approvalStatusName === '已取消' || active.value === '0')) {
        approvalDelete({ id: row.id, taskId: row.taskId! }).then(() => {
          ElMessage.success(`已${type}`)
          fetchData()
        })
      }
    })
  }
}
// 拒绝
const refuse = (comments: string, taskId: string, id: string) => {
  const params = {
    id,
    taskId, // 任务id
    comments, // 拒绝原因
  }
  refuseApproval(params).then((res) => {
    ElMessage({
      type: 'success',
      message: '已拒绝',
    })
    fetchData(true)
  })
}

// 驳回
const reject = (comments: string, taskId: string, id: string) => {
  const params = {
    id,
    taskId, // 任务id
    comments, // 拒绝原因
  }
  rejectApproval(params).then((res) => {
    ElMessage({
      type: 'success',
      message: '已驳回',
    })
    fetchData(true)
  })
}

// 点击文件编号
const handleClickFollowLink = (row: any) => {
  $router.push({
    path: `plan/detail/${row.planId}`,
    query: {
      approvalStatusName: '全部', // 审批状态名称
      processId: row.processId, // 流程实例id
      taskId: row.taskId, // 任务id
    },
  })
}
// -----------------------------------------审批------------------------------------------------
// 审批结束回调
const approvalSuccess = () => {
  fetchData(true)
}

// 切换tab状态
const changeCurrentButton = (val: string) => {
  active.value = val
  listQuery.value.approvalStatus = active.value
  window.sessionStorage.setItem(buttonBoxActive, val)
  fetchData()
}

// ------------------------------------------钩子------------------------------------------------
watch(dateRange, (val) => { //	检定有效期
  if (val) {
    listQuery.value.measureValidDateStart = `${val[0]}`
    listQuery.value.measureValidDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.measureValidDateStart = ''
    listQuery.value.measureValidDateEnd = ''
  }
})
watch(planTraceTimeDateRange, (val) => {
  if (val) {
    listQuery.value.planTraceTimeStart = `${val[0]}`
    listQuery.value.planTraceTimeEnd = `${val[1]}`
  }
  else {
    listQuery.value.planTraceTimeStart = ''
    listQuery.value.planTraceTimeEnd = ''
  }
})

watch(createDateRange, (val) => {
  if (val) {
    listQuery.value.createTimeStart = `${val[0]}`
    listQuery.value.createTimeEnd = `${val[1]}`
  }
  else {
    listQuery.value.createTimeStart = ''
    listQuery.value.createTimeEnd = ''
  }
})

watch(() => active.value, (val) => {
  if (val === '10') { // 审批把审批状态加上
    if (columns.value[columns.value.length - 1].value !== 'approvalStatusName') {
      columns.value.push({ text: '审批状态', value: 'approvalStatusName', align: 'center' })
    }
  }
  else { // 其他不显示审批状态
    if (columns.value[columns.value.length - 1].value === 'approvalStatusName') {
      columns.value.pop()
    }
  }
}, { immediate: true })

onMounted(async () => {
  listQuery.value.labCode = user.bizLabCode // 实验室
  listQuery.value.groupCode = user.groupNo // 部门
  await getDict()
  if (window.sessionStorage.getItem(buttonBoxActive)) {
    active.value = window.sessionStorage.getItem(buttonBoxActive)!
  }
  else {
    active.value = menu.value.find(item => item.name === '待确认')!.id as string // 全部
  }
})
</script>

<template>
  <div>
    <!-- 布局 -->
    <app-container>
      <search-area :need-clear="true" @search="searchList" @clear="clearList">
        <search-item v-if="active !== '12'">
          <el-input v-model.trim="listQuery.confirmNo" placeholder="文件编号" class="short-input" clearable />
        </search-item>
        <search-item v-if="active !== '12'">
          <el-input v-model.trim="listQuery.confirmName" placeholder="文件名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.equipmentName" placeholder="设备名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.model" placeholder="规格型号" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.manufacturer" placeholder="生产厂家" clearable />
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.meterIdentify"
            class="short-input"
            placeholder="计量标识"
            clearable
          >
            <el-option v-for="item of meterIdentifyList" :key="item.value" :label="item.name" :value="item.name" />
          </el-select>
        </search-item>
        <search-item>
          <el-date-picker
            v-model="dateRange"
            class="short-input"
            type="daterange"
            range-separator="至"
            format="YYYY-MM-DD"
            value-format="YYYY-MM-DD"
            start-placeholder="检定有效期(开始)"
            end-placeholder="检定有效期(结束)"
          />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.standardName" placeholder="所属测量标准名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.traceWay"
            class="short-input"
            placeholder="溯源方式"
            clearable
          >
            <el-option v-for="item of traceWayList" :key="item.value" :label="item.name" :value="item.name" />
          </el-select>
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.supplierName" placeholder="溯源机构名称" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-date-picker
            v-model="planTraceTimeDateRange"
            class="short-input"
            type="datetimerange"
            range-separator="至"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
            start-placeholder="计划溯源时间(开始)"
            end-placeholder="计划溯源时间(结束)"
          />
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.labCode"
            placeholder="实验室"
            class="short-input"
            filterable
            clearable
          >
            <el-option v-for="item in labCodeList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.groupCode"
            placeholder="部门"
            class="short-input"
            filterable
            clearable
          >
            <el-option v-for="item in groupCodeList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item v-if="active !== '12'">
          <el-input
            v-model.trim="listQuery.createUserName"
            placeholder="创建人"
            class="short-input"
            clearable
          />
        </search-item>
        <search-item v-if="active !== '12'">
          <el-date-picker
            v-model="createDateRange"
            type="datetimerange"
            range-separator="至"
            format="YYYY-MM-DD HH:mm:ss"
            value-format="YYYY-MM-DD HH:mm:ss"
            start-placeholder="创建时间(开始)"
            end-placeholder="创建时间(结束)"
          />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.planNo" :placeholder="active === '12' ? '文件编号' : '溯源计划文件编号'" class="short-input" clearable />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.planName" :placeholder="active === '12' ? '文件名称' : '溯源计划文件编号'" class="short-input" clearable />
        </search-item>
      </search-area>
      <table-container>
        <!-- 全部的时候展示按钮 -->
        <template v-if="active === '0'" #btns-right>
          <!-- <icon-button icon="icon-add" title="新建" type="primary" @click="add" /> -->
          <icon-button icon="icon-export" title="导出" type="primary" @click="exportAll" />
        </template>
        <normal-table
          :data="list" :total="total" :columns="active === '12' ? columnsToConfirm : columns" :query="listQuery" :list-loading="loadingTable"
          is-showmulti-select @change="changePage" @multi-select="handleSelectionChange"
          @handle-click-follow-link="handleClickFollowLink"
        >
          <template #preColumns>
            <el-table-column label="序号" width="55" align="center">
              <template #default="scope">
                {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
              </template>
            </el-table-column>
          </template>
          <template #columns>
            <el-table-column
              label="操作"
              align="center"
              fixed="right"
              :width="operateWidth"
            >
              <template #default="{ row }">
                <el-button
                  v-if="active !== '1' && active !== '6' && active !== '5'"
                  size="small"
                  type="primary"
                  link
                  @click="handleEdit(row, 'detail')"
                >
                  查看
                </el-button>
                <el-button
                  v-if=" active === '1' || active === '6' || active === '5'"
                  size="small"
                  type="primary"
                  link
                  @click="handleEdit(row, 'edit')"
                >
                  查看
                </el-button>
                <el-button
                  v-if="row.approvalStatusName === '待审批'"
                  size="small"
                  link
                  type="primary"
                  @click="handleEdit(row, '同意')"
                >
                  同意
                </el-button>
                <el-button
                  v-if="row.approvalStatusName === '待审批' && (`${row.decisionItem}` === '1' || `${row.decisionItem}` === '2')"
                  size="small"
                  link
                  type="warning"
                  @click="handleEdit(row, '驳回')"
                >
                  驳回
                </el-button>
                <el-button
                  v-if="row.approvalStatusName === '待审批' && (`${row.decisionItem}` === '1' || `${row.decisionItem}` === '3')"
                  size="small"
                  link
                  type="danger"
                  @click="handleEdit(row, '拒绝')"
                >
                  拒绝
                </el-button>
                <!-- <el-button
                  v-if="active === '0'"
                  size="small"
                  link
                  type="primary"
                  @click="handleEdit(row, 'edit')"
                >
                  编辑
                </el-button> -->

                <!-- 是发起者且审批中可以取消 -->
                <el-button
                  v-if="row.approvalStatusName === '审批中' && active !== '7' && active !== '0'"
                  size="small"
                  link
                  type="info"
                  @click="handleEdit(row, '取消')"
                >
                  取消
                </el-button>
                <el-button
                  v-if="active !== '7' && (row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消')"
                  size="small"
                  link
                  type="danger"
                  @click="handleEdit(row, '删除')"
                >
                  删除
                </el-button>
                <!-- v-if="active === '12' && row.labCode === user.bizLabCode && row.groupCode === user.groupNo" -->
                <el-button
                  v-if="active === '12' && user.bizLabCode === row.labCode"
                  size="small"
                  link
                  type="primary"
                  @click="handleEdit(row, '结果确认')"
                >
                  结果确认
                </el-button>
              </template>
            </el-table-column>
          </template>
        </normal-table>
      </table-container>
      <!-- 审批弹窗 -->
      <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" @reject="reject" />
      <!-- 右上角按钮集合 -->
      <button-box :active="active" :total-refuse="totalRefuse" :total-approval="totalApproval" :total-to-approval="totalToApproval" :menu="menu" @change-current-button="changeCurrentButton" />
    </app-container>
  </div>
</template>