|
@@ -30,10 +30,6 @@
|
30
|
30
|
|
31
|
31
|
<!-- 选择项目 -->
|
32
|
32
|
<uni-forms-item label="选择项目" required class="form-item" v-if="!isScattered" name="projectId">
|
33
|
|
- <!-- <ProjectPicker v-model="formData.projectId" placeholder="请选择项目" :labelKey="'projectName'"
|
34
|
|
- :valueKey="'projectId'" @change="handleProjectChange"
|
35
|
|
- :customStyle="{ borderColor: '#e5e5e5', borderRadius: '8px' }" v-if="taskName == '工作填报'" /> -->
|
36
|
|
- <!-- <ProjectInfo :project="projectObj" v-else></ProjectInfo> -->
|
37
|
33
|
<u-button type="primary" @click="openProject = true" v-if="taskName == '工作填报'">选择项目</u-button>
|
38
|
34
|
<ProjectPicker :visible.sync="openProject" :selected.sync="selectedProject" @confirm="handleConfirm" />
|
39
|
35
|
<ProjectInfo :project="projectObj"></ProjectInfo>
|
|
@@ -49,13 +45,25 @@
|
49
|
45
|
<uni-forms-item label="工作细项" required class="form-item" name="workItem">
|
50
|
46
|
<picker @change="bindWorkItemChange" :value="formData.workItem" :range="workItemList"
|
51
|
47
|
:disabled="taskName != '工作填报'">
|
52
|
|
- <view class="uni-input">
|
53
|
|
- <uni-easyinput type="text" :disabled="taskName != '工作填报'" v-model="formData.workItem"
|
54
|
|
- @click="showType = true" placeholder="请选择" :styles="inputStyle" />
|
|
48
|
+ <view class="picker-selector" :class="{ 'picker-disabled': taskName != '工作填报' }">
|
|
49
|
+ <text class="picker-text" :class="{ 'picker-placeholder': !formData.workItem }">
|
|
50
|
+ {{ formData.workItem || '请选择' }}
|
|
51
|
+ </text>
|
|
52
|
+ <uni-icons type="arrowdown" size="16" color="#c0c4cc"></uni-icons>
|
55
|
53
|
</view>
|
56
|
54
|
</picker>
|
57
|
55
|
</uni-forms-item>
|
58
|
56
|
|
|
57
|
+ <!-- 工作日期 -->
|
|
58
|
+ <uni-forms-item label="工作日期" required class="form-item" name="beginDate">
|
|
59
|
+ <uni-datetime-picker v-if="taskName == '工作填报'" type="daterange" v-model="dateRange" start-placeholder="开始日期"
|
|
60
|
+ end-placeholder="结束日期" range-separator="至" return-type="string" @change="handleDateRangeChange" :border="true"
|
|
61
|
+ :clear-icon="true" />
|
|
62
|
+ <view v-else class="date-display">
|
|
63
|
+ <text class="date-text">{{ formatDateRange() }}</text>
|
|
64
|
+ </view>
|
|
65
|
+ </uni-forms-item>
|
|
66
|
+
|
59
|
67
|
<!-- 具体内容 -->
|
60
|
68
|
<uni-forms-item label="具体内容" required class="form-item" name="workContent">
|
61
|
69
|
<uni-easyinput :disabled="taskName != '工作填报'" type="textarea" v-model="formData.workContent"
|
|
@@ -64,7 +72,7 @@
|
64
|
72
|
|
65
|
73
|
<!-- 工天 -->
|
66
|
74
|
<uni-forms-item label="工天" required class="form-item" name="workLoad">
|
67
|
|
- <uni-easyinput :disabled="taskName != '工作填报'" type="number" v-model="formData.workLoad" placeholder="请输入所需工天"
|
|
75
|
+ <uni-easyinput :disabled="taskName != '工作填报'" type="number" v-model="formData.workLoad" placeholder="请输入工天"
|
68
|
76
|
:styles="inputStyle">
|
69
|
77
|
<text slot="right" class="unit">天</text>
|
70
|
78
|
</uni-easyinput>
|
|
@@ -118,7 +126,7 @@ export default {
|
118
|
126
|
startUserName: String, // 流程发起人
|
119
|
127
|
},
|
120
|
128
|
created() {
|
121
|
|
- this.applierUserName = this.startUserName;
|
|
129
|
+ this.applierUserName = this.startUserName;
|
122
|
130
|
this.getProjectList();
|
123
|
131
|
this.initForm();
|
124
|
132
|
if (this.taskName != '工作填报') {
|
|
@@ -139,6 +147,8 @@ export default {
|
139
|
147
|
projectId: '',
|
140
|
148
|
workType: '',
|
141
|
149
|
workItem: '',
|
|
150
|
+ beginDate: '',
|
|
151
|
+ endDate: '',
|
142
|
152
|
workContent: '',
|
143
|
153
|
workLoad: '',
|
144
|
154
|
price: 200,
|
|
@@ -165,6 +175,18 @@ export default {
|
165
|
175
|
errorMessage: '请选择工作细项',
|
166
|
176
|
},]
|
167
|
177
|
},
|
|
178
|
+ beginDate: {
|
|
179
|
+ rules: [{
|
|
180
|
+ required: true,
|
|
181
|
+ errorMessage: '请选择开始日期',
|
|
182
|
+ },]
|
|
183
|
+ },
|
|
184
|
+ endDate: {
|
|
185
|
+ rules: [{
|
|
186
|
+ required: true,
|
|
187
|
+ errorMessage: '请选择结束日期',
|
|
188
|
+ },]
|
|
189
|
+ },
|
168
|
190
|
workContent: {
|
169
|
191
|
rules: [{
|
170
|
192
|
required: true,
|
|
@@ -174,7 +196,7 @@ export default {
|
174
|
196
|
workLoad: {
|
175
|
197
|
rules: [{
|
176
|
198
|
required: true,
|
177
|
|
- errorMessage: '请输入工作量',
|
|
199
|
+ errorMessage: '请输入工天',
|
178
|
200
|
},]
|
179
|
201
|
},
|
180
|
202
|
coefficient: {
|
|
@@ -205,7 +227,7 @@ export default {
|
205
|
227
|
borderRadius: '8px',
|
206
|
228
|
height: '100px'
|
207
|
229
|
},
|
208
|
|
- showType: false,
|
|
230
|
+
|
209
|
231
|
workTypeColumns: [{
|
210
|
232
|
text: '外业',
|
211
|
233
|
value: '外业',
|
|
@@ -218,12 +240,34 @@ export default {
|
218
|
240
|
workItemList: [],
|
219
|
241
|
hasForm: false,
|
220
|
242
|
show: false,
|
|
243
|
+ isSubmitting: false, // 提交状态
|
221
|
244
|
};
|
222
|
245
|
},
|
|
246
|
+ computed: {
|
|
247
|
+ dateRange: {
|
|
248
|
+ get() {
|
|
249
|
+ if (this.formData.beginDate && this.formData.endDate) {
|
|
250
|
+ return [this.formData.beginDate, this.formData.endDate];
|
|
251
|
+ }
|
|
252
|
+ return [];
|
|
253
|
+ },
|
|
254
|
+ set(value) {
|
|
255
|
+ if (value && value.length === 2) {
|
|
256
|
+ this.formData.beginDate = value[0];
|
|
257
|
+ this.formData.endDate = value[1];
|
|
258
|
+ } else {
|
|
259
|
+ this.formData.beginDate = '';
|
|
260
|
+ this.formData.endDate = '';
|
|
261
|
+ }
|
|
262
|
+ }
|
|
263
|
+ }
|
|
264
|
+ },
|
223
|
265
|
methods: {
|
224
|
266
|
handleConfirm(project) {
|
225
|
267
|
this.selectedProject = project;
|
226
|
268
|
this.projectObj = project;
|
|
269
|
+ // 同时设置formData中的projectId,避免表单验证失败
|
|
270
|
+ this.formData.projectId = project.projectId;
|
227
|
271
|
},
|
228
|
272
|
initForm() {
|
229
|
273
|
if (this.taskName == '工作填报') {
|
|
@@ -246,6 +290,19 @@ export default {
|
246
|
290
|
this.projectObj = res.data.project;
|
247
|
291
|
this.selectedProject = res.data.project;
|
248
|
292
|
this.bindWorkTypeChange(this.formData.workType);
|
|
293
|
+
|
|
294
|
+ // 处理日期范围和工天的关系
|
|
295
|
+ if (!this.formData.beginDate) {
|
|
296
|
+ this.formData.beginDate = '';
|
|
297
|
+ }
|
|
298
|
+ if (!this.formData.endDate) {
|
|
299
|
+ this.formData.endDate = '';
|
|
300
|
+ }
|
|
301
|
+ if (this.formData.beginDate && this.formData.endDate) {
|
|
302
|
+ // 如果有日期范围,计算建议工天数但不覆盖现有值
|
|
303
|
+ this.calculateWorkDays();
|
|
304
|
+ }
|
|
305
|
+
|
249
|
306
|
this.countMoney();
|
250
|
307
|
} else {
|
251
|
308
|
this.hasForm = false;
|
|
@@ -296,29 +353,87 @@ export default {
|
296
|
353
|
let result = Number(this.formData.price) * Number(this.formData.workLoad) * Number(this.formData.coefficient)
|
297
|
354
|
this.money = result.toFixed(2)
|
298
|
355
|
},
|
299
|
|
- async save() {
|
300
|
|
- if (!this.isScattered) {
|
301
|
|
- this.formData.projectId = this.projectObj.projectId;
|
302
|
|
- } else {
|
303
|
|
- this.formData.projectId = ''
|
|
356
|
+ handleDateRangeChange(range) {
|
|
357
|
+ this.dateRange = range;
|
|
358
|
+ this.calculateWorkDays();
|
|
359
|
+ },
|
|
360
|
+ calculateWorkDays() {
|
|
361
|
+ if (!this.formData.beginDate || !this.formData.endDate) {
|
|
362
|
+ return;
|
304
|
363
|
}
|
305
|
|
- if (this.hasForm) {
|
306
|
|
- let updateRes = await updateDeclare(this.formData);
|
307
|
|
- } else {
|
308
|
|
- this.formData.formId = this.taskForm.formId;
|
309
|
|
- let addRes = await addDeclare(this.formData);
|
310
|
|
- if (addRes.code == 200) {
|
311
|
|
- this.hasForm = true;
|
|
364
|
+
|
|
365
|
+ const startDate = new Date(this.formData.beginDate);
|
|
366
|
+ const endDate = new Date(this.formData.endDate);
|
|
367
|
+
|
|
368
|
+ if (startDate && endDate && startDate <= endDate) {
|
|
369
|
+ // 计算日期差(包含开始和结束日期)
|
|
370
|
+ const timeDiff = endDate.getTime() - startDate.getTime();
|
|
371
|
+ const daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24)) + 1;
|
|
372
|
+
|
|
373
|
+ // 直接设置工天
|
|
374
|
+ this.formData.workLoad = daysDiff;
|
|
375
|
+ }
|
|
376
|
+ },
|
|
377
|
+
|
|
378
|
+ formatDateRange() {
|
|
379
|
+ if (this.formData.beginDate && this.formData.endDate) {
|
|
380
|
+ const beginDate = this.formData.beginDate.split(' ')[0]; // 只取日期部分,去掉时间
|
|
381
|
+ const endDate = this.formData.endDate.split(' ')[0];
|
|
382
|
+ return `${beginDate} 到 ${endDate}`;
|
|
383
|
+ }
|
|
384
|
+ return '未选择日期';
|
|
385
|
+ },
|
|
386
|
+ async save(showToast = true) {
|
|
387
|
+ try {
|
|
388
|
+ if (!this.isScattered) {
|
|
389
|
+ this.formData.projectId = this.projectObj.projectId;
|
312
|
390
|
} else {
|
313
|
|
- this.hasForm = false;
|
|
391
|
+ this.formData.projectId = ''
|
314
|
392
|
}
|
|
393
|
+
|
|
394
|
+ let result;
|
|
395
|
+ if (this.hasForm) {
|
|
396
|
+ result = await updateDeclare(this.formData);
|
|
397
|
+ } else {
|
|
398
|
+ this.formData.formId = this.taskForm.formId;
|
|
399
|
+ result = await addDeclare(this.formData);
|
|
400
|
+ if (result.code == 200) {
|
|
401
|
+ this.hasForm = true;
|
|
402
|
+ } else {
|
|
403
|
+ this.hasForm = false;
|
|
404
|
+ }
|
|
405
|
+ }
|
|
406
|
+
|
|
407
|
+ if (result && result.code === 200) {
|
|
408
|
+ if (showToast) {
|
|
409
|
+ uni.showToast({
|
|
410
|
+ title: '保存成功',
|
|
411
|
+ icon: 'success'
|
|
412
|
+ });
|
|
413
|
+ }
|
|
414
|
+ return Promise.resolve(result);
|
|
415
|
+ } else {
|
|
416
|
+ throw new Error(result?.msg || '保存失败');
|
|
417
|
+ }
|
|
418
|
+ } catch (error) {
|
|
419
|
+ console.error('保存失败:', error);
|
|
420
|
+ if (showToast) {
|
|
421
|
+ uni.showToast({
|
|
422
|
+ title: error.message || '保存失败',
|
|
423
|
+ icon: 'error'
|
|
424
|
+ });
|
|
425
|
+ }
|
|
426
|
+ return Promise.reject(error);
|
315
|
427
|
}
|
316
|
|
- uni.showToast({
|
317
|
|
- title: '保存成功',
|
318
|
|
- icon: 'success'
|
319
|
|
- });
|
320
|
428
|
},
|
321
|
429
|
submitForm() {
|
|
430
|
+ // 在表单验证前确保projectId被正确设置
|
|
431
|
+ if (!this.isScattered && this.projectObj && this.projectObj.projectId) {
|
|
432
|
+ this.formData.projectId = this.projectObj.projectId;
|
|
433
|
+ } else if (this.isScattered) {
|
|
434
|
+ this.formData.projectId = '';
|
|
435
|
+ }
|
|
436
|
+
|
322
|
437
|
this.$refs.form.validate().then(res => {
|
323
|
438
|
this.taskForm.variables.skip = false;
|
324
|
439
|
if (!this.projectObj.projectLeader) {
|
|
@@ -332,13 +447,46 @@ export default {
|
332
|
447
|
console.log('表单错误信息:', err);
|
333
|
448
|
})
|
334
|
449
|
},
|
335
|
|
- confirmSubmit() {
|
336
|
|
- if (this.taskName == '工作填报') {
|
337
|
|
- this.declareSubmit();
|
338
|
|
- } else if (this.taskName == '项目负责人审核' || this.taskName == '部门负责人审核') {
|
339
|
|
- this.approveForm();
|
340
|
|
- } else {
|
341
|
|
- this.confirmForm();
|
|
450
|
+ async confirmSubmit() {
|
|
451
|
+ if (this.isSubmitting) return; // 防止重复提交
|
|
452
|
+
|
|
453
|
+ try {
|
|
454
|
+ this.isSubmitting = true;
|
|
455
|
+
|
|
456
|
+ // 显示保存中提示
|
|
457
|
+ uni.showLoading({
|
|
458
|
+ title: '正在保存...'
|
|
459
|
+ });
|
|
460
|
+
|
|
461
|
+ // 先保存表单,不显示保存成功提示
|
|
462
|
+ await this.save(false);
|
|
463
|
+
|
|
464
|
+ uni.hideLoading();
|
|
465
|
+
|
|
466
|
+ if (this.taskName != '填报人确认') {
|
|
467
|
+ // 显示提交中提示
|
|
468
|
+ uni.showLoading({
|
|
469
|
+ title: '正在提交...'
|
|
470
|
+ });
|
|
471
|
+ }
|
|
472
|
+
|
|
473
|
+ // 保存成功后执行相应的提交流程
|
|
474
|
+ if (this.taskName == '工作填报') {
|
|
475
|
+ await this.declareSubmit();
|
|
476
|
+ } else if (this.taskName == '项目负责人审核' || this.taskName == '部门负责人审核') {
|
|
477
|
+ await this.approveForm();
|
|
478
|
+ } else {
|
|
479
|
+ await this.confirmForm();
|
|
480
|
+ }
|
|
481
|
+ } catch (error) {
|
|
482
|
+ console.error('保存失败,无法提交:', error);
|
|
483
|
+ uni.hideLoading();
|
|
484
|
+ uni.showToast({
|
|
485
|
+ title: '保存失败,请重试',
|
|
486
|
+ icon: 'error'
|
|
487
|
+ });
|
|
488
|
+ } finally {
|
|
489
|
+ this.isSubmitting = false;
|
342
|
490
|
}
|
343
|
491
|
},
|
344
|
492
|
async declareSubmit() {
|
|
@@ -347,25 +495,21 @@ export default {
|
347
|
495
|
this.taskForm.variables.approval = approval
|
348
|
496
|
} else {
|
349
|
497
|
let resData = await getUsersDeptLeader({
|
350
|
|
- userId: this.form.userId
|
|
498
|
+ userId: this.formData.userId
|
351
|
499
|
});
|
352
|
500
|
if (resData.data) {
|
353
|
501
|
this.taskForm.variables.approval = resData.data.userId
|
354
|
502
|
this.taskForm.variables.skip = true;
|
355
|
503
|
}
|
356
|
504
|
}
|
357
|
|
- if (this.hasForm) {
|
358
|
|
- updateDeclare(this.formData);
|
359
|
|
- } else {
|
360
|
|
- this.formData.formId = this.taskForm.formId;
|
361
|
|
- addDeclare(this.formData);
|
362
|
|
- }
|
|
505
|
+ // 数据已在confirmSubmit中保存,直接进行流程提交
|
363
|
506
|
this.handleComplete(this.taskForm);
|
364
|
507
|
},
|
365
|
508
|
async approveForm() {
|
366
|
509
|
if (this.taskName == '项目负责人审核') {
|
367
|
510
|
this.formData.checkStatus = '1';
|
368
|
|
- updateDeclare(this.formData);
|
|
511
|
+ // 更新状态后需要再次保存
|
|
512
|
+ await updateDeclare(this.formData);
|
369
|
513
|
let resData = await getUsersDeptLeader({
|
370
|
514
|
userId: this.formData.userId
|
371
|
515
|
});
|
|
@@ -376,15 +520,17 @@ export default {
|
376
|
520
|
} else if (this.taskName == '部门负责人审核') {
|
377
|
521
|
this.formData.checkStatus = '1';
|
378
|
522
|
this.formData.auditStatus = '1';
|
379
|
|
- updateDeclare(this.formData);
|
|
523
|
+ // 更新状态后需要再次保存
|
|
524
|
+ await updateDeclare(this.formData);
|
380
|
525
|
this.taskForm.variables.approval = this.formData.userId;
|
381
|
526
|
this.handleComplete(this.taskForm);
|
382
|
527
|
}
|
383
|
528
|
},
|
384
|
529
|
confirmForm() {
|
385
|
|
- this.$modal.confirm('最后一个节点,提交将结束流程,是否提交?').then(() => {
|
|
530
|
+ return this.$modal.confirm('最后一个节点,提交将结束流程,是否提交?').then(async () => {
|
386
|
531
|
this.formData.confirmStatus = '1';
|
387
|
|
- updateDeclare(this.formData);
|
|
532
|
+ // 更新确认状态后需要再次保存
|
|
533
|
+ await updateDeclare(this.formData);
|
388
|
534
|
this.handleComplete(this.taskForm);
|
389
|
535
|
})
|
390
|
536
|
},
|
|
@@ -394,6 +540,7 @@ export default {
|
394
|
540
|
};
|
395
|
541
|
getNextFlowNode(params).then(() => {
|
396
|
542
|
complete(taskForm).then(response => {
|
|
543
|
+ uni.hideLoading(); // 隐藏loading
|
397
|
544
|
uni.showToast({
|
398
|
545
|
title: response.msg,
|
399
|
546
|
icon: 'success'
|
|
@@ -403,9 +550,22 @@ export default {
|
403
|
550
|
url: '/pages/message/index'
|
404
|
551
|
})
|
405
|
552
|
}, 500);
|
|
553
|
+ }).catch(error => {
|
|
554
|
+ uni.hideLoading(); // 隐藏loading
|
|
555
|
+ console.error('提交失败:', error);
|
|
556
|
+ uni.showToast({
|
|
557
|
+ title: '提交失败,请重试',
|
|
558
|
+ icon: 'error'
|
|
559
|
+ });
|
406
|
560
|
})
|
|
561
|
+ }).catch(error => {
|
|
562
|
+ uni.hideLoading(); // 隐藏loading
|
|
563
|
+ console.error('获取下一节点失败:', error);
|
|
564
|
+ uni.showToast({
|
|
565
|
+ title: '提交失败,请重试',
|
|
566
|
+ icon: 'error'
|
|
567
|
+ });
|
407
|
568
|
})
|
408
|
|
-
|
409
|
569
|
},
|
410
|
570
|
}
|
411
|
571
|
};
|
|
@@ -473,4 +633,50 @@ export default {
|
473
|
633
|
color: #999;
|
474
|
634
|
padding: 0 10px;
|
475
|
635
|
}
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+.date-display {
|
|
640
|
+ padding: 10px;
|
|
641
|
+ border: 1px solid #e5e5e5;
|
|
642
|
+ border-radius: 8px;
|
|
643
|
+ background-color: #f7f6f6;
|
|
644
|
+ min-height: 44px;
|
|
645
|
+ display: flex;
|
|
646
|
+ align-items: center;
|
|
647
|
+}
|
|
648
|
+
|
|
649
|
+.date-text {
|
|
650
|
+ font-size: 14px;
|
|
651
|
+ color: #333333;
|
|
652
|
+ line-height: 1.4;
|
|
653
|
+}
|
|
654
|
+
|
|
655
|
+.picker-selector {
|
|
656
|
+ display: flex;
|
|
657
|
+ align-items: center;
|
|
658
|
+ justify-content: space-between;
|
|
659
|
+ padding: 10px;
|
|
660
|
+ border: 1px solid #e5e5e5;
|
|
661
|
+ border-radius: 8px;
|
|
662
|
+ background-color: #fff;
|
|
663
|
+ min-height: 44px;
|
|
664
|
+ box-sizing: border-box;
|
|
665
|
+}
|
|
666
|
+
|
|
667
|
+.picker-selector.picker-disabled {
|
|
668
|
+ background-color: #f7f6f6;
|
|
669
|
+ color: #333333;
|
|
670
|
+}
|
|
671
|
+
|
|
672
|
+.picker-text {
|
|
673
|
+ flex: 1;
|
|
674
|
+ font-size: 14px;
|
|
675
|
+ color: #333;
|
|
676
|
+ line-height: 1.4;
|
|
677
|
+}
|
|
678
|
+
|
|
679
|
+.picker-text.picker-placeholder {
|
|
680
|
+ color: #c0c4cc;
|
|
681
|
+}
|
476
|
682
|
</style>
|