<!-- 授权代理委托书列表 -->
<script name="OrderList" lang="ts" setup>
import { ElMessage, ElMessageBox, dayjs } from 'element-plus'
import type{ DateModelType } from 'element-plus'
import type { IListQuery, IOrderInfo } from './person-order'
import ApprovalDialog from '@/views/resource/common/approvalDialog.vue'
import { getDictByCode } from '@/api/system/dict'
import type { IMenu } from '@/components/buttonBox/buttonBox'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { draftDelete, getOrderList, orderApprDelete, refuseApproval, revokeApproval } from '@/api/resource/order'
import { SCHEDULE } from '@/utils/scheduleDict'
// import { exportFile } from '@/utils/exportUtils'
const active = ref('')
const menu = ref<IMenu[]>([]) // 审批状态按钮组合
const approvalStatusList = ref<String[]>([
'全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消',
])
const buttonBoxActive = 'orderApproval' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
const flowFormId = SCHEDULE.ACCREDIT_ORDER_APPROVAL // 资源管理 - 授权(代理)委托书
const { proxy } = getCurrentInstance() as any
const router = useRouter()
// 弹窗子组件
const apprDial = ref()
// 查询条件
const searchQuery = ref<IListQuery>({
orderNo: '', // 委托书编号
createUserName: '', // 创建人
createTimeStart: '', // 创建时间-起始
createTimeEnd: '', // 创建时间-结束
approvalStatus: active.value, // 审批状态
formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值
offset: 1,
limit: 20,
})
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
// 表头
const columns = ref<TableColumn[]>([
{ text: '文件编号', value: 'orderNo', align: 'center' },
{ text: '授权(代理)人', value: 'authorizePersonName', align: 'center' },
{ text: '授权地点', value: 'authorizeLocation', align: 'center' },
{ text: '授权职责', value: 'authorizeDuty', align: 'center' },
{ text: '创建人', value: 'createUserName', align: 'center', width: 120 },
{ text: '创建时间', value: 'createTime', align: 'center' },
{ text: '审批状态', value: 'approvalStatusName', align: 'center', width: 120 },
])
const statusColumn = ref<TableColumn>({ text: '审批状态', value: 'approvalStatusName', align: 'center', width: 120 })
const orderList = ref<Array<IOrderInfo>>([]) // 表格数据
// 逻辑
const pirintList = () => {
}
const addOrder = () => {
router.push({
query: {
type: 'create',
},
path: 'order/detail',
})
}
// 点击编辑按钮
const updateInfo = (row: IOrderInfo) => {
sessionStorage.setItem('orderInfo', JSON.stringify(row))
router.push({
query: {
type: 'update',
id: row.id,
status: active.value,
},
path: 'order/detail',
})
}
const detail = (row: IOrderInfo) => {
if (active.value === '0') {
// 全部时 查看和打印文件流
router.push({
query: {
id: row.id,
},
path: 'order/approved/detail',
})
}
else if (active.value === '1') {
// 草稿箱的 查看 是可以编辑的组件
updateInfo(row)
}
else {
// 将行数据存入缓存 用来在路由之间传递数据
sessionStorage.setItem('orderInfo', JSON.stringify(row))
router.push({
query: {
type: 'detail',
id: row.id,
status: active.value,
},
path: 'order/detail',
})
}
}
const deleteById = (row: IOrderInfo) => {
ElMessageBox.confirm(
`确认删除审批单 ${row.orderNo} 吗?`,
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
).then(() => {
if (active.value === '1') {
draftDelete({ id: row.id }).then((res) => {
if (res.code === 200) {
ElMessage.success(`审批单 ${row.orderNo} 删除成功`)
fetchData(true)
}
else {
ElMessage.error(`审批单 ${row.orderNo} 删除失败:${res.message}`)
}
})
}
else if (active.value === '6') {
orderApprDelete({ id: row.id, taskId: row.taskId }).then((res) => {
if (res.code === 200) {
ElMessage.success(`审批单 ${row.orderNo} 删除成功`)
fetchData(true)
}
else {
ElMessage.error(`审批单 ${row.orderNo} 删除失败:${res.message}`)
}
})
}
})
}
// 流程审批-同意
const approvalAgreeHandler = (row: IOrderInfo) => {
apprDial.value.initDialog('agree', row.id, row.taskId, '')
}
// 流程审批-拒绝
const approvalRefuseHandler = (row: IOrderInfo) => {
apprDial.value.initDialog('refuse', row.id, row.taskId, '')
}
// 取消(撤回审批单)
const revokeApprById = (row: IOrderInfo) => {
apprDial.value.initDialog('revoke', row.id, row.taskId, row.processId)
}
// 流程操作之后刷新
const afterApprovalHandler = () => {
fetchData(true)
}
// 取消
const orderRevokeHandler = (param: any) => {
revokeApproval(param).then((res) => {
if (res.code === 200) {
ElMessage.success('流程取消成功')
}
else {
ElMessage.error(`流程取消失败:${res.message}`)
}
// 关闭弹窗
apprDial.value.handleClose()
fetchData(true)
})
}
// 拒绝
const orderRefuseHandler = (param: any) => {
refuseApproval(param).then((res) => {
if (res.code === 200) {
ElMessage.success('拒绝审批完成')
}
else {
ElMessage.error(`拒绝审批失败:${res.message}`)
}
// 关闭弹窗
apprDial.value.handleClose()
fetchData(true)
})
}
// 数据查询
function fetchData(isNowPage = false) {
loadingTable.value = true
if (!isNowPage) {
// 是否显示当前页,否则跳转第一页
searchQuery.value.offset = 1
}
if (searchQuery.value.approvalStatus === '10') { searchQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传''
getOrderList(searchQuery.value).then((response) => {
orderList.value = response.data.rows
total.value = parseInt(response.data.total)
loadingTable.value = false
}).catch(() => {
loadingTable.value = false
})
}
const searchList = () => {
fetchData(true)
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 reset = () => {
searchQuery.value = {
orderNo: '', // 委托书编号
createUserName: '', // 创建人
createTimeStart: '', // 创建时间-起始
createTimeEnd: '', // 创建时间-结束
approvalStatus: active.value, // 审批状态
formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),此处为固定值
offset: 1,
limit: 20,
}
dateRange.value = ['', '']
fetchData(true)
}
const changeCurrentButton = (val: string) => {
active.value = val // 此时的tab
window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态
const hasStatus = columns.value.filter((col) => {
return col.value === statusColumn.value.value
})
if (val === '0') {
// 全部的时候不要显示审批状态
if (hasStatus.length > 0) {
columns.value.pop()
}
}
else {
// 其他状态下要显示审批状态字段
if (hasStatus.length === 0) {
columns.value.push(statusColumn.value)
}
}
reset() // 刷新
}
const getApprovalStatusDict = () => {
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 getDict = async () => {
getApprovalStatusDict()
}
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 = ''
}
})
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 (sessionStorage.getItem(buttonBoxActive) !== undefined && sessionStorage.getItem(buttonBoxActive) !== null) {
active.value = window.sessionStorage.getItem(buttonBoxActive)!
}
else {
active.value = '0' // 全部
}
})
</script>
<template>
<app-container>
<!-- 筛选条件 -->
<search-area :need-clear="true" @search="searchList" @clear="reset">
<search-item>
<el-input v-model="searchQuery.orderNo" placeholder="文件编号" clearable />
</search-item>
<search-item>
<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-area>
<!-- 表格数据展示 -->
<table-container>
<!-- 表头区域 -->
<template v-if="active === '0'" #btns-right>
<!-- <icon-button v-if="proxy.hasPerm('/resource/person/order/export')" icon="icon-export" title="打印" @click="pirintList" /> -->
<icon-button v-if="proxy.hasPerm('/resource/person/order/add')" icon="icon-add" title="新建" @click="addOrder" />
</template>
<!-- 表格区域 -->
<normal-table
id="orderTabel"
:data="orderList" :total="total" :columns="columns"
:query="{ limit: searchQuery.limit, offset: searchQuery.offset }"
:list-loading="loadingTable"
@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 fixed="right" label="操作" align="center" width="130">
<template #default="{ row }">
<el-button v-if="active === '0'" size="small" type="primary" link @click="detail(row)">
查看
</el-button>
<el-button v-else size="small" type="primary" link @click="detail(row)">
查看
</el-button>
<el-button v-if="(active === '1' || active === '6') && proxy.hasPerm(`/resource/person/order/delAppr`)" size="small" type="danger" link @click="deleteById(row)">
删除
</el-button>
<template v-if="active === '2'">
<el-button size="small" type="primary" link @click="approvalAgreeHandler(row)">
同意
</el-button>
<el-button 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="orderRefuseHandler"
@on-revoke="orderRevokeHandler"
/>
<!-- 右上角按钮集合 -->
<button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" />
</app-container>
</template>