index.vue
16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
<el-form-item label="日期" prop="date">
<el-date-picker v-model="queryParams.date" format="YYYY-MM" value-format="YYYY-MM" type="month"
placeholder="选择开始日期" />
</el-form-item>
<el-form-item label="工号" prop="jobCode">
<el-input v-model="queryParams.jobCode" placeholder="请输入工号" clearable @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item label="姓名" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item label="工种" prop="posts">
<el-input v-model="queryParams.posts" placeholder="请输入工种" clearable @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
</el-form-item>
<el-form-item>
<el-text class="mx-1" size="small">注意:当前页面只显示已经生成了排班的人员,管理员只能编辑未来的排班明细,排班明细是每个人每月只会生成一次</el-text>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="success" plain icon="Edit" @click="handleEdit">编 辑</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="primary" plain icon="User" :disabled="single" @click="handleUser">顶 班</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="Clock" @click="handleCreateAttendance">生成当月</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="Refresh" @click="handleAgainCreateAttendance">重新生成</el-button>
</el-col>
</el-row>
<el-table max-height="600" v-loading="loading" :stripe="true" :data="driverList" border
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="40" align="center" fixed="left" />
<el-table-column label="工号" show-overflow-tooltip="true" align="center" width="100" prop="jobCode" fixed="left" />
<el-table-column label="姓名" show-overflow-tooltip="true" align="center" width="100" prop="name" fixed="left" />
<el-table-column label="部门" show-overflow-tooltip="true" align="center" width="100" prop="fleetName"
fixed="left" />
<el-table-column label="工种" show-overflow-tooltip="true" align="center" width="100" prop="posts" fixed="left" />
<el-table-column label="班次" show-overflow-tooltip="true" align="center" width="100" prop="ruleDictName"
fixed="left" />
<el-table-column v-for="(item, index) in globalDateFields" :label="item.date" align="center">
<el-table-column :label="item.weekDay" align="center" width="225" :prop="item.date" />
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize" @pagination="getList" />
<!-- 删除和修改对话框 -->
<el-dialog :title="title" v-model="open" width="800px" append-to-body>
<template #header>
<el-radio-group v-model="radio" size="large">
<el-radio-button label="修改" />
<el-radio-button label="删除" />
</el-radio-group>
</template>
<el-text v-show="radio == '删除'" class="mx-1" size="small">删除操作请使用在离职员工身上,删除了的记录是没办法进行修改的</el-text>
<div v-show="radio == '修改'" style="margin-bottom: 30px;">
<schedulingAdd v-if="open" :schedulingNowValue="schedulingNowValue" ref="schedulingChildren"
:schedulingOptions="schedulingOptions" />
</div>
<!-- 修改|删除 -->
<el-form :inline="true" label-width="100px">
<!-- 选择人员 -->
<el-form-item>
<people ref="updateChildren" leftTitle="所有人员" rightTitle="已选择人员" />
</el-form-item>
<el-form-item label="开始日期">
<el-date-picker v-model="startDate" format="YYYY-MM-DD" value-format="YYYY-MM-DD" type="date"
placeholder="选择开始日期" :disabled-date="disabledDate" />
</el-form-item>
<el-form-item label="结束日期">
<el-date-picker v-model="endDate" format="YYYY-MM-DD" value-format="YYYY-MM-DD" type="date"
placeholder="选择开始日期" :disabled-date="disabledDate" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel">取 消</el-button>
</div>
</template>
</el-dialog>
<!-- 顶班 -->
<el-dialog :title="'顶班 ' + jobCodes + '/' + name" v-model="updateDataFlag" width="800px" append-to-body>
<el-text class="mx-1" size="small">规则不选择默认顶替当天排班规则,被顶班人员会自动设置为休息。</el-text>
<schedulingAdd v-if="updateDataFlag" ref="schedulingChildrenSecond" :schedulingNowValue="schedulingNowValue"
:schedulingOptions="schedulingOptions" />
<el-form :inline="true" style="margin-top: 15px;" v-if="updateDataFlag" ref="updateDataRef"
:model="updateDataUser" label-width="100px">
<el-form-item label="顶班日期" :required="true">
<el-date-picker v-model="updateDataUser.date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" type="date"
placeholder="选择顶班日期" @change="handleDateChange" :disabled-date="disabledDate" />
</el-form-item>
<el-form-item label="顶班员工" :required="true">
<el-select v-model="otherJobCode" :disabled="!updateDataUser.date" filterable placeholder="选择顶班人员">
<el-option v-for="item in peopleList" :key="item.jobCode" :label="item.label" :value="item.jobCode" />
</el-select>
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitFormUpdate">确 定</el-button>
<el-button @click="cancelUpdate">取 消</el-button>
</div>
</template>
</el-dialog>
<!-- 重新生成 -->
<el-dialog title="重新生成" v-model="againCreateFlag" width="800px" append-to-body>
<el-form :model="againCreateRequestVo">
<el-form-item>
<el-tooltip effect="dark" content="重新生成的排班不会覆盖今天及之前的排班数据,且会按照最新的排班设置生成,如果不小心删除了排班也可以通过重新生成按钮生成一次。"
placement="right"><el-icon>
<QuestionFilled />
</el-icon>
</el-tooltip>
</el-form-item>
<el-form-item label="日期" prop="month">
<el-date-picker v-model="againCreateRequestVo.month" format="YYYY-MM" value-format="YYYY-MM" type="month"
placeholder="选择重新生成月份" />
</el-form-item>
<el-form-item label="人员" prop="jobCode">
<people ref="newAddChildren" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitAgainCreate">确 定</el-button>
<el-button @click="cancelAgainCreate">取 消</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="Driver">
import { againCreateAttendance, createAttendance, deleteAttendance, getPeopleList, getTodayFreeUser, updateAttendance, updateSchedulingByUser } from '@/api/attendance/attendance';
import { listSchedulingAll } from "@/api/scheduling/scheduling";
import moment from 'moment';
// @ts-ignore
import { reactive, watch } from 'vue';
import schedulingAdd from '../../schedulingAssociateNum/Attendance/scheduling/index.vue';
import people from '../components/people/index.vue';
const { proxy } = getCurrentInstance();
// 全局日期
let globalDateFields = ref([]);
const againCreateRequestVo = ref({
month: null,
jobCode: null
})
const updateChildren = ref(null)
const newAddChildren = ref(null)
const peopleList = ref([])
const otherJobCode = ref(null)
const schedulingChildren = ref(null);
const schedulingChildrenSecond = ref(null);
const name = ref(null);
const radio = ref("修改")
const driverList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const jobCodes = ref([]);
const single = ref(true);
const total = ref(0);
const title = ref("");
const schedulingOptions = ref(null)
const startDate = ref(moment(new Date()).add(1, 'days').format("YYYY-MM-DD"))
const endDate = ref()
const schedulingNowValue = ref()
const againCreateFlag = ref(false)
const data = reactive({
form: {},
queryParams: {
jobCode: null,
posts: null,
name: null,
fleetName: null,
pageNum: 1,
pageSize: 10,
}
});
// 顶班请求体
const updateDataUser = ref({
jobCode: null,
ruleId: null,
otherJobCode: null,
date: null,
type: 1,
})
const resetUpdateDataUser = () => {
updateDataUser.value = {
jobCode: null,
ruleId: null,
otherJobCode: null,
date: null,
}
otherJobCode.value = null
schedulingNowValue.value = null
proxy.resetForm("updateDataRef");
}
const updateDataFlag = ref(false)
const handleCreateAttendance = () => {
proxy.$modal.confirm('确定生成当月的排班吗?').then(function () {
loading.value = true
return createAttendance(queryParams.value.date);
}).then(res => {
loading.value = false
proxy.$modal.msgSuccess("生成成功");
getList();
}).catch(res => {
loading.value = false
getList();
})
}
const { queryParams, form, rules } = toRefs(data);
/** 查询驾驶员信息列表 */
function getList() {
loading.value = true;
getPeopleList(queryParams.value).then((response) => {
driverList.value = response.rows.map(item => {
let nowItem = {
fleetName: item.fleetName,
jobCode: item.jobCode,
name: item.name,
posts: item.posts,
ruleDictName: item.ruleDictName
}
for (let index = 0; index < item.monthList.length; index++) {
const element = item.monthList[index];
nowItem[element.day] = element.rangeTime;
}
return nowItem;
})
total.value = response.total;
loading.value = false;
});
}
const disabledDate = (date) => {
const today = new Date()
const lastDayOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
return date < today;
}
// 取消按钮
function cancel() {
open.value = false;
reset();
}
// 表单重置
function reset() {
form.value = {
id: null,
jobCode: null,
name: null,
posts: null,
};
}
/**
* 获取所有日期
*/
function getCurrentMonthDaysOfWeek() {
let splitString = queryParams.value.date.split('-');
const year = Number(splitString[0]);
const month = Number(splitString[1] - 1);
globalDateFields.value = []
// 获取当前月份的第一天
const firstDayOfMonth = moment({ year, month }).startOf('month');
// 获取当前月份的最后一天
const lastDayOfMonth = moment({ year, month }).endOf('month');
// 遍历每一天并获取日期和星期
const currentDay = moment(firstDayOfMonth);
while (currentDay.isSameOrBefore(lastDayOfMonth)) {
const date = currentDay.format('MM月DD日');
const weekDay = getWeek(currentDay.day());
// 初始值
globalDateFields.value.push({
date: date,
weekDay: weekDay
})
currentDay.add(1, 'day');
}
}
/**
* 根据日期获取星期
* @param {*} week
*/
function getWeek(week) {
switch (week) {
case 1:
return '周一'
case 2:
return '周二'
case 3:
return '周三'
case 4:
return '周四'
case 5:
return '周五'
case 6:
return '周六'
case 0:
return '周日'
}
}
/** 搜索按钮操作 */
function handleQuery() {
queryParams.value.pageNum = 1;
getList();
getCurrentMonthDaysOfWeek();
}
/** 重置按钮操作 */
function resetQuery() {
proxy.resetForm("queryRef");
handleQuery();
}
// 多选框选中数据
function handleSelectionChange(selection) {
jobCodes.value = selection.map((item) => item.jobCode);
single.value = selection.length != 1;
if (!single.value) {
name.value = selection[0].name
}
}
/** 编辑按钮操作 */
function handleEdit() {
title.value = "编辑排班明细"
// 获取规则
listSchedulingAll().then(res => {
schedulingOptions.value = res.data;
open.value = true
})
}
/** 提交按钮 */
function submitForm() {
if (radio.value == "修改") {
handleUpdate()
} else {
handleDelete()
}
}
function cancelUpdate() {
updateDataFlag.value = false;
}
const handleLeftChange = (val) => {
// console.log(val);
}
const handleRightChange = (val) => {
// console.log(val);
}
/**
* 处理顶班
*/
function handleUser() {
// 获取规则
listSchedulingAll().then(res => {
schedulingOptions.value = res.data;
updateDataFlag.value = true
})
}
function handleDateChange(val) {
otherJobCode.value = null;
peopleList.value = []
getTodayFreeUser({ date: val }).then(res => {
peopleList.value = res.data.map(item => {
return {
jobCode: item.jobCode,
label: item.jobCode + '/' + item.name
}
})
})
}
/**
* 顶班修改
*/
function submitFormUpdate() {
proxy.$refs["updateDataRef"].validate(valid => {
if (valid) {
proxy.$modal.confirm('是否确定顶班工号为"' + jobCodes.value[0] + '"的数据项?').then(function () { })
.then(function () {
updateDataUser.value.jobCode = jobCodes.value[0]
updateDataUser.value.otherJobCode = otherJobCode.value;
if (schedulingChildrenSecond.value.childrenItemValue) {
updateDataUser.value.ruleId = schedulingChildrenSecond.value.childrenItemValue.id
}
if (updateDataUser.value.ruleId) {
updateDataUser.value.type = 2
} else {
updateDataUser.value.type = 1
}
return updateSchedulingByUser(updateDataUser.value);
})
.then(res => {
proxy.$modal.msgSuccess("顶班成功");
updateDataFlag.value = false
getList()
resetUpdateDataUser()
})
}
})
}
watch(updateDataFlag, (val1, val2) => {
if (!updateDataFlag.value) {
resetUpdateDataUser();
}
}
)
watch(againCreateFlag, (val1, val2) => {
// if (!againCreateFlag.value) {
// againCreateRequestVo.value = {
// month: null,
// jobCode: []
// }
// }
})
function handleAgainCreateAttendance() {
againCreateFlag.value = true;
}
function handleUpdate() {
// 判断当前规则是否为空
if (updateChildren.value.childrenItemValue && schedulingChildren.value.childrenItemValue) {
console.log(updateChildren.value.childrenItemValue);
console.log(schedulingChildren.value.childrenItemValue);
let updateData = {
jobCode: updateChildren.value.childrenItemValue,
ruleId: schedulingChildren.value.childrenItemValue.id,
startDate: startDate.value,
endDate: endDate.value
}
proxy.$modal
.confirm('是否确认修改排班明细')
.then(function () {
return updateAttendance(updateData)
})
.then(res => {
proxy.$modal.msgSuccess("对应的排班明细已经修改成功");
getList();
open.value = false
})
.catch(() => {
open.value = false
})
}
}
const submitAgainCreate = () => {
proxy.$modal
.confirm('确定要重新生成吗?')
.then(function () {
againCreateRequestVo.value.jobCode = newAddChildren.value.childrenItemValue
return againCreateAttendance(againCreateRequestVo.value)
})
.then((res) => {
proxy.$modal.msgSuccess("重新生成完毕!");
againCreateFlag.value = false
getList()
})
}
const cancelAgainCreate = () => {
againCreateFlag.value = false
}
/** 删除操作 */
function handleDelete() {
let deleteData = {
jobCode: updateChildren.value.childrenItemValue,
startDate: startDate.value,
endDate: endDate.value
}
proxy.$modal
.confirm('是否确认删除排班明细')
.then(function () {
return deleteAttendance(deleteData)
})
.then((res) => {
proxy.$modal.msgSuccess("对应的排班明细已经删除成功");
getList();
open.value = false
})
}
queryParams.value.date = moment().format("YYYY-MM")
getList();
getCurrentMonthDaysOfWeek();
</script>
<style scoped>
.people-container {
display: flex;
justify-content: center;
align-items: center;
}
</style>