Newer
Older
xc-business-system / src / views / resource / customer / suggestForm / list.vue
dutingting on 12 Feb 17 KB 资源管理、质量管理驳回
<!-- 委托方意见登记表列表 -->
<script name="SuggestFormList" lang="ts" setup>
import { ElMessage, ElMessageBox, dayjs } from 'element-plus'
import type { DateModelType } from 'element-plus'
import type { ICustomerSuggestInfo, IHandleListQuery, IListQuery } from './customer-suggest'
import type { IDictType } from '@/commonInterface/resource-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import ApprovalDialog from '@/views/resource/common/approvalDialog.vue'
import { deleteFormDraft, deleteFormRevoked, exportList, getFormList, getFormToBeHandleList, refuseApproval, rejectApproval, revokeApproval } from '@/api/resource/suggestForm'
import { getDictByCode } from '@/api/system/dict'
import { SCHEDULE } from '@/utils/scheduleDict'
import { exportFile } from '@/utils/exportUtils'
import useBridgeCount from '@/components/buttonBox/useBridgeCount'

// 定义常量
const buttonBoxActive = 'suggestFormApproval' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
const flowFormId = SCHEDULE.CUSTOMER_OPINION_REGISTER_APPROVAL // 资源管理 - 委托方意见登记表

const { proxy } = getCurrentInstance() as any
const router = useRouter()

// 选中的审批状态按钮
const active = ref('')
const menu = ref<IMenu[]>([]) // 审批状态按钮组合
const approvalStatusList = ref<String[]>([
  '全部', '待处理', '已审批', '待审批', '审批', '审批中', '已通过', '未通过', '已取消',
])

const handleStatusDict = ref<Array<IDictType>>([])
const labCodeDict = ref<Array<IDictType>>([])

// 弹窗子组件
const apprDial = ref()

// 查询条件
const searchQuery = ref<IListQuery>({
  formNo: '', // 通知单编号
  customerName: '',
  customerDeptName: '',
  createUserName: '', // 创建人名字
  createTimeStart: '', // 创建时间-起始
  createTimeEnd: '', // 创建时间-结束
  approvalStatus: active.value, // 审批状态
  labCode: '',
  handleStatus: '',
  formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值
  offset: 1,
  limit: 20,
})
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const total = ref(0) // 数据条数
const totalToApproval = ref(0) // 待审批数据条数
const totalApproval = ref(0) // 审批中数据条数
const totalRefuse = ref(0) // 未通过数据条数
const loadingTable = ref(false) // 表格loading

const handleSearchQuery = ref<IHandleListQuery>({
  formNo: '', // 通知单编号
  customerName: '',
  customerDeptName: '',
  createUserName: '', // 创建人名字
  createTimeStart: '', // 创建时间-起始
  createTimeEnd: '', // 创建时间-结束
  labCode: '',
  handleStatus: '',
  offset: 1,
  limit: 20,
})

// 表头
const columns = ref<TableColumn[]>([
  { text: '文件编号', value: 'formNo', align: 'center', width: '180' },
  { text: '意见反馈单位', value: 'customerName', align: 'center' },
  { text: '意见反馈部门', value: 'customerDeptName', align: 'center' },
  { text: '意见对象', value: 'labCodeName', align: 'center' },
  { text: '创建人', value: 'originCreateUserName', align: 'center', width: '150' },
  { text: '创建时间', value: 'createTime', align: 'center', width: '180' },
  { text: '处置情况', value: 'handleStatusName', align: 'center', width: '150' },
])
const suggestList = ref<Array<ICustomerSuggestInfo>>([]) // 表格数据
const suggestListSelected = ref<Array<ICustomerSuggestInfo>>([]) // 表格多选

const reset = () => {
  searchQuery.value = {
    formNo: '', // 委托方编号
    customerName: '', // 委托方名字
    customerDeptName: '', // 联系人
    createUserName: '',
    createTimeStart: '', // 创建时间-起始
    createTimeEnd: '', // 创建时间-结束
    labCode: '',
    handleStatus: '',
    approvalStatus: active.value, // 审批状态
    formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值
    offset: 1,
    limit: 20,
  }
  dateRange.value = ['', '']
  fetchData(true)
}

