Newer
Older
jh-business-system / src / views / certManage / list.vue
dutingting 1 day ago 18 KB 数据管理
<!-- 证书管理列表 -->
<script name="BusinessCertManageList" lang="ts" setup>
import { getCurrentInstance, ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { IList, IListQuery } from './cert-interface'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { printPdf } from '@/utils/printUtils'
import { exportFile } from '@/utils/exportUtils'
import { getDictByCode } from '@/api/system/dict'
import { approvalDelete, cancelApproval, createMeasureCert, draftDelete, exportCertList, getCertList, refuseCert, rejectApproval, submitCert } from '@/api/business/certManage/cert'
import { SCHEDULE } from '@/utils/scheduleDict'
import type { deptType, dictType } from '@/global'
import ButtonBox from '@/components/buttonBox/buttonBox.vue'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import useBridgeCount from '@/components/buttonBox/useBridgeCount'
import { getPhotoUrl } from '@/api/system/tool'
const { proxy } = getCurrentInstance() as any
const $router = useRouter()
const buttonBoxActive = 'CertPrint' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
// 右上角按钮
const menu = ref<IMenu[]>([]) // 右上角审批状态按钮组合
const active = ref('') // 选中的按钮
const activeTitle = ref('') // active对应的审批状态名字
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const expirationDateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据

// 查询条件
const listQuery = ref<IListQuery>({
  approvalStatus: active.value, //	审批状态类型code,导出接口不用传
  certificateName: '', //	证书名称
  certificateNo: '', //	证书编号
  conclusion: '', //	结论
  customerName: '', //	委托方
  deptName: '', //	实验室/使用部门
  formId: SCHEDULE.CERTIFICATE_PRINT_APPROVAL, //	表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
  manufactureNo: '', //	出厂编号
  measureCategory: '', //	业务类型
  model: '', //	规格型号
  sampleName: '', //	受检设备名称
  staffName: '', //	检定员名字
  offset: 1,
  limit: 20,
})

// 表头
const columns = ref<TableColumn[]>([
  { text: '证书编号', value: 'certificateNo', width: '160', align: 'center' },
  { text: '证书名称', value: 'certificateName', align: 'center' },
  // { text: '任务单编号', value: 'orderNo', width: '160', align: 'center' },
  { text: '委托方名称', value: 'customerName', align: 'center' },
  // { text: '使用部门', value: 'deptName', align: 'center' },
  { text: '设备名称', value: 'sampleName', align: 'center' },
  { text: '规格型号', value: 'model', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  { text: '业务类型', value: 'measureCategory', align: 'center' },
  { text: '检定日期', value: 'traceDate', align: 'center', width: '120' },
  { text: '检定结论', value: 'conclusion', align: 'center' },
  // { text: '检定有效期', value: 'expirationDate', align: 'center', width: '120' },
  { text: '实验室', value: 'deptName', align: 'center', width: '100' },
  // { text: '部门', value: 'groupCodeName', align: 'center', width: '120' },
  // { text: '检定员', value: 'createUserName', align: 'center' },
])
// 表格数据
const list = ref<IList[]>([])
// 总数
const total = ref(0)
const totalToApproval = ref(0) // 待审批数据条数
const totalApproval = ref(0) // 审批中数据条数
const totalRefuse = ref(0) // 未通过数据条数
// 表格加载状态
const loadingTable = ref(false)
// 选中的内容
const checkoutList = ref<string[]>([])

// --------------------------------------字典---------------------------------------------
const measureCategoryList = ref<dictType[]>([])// 业务类型
const conclusionList = ref<dictType[]>([])// 检定结论
const useDeptList = ref<deptType[]>([]) // 所属部门列表
const labDeptList = ref<deptType[]>([]) // 实验室
function getDict() {
  loadingTable.value = true

  // 业务类型
  getDictByCode('businessType').then((response) => {
    measureCategoryList.value = response.data
  })

  // 结论
  getDictByCode('bizConclusion').then((response) => {
    conclusionList.value = response.data
  })

  // 实验室
  getDictByCode('bizGroupCodeEquipment').then((response) => {
    labDeptList.value = response.data
  })

  // eslint-disable-next-line no-async-promise-executor
  return new Promise(async (resolve, reject) => {
    const data_Print = await getDictByCode('printStatus')
    const data_approval = await getDictByCode('approvalStatus')
    const response = [...data_Print.data, ...data_approval.data]

    // 制作右上角的菜单
    const tempMenu = ['全部', '草稿箱', '待审批', '审批中', '已通过', '未通过', '已取消']
    tempMenu.forEach((item) => {
      const tempFindData = response.find((e: { name: string; value: string }) => e.name === item)
      if (tempFindData) {
        menu.value.push({
          name: tempFindData.name,
          id: `${tempFindData.value}`,
        })
      }
    })
    if (window.sessionStorage.getItem(buttonBoxActive)) {
      active.value = window.sessionStorage.getItem(buttonBoxActive)!
    }
    else {
      active.value = menu.value.find(item => item.name === '全部')!.id as string // 全部
    }
  })
}

// -----------------------------------------列表数据---------------------------------------------

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getCertList(listQuery.value).then((response) => {
    list.value = response.data.rows.map((item: { traceDate: string; expirationDate: string; labCodeName: string }) => {
      return {
        ...item,
        traceDate: item.traceDate ? dayjs(item.traceDate).format('YYYY-MM-DD') : item.traceDate, // 检定日期
        expirationDate: item.expirationDate ? dayjs(item.expirationDate).format('YYYY-MM-DD') : item.expirationDate, // 检定有效期
      }
    })
    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 searchList = () => {
  fetchData(true)
}
// 点击重置
const clearList = () => {
  listQuery.value = {
    approvalStatus: active.value, //	审批状态类型code,导出接口不用传
    certificateName: '', //	证书名称
    certificateNo: '', //	证书编号
    conclusion: '', //	结论
    customerName: '', //	委托方
    deptName: '', //	实验室/使用部门
    formId: SCHEDULE.CERTIFICATE_PRINT_APPROVAL, //	表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
    manufactureNo: '', //	出厂编号
    measureCategory: '', //	业务类型
    model: '', //	规格型号
    sampleName: '', //	受检设备名称
    staffName: '', //	检定员名字
    offset: 1,
    limit: 20,
  }
  dateRange.value = ['', ''] // 清空时间
  expirationDateRange.value = ['', '']
  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 approvalDialog = ref() // 审批组件ref
const approvalRow: any = ref() // 审批行数据
// 审批
const handleDistribute = (row: IList, type: string) => {
  approvalRow.value = row
  switch (type) {
    case 'agree':
      approvalDialog.value.initDialog('agree', row.taskId)
      fetchData(true)
      break
    case 'reject':
      approvalDialog.value.initDialog('reject', row.taskId, row.id)
      fetchData(true)
      break
    case 'refuse':
      approvalDialog.value.initDialog('reject', row.taskId, row.id)
      fetchData(true)
      break
    case 'revoke':
    {
      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)
          })
        })
      break
    }
  }
}

