liujie
3 天以前 cd3c4cf63ec9d415fefa7f146352c810606d869c
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
/**
 * 初始化代检车订单管理详情对话框
 */
var TOrderCheckInfoDlg = {
    tOrderCheckInfoData : {}
};
 
/**
 * 清除数据
 */
TOrderCheckInfoDlg.clearData = function() {
    this.tOrderCheckInfoData = {};
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TOrderCheckInfoDlg.set = function(key, val) {
    this.tOrderCheckInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TOrderCheckInfoDlg.get = function(key) {
    return $("#" + key).val();
}
 
/**
 * 关闭此对话框
 */
TOrderCheckInfoDlg.close = function() {
    parent.layer.close(window.parent.TOrderCheck.layerIndex);
}
 
/**
 * 收集数据
 */
TOrderCheckInfoDlg.collectData = function() {
    this
    .set('id')
    .set('code')
    .set('checkCode')
    .set('userId')
    .set('driverId')
    .set('branchOfficeId')
    .set('orderTakingTime')
    .set('arrivalTimeAtTheAppointmentPoint')
    .set('startTime')
    .set('endTime')
    .set('goTime')
    .set('successTime')
    .set('startAddress')
    .set('startLat')
    .set('startLng')
    .set('endAddress')
    .set('endLat')
    .set('endLng')
    .set('orderMoney')
    .set('payMoney')
    .set('checkMoney')
    .set('discountedPriceCheck')
    .set('discountedPrice')
    .set('couponIdCheck')
    .set('couponId')
    .set('payType')
    .set('payTime')
    .set('checkPayTime')
    .set('orderNo')
    .set('checkOrderNo')
    .set('state')
    .set('status')
    .set('createTime')
    .set('checkStatus')
    .set('checkIntro')
    .set('checkImg')
    .set('commentRate')
    .set('commentStr')
    .set('commentTime')
    .set('reservationTime')
    .set('provinceCode')
    .set('cityCode')
    .set('arerCode')
    .set('reInspection')
    .set('source');
}
/**
 * 验证数据是否为空
 */
TOrderCheckInfoDlg.validate = function () {
    var startAddress = this.tOrderCheckInfoData.startAddress;
    if (startAddress == null || startAddress.trim() === "") {
        Feng.error("请输入取车位置!");
        return false;
    }
 
    var endAddress = this.tOrderCheckInfoData.endAddress;
    if (endAddress == null || endAddress.trim() === "") {
        Feng.error("请输入还车地址!");
        return false;
    }
 
    var reservationTime = this.tOrderCheckInfoData.reservationTime;
    if (reservationTime == null || reservationTime.trim() === "") {
        Feng.error("请选择预约时间!");
        return false;
    }
 
    return true;
};
/**
 * 提交添加
 */
TOrderCheckInfoDlg.addSubmit = function() {
 
    this.clearData();
    this.collectData();
    // 验证表单数据
    if (!this.validate()) {
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tOrderCheck/add", function(data){
        if (data.code == 200) {
            Feng.success("新建订单成功!");
            window.parent.TOrderCheck.table.refresh();
            TOrderCheckInfoDlg.close();
        } else {
            Feng.error("新建订单失败!" + data.message + "!");
        }
 
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.tOrderCheckInfoData);
    ajax.start();
}
 
/**
 * 提交修改
 */
TOrderCheckInfoDlg.editSubmit = function() {
 
    this.clearData();
    this.collectData();
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tOrderCheck/update", function(data){
        Feng.success("修改成功!");
        window.parent.TOrderCheck.table.refresh();
        TOrderCheckInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.tOrderCheckInfoData);
    ajax.start();
}
 
$(function() {
 
});
 
/**
 * 订单详情页面管理
 */
var OrderDetail = {
    id: "OrderDetail",
    layerIndex: -1,
    dispatchLayerIndex: null // 新增:用于存储派单弹窗的索引
};
 
/**
 * 初始化时间线(如果在详情页面)
 */
OrderDetail.initTimeline = function() {
    if (!window.orderData || window.orderData === '' || $('#orderTimeline').length === 0) {
        console.error('订单数据未找到或时间线容器不存在');
        return;
    }
 
    try {
        var orderDataObj = JSON.parse(window.orderData);
        var timelineHtml = OrderDetail.generateTimeline(orderDataObj.state, orderDataObj);
        $('#orderTimeline').html(timelineHtml);
    } catch (e) {
        console.error('解析订单JSON数据失败:', e);
    }
};
 
/**
 * 生成时间线HTML
 */
OrderDetail.generateTimeline = function(currentState, orderData) {
    // 订单状态为已取消时,不展示时间线
    if (currentState === 111) {
        return '<div style="text-align: center; color: #f56c6c; font-size: 16px; padding: 20px;">订单已取消</div>';
    }
    
    var timelineSteps = [
        {code: 100, title: '等待平台派单', desc: '订单已创建,等待系统派单'},
        {code: 101, title: '等待司机接单', desc: '已派单给司机,等待司机确认'},
        {code: 102, title: '司机已接单', desc: '司机已接单,正在前往取车地点'},
        {code: 104, title: '司机到达取车地', desc: '司机已到达,等待开始车检服务'},
        {code: 105, title: '司机开始车检服务', desc: '车检服务进行中,预计等待3-5小时'},
        {code: 106, title: '车检完成', desc: '车辆检测已完成'},
        {code: 107, title: '司机前往还车地', desc: '司机正在前往还车地点'},
        {code: 108, title: '用户支付服务费', desc: '服务完成,等待用户支付服务费'},
        {code: 109, title: '服务完成', desc: '用户已支付,服务完成'},
        {code: 110, title: '用户评价', desc: '用户对本次服务进行评价'}
    ];
    
    var html = '';
    
    for (var i = 0; i < timelineSteps.length; i++) {
        var step = timelineSteps[i];
        var stepClass = OrderDetail.getStepClass(step.code, currentState);
        var stepDetail = OrderDetail.getStepDetail(step.code, orderData);
        
        var title = step.title;
        // 当订单已非待派单状态,将第一个节点标题改为“平台已派单”
        if (step.code === 100 && currentState !== 100) {
            title = '平台已派单';
        }
        if (step.code === 101 && currentState !== 101) {
            continue;
        }
        html += '<div class="timeline-step ' + stepClass + '">';
        html += '    <div class="timeline-node"></div>';
        html += '    <div class="timeline-content">';
        html += '        <div class="timeline-title">' + title + '</div>';
        // html += '        <div class="timeline-detail">' + step.desc + '</div>';
        
        // 添加详细信息
        if (stepDetail) {
            html += stepDetail;
        }
        
        html += '    </div>';
        html += '</div>';
    }
    
    return html;
};
 
/**
 * 获取步骤样式类
 */
OrderDetail.getStepClass = function(stepCode, currentState) {
    // 特殊处理待派单状态,确保第一个节点激活
    if (currentState === 100 && stepCode === 100) {
        return 'active';
    }
    
    if (currentState > stepCode) {
        return 'completed';
    } else if (currentState === stepCode) {
        return 'active';
    } else {
        return 'disabled';
    }
};
 
/**
 * 获取步骤详细信息
 */
OrderDetail.getStepDetail = function (stepCode, orderData) {
    var html = '';
 
    switch (stepCode) {
        case 100: // 等待平台派单
            if (orderData.state >= 101) {
                if (orderData.dispatchTimeFormat) {
                    html += '<div class="timeline-detail"><strong>派单时间:</strong>' + orderData.dispatchTimeFormat + '</div>';
                }
                if (orderData.driverName) {
                    html += '<div class="timeline-detail"><strong>司机:</strong>' + orderData.driverName + ' ' + orderData.driverPhone + '</div>';
                }
                if (orderData.operatorName) {
                    html += '<div class="timeline-detail"><strong>操作人:</strong>' + orderData.operatorName + '</div>';
                }
            }
            break;
 
        case 101: // 等待司机接单
            // 详情已移至 case 100
            break;
 
        case 102: // 司机已接单
            if (orderData.state >= 102) {
                if (orderData.orderTakingTimeFormat) {
                    html += '<div class="timeline-detail"><strong>接单时间:</strong>' + orderData.orderTakingTimeFormat + '</div>';
                }
                if (orderData.driverName) {
                    html += '<div class="timeline-detail"><strong>司机:</strong>' + orderData.driverName + ' ' + orderData.driverPhone + '</div>';
                }
            }
            break;
 
        case 104: // 司机到达取车地
            if (orderData.state >= 104) {
                if (orderData.arrivalTimeAtTheAppointmentPointFormat) {
                    html += '<div class="timeline-detail"><strong>到达时间:</strong>' + orderData.arrivalTimeAtTheAppointmentPointFormat + '</div>';
                }
                // 如果是当前状态,则提示等待支付
                if (orderData.state === 104) {
                    html += '<div class="timeline-detail" style="color: #f8ac59;"><strong>等待用户支付车检费</strong></div>';
                }
                if (orderData.state >= 105 && orderData.checkMoney) {
                    html += '<div class="timeline-detail"><strong>用户已支付车检费:</strong>¥' + orderData.checkMoney + '</div>';
                    if (orderData.checkPayTimeFormat) {
                        html += '<div class="timeline-detail"><strong>支付时间:</strong>' + orderData.checkPayTimeFormat + '</div>';
                    }
                }
            }
            break;
 
        case 105: // 司机开始车检服务
            if (orderData.state >= 105) {
                html += '<div class="timeline-detail"><strong>预计等待3-5小时</strong></div>';
            }
            break;
 
        case 106: // 车检完成
            if (orderData.state >= 106) {
                if (orderData.endTimeFormat) {
                    html += '<div class="timeline-detail"><strong>完成时间:</strong>' + orderData.endTimeFormat + '</div>';
                }
                if (orderData.checkResult) {
                    html += '<div class="timeline-detail"><strong>车检结果:</strong>' + orderData.checkResult + '</div>';
                }
                if (orderData.checkIntro) {
                    html += '<div class="timeline-detail"><strong>详细说明:</strong>' + orderData.checkIntro + '</div>';
                }
                if (orderData.checkImgList && orderData.checkImgList.length > 0) {
                    html += '<div class="timeline-detail"><strong>凭证图片:</strong></div>';
                    orderData.checkImgList.forEach(function (img) {
                        html += '<img src="' + img + '" style="max-width: 100px; max-height: 100px; margin: 5px; border: 1px solid #ddd; cursor: pointer;" onclick="OrderDetail.viewImage(this.src)">';
                    });
                }
            }
            break;
 
        case 107: // 司机前往还车地
            if (orderData.state >= 107) {
                if (orderData.goTimeFormat) {
                    html += '<div class="timeline-detail"><strong>出发时间:</strong>' + orderData.goTimeFormat + '</div>';
                }
                if (orderData.endAddress) {
                    html += '<div class="timeline-detail"><strong>还车地址:</strong>' + orderData.endAddress + '</div>';
                }
            }
            break;
 
        case 108: // 用户支付服务费
 
            if (orderData.successTimeFormat) {
                html += '<div class="timeline-detail"><strong>还车时间:</strong>' + orderData.successTimeFormat + '</div>';
            }
            if (orderData.state == 108) {
                html += '<div class="timeline-detail"><strong>等待用户支付服务费</strong></div>';
            }
            break;
 
        case 109: // 服务完成
            if (orderData.state >= 109) {
                if (orderData.state >= 108) {
                    if (orderData.payTimeFormat) {
                        html += '<div class="timeline-detail"><strong>服务费支付时间:</strong>' + orderData.payTimeFormat + '</div>';
                    }
                    if (orderData.payMoney) {
                        html += '<div class="timeline-detail"><strong>服务费:¥:</strong>' + orderData.payMoney + '</div>';
                    }
                    if (orderData.discountedPrice) {
                        html += '<div class="timeline-detail"><strong>优惠券:¥</strong>' + orderData.discountedPrice + '</div>';
                    }
                    if (orderData.payMoney && orderData.discountedPrice) {
                        html += '<div class="timeline-detail"><strong>实付:¥</strong>' + (orderData.payMoney - orderData.discountedPrice) + '</div>';
                    }
                    if (orderData.payType) {
                        html += '<div class="timeline-detail"><strong>支付方式:</strong>' + (orderData.payType == 1 ? '微信' : '支付宝') + '</div>';
                    }
                }
            }
            break;
 
        case 110: // 用户评价
            if (orderData.state >= 110) {
                if (orderData.commentTimeFormat) {
                    html += '<div><strong>评价时间:</strong>' + orderData.commentTimeFormat + '</div>';
                }
                if (orderData.commentContent) {
                    html += '<div><strong>评价内容:</strong>' + orderData.commentContent + '</div>';
                }
                if (orderData.commentRate) {
                    var stars = '';
                    for (var i = 1; i <= 5; i++) {
                        stars += i <= orderData.commentRate ? '⭐' : '☆';
                    }
                    html += '<div class="timeline-detail"><strong>评价:</strong>' + stars + '</div>';
                }
                if (orderData.commentImgList && orderData.commentImgList.length > 0) {
                    html += '<div><strong>评价图片:</strong></div>';
                    orderData.commentImgList.forEach(function (img) {
                        html += '<img src="' + img + '" style="max-width: 100px; max-height: 100px; margin: 5px; border: 1px solid #ddd; cursor: pointer;" onclick="OrderDetail.viewImage(this.src)">';
                    });
                }
            }
            break;
    }
 
    return html;
};
 
/**
 * 打开派单页面
 */
OrderDetail.openDispatch = function(orderId, type) {
    var title = type === 1 ? '派单' : '改派';
    var url = Feng.ctxPath + '/tOrderCheck/tOrderCheck_dispatch/' + orderId + '/' + type;
    
    var me = this;
    this.dispatchLayerIndex = layer.open({
        type: 2,
        title: title,
        area: ['90%', '90%'],
        fix: false,
        maxmin: true,
        content: url,
        success: function(layero, index) {
            var iframeWin = window[layero.find('iframe')[0]['name']];
            // 定义回调函数,供子页面调用
            iframeWin.onDispatchSuccess = function() {
                layer.close(me.dispatchLayerIndex); // 关闭派单弹窗
                window.location.reload(); // 刷新详情页
            };
        }
    });
};
 
/**
 * 查看大图
 */
OrderDetail.viewImage = function(src) {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 1,
        skin: 'layui-layer-nobg', //无背景
        shadeClose: true,
        content: '<img src="' + src + '" style="max-width: 100%; max-height: 100%; display: block; margin: auto;">',
        area: ['90%', '90%']
    });
};
 
/**
 * 关闭详情页面
 */
OrderDetail.closeDetail = function() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
};
 
// 页面加载完成后初始化时间线
$(document).ready(function() {
    if (typeof OrderDetail !== 'undefined' && window.orderData) {
        OrderDetail.initTimeline();
    }
});
 
// 兼容某些场景下ready事件过早触发的问题
$(window).on('load', function() {
    // 如果时间线仍然是空的,再尝试初始化一次
    if (typeof OrderDetail !== 'undefined' && window.orderData && $('#orderTimeline').html().trim() === '') {
        OrderDetail.initTimeline();
    }
});