f0ec74d6
刘淇
大区经理派单
|
1
2
3
4
5
|
<template>
<view class="page-container">
<view class="work-order-form-content commonPageLRpadding">
<up-form
label-position="left"
|
ecbfbe06
刘淇
树巡检记录
|
6
|
:model="baseForm"
|
f0ec74d6
刘淇
大区经理派单
|
7
8
9
|
ref="workOrderFormRef"
labelWidth="200rpx"
>
|
ecbfbe06
刘淇
树巡检记录
|
10
|
<!-- 1. 工单位置(地图选择)【公共项】 -->
|
f0ec74d6
刘淇
大区经理派单
|
11
12
13
14
15
16
17
18
|
<up-form-item
label="工单位置"
prop="workLocation"
border-bottom
required
@click="chooseWorkLocation(); hideKeyboard()"
>
<up-input
|
ecbfbe06
刘淇
树巡检记录
|
19
|
v-model="baseForm.workLocation"
|
f0ec74d6
刘淇
大区经理派单
|
20
21
22
23
24
25
26
|
border="none"
readonly
suffix-icon="map-fill"
placeholder="点击选择工单位置"
></up-input>
</up-form-item>
|
ecbfbe06
刘淇
树巡检记录
|
27
|
<!-- 2. 情况描述【公共项】 -->
|
f0ec74d6
刘淇
大区经理派单
|
28
29
30
31
|
<up-form-item
label="情况描述"
prop="problemDesc"
required
|
ecbfbe06
刘淇
树巡检记录
|
32
|
border-bottom
|
f0ec74d6
刘淇
大区经理派单
|
33
34
35
|
>
<up-textarea
placeholder="请输入情况描述(最多200字)"
|
ecbfbe06
刘淇
树巡检记录
|
36
|
v-model.trim="baseForm.problemDesc"
|
f0ec74d6
刘淇
大区经理派单
|
37
38
39
40
41
42
43
|
count
maxlength="200"
rows="4"
@blur="() => workOrderFormRef.validateField('problemDesc')"
></up-textarea>
</up-form-item>
|
ecbfbe06
刘淇
树巡检记录
|
44
45
|
<!-- 3. 问题照片【公共项】 -->
<up-form-item label="问题照片" prop="problemImgs" required >
|
f0ec74d6
刘淇
大区经理派单
|
46
|
<up-upload
|
8ddc6f6e
刘淇
登录 修改样式
|
47
|
:file-list="problemImgs.imgList.value || []"
|
f0ec74d6
刘淇
大区经理派单
|
48
49
50
51
52
53
|
@after-read="problemImgs.uploadImgs"
@delete="problemImgs.deleteImg"
multiple
:width="70"
:height="70"
:max-count="problemImgs.uploadConfig.maxCount"
|
ecbfbe06
刘淇
树巡检记录
|
54
|
:upload-text="problemImgs.uploadText"
|
f0ec74d6
刘淇
大区经理派单
|
55
56
57
58
|
:size-type="problemImgs.uploadConfig.sizeType"
></up-upload>
</up-form-item>
|
ecbfbe06
刘淇
树巡检记录
|
59
60
|
<!-- 多组派单区域 -->
<view class="dispatch-list-wrap">
|
f0ec74d6
刘淇
大区经理派单
|
61
|
<view class="dispatch-title">派单情况</view>
|
ecbfbe06
刘淇
树巡检记录
|
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
|
<!-- 循环渲染每组派单 -->
<view class="dispatch-item" v-for="(item, idx) in dispatchList" :key="idx">
<view class="item-head">
<text>派单{{ idx + 1 }}</text>
<!-- 数量大于1才显示红色关闭X -->
<up-icon
v-if="dispatchList.length > 1"
name="close"
color="#f53f3f"
size="26"
class="close-icon"
@click="delDispatchItem(idx)"
></up-icon>
</view>
<!-- 业务线 -->
<up-form-item
label="业务线"
prop="busiLineCn"
border-bottom
required
@click="handleActionSheetOpen('busiLine', idx); hideKeyboard()"
>
<up-input
v-model="item.busiLineCn"
disabled
disabled-color="#ffffff"
placeholder="请选择业务线"
border="none"
></up-input>
<template #right>
<up-icon name="arrow-right" size="16"></up-icon>
</template>
</up-form-item>
<!-- 问题类型 -->
<up-form-item
label="问题类型"
prop="orderName"
border-bottom
required
@click="openCascader(idx); hideKeyboard()"
>
<up-input
v-model="item.orderName"
disabled
disabled-color="#ffffff"
placeholder="请选择问题类型"
border="none"
></up-input>
<template #right>
<up-icon name="arrow-right" size="16"></up-icon>
</template>
</up-form-item>
<!-- 道路名称 -->
<up-form-item
label="道路名称"
prop="roadName"
border-bottom
required
@click="handleActionSheetOpen('roadName', idx); hideKeyboard()"
|
f0ec74d6
刘淇
大区经理派单
|
125
|
>
|
ecbfbe06
刘淇
树巡检记录
|
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
|
<up-input
v-model="item.roadName"
readonly
disabled-color="#ffffff"
placeholder="请先选择工单位置"
border="none"
></up-input>
<template #right>
<up-icon name="arrow-right" size="16"></up-icon>
</template>
</up-form-item>
<!-- 紧急程度 -->
<up-form-item
label="紧急程度"
prop="pressingTypeName"
border-bottom
required
@click="handleActionSheetOpen('pressingType', idx); hideKeyboard()"
>
<up-input
v-model="item.pressingTypeName"
disabled
disabled-color="#ffffff"
placeholder="请选择紧急程度"
border="none"
></up-input>
<template #right>
<up-icon name="arrow-right" size="16"></up-icon>
</template>
</up-form-item>
<!-- 每组派单独立:希望完成时间 -->
<up-form-item
label="希望完成时间"
@click="openItemDatePicker(idx); hideKeyboard()"
>
<up-input
v-model="item.expectedFinishDate"
border="none"
readonly
placeholder="点击选择时间"
></up-input>
<template #right>
<view v-if="item.expectedFinishDate" @click.stop>
<up-icon name="close" size="16" @click.stop="clearItemDate(idx)"></up-icon>
</view>
<up-icon name="arrow-right" size="16" v-else></up-icon>
</template>
</up-form-item>
</view>
|
f0ec74d6
刘淇
大区经理派单
|
178
179
|
</view>
|
ecbfbe06
刘淇
树巡检记录
|
180
181
182
183
184
185
186
187
188
189
|
<!-- 新增派单按钮 -->
<view class="add-dispatch-btn-wrap" v-if="!isRenew">
<up-button
type="primary"
plain
text="新增派单"
:disabled="dispatchList.length >= 3"
@click="addDispatchItem"
></up-button>
</view>
|
f0ec74d6
刘淇
大区经理派单
|
190
191
192
193
194
|
</up-form>
</view>
<!-- 底部提交按钮 -->
<view class="fixed-bottom-btn-wrap">
|
8ddc6f6e
刘淇
登录 修改样式
|
195
|
<up-button type="primary" text="提交工单" @click="submitWorkOrder"></up-button>
|
f0ec74d6
刘淇
大区经理派单
|
196
197
|
</view>
|
ecbfbe06
刘淇
树巡检记录
|
198
|
<!-- 通用下拉弹窗:业务线 / 道路 / 紧急程度 共用 -->
|
f0ec74d6
刘淇
大区经理派单
|
199
200
201
202
203
204
205
206
|
<up-action-sheet
:show="showActionSheet"
:actions="currentActionSheetData.list"
:title="currentActionSheetData.title"
@close="handleActionSheetClose"
@select="handleActionSheetSelect"
></up-action-sheet>
|
ecbfbe06
刘淇
树巡检记录
|
207
208
209
210
211
212
213
214
215
216
217
|
<!-- 问题类型 级联选择器 -->
<up-cascader
v-model="cascaderValue"
:data="cascaderOptions"
v-model:show="showCascader"
title="问题类型"
:auto-close="false"
@confirm="cascaderConfirm"
></up-cascader>
<!-- 单独时间选择器(给每组派单用) -->
|
f0ec74d6
刘淇
大区经理派单
|
218
|
<up-datetime-picker
|
ecbfbe06
刘淇
树巡检记录
|
219
220
|
:show="showItemDatePicker"
v-model="tempDateValue"
|
f0ec74d6
刘淇
大区经理派单
|
221
|
mode="datetime"
|
ecbfbe06
刘淇
树巡检记录
|
222
223
224
|
:min-date="Date.now()"
@cancel="closeItemDatePicker"
@confirm="itemDateConfirm"
|
f0ec74d6
刘淇
大区经理派单
|
225
226
227
228
229
|
></up-datetime-picker>
</view>
</template>
<script setup>
|
8ddc6f6e
刘淇
登录 修改样式
|
230
231
|
import { ref, reactive, nextTick } from 'vue'
import { onReady, onShow, onLoad, onBackPress } from '@dcloudio/uni-app';
|
f0ec74d6
刘淇
大区经理派单
|
232
|
import { useUploadImgs } from '@/common/utils/useUploadImgs'
|
ecbfbe06
刘淇
树巡检记录
|
233
|
import { getRoadListByLatLng, getProblemListByType } from '@/api/common'
|
8ddc6f6e
刘淇
登录 修改样式
|
234
|
import {
|
ecbfbe06
刘淇
树巡检记录
|
235
|
daquUniversalApproval, qyUniversalApproval, qyWorkorderCreate,dycCreateBatchNew,
|
8ddc6f6e
刘淇
登录 修改样式
|
236
237
|
dcyUniversalApproval, daquWorkorderCreate, dcyWorkorderCreate
} from '@/api/regional-order-manage/regional-order-manage'
|
f0ec74d6
刘淇
大区经理派单
|
238
239
240
|
import { timeFormat } from '@/uni_modules/uview-plus'
import { nextStepMap } from '@/common/utils/common'
import { useUserStore } from '@/pinia/user';
|
71518877
王彪总
业务线 小程序不用写死,从后端接口获取
|
241
|
import { getDictLabel, getDictValue } from '@/common/utils/dict';
|
f0ec74d6
刘淇
大区经理派单
|
242
|
|
ecbfbe06
刘淇
树巡检记录
|
243
|
// ========== 常量配置区 ==========
|
8ddc6f6e
刘淇
登录 修改样式
|
244
|
const CONST = {
|
8ddc6f6e
刘淇
登录 修改样式
|
245
|
DICT_PRESSING_TYPE: 'workorder_pressing_type',
|
71518877
王彪总
业务线 小程序不用写死,从后端接口获取
|
246
247
|
// 业务线的中文名/编码统一取自数据字典(系统管理 → 字典管理),不再硬编码
DICT_BUSI_LINE: 'business_line',
|
8ddc6f6e
刘淇
登录 修改样式
|
248
|
UPLOAD_CONFIG: { maxCount: 3, uploadText: '选择问题照片', sizeType: ['compressed'] },
|
8ddc6f6e
刘淇
登录 修改样式
|
249
|
PAGE_ORDER_LIST: '/pages-sub/problem/regional-order-manage/index',
|
ecbfbe06
刘淇
树巡检记录
|
250
|
ROLE: { MANAGER: 'regional_manager', INSPECTOR: 'Inspector_global', PATROL: 'patrol_global' , LEADER: 'Inspector_global_leader'}
|
8ddc6f6e
刘淇
登录 修改样式
|
251
|
}
|
f0ec74d6
刘淇
大区经理派单
|
252
|
|
ecbfbe06
刘淇
树巡检记录
|
253
|
// ========== 全局实例 & 基础状态 ==========
|
8ddc6f6e
刘淇
登录 修改样式
|
254
255
256
257
|
const userStore = useUserStore();
const USER_ROLES = userStore.userInfo?.roles || [];
const workOrderFormRef = ref(null);
const showActionSheet = ref(false);
|
8ddc6f6e
刘淇
登录 修改样式
|
258
259
|
const isRenew = ref(false);
const renewOrderData = ref(null);
|
f0ec74d6
刘淇
大区经理派单
|
260
|
|
ecbfbe06
刘淇
树巡检记录
|
261
262
263
264
265
266
267
268
269
270
|
// 当前操作的派单项下标
const currentDispatchIndex = ref(0);
// 三级级联选择器
const showCascader = ref(false);
const cascaderValue = ref([]);
const cascaderOptions = ref([]);
// 下拉弹窗数据
const currentActionSheetData = reactive({ type: '', list: [], title: '', index: 0 });
|
8ddc6f6e
刘淇
登录 修改样式
|
271
|
const roadNameList = ref([]);
|
8ddc6f6e
刘淇
登录 修改样式
|
272
|
const pressingTypeList = ref([]);
|
f0ec74d6
刘淇
大区经理派单
|
273
|
const busiLineOptions = ref([]);
|
ecbfbe06
刘淇
树巡检记录
|
274
275
276
277
278
279
|
const currentBusiLineCode = ref('');
// 每组派单独立时间选择器
const showItemDatePicker = ref(false);
const tempDateValue = ref(Date.now());
const curSelectDateIndex = ref(-1);
|
f0ec74d6
刘淇
大区经理派单
|
280
|
|
ecbfbe06
刘淇
树巡检记录
|
281
|
// 图片上传
|
f0ec74d6
刘淇
大区经理派单
|
282
|
const problemImgs = useUploadImgs({
|
8ddc6f6e
刘淇
登录 修改样式
|
283
|
...CONST.UPLOAD_CONFIG,
|
f0ec74d6
刘淇
大区经理派单
|
284
285
286
|
formRef: workOrderFormRef,
fieldName: 'problemImgs'
})
|
8ddc6f6e
刘淇
登录 修改样式
|
287
|
if (!Array.isArray(problemImgs.rawImgList.value)) problemImgs.rawImgList.value = [];
|
f0ec74d6
刘淇
大区经理派单
|
288
|
|
ecbfbe06
刘淇
树巡检记录
|
289
290
291
292
293
294
|
// ========== 公共表单(所有派单共用) ==========
const baseForm = reactive({
workLocation: '',
problemDesc: '',
lat: 0,
lon: 0
|
4c54ad5d
刘淇
转工单 选择是 传紧急程度和...
|
295
|
})
|
f0ec74d6
刘淇
大区经理派单
|
296
|
|
ecbfbe06
刘淇
树巡检记录
|
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
// ========== 派单列表(多组派单核心数组) ==========
const createDispatchItem = (defaultBusiLine = null) => {
return {
busiLineCn: defaultBusiLine?.name || '',
busiLineCode: defaultBusiLine?.value || '',
roadId: 0,
roadName: '',
orderName: '',
orderCode: '',
pressingType: '',
pressingTypeName: '',
expectedFinishDate: '' // 每组独立完成时间
}
}
// 初始化默认 1 组派单
const dispatchList = ref([createDispatchItem()])
// ========== 表单校验规则 ==========
|
f0ec74d6
刘淇
大区经理派单
|
315
|
const workOrderFormRules = reactive({
|
8ddc6f6e
刘淇
登录 修改样式
|
316
|
workLocation: [{ type: 'string', required: true, message: '请选择工单位置', trigger: ['change', 'blur'] }],
|
f0ec74d6
刘淇
大区经理派单
|
317
318
319
320
321
322
323
|
problemDesc: [
{ type: 'string', required: true, message: '请输入情况描述', trigger: ['change', 'blur'] },
{ type: 'string', min: 3, max: 200, message: '情况描述需3-200字', trigger: ['change', 'blur'] }
],
problemImgs: [problemImgs.imgValidateRule]
})
|
ecbfbe06
刘淇
树巡检记录
|
324
|
// ========== 工具方法 ==========
|
71518877
王彪总
业务线 小程序不用写死,从后端接口获取
|
325
326
327
328
329
330
331
332
333
334
335
336
337
|
// 中文名 → 编码。注:字典未拉到时(登录时字典请求是容错的)选项里放的就是原始编码,
// 故对「非中文」入参原样返回;中文名解析不到仍返回空串,沿用调用方原有的异常提示
const busiLineCnToEn = (cn) => {
if (!cn) return '';
const code = getDictValue(CONST.DICT_BUSI_LINE, cn);
if (code) return code;
return /[一-龥]/.test(cn) ? '' : cn;
};
// 编码 → 中文名。字典未拉到时兜底显示原始编码,保证选项不为空、页面仍可用
const busiLineEnToCn = (en) => {
if (!en) return '';
return getDictLabel(CONST.DICT_BUSI_LINE, en) || en;
};
|
8ddc6f6e
刘淇
登录 修改样式
|
338
|
const toOrderListPage = () => uni.reLaunch({ url: CONST.PAGE_ORDER_LIST });
|
8ddc6f6e
刘淇
登录 修改样式
|
339
|
const formatDate = (dateVal, fmt = 'yyyy-mm-dd hh:MM:ss') => dateVal ? timeFormat(dateVal, fmt) : '';
|
ecbfbe06
刘淇
树巡检记录
|
340
341
|
const dateToTimestamp = (dateStr) => dateStr ? new Date(dateStr).getTime() : '';
|
8ddc6f6e
刘淇
登录 修改样式
|
342
|
/**
|
ecbfbe06
刘淇
树巡检记录
|
343
|
* 加载三级问题类型级联数据
|
8ddc6f6e
刘淇
登录 修改样式
|
344
|
*/
|
ecbfbe06
刘淇
树巡检记录
|
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
|
const loadProblemCascader = async (parentCode) => {
if (!parentCode) {
cascaderOptions.value = [];
return;
}
try {
uni.showLoading({ title: '加载类型中...' });
const res = await getProblemListByType({ parentCode });
cascaderOptions.value = res|| [];
} catch (err) {
console.error('加载问题类型失败', err);
uni.showToast({ title: '问题类型加载失败', icon: 'none' });
cascaderOptions.value = [];
} finally {
uni.hideLoading();
}
};
/** 打开级联选择器 */
const openCascader = (idx) => {
currentDispatchIndex.value = idx;
const item = dispatchList.value[idx];
if (!item.busiLineCode) {
uni.showToast({ title: '请先选择业务线', icon: 'none' });
return;
}
if (!cascaderOptions.value || cascaderOptions.value.length === 0) {
uni.showToast({ title: '正在加载问题类型,请稍等', icon: 'none' });
loadProblemCascader(item.busiLineCode);
return;
}
cascaderValue.value = [];
showCascader.value = true;
};
/** 级联选择确认回调 */
const cascaderConfirm = (selectedArr) => {
const idx = currentDispatchIndex.value;
const item = dispatchList.value[idx];
console.log('最终选中值数组:', selectedArr);
const getLabelByValueList = (list, valList) => {
const labelArr = [];
let currentList = list;
for (const val of valList) {
const target = currentList.find(item => item.value === val);
if (!target) break;
labelArr.push(target.label);
currentList = target.children || [];
}
return labelArr.join('/');
};
const fullLabel = getLabelByValueList(cascaderOptions.value, selectedArr);
item.orderName = fullLabel;
item.orderCode = selectedArr.at(-1);
cascaderValue.value = selectedArr;
workOrderFormRef.value?.validateField('orderName');
};
// ========== 每组派单 时间选择相关 ==========
const openItemDatePicker = (idx) => {
curSelectDateIndex.value = idx;
tempDateValue.value = Date.now();
showItemDatePicker.value = true;
};
const closeItemDatePicker = () => {
showItemDatePicker.value = false;
curSelectDateIndex.value = -1;
};
const itemDateConfirm = (e) => {
const idx = curSelectDateIndex.value;
if (idx > -1 && dispatchList.value[idx]) {
dispatchList.value[idx].expectedFinishDate = formatDate(e.value);
}
closeItemDatePicker();
};
const clearItemDate = (idx) => {
dispatchList.value[idx].expectedFinishDate = '';
};
// ========== 新增 / 删除 派单项 ==========
/** 新增派单 */
const addDispatchItem = () => {
if (dispatchList.value.length >= 3) return;
// 新项:业务线默认第一个,其余置空
const firstBusi = busiLineOptions.value[0] || null;
dispatchList.value.push(createDispatchItem(firstBusi));
if(firstBusi) {
currentBusiLineCode.value = firstBusi.value;
loadProblemCascader(firstBusi.value);
}
};
|
8ddc6f6e
刘淇
登录 修改样式
|
438
|
|
ecbfbe06
刘淇
树巡检记录
|
439
440
441
442
443
444
445
446
447
|
/** 删除派单项 */
const delDispatchItem = (idx) => {
if (dispatchList.value.length <= 1) return;
dispatchList.value.splice(idx, 1);
};
// 生命周期
onLoad(async (options) => {
|
8ddc6f6e
刘淇
登录 修改样式
|
448
|
initBusiLineOptions();
|
ecbfbe06
刘淇
树巡检记录
|
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
|
// 初始化第一组派单默认业务线
if (busiLineOptions.value.length) {
const firstLine = busiLineOptions.value[0];
dispatchList.value[0].busiLineCn = firstLine.name;
dispatchList.value[0].busiLineCode = firstLine.value;
currentBusiLineCode.value = firstLine.value;
// 非重新提交才默认加载级联
if (!(options.isRenew == 1 && options.tempKey)) {
loadProblemCascader(firstLine.value);
}
}
// 重新提交场景:等待回显完成
if (options.isRenew == 1 && options.tempKey) {
await handleRenewOptions(options.tempKey);
}
|
f0ec74d6
刘淇
大区经理派单
|
464
465
466
|
});
onReady(() => {
|
8ddc6f6e
刘淇
登录 修改样式
|
467
468
469
470
|
nextTick(() => {
workOrderFormRef.value?.setRules(workOrderFormRules);
});
});
|
f0ec74d6
刘淇
大区经理派单
|
471
472
|
onShow(() => {
|
8ddc6f6e
刘淇
登录 修改样式
|
473
474
|
pressingTypeList.value = uni.$dict.transformLabelValueToNameValue(uni.$dict.getDictSimpleList(CONST.DICT_PRESSING_TYPE));
});
|
f0ec74d6
刘淇
大区经理派单
|
475
|
|
ecbfbe06
刘淇
树巡检记录
|
476
477
478
479
480
481
482
|
// 物理返回拦截
onBackPress(() => {
uni.redirectTo({ url: CONST.PAGE_ORDER_LIST });
return true;
});
// ========== 业务线相关 ==========
|
8ddc6f6e
刘淇
登录 修改样式
|
483
484
|
const initBusiLineOptions = () => {
const rawBusiLines = userStore.userInfo?.user?.busiLine?.split(',') || [];
|
ecbfbe06
刘淇
树巡检记录
|
485
486
487
488
|
busiLineOptions.value = rawBusiLines.map(item => ({
name: busiLineEnToCn(item.trim()),
value: item.trim()
}));
|
8ddc6f6e
刘淇
登录 修改样式
|
489
490
|
};
|
ecbfbe06
刘淇
树巡检记录
|
491
492
493
494
495
496
497
498
499
|
/** 业务线切换联动清空数据并重新加载级联 */
const handleBusiLineChange = (code, idx) => {
const item = dispatchList.value[idx];
item.roadName = '';
item.roadId = 0;
item.orderName = '';
item.orderCode = '';
cascaderValue.value = [];
roadNameList.value = [];
|
f0ec74d6
刘淇
大区经理派单
|
500
|
|
ecbfbe06
刘淇
树巡检记录
|
501
502
|
currentBusiLineCode.value = code;
loadProblemCascader(code);
|
f0ec74d6
刘淇
大区经理派单
|
503
|
|
ecbfbe06
刘淇
树巡检记录
|
504
|
if(baseForm.workLocation) getRoadListByBusiLine();
|
f0ec74d6
刘淇
大区经理派单
|
505
506
|
};
|
ecbfbe06
刘淇
树巡检记录
|
507
|
/** 根据经纬度+业务线获取道路列表 */
|
f0ec74d6
刘淇
大区经理派单
|
508
|
const getRoadListByBusiLine = async () => {
|
ecbfbe06
刘淇
树巡检记录
|
509
510
|
if (!baseForm.lat || !baseForm.lon) return;
const busiLineEn = busiLineCnToEn(dispatchList.value[0].busiLineCn);
|
8ddc6f6e
刘淇
登录 修改样式
|
511
|
if (!busiLineEn) return uni.showToast({ title: '业务线选择异常', icon: 'none' });
|
f0ec74d6
刘淇
大区经理派单
|
512
513
514
|
try {
uni.showLoading({ title: '获取道路名称中...' });
|
ecbfbe06
刘淇
树巡检记录
|
515
516
517
518
519
|
const roadRes = await getRoadListByLatLng({
busiLine: busiLineEn,
latitude: baseForm.lat,
longitude: baseForm.lon
});
|
8ddc6f6e
刘淇
登录 修改样式
|
520
|
roadNameList.value = Array.isArray(roadRes)
|
ecbfbe06
刘淇
树巡检记录
|
521
522
|
? roadRes.map(item => ({ name: item.roadName || '', code: item.roadCode || '', id: item.roadId || 0 }))
: [{ name: '未查询到道路名称', code: '', id: 0 }];
|
8ddc6f6e
刘淇
登录 修改样式
|
523
|
!Array.isArray(roadRes) && uni.showToast({ title: '未查询到该位置的道路信息', icon: 'none' });
|
f0ec74d6
刘淇
大区经理派单
|
524
|
} catch (err) {
|
f0ec74d6
刘淇
大区经理派单
|
525
|
console.error('获取道路名称失败:', err);
|
f0ec74d6
刘淇
大区经理派单
|
526
|
roadNameList.value = [{ name: '获取失败,请重新选择位置', code: '', id: 0 }];
|
8ddc6f6e
刘淇
登录 修改样式
|
527
528
529
|
uni.showToast({ title: '获取道路名称失败,请重试', icon: 'none' });
} finally {
uni.hideLoading();
|
f0ec74d6
刘淇
大区经理派单
|
530
531
532
|
}
};
|
ecbfbe06
刘淇
树巡检记录
|
533
534
535
536
|
// ========== 通用下拉弹窗方法(支持下标) ==========
const handleActionSheetOpen = (type, idx) => {
currentDispatchIndex.value = idx;
if (type === 'roadName' && !baseForm.workLocation) {
|
8ddc6f6e
刘淇
登录 修改样式
|
537
|
return uni.showToast({ title: '请先选择工单位置', icon: 'none' });
|
f0ec74d6
刘淇
大区经理派单
|
538
|
}
|
f0ec74d6
刘淇
大区经理派单
|
539
|
const configMap = {
|
ecbfbe06
刘淇
树巡检记录
|
540
|
busiLine: { title: '请选择业务线', list: busiLineOptions.value },
|
8ddc6f6e
刘淇
登录 修改样式
|
541
|
roadName: { title: '请选择道路名称', list: roadNameList.value },
|
8ddc6f6e
刘淇
登录 修改样式
|
542
543
|
pressingType: { title: '请选择紧急程度', list: pressingTypeList.value }
};
|
ecbfbe06
刘淇
树巡检记录
|
544
|
Object.assign(currentActionSheetData, configMap[type], { type, index: idx });
|
8ddc6f6e
刘淇
登录 修改样式
|
545
546
|
showActionSheet.value = true;
};
|
f0ec74d6
刘淇
大区经理派单
|
547
548
|
const handleActionSheetClose = () => {
|
8ddc6f6e
刘淇
登录 修改样式
|
549
|
showActionSheet.value = false;
|
ecbfbe06
刘淇
树巡检记录
|
550
|
Object.assign(currentActionSheetData, { type: '', list: [], title: '', index: 0 });
|
8ddc6f6e
刘淇
登录 修改样式
|
551
|
};
|
f0ec74d6
刘淇
大区经理派单
|
552
553
|
const handleActionSheetSelect = (e) => {
|
ecbfbe06
刘淇
树巡检记录
|
554
555
|
const { type, index } = currentActionSheetData;
const item = dispatchList.value[index];
|
f0ec74d6
刘淇
大区经理派单
|
556
|
switch (type) {
|
ecbfbe06
刘淇
树巡检记录
|
557
558
559
560
|
case 'busiLine':
item.busiLineCn = e.name;
item.busiLineCode = e.value;
handleBusiLineChange(e.value, index);
|
8ddc6f6e
刘淇
登录 修改样式
|
561
|
break;
|
ecbfbe06
刘淇
树巡检记录
|
562
563
564
565
566
|
case 'roadName':
item.roadName = e.name;
item.roadId = e.code;
console.log('选中道路对象e:', e)
console.log('赋值后 roadId:', item.roadName, '类型:', typeof item.roadId)
|
8ddc6f6e
刘淇
登录 修改样式
|
567
|
break;
|
f0ec74d6
刘淇
大区经理派单
|
568
|
case 'pressingType':
|
ecbfbe06
刘淇
树巡检记录
|
569
570
|
item.pressingType = e.value;
item.pressingTypeName = e.name;
|
8ddc6f6e
刘淇
登录 修改样式
|
571
|
break;
|
f0ec74d6
刘淇
大区经理派单
|
572
|
}
|
8ddc6f6e
刘淇
登录 修改样式
|
573
574
|
handleActionSheetClose();
};
|
f0ec74d6
刘淇
大区经理派单
|
575
|
|
ecbfbe06
刘淇
树巡检记录
|
576
|
// ========== 页面交互方法 ==========
|
8ddc6f6e
刘淇
登录 修改样式
|
577
|
const hideKeyboard = () => uni.hideKeyboard();
|
f0ec74d6
刘淇
大区经理派单
|
578
|
|
ecbfbe06
刘淇
树巡检记录
|
579
|
/** 选择地图位置 */
|
f0ec74d6
刘淇
大区经理派单
|
580
581
582
|
const chooseWorkLocation = () => {
uni.chooseLocation({
success: async (res) => {
|
ecbfbe06
刘淇
树巡检记录
|
583
584
585
586
587
588
589
590
591
|
baseForm.workLocation = res.name;
baseForm.lat = res.latitude;
baseForm.lon = res.longitude;
// 清空所有组道路
dispatchList.value.forEach(item => {
item.roadName = '';
item.roadId = 0;
})
workOrderFormRef.value?.validateField(['workLocation']);
|
f0ec74d6
刘淇
大区经理派单
|
592
593
594
|
await getRoadListByBusiLine();
},
fail: (err) => {
|
8ddc6f6e
刘淇
登录 修改样式
|
595
596
597
|
console.error('选择位置失败:', err);
const errMsg = err.errMsg.includes('auth deny') ? '请开启位置权限后重试' : '选择位置失败,请重试';
uni.showToast({ title: errMsg, icon: 'none' });
|
f0ec74d6
刘淇
大区经理派单
|
598
599
|
}
})
|
8ddc6f6e
刘淇
登录 修改样式
|
600
|
};
|
f0ec74d6
刘淇
大区经理派单
|
601
|
|
ecbfbe06
刘淇
树巡检记录
|
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
/** 重新提交数据回显 */
const handleRenewOptions = async (tempKey) => {
isRenew.value = true;
try {
const orderData = uni.getStorageSync(tempKey);
if (orderData && typeof orderData === 'object') {
renewOrderData.value = orderData;
await echoOrderData(orderData); // 等待回显执行完毕
} else {
uni.showToast({ title: '工单数据不存在,无法重新提交', icon: 'none' });
setTimeout(toOrderListPage, 1000);
}
} catch (error) {
console.error('读取工单数据失败:', error);
uni.showToast({ title: '数据读取异常,无法重新提交', icon: 'none' });
setTimeout(toOrderListPage, 1000);
} finally {
uni.removeStorageSync(tempKey);
}
};
/** 工单数据回显 */
const echoOrderData = async (orderItem) => {
const busiCode = orderItem.busiLine || '';
// 回显公共字段
baseForm.workLocation = orderItem.lonLatAddress || orderItem.roadName || '';
baseForm.problemDesc = orderItem.remark || '';
baseForm.lat = orderItem.lat || 0;
baseForm.lon = orderItem.lon || 0;
console.log(orderItem)
console.log(orderItem.orderCode)
// 回显第一组派单
if(dispatchList.value[0]){
const firstItem = dispatchList.value[0]
firstItem.busiLineCn = busiLineEnToCn(busiCode);
firstItem.busiLineCode = busiCode;
firstItem.roadId = orderItem.roadId || 0;
firstItem.roadName = orderItem.roadName || '';
firstItem.orderName = orderItem.orderName || '';
firstItem.orderCode = orderItem.orderCode || ''; // 回显编码
firstItem.pressingType = orderItem.pressingType || '';
firstItem.pressingTypeName = uni.$dict.getDictLabel(CONST.DICT_PRESSING_TYPE, orderItem.pressingType) || '';
firstItem.expectedFinishDate = orderItem.expectedFinishDate ? formatDate(orderItem.expectedFinishDate) : '';
}
// 图片回显
if (Array.isArray(orderItem.problemsImgs) && orderItem.problemsImgs.length) {
const imgList = orderItem.problemsImgs.map((url, idx) => ({ url, name: `renew_img_${idx}`, status: 'success' }));
problemImgs.imgList.value = imgList;
problemImgs.rawImgList.value = imgList;
}
// ========== 关键修复:业务线加载完级联数据后,回填 cascaderValue ==========
if (busiCode) {
// 先加载级联选项
await loadProblemCascader(busiCode);
// 根据回显的 orderCode 反向匹配级联路径,赋值给 cascaderValue
const targetCode = orderItem.orderCode
if (targetCode && cascaderOptions.value.length) {
// 递归查找级联选中路径
const findCascaderPath = (list, targetVal, path = []) => {
for (const node of list) {
const newPath = [...path, node.value]
if (node.value === targetVal) {
return newPath
}
if (node.children && node.children.length) {
const res = findCascaderPath(node.children, targetVal, newPath)
if (res) return res
}
}
return null
}
const selectPath = findCascaderPath(cascaderOptions.value, targetCode)
if (selectPath) {
cascaderValue.value = selectPath
}
}
}
if (orderItem.lat && orderItem.lon) getRoadListByBusiLine();
};
// ========== 接口分发(按角色) ==========
|
8ddc6f6e
刘淇
登录 修改样式
|
689
690
691
692
|
const callApiByRole = async (params, isRenewFlag) => {
if (isRenewFlag) {
if (USER_ROLES.includes(CONST.ROLE.MANAGER)) return await daquUniversalApproval(params);
if (USER_ROLES.includes(CONST.ROLE.INSPECTOR)) return await dcyUniversalApproval(params);
|
ecbfbe06
刘淇
树巡检记录
|
693
|
if (USER_ROLES.includes(CONST.ROLE.LEADER)) return await dcyUniversalApproval(params);
|
8ddc6f6e
刘淇
登录 修改样式
|
694
695
|
if (USER_ROLES.includes(CONST.ROLE.PATROL)) return await qyUniversalApproval(params);
} else {
|
ecbfbe06
刘淇
树巡检记录
|
696
697
|
console.log('dasda')
console.log(CONST.ROLE.INSPECTOR)
|
8ddc6f6e
刘淇
登录 修改样式
|
698
|
if (USER_ROLES.includes(CONST.ROLE.MANAGER)) return await daquWorkorderCreate(params);
|
ecbfbe06
刘淇
树巡检记录
|
699
700
701
|
// if (USER_ROLES.includes(CONST.ROLE.INSPECTOR)) return await dcyWorkorderCreate(params);
if (USER_ROLES.includes(CONST.ROLE.INSPECTOR)) return await dycCreateBatchNew(params);
if (USER_ROLES.includes(CONST.ROLE.LEADER)) return await dycCreateBatchNew(params);
|
8ddc6f6e
刘淇
登录 修改样式
|
702
|
if (USER_ROLES.includes(CONST.ROLE.PATROL)) return await qyWorkorderCreate(params);
|
ecbfbe06
刘淇
树巡检记录
|
703
704
|
|
8ddc6f6e
刘淇
登录 修改样式
|
705
706
|
}
};
|
f0ec74d6
刘淇
大区经理派单
|
707
|
|
ecbfbe06
刘淇
树巡检记录
|
708
|
// ========== 提交工单(纯数组提交,无 dispatchList,校验 roadId 非0) ==========
|
f0ec74d6
刘淇
大区经理派单
|
709
710
|
const submitWorkOrder = async () => {
try {
|
ecbfbe06
刘淇
树巡检记录
|
711
|
// 校验公共表单
|
8ddc6f6e
刘淇
登录 修改样式
|
712
|
await workOrderFormRef.value.validate();
|
ecbfbe06
刘淇
树巡检记录
|
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
|
// 校验:同一业务线 + 同一问题类型 不允许重复
const list = dispatchList.value;
const keySet = new Set();
let hasRepeat = false;
for (const item of list) {
const busi = (item.busiLineCn || '').trim();
const type = (item.orderName || '').trim();
// 拼接唯一标识
const uniqueKey = `${busi}_${type}`;
if (keySet.has(uniqueKey)) {
hasRepeat = true;
break;
}
keySet.add(uniqueKey);
}
if (hasRepeat) {
uni.showToast({
title: '存在同业务同问题类型,请修改后再提交',
icon: 'none'
});
return;
}
// ==============================================
// 组装纯数组,不再包裹 dispatchList
const submitArr = dispatchList.value.map(item => {
return {
roadId: item.roadId,
roadName: item.roadName,
orderName: item.orderName,
orderCode: item.orderCode,
pressingType: item.pressingType,
busiLine: busiLineCnToEn(item.busiLineCn),
busiType: busiLineCnToEn(item.busiLineCn),
expectedFinishDate: dateToTimestamp(item.expectedFinishDate),
problemsImgs: problemImgs.getSuccessImgUrls(),
remark: baseForm.problemDesc.trim(),
latLonType: 2,
lat: baseForm.lat,
lon: baseForm.lon,
lonLatAddress: baseForm.workLocation,
sourceId: 1,
sourceName: item.busiLineCn
}
});
// 逐项校验:保证 roadId 不为 0,以及其他必填项
for (let i = 0; i < submitArr.length; i++) {
const row = submitArr[i];
const num = i + 1;
if (!row.roadId || row.roadId === 0) {
uni.showToast({ title: `第${num}条派单请选择道路名称`, icon: 'none' });
return;
}
if (!row.busiLine) {
uni.showToast({ title: `第${num}条派单请选择业务线`, icon: 'none' });
return;
}
if (!row.orderCode) {
uni.showToast({ title: `第${num}条派单请选择问题类型`, icon: 'none' });
return;
}
if (!row.pressingType) {
uni.showToast({ title: `第${num}条派单请选择紧急程度`, icon: 'none' });
return;
}
}
|
8ddc6f6e
刘淇
登录 修改样式
|
783
784
|
uni.showLoading({ title: '提交中...', mask: true });
|
8ddc6f6e
刘淇
登录 修改样式
|
785
|
|
ecbfbe06
刘淇
树巡检记录
|
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
|
let submitParams;
if (isRenew.value) {
// 重新提交:外层对象 + list 承载数组
submitParams = {
workerDataId: renewOrderData.value.id,
taskKey: renewOrderData.value.taskKey,
taskId: renewOrderData.value.taskId,
operateType: nextStepMap[renewOrderData.value.taskKey]?.operateTypeRenew || '',
agree: 0,
reason: baseForm.problemDesc.trim(),
...submitArr[0]
};
} else {
// 新建工单:根节点直接为纯数组
submitParams = submitArr;
}
console.log(submitParams)
|
8ddc6f6e
刘淇
登录 修改样式
|
805
806
|
await callApiByRole(submitParams, isRenew.value);
|
ecbfbe06
刘淇
树巡检记录
|
807
808
809
810
811
|
uni.showToast({
title: isRenew.value ? '重新提交成功' : '工单提交成功',
icon: 'success',
duration: 1000
});
|
8ddc6f6e
刘淇
登录 修改样式
|
812
|
setTimeout(toOrderListPage, 1000);
|
f0ec74d6
刘淇
大区经理派单
|
813
|
} catch (error) {
|
8ddc6f6e
刘淇
登录 修改样式
|
814
|
uni.hideLoading();
|
f0ec74d6
刘淇
大区经理派单
|
815
|
if (!Array.isArray(error)) {
|
8ddc6f6e
刘淇
登录 修改样式
|
816
|
console.error(isRenew.value ? '工单重新提交失败:' : '工单提交失败:', error);
|
ecbfbe06
刘淇
树巡检记录
|
817
818
819
820
821
|
uni.showToast({
title: error.msg || '提交失败,请重试',
icon: 'none',
duration: 2000
});
|
f0ec74d6
刘淇
大区经理派单
|
822
823
824
|
}
}
}
|
4c54ad5d
刘淇
转工单 选择是 传紧急程度和...
|
825
826
|
</script>
|
f0ec74d6
刘淇
大区经理派单
|
827
|
<style lang="scss" scoped>
|
f0ec74d6
刘淇
大区经理派单
|
828
829
|
.page-container {
min-height: 100vh;
|
ecbfbe06
刘淇
树巡检记录
|
830
|
padding-bottom: 100rpx;
|
8ddc6f6e
刘淇
登录 修改样式
|
831
|
background: #fafafa;
|
f0ec74d6
刘淇
大区经理派单
|
832
|
}
|
4c54ad5d
刘淇
转工单 选择是 传紧急程度和...
|
833
|
|
f0ec74d6
刘淇
大区经理派单
|
834
835
836
837
|
.work-order-form-content {
background: #fff;
}
|
ecbfbe06
刘淇
树巡检记录
|
838
|
.dispatch-list-wrap {
|
8ddc6f6e
刘淇
登录 修改样式
|
839
840
841
|
padding-top: 24rpx;
margin-top: 8rpx;
border-top: 1px solid #f5f5f5;
|
ecbfbe06
刘淇
树巡检记录
|
842
|
}
|
8ddc6f6e
刘淇
登录 修改样式
|
843
|
|
ecbfbe06
刘淇
树巡检记录
|
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
|
.dispatch-title {
font-size: 32rpx;
font-weight: 600;
color: $u-primary;
margin-bottom: 20rpx;
padding-left: 10rpx;
}
.dispatch-item {
position: relative;
border: 1px solid #eee;
border-radius: 12rpx;
padding: 20rpx;
margin-bottom: 20rpx;
background: #fdfdfd;
.item-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16rpx;
font-size: 28rpx;
font-weight: 500;
}
.close-icon {
position: absolute;
top: 20rpx;
right: 20rpx;
|
8ddc6f6e
刘淇
登录 修改样式
|
873
|
}
|
f0ec74d6
刘淇
大区经理派单
|
874
|
}
|
ecbfbe06
刘淇
树巡检记录
|
875
876
877
878
|
.add-dispatch-btn-wrap {
margin: 20rpx 0;
}
|
4c54ad5d
刘淇
转工单 选择是 传紧急程度和...
|
879
|
</style>
|