// 拒绝
const refuse = (comments: string, taskId: string, id: string) => {
  const params = {
    id,
    taskId, // 任务id
    comments, // 拒绝原因
  }
  refuseCert(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 approvalSuccess = () => {
  fetchData(true)
  const params = {
    deptName: approvalRow.value.deptName,
    id: approvalRow.value.id,
    taskId: approvalRow.value.taskId,
  }
  createMeasureCert(params).then(() => {
    fetchData(true)
  })
}

// ----------------------------------------按钮----------------------------------------------
// 按钮切换
const changeCurrentButton = (val: string) => {
  active.value = val
  activeTitle.value = menu.value.find(item => item.id === val)!.name
  window.sessionStorage.setItem(buttonBoxActive, val)
  clearList()
}
// 点击新建
const add = () => {
  $router.push({
    path: '/cert/add',
  })
}
// ----------------------------------------操作---------------------------------------------

// 点击详情
const handleDetail = (row: IList, type: 'detail' | 'edit') => {
  $router.push({
    path: `/cert/${type}/${row.id}`,
    query: {
      ...row,
      approvalStatusName: row.approvalStatusName, // 审批状态名称
      processId: row.processId, // 流程实例
      taskId: row.taskId, // 任务id,用于同意、驳回、拒绝审批
      decisionItem: row.decisionItem,
      deptName: row.deptName, // 实验室
    },
  })
}

// 点击删除
const handleDelete = (row: any) => {
  ElMessageBox.confirm(
    '确认删除吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    if (activeTitle.value === '草稿箱') {
      draftDelete({ id: row.id }).then(() => {
        ElMessage.success('已删除')
        fetchData(true)
      })
    }
    else if (activeTitle.value === '已取消') {
      approvalDelete({ id: row.id }).then(() => {
        ElMessage.success('已删除')
        fetchData(true)
      })
    }
  })
}