const searchList = () => {
  fetchData(true)
}

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    searchQuery.value.offset = 1
  }

  const targetMenu = menu.value.filter((m) => { return m.id === active.value })
  if (targetMenu.length > 0) {
    if (targetMenu[0].name === '待处理') {
      // 查询待处理
      searchQuery.value.approvalStatus = ''
      searchQuery.value.formId = ''
      getFormToBeHandleList(handleSearchQuery.value).then((res) => {
        if (res.code === 200) {
          suggestList.value = res.data.rows
          total.value = parseInt(res.data.total)
        }
        loadingTable.value = false
      })

      // 获取待审批,审批中,未通过数据数量
      useBridgeCount(searchQuery.value).then((res: any) => {
        totalToApproval.value = res.totalToApproval // 待审批数据条数
        totalApproval.value = res.totalApproval // 审批中数据条数
        totalRefuse.value = res.totalRefuse // 未通过数据条数
      })
    }
    else {
      // 查询其他审批流程
      if (searchQuery.value.approvalStatus === '10') { searchQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传''

      getFormList(searchQuery.value).then((response) => {
        if (response.code === 200) {
          suggestList.value = response.data.rows

          total.value = parseInt(response.data.total)
        }
        loadingTable.value = false
      }).catch(() => {
        loadingTable.value = false
      })

      // 获取待审批,审批中,未通过数据数量
      useBridgeCount(searchQuery.value).then((res: any) => {
        totalToApproval.value = res.totalToApproval // 待审批数据条数
        totalApproval.value = res.totalApproval // 审批中数据条数
        totalRefuse.value = res.totalRefuse // 未通过数据条数
      })
    }
  }
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    searchQuery.value.limit = val.size
  }
  if (val && val.page) {
    searchQuery.value.offset = val.page
  }
  fetchData(true)
}

// 导出
const batchExportSuggestForm = () => {
  const ids: string[] = []
  suggestListSelected.value.forEach((item: ICustomerSuggestInfo) => {
    ids.push(item.id!)
  })

  if (ids.length === 0) {
    // 没有选择导出所有
    exportList(searchQuery.value).then((res) => {
      exportFile(res.data, `委托方意见登记表-${dayjs().format('YYYYMMDDHHmmss')}.xls`)
    })
  }
  else {
    exportList({ ids }).then((res) => {
      exportFile(res.data, `委托方意见登记表-${dayjs().format('YYYYMMDDHHmmss')}.xls`)
    })
  }
}

// 多选改变
const suggestSelected = (e: any) => {
  suggestListSelected.value = e
}

const detail = (row: ICustomerSuggestInfo) => {
  if (active.value === '0') {
    // 全部时 查看和打印文件流
    router.push({
      query: {
        id: row.id,
        decisionItem: row.decisionItem,
        taskId: row.taskId,
      },
      path: 'suggestForm/approved/detail',
    })
  }
  else if (active.value === '11' && row.handleStatus === '1' && row.reasonAndConclusion === '') {
    // 待处理时且未填写原因 表示为在实施人处 新建处置流程
    sessionStorage.setItem('suggestFormInfo', JSON.stringify(row))
    router.push({
      query: {
        type: 'create',
      },
      path: 'suggestForm/detail',
    })
  }
  else if (active.value === '1' || active.value === '11') {
    // 草稿箱或待处理可以编辑
    sessionStorage.setItem('suggestFormInfo', JSON.stringify(row))
    router.push({
      query: {
        type: 'update',
        id: row.id,
        status: active.value,
        decisionItem: row.decisionItem,
        taskId: row.taskId,
      },
      path: 'suggestForm/detail',
    })
  }
  else {
  // 其余情况下只能查看
    sessionStorage.setItem('suggestFormInfo', JSON.stringify(row))
    router.push({
      query: {
        type: 'detail',
        id: row.id,
        status: active.value,
        decisionItem: row.decisionItem,
        taskId: row.taskId,
      },
      path: 'suggestForm/detail',
    })
  }
}

