Newer
Older
xc-business-system / src / views / quality / internal / dissatisfied / index.vue
liyaguang on 22 Apr 18 KB merge
<!-- 内部审核不符合项报告 -->
<script name="InternalDissatisfied" lang="ts" setup>
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import { getDictByCode } from '@/api/system/dict'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { SCHEDULE } from '@/utils/scheduleDict'
import ApprovalDialog from '@/components/ApprovalCustom/ApprovalDialog.vue'
import { approvalDelete, cancelApproval, delteQualityDissatisfied, draftDelete, exportQualityDissatisfiedZip, getDissatisfiedList, refuseApproval, rejectApproval, submitQualityDissatisfied } from '@/api/quality/internal/dissatisfied'
import { AGREE, TASKNAME } from '@/views/quality/agree'
import { getSearchDept } from '@/api/quality/supervise/record'
import filePreview from '@/views/quality/supervise/record/components/filePreviewSingle.vue'
import selectUser from '@/views/quality/components/selectUser.vue'
import useUserStore from '@/store/modules/user'
import useBridgeCount from '@/components/buttonBox/useBridgeCount'
import { exportFile } from '@/utils/exportUtils'

const userStore = useUserStore()
const active = ref<string>('全部')
const approvalDialog = ref() // 审批对话ref
// 查询条件
const listQuery = ref({
  approvalStatus: active.value === '10' ? '' : active.value,
  fileCode: '',
  bizLabCode: '',
  deptId: '',
  creatorName: '',
  reviewFormFileName: '',
  createTimeEnd: '',
  createTimeStart: '',
  offset: 1,
  limit: 20,
})
// 开始结束时间
// const datetimerange = ref()
// watch(() => datetimerange.value, (newVal) => {
//   listQuery.value.createTimeStart = ''
//   listQuery.value.createTimeEnd = ''
//   if (Array.isArray(newVal)) {
//     if (newVal.length) {
//       listQuery.value.createTimeStart = `${newVal[0]} 00:00:00`
//       listQuery.value.createTimeEnd = `${newVal[1]} 23:59:59`
//     }
//   }
// })
// 列表数据
const tableList = ref([])
const total = ref(0)
const totalToApproval = ref(0) // 待审批数据条数
const totalApproval = ref(0) // 审批中数据条数
const totalRefuse = ref(0) // 未通过数据条数
const loadingTable = ref(true)
const checkoutList = ref<string[]>([])// 选中的内容
// 列
const columns = ref<TableColumn[]>([
  { text: '文件编号', value: 'fileCode', align: 'center' },
  { text: '文件名称', value: 'fileName', align: 'center' },
  { text: '受审核部门', value: 'deptName', align: 'center' },
  { text: '内审员', value: 'creatorName', align: 'center' },
])
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getDissatisfiedList({ ...listQuery.value, formId: SCHEDULE.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL }).then((response) => {
    tableList.value = response.data.rows
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
  // 获取待审批,审批中,未通过数据数量
  useBridgeCount({ ...listQuery.value, formId: SCHEDULE.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL }).then((res: any) => {
    totalToApproval.value = res.totalToApproval // 待审批数据条数
    totalApproval.value = res.totalApproval // 审批中数据条数
    totalRefuse.value = res.totalRefuse // 未通过数据条数
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置查询条件
const clearList = () => {
  // datetimerange.value = []
  listQuery.value = {
    approvalStatus: active.value === '10' ? '' : active.value,
    fileCode: '',
    bizLabCode: '',
    deptId: '',
    creatorName: '',
    reviewFormFileName: '',
    createTimeEnd: '',
    createTimeStart: '',
    offset: 1,
    limit: 20,
  }
  searchList()
}
// 多选发生改变时
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)
}
// 右上角菜单
const buttonBoxActive = 'InternalDissatisfied'
const labelList = ref<{ id: string; value: string; name: string }[]>()// 实验室
const deptList = ref<{ deptName: string; deptId: string }[]>([]) // 部门列表
const deptAllList = ref<{ deptName: string; deptId: string }[]>([]) // 部门列表
const menu = ref<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}`,
      })
      // active.value = tempFindData
    }
  })
  // 获取实验室字典
  getDictByCode('bizLabCode').then((res) => {
    labelList.value = res.data
  })
  getSearchDept({ labCode: '' }).then((res) => {
    deptList.value = res.data
    deptAllList.value = res.data
  })
}
watch(() => listQuery.value.bizLabCode, (newVal) => {
  if (newVal) {
    listQuery.value.deptId = ''
    getSearchDept({ labCode: newVal }).then((res) => {
      deptList.value = res.data
    })
  }
  else {
    deptList.value = deptAllList.value
  }
}, {
  deep: true,
})
const changeCurrentButton = (val: string) => {
  if (/[\u4E00-\u9FA5]/.test(val)) {
    return
  }
  active.value = val
  window.sessionStorage.setItem(buttonBoxActive, val)
  clearList() // 刷新
}
// 新建
const $router = useRouter()
const handler = (type: string, row: any) => {
  $router.push({
    path: `/internaldissatisfied/${type}`,
  })
}
// 选择审批人
const userRef = ref()
const slectUserFun = () => {
  userRef.value.initDialog()
}
// 确认审批人
const submitRowId = ref('')
const confirmUser = (data: any) => {
  submitQualityDissatisfied({ id: submitRowId.value, formId: SCHEDULE.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL, assignees: data }).then(() => {
    ElMessage.success('已提交')
    fetchData()
  })
}
const handleEdit = (row: any, type: string) => {
  if (type === 'update' || type === 'detail' || type === 'create') { // 编辑、详情
    $router.push({
      path: `/internaldissatisfied/${type}/${row.id}`,
      query: {
        approvalStatusName: active.value === '0' ? '全部' : active.value === '7' ? '已审批' : row.approvalStatusName, // 审批状态名称
        processId: row.processId, // 流程实例id
        taskId: row.taskId, // 任务id
        id: row.id,
        decisionItem: row.decisionItem,
      },
    })
  }
  else if (type === '同意') {
    approvalDialog.value.initDialog('agree', row.taskId, row.id, row.processId)
  }
  else if (type === '驳回') {
    approvalDialog.value.initDialog('reject', row.taskId, row.id, row.processId)
  }
  else if (type === '拒绝') {
    approvalDialog.value.initDialog('refuse', row.taskId, row.id, row.processId)
  }
  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)
        delteQualityDissatisfied({ id: row.id }).then(() => {
          ElMessage.success(`已${type}`)
          fetchData()
        })
      }
      else if (type === '提交' && active.value === '1') {
        submitRowId.value = row.id
        slectUserFun()
        // submitQualityDissatisfied({ id: row.id, formId: SCHEDULE.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL }).then(() => {
        //   ElMessage.success(`已${type}`)
        //   fetchData()
        // })
      }
    })
  }
}
// 审批结束回调
const approvalSuccess = () => {
  fetchData(true)
}
// 拒绝
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 param = {
    id,
    taskId, // 任务id
    comments, // 拒绝原因
  }
  rejectApproval(param).then((res) => {
    if (res.code === 200) {
      ElMessage.success('已驳回')
    }
    else {
      ElMessage.error(`驳回失败:${res.message}`)
    }
    fetchData(true)
  })
}
onMounted(async () => {
  await getDict()
  if (window.sessionStorage.getItem(buttonBoxActive) && !(/[\u4E00-\u9FA5]/.test(window.sessionStorage.getItem(buttonBoxActive) || '全部'))) {
    active.value = window.sessionStorage.getItem(buttonBoxActive)!
  }
  else {
    active.value = menu.value.find(item => item.name === '全部')!.id as string // 全部
  }
})
const { proxy } = getCurrentInstance() as any

// 导出
const exportList = () => {
  if (!tableList.value.length) {
    ElMessage.warning('暂无导出数据')
    return
  }
  const params = {
    ...listQuery.value,
    ids: checkoutList.value,
  }
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  exportQualityDissatisfiedZip(params).then((res) => {
    if (res.data.type.includes('zip') && res.data.size) {
      const blob = new Blob([res.data])
      loading.close()
      exportFile(blob, '内部审核不符合项报告.zip')
    }
    else {
      ElMessage.warning('导出失败')
      loading.close()
    }
  })
}
</script>

<template>
  <app-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" :agree="AGREE.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL" :last-name="TASKNAME.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL" @on-success="approvalSuccess" @refuse="refuse" @reject="reject"
    :form-id="SCHEDULE.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL" :show-next-text="true"
    />
    <!-- 选择审批人 -->
    <select-user :form-id="SCHEDULE.INTERNAL_AUDIT_NONCONFORMITIES_APPROVAL" :show-next-text="true" ref="userRef" @confirm="confirmUser" />
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input v-model="listQuery.fileCode" placeholder="文件编号" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.bizLabCode" placeholder="实验室" class="short-input" filterable clearable>
          <el-option v-for="item in labelList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.deptId" placeholder="受审核部门" class="short-input" filterable clearable>
          <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
        </el-select>
      </search-item>
      <search-item>
        <el-input v-model="listQuery.creatorName" placeholder="内审员" clearable />
        <!-- <el-select
          v-model="listQuery.creatorName"
          placeholder="内审员"
          class="short-input"
          filterable
        >
          <el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.value" />
        </el-select> -->
      </search-item>
      <search-item>
        <el-date-picker v-model="listQuery.createTimeStart" type="year" value-format="YYYY-MM-DD HH:mm:ss"
          placeholder="创建开始年份" />
      </search-item>
      <search-item>
        <el-date-picker v-model="listQuery.createTimeEnd" type="year" value-format="YYYY-MM-DD HH:mm:ss"
          placeholder="创建结束年份" />
      </search-item>
      <!-- <search-item>
        <el-date-picker
          v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD"
          format="YYYY-MM-DD" range-separator="至" start-placeholder="创建开始时间" end-placeholder="创建结束时间"
          clearable
        />
      </search-item> -->
      <search-item>
        <el-input v-model="listQuery.reviewFormFileName" placeholder="关联内审检查表" clearable />
      </search-item>
    </search-area>

    <table-container>
      <template v-if="active === '0'" #btns-right>
        <icon-button v-if="proxy.hasPerm('/quality/internal/dissatisfied/add')" icon="icon-add" title="新建"
          type="primary" @click="handler('create', {})" />
        <icon-button v-if="proxy.hasPerm('/quality/internal/dissatisfied/export')" icon="icon-export" title="导出"
          type="primary" @click="exportList" />
      </template>
      <normal-table :data="tableList" :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">
            <template #default="{ row }">
              {{ row.corrTerms }}
              <!-- <div class="container">
                <div v-for="(item, index) in row.nonReviewFiles || []" :key="item.id" :class="`${index === 0 ? '' : 'item'}`">
                  <file-preview :minio-file-name="item.fileName" :minio-file-path="item.filePath || ''" />
                </div>
              </div> -->
            </template>
          </el-table-column>
          <el-table-column label="关联内审检查表" align="center">
            <template #default="{ row }">
              {{ row.reviewForm.fileName }}
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center">
            <template #default="{ row }">
              {{ row.createTime }}
            </template>
          </el-table-column>
          <el-table-column label="问题文件" align="center">
            <template #default="{ row }">
              <div class="container">
                <div v-for="(item, index) in row.nonReviewFiles || []" :key="item.id"
                  :class="`${index === 0 ? '' : 'item'}`">
                  <file-preview :minio-file-name="item.fileName" :minio-file-path="item.filePath || ''" />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column v-if="active !== '0'" label="审批状态" align="center">
            <template #default="{ row }">
              {{ row.approvalStatusName }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right">
            <template #default="{ row }">
              <el-button v-if="active === '1' && proxy.hasPerm('/quality/internal/dissatisfied/submit')" size="small"
                type="primary" link @click="handleEdit(row, '提交')">
                提交
              </el-button>
              <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, 'update')">
                查看
              </el-button>
              <el-button v-if="row.approvalStatus === '2' && proxy.hasPerm('/quality/internal/dissatisfied/agree')"
                size="small" link type="primary" @click="handleEdit(row, '同意')">
                同意
              </el-button>
              <el-button
                v-if="row.approvalStatus === '2' && (`${row.decisionItem}` === '1' || `${row.decisionItem}` === '2')"
                size="small" link type="warning" @click="handleEdit(row, '驳回')">
                驳回
              </el-button>
              <el-button
                v-if="row.approvalStatus === '2' && proxy.hasPerm('/quality/internal/dissatisfied/reject') && (`${row.decisionItem}` === '1' || `${row.decisionItem}` === '3')"
                size="small" link type="danger" @click="handleEdit(row, '拒绝')">
                拒绝
              </el-button>
              <el-button v-if="active === '0' && proxy.hasPerm('/quality/internal/dissatisfied/update')" size="small"
                link type="primary" :disabled="row.creator !== userStore.id" @click="handleEdit(row, 'update')">
                编辑
              </el-button>

              <!-- 是发起者且审批中可以取消 -->
              <el-button
                v-if="row.approvalStatusName === '审批中' && active !== '7' && active !== '0' && proxy.hasPerm('/quality/internal/dissatisfied/cancel')"
                size="small" link type="info" @click="handleEdit(row, '取消')">
                取消
              </el-button>
              <el-button
                v-if="active !== '7' && (active === '0' || row.approvalStatusName === '草稿箱' || row.approvalStatusName === '已取消') && proxy.hasPerm('/quality/internal/dissatisfied/delete')"
                size="small" link type="danger" @click="handleEdit(row, '删除')">
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>