houzhongjian
2024-08-08 820397e43a0b64d35c6d31d2a55475061438593b
提交 | 用户 | 时间
820397 1 <template>
H 2
3   <ContentWrap>
4     <!-- 搜索工作栏 -->
5     <el-form
6       ref="queryFormRef"
7       :inline="true"
8       :model="queryParams"
9       class="-mb-15px"
10       label-width="68px"
11     >
12       <el-form-item label="请假类型" prop="type">
13         <el-select
14           v-model="queryParams.type"
15           class="!w-240px"
16           clearable
17           placeholder="请选择请假类型"
18         >
19           <el-option
20             v-for="dict in getIntDictOptions(DICT_TYPE.BPM_OA_LEAVE_TYPE)"
21             :key="dict.value"
22             :label="dict.label"
23             :value="dict.value"
24           />
25         </el-select>
26       </el-form-item>
27       <el-form-item label="申请时间" prop="createTime">
28         <el-date-picker
29           v-model="queryParams.createTime"
30           :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
31           class="!w-240px"
32           end-placeholder="结束日期"
33           start-placeholder="开始日期"
34           type="daterange"
35           value-format="YYYY-MM-DD HH:mm:ss"
36         />
37       </el-form-item>
38       <el-form-item label="审批结果" prop="status">
39         <el-select
40           v-model="queryParams.status"
41           class="!w-240px"
42           clearable
43           placeholder="请选择审批结果"
44         >
45           <el-option
46             v-for="dict in getIntDictOptions(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS)"
47             :key="dict.value"
48             :label="dict.label"
49             :value="dict.value"
50           />
51         </el-select>
52       </el-form-item>
53       <el-form-item label="原因" prop="reason">
54         <el-input
55           v-model="queryParams.reason"
56           class="!w-240px"
57           clearable
58           placeholder="请输入原因"
59           @keyup.enter="handleQuery"
60         />
61       </el-form-item>
62       <el-form-item>
63         <el-button @click="handleQuery">
64           <Icon class="mr-5px" icon="ep:search" />
65           搜索
66         </el-button>
67         <el-button @click="resetQuery">
68           <Icon class="mr-5px" icon="ep:refresh" />
69           重置
70         </el-button>
71         <el-button plain type="primary" @click="handleCreate()">
72           <Icon class="mr-5px" icon="ep:plus" />
73           发起请假
74         </el-button>
75       </el-form-item>
76     </el-form>
77   </ContentWrap>
78
79   <!-- 列表 -->
80   <ContentWrap>
81     <el-table v-loading="loading" :data="list">
82       <el-table-column align="center" label="申请编号" prop="id" />
83       <el-table-column align="center" label="状态" prop="status">
84         <template #default="scope">
85           <dict-tag :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS" :value="scope.row.status" />
86         </template>
87       </el-table-column>
88       <el-table-column
89         :formatter="dateFormatter"
90         align="center"
91         label="开始时间"
92         prop="startTime"
93         width="180"
94       />
95       <el-table-column
96         :formatter="dateFormatter"
97         align="center"
98         label="结束时间"
99         prop="endTime"
100         width="180"
101       />
102       <el-table-column align="center" label="请假类型" prop="type">
103         <template #default="scope">
104           <dict-tag :type="DICT_TYPE.BPM_OA_LEAVE_TYPE" :value="scope.row.type" />
105         </template>
106       </el-table-column>
107       <el-table-column align="center" label="原因" prop="reason" />
108       <el-table-column
109         :formatter="dateFormatter"
110         align="center"
111         label="申请时间"
112         prop="createTime"
113         width="180"
114       />
115       <el-table-column align="center" label="操作" width="200">
116         <template #default="scope">
117           <el-button
118             v-hasPermi="['bpm:oa-leave:query']"
119             link
120             type="primary"
121             @click="handleDetail(scope.row)"
122           >
123             详情
124           </el-button>
125           <el-button
126             v-hasPermi="['bpm:oa-leave:query']"
127             link
128             type="primary"
129             @click="handleProcessDetail(scope.row)"
130           >
131             进度
132           </el-button>
133           <el-button
134             v-if="scope.row.result === 1"
135             v-hasPermi="['bpm:oa-leave:create']"
136             link
137             type="danger"
138             @click="cancelLeave(scope.row)"
139           >
140             取消
141           </el-button>
142         </template>
143       </el-table-column>
144     </el-table>
145     <!-- 分页 -->
146     <Pagination
147       v-model:limit="queryParams.pageSize"
148       v-model:page="queryParams.pageNo"
149       :total="total"
150       @pagination="getList"
151     />
152   </ContentWrap>
153 </template>
154 <script lang="ts" setup>
155 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
156 import { dateFormatter } from '@/utils/formatTime'
157 import * as LeaveApi from '@/api/bpm/leave'
158 import * as ProcessInstanceApi from '@/api/bpm/processInstance'
159
160 defineOptions({ name: 'BpmOALeave' })
161
162 const message = useMessage() // 消息弹窗
163 const router = useRouter() // 路由
164 const { t } = useI18n() // 国际化
165
166 const loading = ref(true) // 列表的加载中
167 const total = ref(0) // 列表的总页数
168 const list = ref([]) // 列表的数据
169 const queryParams = reactive({
170   pageNo: 1,
171   pageSize: 10,
172   type: undefined,
173   status: undefined,
174   reason: undefined,
175   createTime: []
176 })
177 const queryFormRef = ref() // 搜索的表单
178
179 /** 查询列表 */
180 const getList = async () => {
181   loading.value = true
182   try {
183     const data = await LeaveApi.getLeavePage(queryParams)
184     list.value = data.list
185     total.value = data.total
186   } finally {
187     loading.value = false
188   }
189 }
190
191 /** 搜索按钮操作 */
192 const handleQuery = () => {
193   queryParams.pageNo = 1
194   getList()
195 }
196
197 /** 重置按钮操作 */
198 const resetQuery = () => {
199   queryFormRef.value.resetFields()
200   handleQuery()
201 }
202
203 /** 添加操作 */
204 const handleCreate = () => {
205   router.push({ name: 'OALeaveCreate' })
206 }
207
208 /** 详情操作 */
209 const handleDetail = (row: LeaveApi.LeaveVO) => {
210   router.push({
211     name: 'OALeaveDetail',
212     query: {
213       id: row.id
214     }
215   })
216 }
217
218 /** 取消请假操作 */
219 const cancelLeave = async (row) => {
220   // 二次确认
221   const { value } = await ElMessageBox.prompt('请输入取消原因', '取消流程', {
222     confirmButtonText: t('common.ok'),
223     cancelButtonText: t('common.cancel'),
224     inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
225     inputErrorMessage: '取消原因不能为空'
226   })
227   // 发起取消
228   await ProcessInstanceApi.cancelProcessInstanceByStartUser(row.id, value)
229   message.success('取消成功')
230   // 刷新列表
231   await getList()
232 }
233
234 /** 审批进度 */
235 const handleProcessDetail = (row) => {
236   router.push({
237     name: 'BpmProcessInstanceDetail',
238     query: {
239       id: row.processInstanceId
240     }
241   })
242 }
243
244 // fix: 列表不刷新的问题。
245 watch(
246   () => router.currentRoute.value,
247   () => {
248     getList()
249   }
250 )
251
252 /** 初始化 **/
253 onMounted(() => {
254   getList()
255 })
256 </script>