// 点击提交
const submit = (row: any) => {
  ElMessageBox.confirm(
    '确认删除吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    const loading = ElLoading.service({
      lock: true,
      text: '加载中...',
      background: 'rgba(255, 255, 255, 0.6)',
    })
    submitCert({ id: row.id, formId: SCHEDULE.CERTIFICATE_PRINT_APPROVAL }).then((res) => {
      ElMessage.success('已提交')
      loading.close()
      fetchData(true)
    })
  })
}
// ---------------------------------------钩子-----------------------------------------------

onMounted(async () => {
  await getDict()
  fetchData()
})
</script>

<template>
  <app-container>
    <search-area
      :need-clear="true"
      @search="searchList" @clear="clearList"
    >
      <search-item>
        <el-input
          v-model.trim="listQuery.certificateNo"
          placeholder="证书编号"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.certificateName"
          placeholder="证书名称"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.customerName"
          placeholder="委托方"
          clearable
          class="short-input"
        />
      </search-item>
      <!-- <search-item>
        <el-input
          v-model.trim="listQuery.deptName"
          placeholder="使用部门"
          clearable
          class="short-input"
        />
      </search-item> -->
      <search-item>
        <el-input
          v-model.trim="listQuery.sampleName"
          placeholder="设备名称"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.model"
          placeholder="规格型号"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.manufactureNo"
          placeholder="出厂编号"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.measureCategory"
          placeholder="业务类型"
          filterable
          clearable
          class="short-input"
        >
          <el-option v-for="item in measureCategoryList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <dept-select
          ref="deptSelect"
          v-model="listQuery.deptName"
          placeholder="实验室"
          :dept-show="true"
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.staffName"
          placeholder="检定员"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.conclusion"
          placeholder="检定结论"
          filterable
          class="short-input"
          clearable
        >
          <el-option v-for="item in conclusionList" :key="item.id" :label="item.name" :value="item.name" />
        </el-select>
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <icon-button icon="icon-add" title="新建" type="primary" @click="add" />
      </template>
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery"
        :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange"
      >
        <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 v-if="!['未打印', '全部'].includes(activeTitle)" label="审批状态" align="center" width="90px" prop="approvalStatusName" />
          <el-table-column label="操作" align="center" fixed="right" width="180">
            <template #default="{ row }">
              <el-button size="small" link type="primary" @click="handleDetail(row, 'detail')">
                查看
              </el-button>
              <el-button v-if="activeTitle === '草稿箱'" size="small" link type="primary" @click="submit(row)">
                提交
              </el-button>
              <el-button v-if="activeTitle === '草稿箱' || activeTitle === '已取消' || row.approvalStatusName === '未通过'" size="small" link type="primary" @click="handleDetail(row, 'edit')">
                编辑
              </el-button>
              <el-button v-if="activeTitle === '待审批'" size="small" type="primary" link @click="handleDistribute(row, 'agree')">
                同意
              </el-button>
              <!-- <el-button
                v-if="row.approvalStatusName === '待审批' && (`${row.decisionItem}` === '1' || `${row.decisionItem}` === '2')"
                size="small"
                link
                type="warning"
                @click="handleDistribute(row, 'reject')"
              >
                驳回
              </el-button> -->
              <el-button v-if="activeTitle === '待审批' && (`${row.decisionItem}` === '1' || `${row.decisionItem}` === '3')" size="small" type="danger" link @click="handleDistribute(row, 'refuse')">
                拒绝
              </el-button>
              <el-button
                v-if="activeTitle === '审批中' && active !== '7' && active !== '0'"
                size="small"
                link
                type="info"
                @click="handleDistribute(row, 'revoke')"
              >
                取消
              </el-button>
              <el-button
                v-if="activeTitle === '草稿箱' || activeTitle === '已取消'"
                size="small"
                link
                type="danger"
                @click="handleDelete(row)"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
    <!-- 右上角审批状态按钮集合 -->
    <button-box :active="active" :total-refuse="totalRefuse" :total-approval="totalApproval" :total-to-approval="totalToApproval" :menu="menu" @change-current-button="changeCurrentButton" />
    <!-- 审批弹窗 -->
    <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" @reject="reject" />
  </app-container>
</template>

<style lang="scss" scoped>
.short-input {
  width: 160px;
}
</style>