Newer
Older
xc-business-system / src / views / business / subpackage / agreement / list.vue
<!-- 测试、校准或检定工作分包协议书列表 -->
<script name="SubpackageReviewList" setup lang="ts">
import type { DateModelType } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { Ref } from 'vue'
import { getCurrentInstance, onMounted, ref, watch } from 'vue'
import dayjs from 'dayjs'
import type { IList, IListQuery } from './agreement-interface'
import UploadFileDialog from './dialog/uploadFileDialog.vue'
// import delReasonDialog from './dialog/delReasonDialog.vue'
import {
  approvalDelete,
  cancelApproval,
  draftDelete,
  exportAgreementList,
  getAgreementList,
  refuseApproval,
  rejectApproval,
} from '@/api/business/subpackage/agreement'
import { getStaffList } from '@/api/resource/register'
import { getDeptTreeList } from '@/api/system/dept'
import { getDictByCode } from '@/api/system/dict'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import ButtonBox from '@/components/buttonBox/buttonBox.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import type { deptType } from '@/global'
import { exportFile } from '@/utils/exportUtils'
import useBridgeCount from '@/components/buttonBox/useBridgeCount'
import { SCHEDULE } from '@/utils/scheduleDict'
import { toTreeList } from '@/utils/structure'

const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const active = ref('')
const operateWidth = ref('180') // 操作栏的宽度
const buttonBoxActive = 'businessSubpackageAgreement' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
const approvalDialog = ref() // 审批对话ref
const delRef = ref() // 删除弹窗组件ref
// 查询条件
const listQuery: Ref<IListQuery> = ref({
  accessNo: '', //	分包评审表编号
  applicantName: '', //		申请人
  applicantTimeEnd: '', //		申请时间结束
  applicantTimeStart: '', //		申请时间开始
  approvalStatus: active.value, // 审批状态
  contacts: '', //		联系人
  formId: SCHEDULE.SUBPACKAGE_AGREEMENT_APPROVAL, // 表单id
  mobile: '', //		电话
  outsourcerId: '', //		分包方id
  outsourcerName: '', //		分包方名称
  protocolNo: '', //		协议书编号
  requireDateEnd: '', //		要求完成日期结束
  requireDateStart: '', //		要求完成日期开始
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const totalToApproval = ref(0) // 待审批数据条数
const totalApproval = ref(0) // 审批中数据条数
const totalRefuse = ref(0) // 未通过数据条数
const loadingTable = ref(false) // 表格loading
const menu = ref<IMenu[]>([]) // 审批状态按钮组合
// 表头
const columns = ref<TableColumn[]>([
  { text: '文件编号', value: 'protocolNo', align: 'center', width: '180' },
  { text: '文件名称', value: 'projectName', align: 'center' },
  { text: '分包评审表', value: 'accessNo_hide', align: 'center', followLink: true, width: '260' },
  { text: '分包方名称', value: 'outsourcerName', align: 'center' },
  { text: '联系人', value: 'contacts', align: 'center' },
  { text: '电话', value: 'mobile', align: 'center' },
  { text: '要求完成日期', value: 'requireDate', align: 'center', width: '120' },
  { text: '申请人', value: 'createUserName', align: 'center' },
  { text: '申请时间', value: 'createTime', align: 'center', width: '180' },
])
const list = ref<IList[]>([]) // 表格数据
const dateRange = ref<[DateModelType, DateModelType]>(['', '']) // 筛选时间段数据
const requireDateRange = ref<[DateModelType, DateModelType]>(['', '']) // 要求完成日期
const checkoutList = ref<string[]>([]) // 选中的内容

// -----------------------------------------字典--------------------------------------------------------------
const useDeptList = ref<deptType[]>([]) // 所属部门列表
const userList = ref<{ [key: string]: string }[]>([]) // 用户列表

// 查询字典
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}`,
      })
    }
  })

  // 获取部门列表
  getDeptTreeList().then((res) => {
    // 转成树结构
    useDeptList.value = toTreeList(res.data, '0', true)
  })
  // 获取用户列表
  getStaffList({ offset: 1, limit: 999999 }).then((res: any) => {
    userList.value = res.data.rows
  })
}
// ------------------------------------------列表数据-------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  if (listQuery.value.approvalStatus === '10') { listQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传''

  getAgreementList(listQuery.value)
    .then((response) => {
      list.value = response.data.rows.map((item: { requireDate: string; accessNo: string }) => {
        return {
          ...item,
          requireDate: item.requireDate ? dayjs(item.requireDate).format('YYYY-MM-DD') : item.requireDate, // 要求完成日期
          followLinkArr: [item.accessNo], // 分包评审表
        }
      })
      total.value = parseInt(response.data.total)
      loadingTable.value = false
    })
    .catch(() => {
      loadingTable.value = false
    })
    // 获取待审批,审批中,未通过数据数量
  useBridgeCount(listQuery.value).then((res: any) => {
    totalToApproval.value = res.totalToApproval // 待审批数据条数
    totalApproval.value = res.totalApproval // 审批中数据条数
    totalRefuse.value = res.totalRefuse // 未通过数据条数
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置
const clearList = () => {
  listQuery.value = {
    accessNo: '', //	分包评审表编号
    applicantName: '', //		申请人
    applicantTimeEnd: '', //		申请时间结束
    applicantTimeStart: '', //		申请时间开始
    approvalStatus: active.value, // 审批状态
    contacts: '', //		联系人
    formId: SCHEDULE.SUBPACKAGE_AGREEMENT_APPROVAL, // 表单id
    mobile: '', //		电话
    outsourcerId: '', //		分包方id
    outsourcerName: '', //		分包方名称
    protocolNo: '', //		协议书编号
    requireDateEnd: '', //		要求完成日期结束
    requireDateStart: '', //		要求完成日期开始
    offset: 1,
    limit: 20,
  }
  dateRange.value = ['', '']
  requireDateRange.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)
}

// ---------------------------------------按钮---------------------------------------------------------------------
// 切换tab状态
const changeCurrentButton = (val: string) => {
  active.value = val // 此时的tab
  window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态
  clearList() // 刷新
}
// 审批结束回调
const approvalSuccess = () => {
  fetchData(true)
}
// -------------------------------------表格上方工具栏---------------------------------------------------

// 新建
const add = () => {
  $router.push({ path: '/agreement/add' })
}
// 导出
const exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  if (list.value.length > 0) {
    const params = {
      accessNo: listQuery.value.accessNo, //	分包评审表编号
      applicantName: listQuery.value.applicantName, //		申请人
      applicantTimeEnd: listQuery.value.applicantTimeEnd, //		申请时间结束
      applicantTimeStart: listQuery.value.applicantTimeStart, //		申请时间开始
      approvalStatus: listQuery.value.approvalStatus, // 审批状态
      contacts: listQuery.value.contacts, //		联系人
      formId: listQuery.value.formId, // 表单id
      mobile: listQuery.value.mobile, //		电话
      outsourcerId: listQuery.value.outsourcerId, //		分包方id
      outsourcerName: listQuery.value.outsourcerName, //		分包方名称
      protocolNo: listQuery.value.protocolNo, //		协议书编号
      requireDateEnd: listQuery.value.requireDateEnd, //		要求完成日期结束
      requireDateStart: listQuery.value.requireDateStart, //		要求完成日期开始
      offset: 1,
      limit: 20,
      ids: checkoutList.value,
    }
    exportAgreementList(params).then((res) => {
      const blob = new Blob([res.data])
      exportFile(blob, '测试、校准或检定工作分包协议书.xlsx')
    })
  }
  else {
    ElMessage.warning('无数据可导出数据')
  }
  loading.close()
}

// ----------------------------------------------操作---------------------------------------------------
const handleEdit = (row: IList, type: string) => {
  if (type === 'edit' || type === 'detail') {
    // // 编辑、详情
    // if (active.value === '0' && type === 'detail') {
    //   $router.push({
    //     path: `/agreementDoc/${type}/${row.id}`,
    //     query: {
    //       approvalStatusName: '全部', // 审批状态名称
    //       processId: row.processId, // 流程实例id
    //       taskId: row.taskId, // 任务id
    //     },
    //   })
    // }
    // else {
    $router.push({
      path: `/agreement/${type}/${row.id}`,
      query: {
        approvalStatusName: active.value === '0' ? '全部' : active.value === '7' ? '已审批' : row.approvalStatusName, // 审批状态名称
        processId: row.processId, // 流程实例id
        taskId: row.taskId, // 任务id
        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 {
    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 uploadFileDialogRef = ref() // 上传分包方签字版组件ref
// 点击上传分包方签字版
const handleUpload = (row: any) => {
  uploadFileDialogRef.value.initDialog(row.id, row.accessOtherFile)
}
// ----------------------------------------------钩子\其他事件------------------------------------------------------
// 点击分包评审表编号
const handleClickFollowLink = (row: any) => {
  $router.push({
    path: `/reviewDoc/detail/${row.accessId}`,
    query: {
      approvalStatusName: '全部', // 审批状态名称
    },
  })
}

watch(dateRange, (val) => {
  if (val) {
    listQuery.value.applicantTimeStart = `${val[0]}`
    listQuery.value.applicantTimeEnd = `${val[1]}`
  }
  else {
    listQuery.value.applicantTimeStart = ''
    listQuery.value.applicantTimeEnd = ''
  }
})

// 监听要求完成日期变化
watch(requireDateRange, (val) => {
  if (val) {
    listQuery.value.requireDateStart = `${val[0]}`
    listQuery.value.requireDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.requireDateStart = ''
    listQuery.value.requireDateEnd = ''
  }
})

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 () => {
  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>
  <app-container>
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input
          v-model.trim="listQuery.protocolNo"
          placeholder="文件编号"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.accessNo"
          placeholder="分包方评审表"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.outsourcerName"
          placeholder="分包机构名称"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.contacts"
          placeholder="联系人"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.mobile"
          placeholder="电话"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="requireDateRange"
          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.applicantName"
          placeholder="申请人"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="dateRange"
          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-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="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>

              <el-button
                v-if="active === '0'"
                size="small"
                link
                type="primary"
                @click="handleUpload(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"
    />
    <!-- 删除弹窗 -->
    <!-- <del-reason-dialog ref="delRef" @on-success="fetchData(true)" /> -->
    <!-- 上传分包方签字版组件 -->
    <upload-file-dialog ref="uploadFileDialogRef" />
  </app-container>
</template>

<style lang="ts" scoped></style>