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
/**
 * 代检车订单管理管理初始化
 */
var TOrderCheck = {
    id: "TOrderCheckTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
TOrderCheck.initColumn = function () {
    return [
        {field: 'selectItem', radio: false},
        {title: '主键', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '下单时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
        {title: '订单编号', field: 'code', visible: true, align: 'center', valign: 'middle'},
        {title: '订单来源', field: 'source', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row) {
                return {1:'小程序',2:'管理后台'}[value] || '未知';
            }
        },
        {title: '预约时间', field: 'reservationTime', visible: true, align: 'center', valign: 'middle'},
        {title: '下单用户昵称', field: 'userName', visible: true, align: 'center', valign: 'middle'},
        {title: '下单用户手机', field: 'userPhone', visible: true, align: 'center', valign: 'middle'},
        {title: '取车地', field: 'startAddress', visible: true, align: 'center', valign: 'middle'},
        {title: '还车地', field: 'endAddress', visible: true, align: 'center', valign: 'middle'},
        {title: '接单司机', field: 'driverName', visible: true, align: 'center', valign: 'middle'},
        {title: '司机电话', field: 'driverPhone', visible: true, align: 'center', valign: 'middle'},
        {title: '状态', field: 'state', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row) {
                switch (value) {
                    case 100: return '待派单';
                    case 101: return '待接单';
                    case 102:
                    case 104:
                    case 105:
                    case 106:
                    case 107:
                    case 108: return '服务中';
                    case 109:
                    case 110: return '已完成';
                    case 111: return '取消';
                    default: return '未知状态';
                }
            }
        },
        {title: '操作', field: 'operate', visible: true, align: 'center', valign: 'middle',width:'10%',
            formatter:function (value, row) {
                const btn = '<a href="#" onclick="TOrderCheck.openTOrderCheckDetail(' + row.id + ')" style="color:blue">详情</a>' + '&nbsp;';
                if (row.state === 100) {
                    return btn + '<a href="#" onclick="TOrderCheck.openDispatchPage(' + row.id + ',1' + ')" style="color:blue">派单</a>';
                } else if (row.state === 101) {
                    return btn + '<a href="#" onclick="TOrderCheck.openDispatchPage(' + row.id + ',2' + ')" style="color:blue">改派</a>';
                } else if (row.state === 111) {
                    return btn + '<a href="#" onclick="TOrderCheck.delete(' + row.id + ')" style="color:blue">删除</a>';
                } else {
                    return btn;
                }
 
            }
        }
 
    ];
};
 
/**
 * 检查是否选中
 */
TOrderCheck.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录!");
        return false;
    }else{
        TOrderCheck.seItem = selected[0];
        return true;
    }
};
 
/**
 * 检查是否选中一个
 */
TOrderCheck.checkSingle = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录!");
        return false;
    }else if(selected.length > 1){
        Feng.info("只能选中一条记录!");
        return;
    }else {
        TOrderCheck.seItem = selected[0];
        return true;
    }
};
/**
 * 点击添加代检车订单管理
 */
TOrderCheck.openAddTOrderCheck = function () {
    var index = layer.open({
        type: 2,
        title: '新建订单',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tOrderCheck/tOrderCheck_add'
    });
    this.layerIndex = index;
};
 
/**
 * 新建订单(对应HTML按钮调用的方法)
 */
TOrderCheck.addOrder = function () {
    this.openAddTOrderCheck();
};
 
/**
 * 打开查看代检车订单管理详情
 */
TOrderCheck.openTOrderCheckDetail = function (id) {
    var index = layer.open({
        type: 2,
        title: '订单详情',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tOrderCheck/tOrderCheck_detail/' + id
    });
    this.layerIndex = index;
};
 
/**
 * 打开派单页
 *type 1:派单 2:改派
 */
TOrderCheck.openDispatchPage = function (id, type) {
    var index = layer.open({
        type: 2,
        title: '派单',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tOrderCheck/tOrderCheck_dispatch/' + id + '/' + type,
 
    });
    this.layerIndex = index;
};
/**
 * 后台取消订单
 */
TOrderCheck.cancel = function () {
    if (this.checkSingle()) {
 
        var selected = $('#' + this.id).bootstrapTable('getSelections');
 
        var id = selected[0].id
        var state = selected[0].state
 
        console.log(id)
        console.log(state)
 
        if (state != 100 && state != 101 && state != 102 && state != 104 && state != 105 && state != 106 && state != 107) {
            Feng.error("该订单当前状态不可取消!")
            return;
        }
        swal({
            title: "您是否确认取消该订单" + "?",
            text: "请谨慎操作",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确认",
            closeOnConfirm: true
        }, function () {
            var ajax = new $ax(Feng.ctxPath + "/tOrderCheck/cancel", function (data) {
                Feng.success("取消订单成功!");
                TOrderCheck.table.refresh();
            }, function (data) {
                Feng.error("取消订单失败!" + data.responseJSON.message + "!");
            });
            ajax.set("tOrderCheckId", id);
            ajax.start();
        });
 
    }
};
/**
 * 批量派单
 */
