5822009a
刘淇
工单管理--新增工单
|
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
|
<script lang="ts">
import {getRoadListByLatLng} from '@/api/common'
import {uploadImages} from '@/common/utils/upload';
import {createQuick} from '@/api/quick-order/quick-order'
import { timeFormat } from '@/uni_modules/uview-plus' // 引入时间格式化工具
export default {
data() {
return {
// 问题照片列表
problemImgsList: [],
// 弹窗显隐控制
showRoadName: false,
showOrderName: false,
showPressingType: false,
show: false,
showBirthday: false, // 生日弹窗控制
// 下拉列表数据
roadNameList: [],
orderNameList: [],
pressingTypeList: [],
finishTime:Date.now(),
// 工单表单数据
workOrderForm: {
roadId: 0, // 道路ID
roadName: '', // 道路名称
workLocation: '', // 工单位置
orderName: '', // 工单名称
pressingType: 0, // 紧急程度值(提交接口用)
pressingTypeName: '', // 紧急程度名称(显示用)
problemDesc: '', // 情况描述
lat: 0, // 纬度
lon: 0, // 经度
finishTime: '', // 完成时间
},
// 表单校验规则
workOrderFormRules: {
workLocation: [
{type: 'string', required: true, message: '请选择工单位置', trigger: ['change', 'blur']}
],
roadName: [
{type: 'string', required: true, message: '请选择道路名称', trigger: ['change', 'blur']}
],
orderName: [
{type: 'string', required: true, message: '请选择工单名称', trigger: ['change', 'blur']}
],
pressingType: [
{type: 'number', required: true, message: '请选择紧急程度', trigger: ['change']}
],
birthday: [ // 新增:生日校验规则
{type: 'string', required: true, message: '请选择生日', trigger: ['change']}
],
problemDesc: [
{type: 'string', required: true, message: '请输入情况描述', trigger: ['change', 'blur']},
{type: 'string', min: 3, max: 200, message: '情况描述需3-200字', trigger: ['change', 'blur']}
],
problemImgs: [
{
required: true,
message: '请上传问题照片',
trigger: 'change',
validator: (rule, value, callback) => {
const hasSuccessImg = this.problemImgsList.some(item => item.status === 'success')
hasSuccessImg ? callback() : callback(new Error('请上传至少1张问题照片'))
}
}
]
}
|
5822009a
刘淇
工单管理--新增工单
|
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
|
},
onReady() {
// 兼容微信小程序,通过setRules设置校验规则
this.$refs.workOrderFormRef.setRules(this.workOrderFormRules)
console.log('工单表单规则初始化完成')
},
onShow(){
console.log(uni.$dict.getDictLabel('ai_image_status', 20))
console.log(uni.$dict.getDictSimpleList('work_name'))
// 初始化工单名称列表
this.orderNameList = uni.$dict.transformLabelValueToNameValue(uni.$dict.getDictSimpleList('work_name'))
console.log('工单名称列表:', this.orderNameList)
// 初始化紧急程度列表
this.pressingTypeList = uni.$dict.transformLabelValueToNameValue(uni.$dict.getDictSimpleList('workorder_pressing_type'))
console.log('紧急程度列表:', this.pressingTypeList)
},
methods: {
/**
* 返回上一页
*/
navigateBack() {
uni.navigateBack()
},
/**
* 删除图片
*/
deleteImg(event, type) {
console.log('删除图片事件:', event, '类型:', type)
if (type === 'problemImgsList') {
this.problemImgsList.splice(event.index, 1)
this.$refs.workOrderFormRef.validateField('problemImgs')
}
uni.showToast({title: '图片删除成功', icon: 'success'})
},
/**
* 上传图片
*/
async uploadImgs(event, type) {
console.log('上传图片事件:', event, '类型:', type)
if (type !== 'problemImgsList') return
const fileList = Array.isArray(event.file) ? event.file : [event.file]
const targetImgList = this.problemImgsList
const filePaths = fileList.map(item => item.url)
const tempItems = fileList.map(item => ({
...item,
status: 'uploading',
message: '上传中'
}))
const startIndex = targetImgList.length
targetImgList.push(...tempItems)
try {
const uploadResultUrls = await uploadImages({
filePaths: filePaths,
ignoreError: true
})
console.log('上传成功的URL列表:', uploadResultUrls)
uploadResultUrls.forEach((url, index) => {
if (targetImgList[startIndex + index]) {
targetImgList.splice(startIndex + index, 1, {
...fileList[index],
status: 'success',
message: '',
url: url
})
}
})
if (uploadResultUrls.length < fileList.length) {
const failCount = fileList.length - uploadResultUrls.length
for (let i = uploadResultUrls.length; i < fileList.length; i++) {
if (targetImgList[startIndex + i]) {
targetImgList.splice(startIndex + i, 1, {
...fileList[i],
status: 'failed',
message: '上传失败'
})
}
}
uni.showToast({title: `成功上传${uploadResultUrls.length}张,失败${failCount}张`, icon: 'none'})
} else {
uni.showToast({title: `成功上传${fileList.length}张图片`, icon: 'success'})
}
this.$refs.workOrderFormRef.validateField('problemImgs')
} catch (err) {
console.error('图片上传失败:', err)
for (let i = 0; i < fileList.length; i++) {
if (targetImgList[startIndex + i]) {
targetImgList.splice(startIndex + i, 1, {
...fileList[i],
status: 'failed',
message: '上传失败'
})
}
}
uni.showToast({title: '图片上传失败,请重试', icon: 'none'})
this.$refs.workOrderFormRef.validateField('problemImgs')
}
},
/**
* 选择工单位置
*/
chooseWorkLocation() {
let that = this
uni.chooseLocation({
success: async (res) => {
that.workOrderForm.roadName = ''
that.workOrderForm.roadId = 0
that.roadNameList = []
that.workOrderForm.workLocation = res.name
that.workOrderForm.lat = res.latitude
that.workOrderForm.lon = res.longitude
that.$refs.workOrderFormRef.validateField('workLocation')
that.$refs.workOrderFormRef.validateField('roadName')
try {
uni.showLoading({title: '获取道路名称中...'})
const roadRes = await getRoadListByLatLng({
companyCode: 'sls',
latitude: res.latitude,
longitude: res.longitude
})
uni.hideLoading()
if (Array.isArray(roadRes)) {
that.roadNameList = roadRes.map((item) => ({
name: item.roadName || '',
code: item.roadCode || '',
id: item.roadId || 0
}))
} else {
that.roadNameList = [{name: '未查询到道路名称', code: '', id: 0}]
uni.showToast({title: '未查询到该位置的道路信息', icon: 'none'})
}
} catch (err) {
uni.hideLoading()
console.error('获取道路名称失败:', err)
uni.showToast({title: '获取道路名称失败,请重试', icon: 'none'})
that.roadNameList = [{name: '获取失败,请重新选择位置', code: '', id: 0}]
}
},
fail: (err) => {
console.error('选择位置失败:', err)
uni.showToast({title: '选择位置失败:' + err.errMsg, icon: 'none'})
}
})
},
/**
* 选择道路名称
*/
handleRoadNameSelect(e) {
console.log('选择道路名称:', e)
this.workOrderForm.roadName = e.name
this.workOrderForm.roadId = e.code
this.showRoadName = false
this.$refs.workOrderFormRef.validateField('roadName')
},
/**
* 选择工单名称
*/
handleOrderNameSelect(e) {
console.log('选择工单名称:', e)
this.workOrderForm.orderName = e.name
this.showOrderName = false
this.$refs.workOrderFormRef.validateField('orderName')
},
/**
* 选择紧急程度
*/
handlePressingTypeSelect(e) {
console.log('选择紧急程度:', e)
this.workOrderForm.pressingType = Number(e.value)
this.workOrderForm.pressingTypeName = e.name
this.showPressingType = false
this.$refs.workOrderFormRef.validateField('pressingType')
},
/**
* 完成时间确认
*/
finishTimeConfirm(e) {
console.log('选择的完成时间:', e)
this.workOrderForm.finishTime = timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss')
this.show = false;
},
/**
* 隐藏键盘
*/
hideKeyboard() {
uni.hideKeyboard()
},
/**
* 提取图片URL数组
*/
getImgUrlList(imgList) {
return imgList.filter(item => item.status === 'success').map(item => item.url)
},
/**
* 提交工单
*/
async submitWorkOrder() {
try {
// 先执行表单校验
await this.$refs.workOrderFormRef.validate()
const submitData = {
roadId: this.workOrderForm.roadId,
roadName: this.workOrderForm.roadName,
imgs: this.getImgUrlList(this.problemImgsList),
remark: this.workOrderForm.problemDesc,
latLonType: 2,
lat: this.workOrderForm.lat,
lon: this.workOrderForm.lon,
lonLatAddress: this.workOrderForm.workLocation,
pressingType: this.workOrderForm.pressingType,
orderName: this.workOrderForm.orderName,
birthday: this.workOrderForm.birthday, // 新增:生日字段提交
finishTime: this.workOrderForm.finishTime, // 新增:完成时间提交
sourceId: 1,
sourceName: '园林',
thirdWorkNo: '',
busiLine:'yl'
}
// 显示加载中
uni.showLoading({title: '提交中...'})
// 调用提交接口
const res = await createQuick(submitData)
uni.hideLoading()
uni.showToast({
title: '工单提交成功',
icon: 'success',
duration: 1000
})
// 延迟跳转
setTimeout(() => {
uni.redirectTo({
url: '/pages-sub/daily/quick-order/index'
})
}, 1000)
} catch (error) {
// 隐藏加载框
uni.hideLoading()
// 区分是表单校验失败还是接口调用失败
if (Array.isArray(error)) {
// 表单校验失败(无需额外提示,uView会自动提示)
} else {
// 接口调用失败
console.error('工单提交失败:', error)
uni.showToast({
title: '提交失败,请重试',
icon: 'none',
duration: 2000
})
}
}
|