Newer
Older
xc-business-system / src / views / quality / internal / report / index.vue
lyg on 23 May 2024 14 KB 自定义图表-折线图
<!-- 内部审核报告 -->
<script name="InternalApproveReport" 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 { approvalDelete, cancelApproval, delteQualityReport, draftDelete, exportQualityReportZip, getReportList, refuseApproval, submitQualityReport } from '@/api/quality/internal/report'
import { SCHEDULE } from '@/utils/scheduleDict'
import ApprovalDialog from '@/components/ApprovalCustom/ApprovalDialog.vue'
import { AGREE, TASKNAME } from '@/views/quality/agree'
import selectUser from '@/views/quality/components/selectUser.vue'
import useUserStore from '@/store/modules/user'
import { exportFile } from '@/utils/exportUtils'

const userStore = useUserStore()
const approvalDialog = ref() // 审批对话ref
const active = ref<string>('全部')
// 查询条件
const listQuery = ref({
  approvalStatus: active.value === '10' ? '' : active.value,
  fileCode: '',
  fileName: '',
  creatorName: '',
  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 loadingTable = ref(true)
const checkoutList = ref<string[]>([])// 选中的内容
// 列
const columns = ref<TableColumn[]>([
  { text: '文件编号', value: 'fileCode', align: 'center' },
  { text: '文件名称', value: 'fileName', align: 'center' },
  { text: '创建人', value: 'creatorName', align: 'center' },
  { text: '创建时间', value: 'createTime', align: 'center' },
])
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getReportList({ ...listQuery.value, formId: SCHEDULE.INTERNAL_AUDIT_APPROVAL }).then((response) => {
    tableList.value = response.data.rows
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置查询条件
const clearList = () => {
  // datetimerange.value = []
  listQuery.value = {
    approvalStatus: active.value === '10' ? '' : active.value,
    fileCode: '',
    fileName: '',
    creatorName: '',
    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 = 'InternalApproveReport'
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
    }
  })
}
const changeCurrentButton = (val: string) => {
  active.value = val
  window.sessionStorage.setItem(buttonBoxActive, val)
  clearList() // 刷新
}
// 新建
const $router = useRouter()
const handler = (type: string, row: any) => {
  $router.push({
    path: `/internalreport/${type}`,
  })
}
// 选择审批人
const userRef = ref()
const slectUserFun = () => {
  userRef.value.initDialog()
}
// 确认审批人
const submitRowId = ref('')
const confirmUser = (data: any) => {
  submitQualityReport({ id: submitRowId.value, formId: SCHEDULE.INTERNAL_AUDIT_APPROVAL, assignees: data }).then(() => {
    ElMessage.success('已提交')
    fetchData()
  })
}
const handleEdit = (row: any, type: string) => {
  if (type === 'update' || type === 'detail' || type === 'create') { // 编辑、详情
    $router.push({
      path: `/internalreport/${type}/${row.id}`,
      query: {
        approvalStatusName: active.value === '0' ? '全部' : active.value === '7' ? '已审批' : row.approvalStatusName, // 审批状态名称
        processId: row.processId, // 流程实例id
        taskId: row.taskId, // 任务id
        id: row.id,
      },
    })
  }
  else if (type === '同意') {
    approvalDialog.value.initDialog('agree', 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)
        delteQualityReport({ id: row.id }).then(() => {
          ElMessage.success(`已${type}`)
          fetchData()
        })
      }
      else if (type === '提交' && active.value === '1') {
        submitRowId.value = row.id
        slectUserFun()
        // submitQualityReport({ id: row.id, formId: SCHEDULE.INTERNAL_AUDIT_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)
  })
}
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 // 全部
  }
  // searchList()
})
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)',
  })
  exportQualityReportZip(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" :menu="menu" @change-current-button="changeCurrentButton" />
    <!-- 审批弹窗 -->
    <approval-dialog ref="approvalDialog" :agree="AGREE.INTERNAL_AUDIT_APPROVAL" :last-name="TASKNAME.INTERNAL_AUDIT_APPROVAL" @on-success="approvalSuccess" @refuse="refuse" />
    <!-- 选择审批人 -->
    <select-user 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-input
          v-model="listQuery.fileName"
          placeholder="文件名称"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model="listQuery.creatorName"
          placeholder="创建人"
          clearable
        />
      </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-area>

    <table-container>
      <template v-if="active === '0'" #btns-right>
        <icon-button v-if="proxy.hasPerm('/quality/internal/report/add')" icon="icon-add" title="新建" type="primary" @click="handleEdit({}, 'create')" />
        <icon-button v-if="proxy.hasPerm('/quality/internal/report/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
            v-if="active !== '0'"
            label="审批状态"
            align="center"
          >
            <template #default="{ row }">
              {{ row.approvalStatusName }}
            </template>
          </el-table-column>

          <el-table-column
            label="操作"
            align="center"
            fixed="right"
            width="140"
          >
            <template #default="{ row }">
              <el-button
                v-if="active === '1' && proxy.hasPerm('/quality/internal/report/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/report/agree')"
                size="small"
                link
                type="primary"
                @click="handleEdit(row, '同意')"
              >
                同意
              </el-button>
              <el-button
                v-if="row.approvalStatus === '2' && proxy.hasPerm('/quality/internal/report/reject')"
                size="small"
                link
                type="danger"
                @click="handleEdit(row, '拒绝')"
              >
                拒绝
              </el-button>
              <el-button
                v-if="active === '0' && proxy.hasPerm('/quality/internal/report/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/report/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/report/delete')"
                size="small"
                link
                type="danger"
                @click="handleEdit(row, '删除')"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>