Newer
Older
xc-business-system / src / views / equipement / standard / book / list.vue
<!-- 标准库台账信息列表 -->
<script name="StandardBookInfoList" lang="ts" setup>
import type { Ref } from 'vue'
import { getCurrentInstance, onMounted, ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import type { DateModelType } from 'element-plus'
import type { IList, IListQuery } from './book-interface'
import delReasonDialog from './dialog/delReasonDialog.vue'
import showPhoto from '@/components/showPhoto/index.vue'
import buttonBox from '@/components/buttonBox/buttonBox.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { SCHEDULE } from '@/utils/scheduleDict'
import { getDictByCode } from '@/api/system/dict'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import useUserStore from '@/store/modules/user'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import { approvalDelete, cancelApproval, draftDelete, getStandardList, getStream, refuseApproval } from '@/api/equipment/standard/book'
import { exportFile } from '@/utils/exportUtils'
import type { deptType } from '@/global'
const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const active = ref('')
const buttonBoxActive = 'StandardBookInfo' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
const operateWidth = ref('150') // 操作栏的宽度
const user = useUserStore() // 用户信息
console.log('ooorrrtt', user.deptType)
const dateRangeNext = ref<[DateModelType, DateModelType]>(['', ''])// 下次复查日期
const dateRangeLast = ref<[DateModelType, DateModelType]>(['', ''])// 最近复查日期
const dateRangeLastChange = ref<[DateModelType, DateModelType]>(['', ''])// 下次变更日期

// 查询条件
const listQuery: Ref<IListQuery> = ref({
  approvalStatus: active.value, //	审批状态类型code,导出接口不用传
  deptId: '', //		部门id
  formId: SCHEDULE.STANDARD_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
  groupCode: '', // 	组别代码
  inUseStatus: '', //	在用状态
  labCode: '', //	实验室名称
  lastChangeDateStart: '', //	最近变更日期开始
  lastChangeDateEnd: '', //	最近变更日期结束
  lastReviewDateStart: '', //	最近复查日期开始
  lastReviewDateEnd: '', //	最近复查日期结束
  nextReviewDateStart: '', //	下次复查日期开始
  nextReviewDateEnd: '', //	下次复查日期结束
  majorType: '', //	专业类别
  standardName: '', //	计量标准库名称
  standardNo: '', //	计量标准证书号
  storageLocation: '', //	存放地点(字典code)
  technologyFileName: '', //	依据技术文件名称
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
const menu = ref<IMenu[]>([]) // 审批状态按钮组合
const approvalDialog = ref() // 审批弹窗组件ref
const delRef = ref() // 删除弹窗组件ref
// 表头
const columns = ref<TableColumn[]>([
  { text: '计量标准证书号', value: 'standardCertNo', align: 'center' },
  { text: '计量标准库名称', value: 'standardName', align: 'center' },
  { text: '实验室', value: 'labCodeName', align: 'center', width: '120' },
  { text: '部门', value: 'groupCodeName', align: 'center', width: '120' },
  { text: '专业类别', value: 'majorTypeName', align: 'center', width: '120' },
  { text: '最近复查日期', value: 'lastReviewDate', align: 'center', width: '120' },
  { text: '下次复查日期', value: 'nextReviewDate', align: 'center', width: '120' },
  { text: '在用状态', value: 'manageStatusName', align: 'center' },
  { text: '最近变更日期', value: 'lastChangeDate', align: 'center', width: '120' },
  { text: '标准证书', value: 'standardCertFile', align: 'center' },
])
const list = ref<IList[]>([]) // 表格数据
const checkoutList = ref<string[]>([])// 选中的内容

// -----------------------------------------字典--------------------------------------------------------------
const bizStandardManagerStateList = ref({}) as any // 在用状态
const labDeptList = ref<deptType[]>([]) // 实验室
const useDeptList = ref<deptType[]>([]) // 部门列表
const majorTypeList = ref<deptType[]>([]) // 部门列表

// 查询字典
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}`,
      })
    }
  })
  // 在用状态
  getDictByCode('bizStandardManagerState').then((response) => {
    bizStandardManagerStateList.value = response.data
  })
  // 实验室
  getDictByCode('bizGroupCodeEquipment').then((response) => {
    labDeptList.value = response.data
  })

  // 部门
  getDictByCode('bizGroupCode').then((response) => {
    useDeptList.value = response.data
  })

  // 专业类别
  getDictByCode('bizMajorType').then((response) => {
    majorTypeList.value = response.data
  })
}
// -------------------------------------------列表数据操作------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  if (listQuery.value.approvalStatus === '10') { listQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传''
  // 检定部门(全部)只能查看本部门的标准库
  // getStandardList({ ...listQuery.value, deptId: active.value === '0' && user.deptType === '3' ? user.deptId : '' }).then((response) => {
  getStandardList({ ...listQuery.value }).then((response) => {
    list.value = response.data.rows.map((item: { lastReviewDate: string; agreementAmount: number; nextReviewDate: string; lastChangeDate: string }) => {
      return {
        ...item,
        lastReviewDate: item.lastReviewDate ? dayjs(item.lastReviewDate).format('YYYY-MM-DD') : item.lastReviewDate, // 最近复查日期
        nextReviewDate: item.nextReviewDate ? dayjs(item.nextReviewDate).format('YYYY-MM-DD') : item.nextReviewDate, // 最近复查日期
        lastChangeDate: item.lastChangeDate || '/', // 最近变更日期
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置
const clearList = () => {
  listQuery.value = {
    approvalStatus: active.value, //	审批状态类型code,导出接口不用传
    deptId: '', //		部门id
    formId: SCHEDULE.STANDARD_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
    groupCode: '', // 	组别代码
    inUseStatus: '', //	在用状态
    labCode: '', //	实验室名称
    lastChangeDateStart: '', //	最近变更日期开始
    lastChangeDateEnd: '', //	最近变更日期结束
    lastReviewDateStart: '', //	最近复查日期开始
    lastReviewDateEnd: '', //	最近复查日期结束
    nextReviewDateStart: '', //	下次复查日期开始
    nextReviewDateEnd: '', //	下次复查日期结束
    majorType: '', //	专业类别
    standardName: '', //	计量标准库名称
    standardNo: '', //	计量标准证书号
    storageLocation: '', //	存放地点(字典code)
    technologyFileName: '', //	依据技术文件名称
    offset: 1,
    limit: 20,
  }
  dateRangeNext.value = ['', '']// 下次复查日期
  dateRangeLast.value = ['', '']// 最近复查日期
  dateRangeLastChange.value = ['', '']// 下次变更日期
  fetchData(true)
}

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

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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)
}

// 改变页容量
function handleSizeChange(val: number) {
  listQuery.value.limit = val
  fetchData()
}
// 改变当前页
function handleCurrentChange(val: number) {
  listQuery.value.offset = val
  fetchData(true)
}

// ------------------------------------------按钮-------------------------------------------------------
// 导出word
const exportWordorPdf = (type: 'word' | 'pdf') => {
  const loading = ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  getStream({
    ids: checkoutList.value,
    pdf: type !== 'word',
    approvalStatus: listQuery.value.approvalStatus, //	审批状态类型code,导出接口不用传
    deptId: listQuery.value.deptId, //		部门id
    formId: listQuery.value.formId, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
    groupCode: listQuery.value.groupCode, // 	组别代码
    inUseStatus: listQuery.value.inUseStatus, //	在用状态
    labCode: listQuery.value.labCode, //	实验室名称
    lastChangeDateStart: listQuery.value.lastChangeDateStart, //	最近变更日期开始
    lastChangeDateEnd: listQuery.value.lastChangeDateEnd, //	最近变更日期结束
    lastReviewDateStart: listQuery.value.lastReviewDateStart, //	最近复查日期开始
    lastReviewDateEnd: listQuery.value.lastReviewDateEnd, //	最近复查日期结束
    nextReviewDateStart: listQuery.value.nextReviewDateStart, //	下次复查日期开始
    nextReviewDateEnd: listQuery.value.nextReviewDateEnd, //	下次复查日期结束
    majorType: listQuery.value.majorType, //	专业类别
    standardName: listQuery.value.standardName, //	计量标准库名称
    standardNo: listQuery.value.standardNo, //	计量标准证书号
    storageLocation: listQuery.value.storageLocation, //	存放地点(字典code)
    technologyFileName: listQuery.value.technologyFileName, //	依据技术文件名称
  }).then((res) => {
    const title = type === 'word' ? '标准库台账管理.doc' : '标准库台账管理.pdf'
    exportFile(res.data, title)
    loading.close()
  })
}

// 新建
const add = () => {
  $router.push({ path: '/standard/add' })
}
// ----------------------------------------------操作---------------------------------------------------
const handleEdit = (row: IList, type: string) => {
  if (type === 'edit' || type === 'detail') { // 编辑、详情
    $router.push({
      path: `/standard/${type}/${row.id}`,
      query: {
        approvalStatusName: active.value === '0' ? '全部' : active.value === '7' ? '已审批' : row.approvalStatusName, // 审批状态名称
        standardNo: row.standardNo, // 标准库编号
        standardId: row.id,
        standardName: row.standardName, // 标准库名称
        processId: row.processId, // 流程实例id
        taskId: row.taskId, // 任务id
      },
    })
  }
  else if (type === '同意') {
    approvalDialog.value.initDialog('agree', row.taskId)
  }
  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 {
    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 === '已取消') {
        approvalDelete({ id: row.id, taskId: row.taskId }).then(() => {
          ElMessage.success(`已${type}`)
          fetchData()
        })
      }
      else if (type === '删除' && active.value === '0') { // 全部的删除
        delRef.value.initDialog(row)
      }
    })
  }
}
// 拒绝
const refuse = (comments: string, taskId: string, id: string) => {
  const params = {
    id,
    taskId, // 任务id
    comments, // 拒绝原因
  }
  refuseApproval(params).then((res) => {
    ElMessage({
      type: 'success',
      message: '已拒绝',
    })
    fetchData(true)
  })
}
// ------------------------------------审批按钮---------------------------------------------------------------------
// 切换tab状态
const changeCurrentButton = (val: string) => {
  active.value = val // 此时的tab
  window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态
  clearList() // 刷新
}
// 审批结束回调
const approvalSuccess = () => {
  fetchData(true)
}
// ----------------------------------------------钩子------------------------------------------------------
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 })

watch(dateRangeNext, (val) => { // 下次复查日期
  if (val) {
    listQuery.value.nextReviewDateStart = `${val[0]}`
    listQuery.value.nextReviewDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.nextReviewDateStart = ''
    listQuery.value.nextReviewDateEnd = ''
  }
})
watch(dateRangeLast, (val) => { // 最近复查日期
  if (val) {
    listQuery.value.lastReviewDateStart = `${val[0]}`
    listQuery.value.lastReviewDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.lastReviewDateStart = ''
    listQuery.value.lastReviewDateEnd = ''
  }
})

watch(dateRangeLastChange, (val) => { // 最近变更日期
  if (val) {
    listQuery.value.lastChangeDateStart = `${val[0]}`
    listQuery.value.lastChangeDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.lastChangeDateStart = ''
    listQuery.value.lastChangeDateEnd = ''
  }
})

onMounted(async () => {
  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 // 全部
  }
})

function TableCellStyle(value: any) {
  if (value.row.colorMark === 1) {
    return 'background-color:#e43c2f !important;color: #000 !important;font-weight: 600 !important;'
  }
  else if (value.row.colorMark === 2) {
    return 'background-color:#f9be15; !important;color: #000 !important;'
  }
}
</script>

<template>
  <app-container>
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input v-model.trim="listQuery.standardNo" placeholder="计量标准证书号" class="short-input" clearable />
      </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.labCode"
          placeholder="实验室"
          class="short-input"
          filterable
          clearable
        >
          <el-option v-for="item in labDeptList" :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 useDeptList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.majorType"
          placeholder="专业类别"
          class="short-input"
          filterable
          clearable
        >
          <el-option v-for="item in majorTypeList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="dateRangeLast"
          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-date-picker
          v-model="dateRangeNext"
          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-select
          v-model="listQuery.inUseStatus"
          placeholder="在用状态"
          class="short-input"
          filterable
          clearable
        >
          <el-option v-for="item in bizStandardManagerStateList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="dateRangeLastChange"
          class="short-input"
          type="daterange"
          range-separator="至"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="最近变更日期(开始)"
          end-placeholder="最近变更日期(结束)"
        />
      </search-item>
    </search-area>

    <table-container>
      <template v-if="active === '0'" #btns-right>
        <icon-button icon="icon-word" title="导出word" type="primary" @click="exportWordorPdf('word')" />
        <icon-button icon="icon-pdf" title="导出pdf" type="primary" @click="exportWordorPdf('pdf')" />
        <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
            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 === '待审批'"
                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' && (active === '0' || row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消')"
                size="small"
                link
                type="danger"
                @click="handleEdit(row, '删除')"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table> -->
      <el-table
        v-loading="loadingTable"
        :data="list"
        border
        style="width: 100%;"
        :row-style="TableCellStyle as any"
        :row-key="(row: any) => { return row.id || row.index }"
        @selection-change="handleSelectionChange"
      >
        <el-table-column :reserve-selection="true" type="selection" width="38" fixed="left" />
        <el-table-column label="序号" width="55" align="center">
          <template #default="scope">
            {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          v-for="item in columns"
          :key="item.value"
          :prop="item.value"
          :label="item.text"
          :width="item.width"
          :show-overflow-tooltip="true"
          align="center"
        >
          <template #default="scope">
            <show-photo v-if="item.value === 'standardCertFile' && scope.row[item.value] !== '/'" :minio-file-name="scope.row[item.value]" style="margin-right: 10px;" />
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="120"
          align="center"
        >
          <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 === '待审批'"
              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' && (active === '0' || row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消')"
              size="small"
              link
              type="danger"
              @click="handleEdit(row, '删除')"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 页码 -->
      <el-pagination
        style="width: 100%;margin-top: 10px;"
        :current-page="listQuery.offset"
        :page-sizes="[5, 10, 20, 30, 50, 100, 150, 200]"
        :page-size="listQuery.limit"
        :total="total"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </table-container>
    <!-- 审批弹窗 -->
    <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" />
    <!-- 右上角按钮集合 -->
    <button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" />
    <!-- 删除弹窗 -->
    <del-reason-dialog ref="delRef" @on-success="fetchData(true)" />
  </app-container>
</template>

<style lang="ts" scoped>

</style>