| | |
| | | <script setup lang="ts"> |
| | | import { computed, ref } from "vue"; |
| | | import { onPullDownRefresh, onReachBottom, onShow } from "@dcloudio/uni-app"; |
| | | import { deleteLeave, getAutoApprovalPolicy, getHrmDicts, getLeavePage, getLeaveProcesses, submitLeave, type ApproveProcess, type Leave } from "../../../api/hrm"; |
| | | import { cancelLeave, deleteLeave, getHrmDicts, getLeavePage, getLeaveProcesses, submitLeave, type ApproveProcess, type Leave } from "../../../api/hrm"; |
| | | import type { DictData } from "../../../api/crm"; |
| | | import { useAuth } from "../../../stores/auth"; |
| | | import { auditClass, displayDate, HRM_DICT, label } from "../shared"; |
| | |
| | | async function submit(row: Leave) { |
| | | if (!state.accessToken || !row.id || !canOperate(row)) return; |
| | | try { |
| | | const automaticApproval = await getAutoApprovalPolicy(state.accessToken).catch(() => false); |
| | | let processKey = "hrm_leave"; |
| | | if (!automaticApproval) { |
| | | const processes = await getLeaveProcesses(state.accessToken); |
| | | if (!processes.length) throw new Error("暂无可用审批流程"); |
| | | const process = await chooseProcess(processes); |
| | | if (!process) return; |
| | | processKey = process.key; |
| | | } |
| | | await submitLeave(state.accessToken, row.id, processKey); |
| | | const processes = await getLeaveProcesses(state.accessToken); |
| | | if (!processes.length) throw new Error("暂无可用审批流程"); |
| | | const process = await chooseProcess(processes); |
| | | if (!process) return; |
| | | await submitLeave(state.accessToken, row.id, process.key); |
| | | uni.showToast({ title: "提交成功", icon: "success" }); |
| | | await load(true); |
| | | } catch (cause) { |
| | |
| | | } |
| | | } |
| | | |
| | | function cancel(row: Leave) { |
| | | if (!state.accessToken || !row.id || !canOperate(row)) return; |
| | | uni.showModal({ title: "撤销申请", content: "确定撤销该请假申请吗?", success: async result => { |
| | | if (!result.confirm || !state.accessToken) return; |
| | | try { await cancelLeave(state.accessToken, row.id!); uni.showToast({ title: "撤销成功", icon: "success" }); await load(true); } |
| | | catch (cause) { uni.showToast({ title: cause instanceof Error ? cause.message : "撤销失败", icon: "none" }); } |
| | | }}); |
| | | } |
| | | function remove(row: Leave) { |
| | | if (!state.accessToken || !row.id || !canOperate(row)) return; |
| | | uni.showModal({ |
| | |
| | | <view v-for="row in rows" :key="row.id" class="card"> |
| | | <view class="head"><view><text class="name">{{ row.userName || "--" }}的请假申请</text><text class="sub">申请编号 {{ row.id }} · {{ row.deptName || "未分配部门" }}</text></view><text :class="['tag', auditClass(row.status)]">{{ label(dicts, HRM_DICT.auditStatus, row.status) }}</text></view> |
| | | <view class="grid"><text>类型:{{ label(dicts, HRM_DICT.leaveType, row.leaveType) }}</text><text>时长:{{ row.duration ?? "--" }} 天</text><text>开始:{{ displayDate(row.startTime) }}</text><text>结束:{{ displayDate(row.endTime) }}</text></view> |
| | | <view class="actions"><button @click="go(row.id, 'detail')">详情</button><button v-if="canOperate(row)&&row.status===0&&hasPermission('hrm:leave:update')" @click="go(row.id)">编辑</button><button v-if="canOperate(row)&&row.status===0&&hasPermission('hrm:leave:submit')" @click="submit(row)">提交</button><button v-if="canOperate(row)&&(row.status===0||row.status===40)&&hasPermission('hrm:leave:delete')" class="danger" @click="remove(row)">删除</button></view> |
| | | <view class="actions"><button @click="go(row.id, 'detail')">详情</button><button v-if="canOperate(row)&&row.status===0&&hasPermission('hrm:leave:update')" @click="go(row.id)">编辑</button><button v-if="canOperate(row)&&row.status===0&&hasPermission('hrm:leave:submit')" @click="submit(row)">提交</button><button v-if="canOperate(row)&&row.status===10&&hasPermission('hrm:leave:cancel')" @click="cancel(row)">撤销</button><button v-if="canOperate(row)&&(row.status===0||row.status===40)&&hasPermission('hrm:leave:delete')" class="danger" @click="remove(row)">删除</button></view> |
| | | </view> |
| | | <view v-if="!rows.length&&!loading&&!error" class="state">暂无本人提交的请假申请</view> |
| | | <view v-else-if="rows.length" class="more">{{ hasMore ? (loading ? "加载中..." : "上拉加载更多") : "没有更多了" }}</view> |