// 删除
const deleteSuggestById = (row: ICustomerSuggestInfo) => {
  ElMessageBox.confirm(
    `确认删除意见登记表 ${row.formNo} 吗?`,
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    if (active.value === '0' || active.value === '1') {
      // 全部 及 草稿箱 中删除
      deleteFormDraft({ id: row.id }).then((res) => {
        if (res.code === 200) {
          ElMessage.success(`意见登记表 ${row.formNo} 删除成功`)
          fetchData(true)
        }
        else {
          ElMessage.error(`意见登记表 ${row.formNo} 删除失败:${res.message}`)
        }
      })
    }
    else if (active.value === '6') {
      // 已取消 中删除
      deleteFormRevoked({ id: row.id }).then((res) => {
        if (res.code === 200) {
          ElMessage.success(`意见登记表 ${row.formNo} 删除成功`)
          fetchData(true)
        }
        else {
          ElMessage.error(`意见登记表 ${row.formNo} 删除失败:${res.message}`)
        }
      })
    }
  })
}

// 审批按钮点击切换事件
const changeCurrentButton = (val: string) => {
  active.value = val // 此时的tab
  sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态

  reset() // 刷新
}

// 流程审批-同意
const approvalAgreeHandler = (row: ICustomerSuggestInfo) => {
  apprDial.value.initDialog('agree', row.id, row.taskId, '')
}
// 流程审批-驳回
const approvalRejectHandler = (row: ICustomerSuggestInfo) => {
  apprDial.value.initDialog('reject', row.id, row.taskId, '')
}
// 流程审批-拒绝
const approvalRefuseHandler = (row: ICustomerSuggestInfo) => {
  apprDial.value.initDialog('refuse', row.id, row.taskId, '')
}

// 取消(撤回审批单)
const revokeApprById = (row: ICustomerSuggestInfo) => {
  const params = {
    processInstanceId: row.processId!,
    comments: '',
    id: row.id,
  }
  ElMessageBox.confirm(
    '确认取消该审批吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  )
    .then(() => {
      revokeApproval(params).then((res) => {
        ElMessage({
          type: 'success',
          message: '已取消',
        })
        fetchData(true)
      })
    })
}

// 流程操作之后刷新
const afterApprovalHandler = () => {
  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}`)
    }
    // 关闭弹窗
    apprDial.value.handleClose()

    fetchData(true)
  })
}

// 拒绝
const formRefuseHandler = (param: any) => {
  refuseApproval(param).then((res) => {
    if (res.code === 200) {
      ElMessage.success('拒绝审批完成')
    }
    else {
      ElMessage.error(`拒绝审批失败:${res.message}`)
    }
    // 关闭弹窗
    apprDial.value.handleClose()

    fetchData(true)
  })
}

// 初始化流程审批状态按钮
const getApprovalStatusDict = async () => {
  await getDictByCode('approvalStatus').then((res) => {
    if (res.code === 200) {
      approvalStatusList.value.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}`,
          })
        }
      })
    }
  })
}

const getLabCodeDict = async () => {
  getDictByCode('bizLabCode').then((res) => {
    if (res.code === 200) {
      labCodeDict.value = res.data
    }
  })
}

const getHandleStatusDict = async () => {
  getDictByCode('handleStatus').then((res) => {
    if (res.code === 200) {
      handleStatusDict.value = res.data
    }
  })
}

const getDict = async () => {
  await getApprovalStatusDict()
  await getLabCodeDict()
  await getHandleStatusDict()
}