TOrderCheck.dispatchBatch = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的记录!");
        return;
    }
    
    // 检查选中订单是否都是可派单状态
    var canDispatchOrders = [];
    for(var i = 0; i < selected.length; i++){
        if(selected[i].state === 100) { // 待派单状态
            canDispatchOrders.push(selected[i]);
        }
    }
    
    if(canDispatchOrders.length === 0){
        Feng.info("选中的订单中没有可派单的订单(状态必须为待派单)!");
        return;
    }
    
    if(canDispatchOrders.length < selected.length){
        Feng.info("已自动过滤掉不可派单的订单,共选择了" + canDispatchOrders.length + "个可派单订单");
    }
    
    // 创建表单并提交订单ID数组到后端
    var orderIds = canDispatchOrders.map(function(order) { return order.id; });
 
    // 使用layer打开批量派单页面
    var index = layer.open({
        type: 2,
        title: '批量派单',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tOrderCheck/tOrderCheck_dispatchBatch?orderIds=' + orderIds.join(',')
    });
    this.layerIndex = index;
    
};
/**
 * 删除代检车订单管理
 */
TOrderCheck.delete = function (id) {
    swal({
        title: "您是否确认删除" + "?",
        text: "请谨慎操作,删除后数据无法恢复!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "删除",
        closeOnConfirm: true
    }, function () {
        var ajax = new $ax(Feng.ctxPath + "/tOrderCheck/delete", function (data) {
            Feng.success("删除成功!");
            TOrderCheck.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("tOrderCheckId",id);
        ajax.start();
    });
};
 
/**
 * 查询代检车订单管理列表
 */
TOrderCheck.search = function () {
    var queryData = {};
    queryData['createTime'] = $("#createTime").val();
    queryData['code'] = $("#code").val();
    queryData['source'] = $("#source").val();
    queryData['userName'] = $("#userName").val();
    queryData['userPhone'] = $("#userPhone").val();
    queryData['state'] = $("#state").val();
    queryData['driverName'] = $("#driverName").val();
    TOrderCheck.table.refresh({query: queryData});
};
/**
 * 重置
 */
TOrderCheck.resetSearch = function (){
    $("#createTime").val('');
    $("#code").val('');
    $("#source").val('');
    $("#userName").val('');
    $("#userPhone").val('');
    $("#state").val('');
    $("#driverName").val('');
    TOrderCheck.search();
}
 
/**
 * 导出车检订单列表
 */
TOrderCheck.export = function () {
    // 显示加载提示
    var loadingIndex = layer.load(1, {shade: [0.1, '#fff']});
    
    try {
        // 获取搜索条件
        var queryData = {};
        queryData['createTime'] = $("#createTime").val();
        queryData['code'] = $("#code").val();
        queryData['source'] = $("#source").val();
        queryData['userName'] = $("#userName").val();
        queryData['userPhone'] = $("#userPhone").val();
        queryData['state'] = $("#state").val();
        queryData['driverName'] = $("#driverName").val();
        
        // 构建导出URL
        var exportUrl = Feng.ctxPath + '/tOrderCheck/export';
        var params = [];
        
        // 构建参数字符串
        for (var key in queryData) {
            if (queryData[key] && queryData[key] !== '') {
                params.push(key + '=' + encodeURIComponent(queryData[key]));
            }
        }
        
        if (params.length > 0) {
            exportUrl += '?' + params.join('&');
        }
        
        // 创建隐藏的iframe来触发下载
        var iframe = document.createElement('iframe');
        iframe.style.display = 'none';
        iframe.src = exportUrl;
        document.body.appendChild(iframe);
        
        // 设置超时时间,在指定时间后移除iframe并关闭加载提示
        setTimeout(function() {
            document.body.removeChild(iframe);
            layer.close(loadingIndex);
            Feng.success("导出完成!");
        }, 3000);
        
    } catch (error) {
        layer.close(loadingIndex);
        Feng.error("导出失败:" + error.message);
        console.error("Export error:", error);
    }
};
$(function () {
    var defaultColunms = TOrderCheck.initColumn();
    var table = new BSTable(TOrderCheck.id, "/tOrderCheck/list", defaultColunms);
    table.setPaginationType("server");
    TOrderCheck.table = table.init();
});