watch(dateRange, (val) => {
  if (val) {
    searchQuery.value.createTimeStart = dayjs(val[0]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD')
    searchQuery.value.createTimeEnd = dayjs(val[1]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD')
  }
  else {
    searchQuery.value.createTimeStart = ''
    searchQuery.value.createTimeEnd = ''
  }
})

onMounted(async () => {
  await getDict()
  if (sessionStorage.getItem(buttonBoxActive) !== undefined && sessionStorage.getItem(buttonBoxActive) !== null) {
    active.value = sessionStorage.getItem(buttonBoxActive)!
  }
  else {
    active.value = '0' // 全部
  }
})
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <search-item width="162px">
        <el-input v-model="searchQuery.formNo" placeholder="文件编号" clearable />
      </search-item>
      <search-item width="162px">
        <el-input v-model="searchQuery.customerName" placeholder="意见反馈单位" clearable />
      </search-item>
      <search-item width="162px">
        <el-input v-model="searchQuery.customerDeptName" placeholder="意见反馈部门" clearable />
      </search-item>
      <search-item width="162px">
        <el-select v-model="searchQuery.labCode" placeholder="意见对象" clearable>
          <el-option v-for="dict in labCodeDict" :key="dict.id" :value="dict.value" :label="dict.name" />
        </el-select>
      </search-item>
      <search-item width="162px">
        <el-input v-model="searchQuery.createUserName" placeholder="创建人" clearable />
      </search-item>
      <search-item>
        <el-date-picker v-model="dateRange" type="daterange" start-placeholder="创建时间(开始)" end-placeholder="创建时间(结束)" />
      </search-item>
      <search-item width="162px">
        <el-select v-model="searchQuery.handleStatus" placeholder="处置情况" clearable>
          <el-option v-for="dict in handleStatusDict" :key="dict.id" :value="dict.value" :label="dict.name" />
        </el-select>
      </search-item>
    </search-area>

    <!-- 表格数据展示 -->
    <table-container>
      <template #btns-right>
        <icon-button v-if="active === '0'" icon="icon-export" title="导出" @click="batchExportSuggestForm" />
      </template>

      <!-- 表格区域 -->
      <normal-table
        :data="suggestList" :total="total" :columns="columns"
        :query="{ limit: searchQuery.limit, offset: searchQuery.offset }"
        :list-loading="loadingTable"
        :is-showmulti-select="true" @multi-select="suggestSelected"
        @change="changePage"
      >
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column v-if="active === '10'" label="审批状态" align="center" width="100">
            <template #default="{ row }">
              {{ row.approvalStatusName }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" align="center" width="180">
            <template #default="{ row }">
              <el-button size="small" type="primary" link @click="detail(row)">
                查看
              </el-button>

              <el-button v-if="(active === '0' || active === '1' || active === '6') && proxy.hasPerm(`/resource/customer/suggestForm/del`)" size="small" type="danger" link @click="deleteSuggestById(row)">
                删除
              </el-button>

              <template v-if="active === '2'">
                <el-button size="small" type="primary" link @click="approvalAgreeHandler(row)">
                  同意
                </el-button>
                <el-button
                  v-if="`${row.decisionItem}` === '1' || `${row.decisionItem}` === '2'"
                  size="small"
                  link
                  type="warning"
                  @click="approvalRejectHandler(row)"
                >
                  驳回
                </el-button>
                <el-button v-if="`${row.decisionItem}` === '1' || `${row.decisionItem}` === '3'" size="small" type="danger" link @click="approvalRefuseHandler(row)">
                  拒绝
                </el-button>
              </template>
              <template v-if="active === '3'">
                <el-button size="small" type="info" link @click="revokeApprById(row)">
                  取消
                </el-button>
              </template>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>

    <!-- 审批单弹窗 -->
    <approval-dialog
      ref="apprDial"
      @on-success="afterApprovalHandler"
      @on-refuse="formRefuseHandler"
      @reject="reject"
    />

    <!-- 右上角按钮集合 -->
    <button-box :active="active" :total-refuse="totalRefuse" :total-approval="totalApproval" :total-to-approval="totalToApproval" :menu="menu" @change-current-button="changeCurrentButton" />
  </app-container>
</template>