yanghb
2023-04-10 b2f678ad387ca24e05a11100ea4583f0f2f730f0
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
/**
 * 车辆管理管理初始化
 */
var SellingCar = {
    id: "SellingCarTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
SellingCar.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '添加时间', field: 'createTime', visible: true, align: 'center', valign: 'middle',width:'150px'},
        {title: '发布来源', field: 'userType', visible: true, align: 'center', valign: 'middle',width:'100px',
            formatter: function (value, row) {
                switch (value) {
                    case 1:
                        return '个人用户';
                    case 2:
                        return '司机用户';
                    case 3:
                        return '企业用户';
                }
            }
        },
        {title: '发布者名称', field: 'pushUser', visible: true, align: 'center', valign: 'middle',width:'150px'},
        {title: '标题', field: 'title', visible: true, align: 'center', valign: 'middle',width:'200px',
            formatter: function (value, row) {
                value = (typeof value == "undefined" ? '-':value);
                return '<span title="' + value + '">' + value + '</span>';
            }
        },
        {title: '车牌号', field: 'carLicensePlate', visible: true, align: 'center', valign: 'middle',width:'200px'},
        {title: '品牌', field: 'brandName', visible: true, align: 'center', valign: 'middle',width:'100px'},
        {title: '车辆颜色', field: 'carColor', visible: true, align: 'center', valign: 'middle',width:'100px'},
        {title: '联系人', field: 'contactsName', visible: true, align: 'center', valign: 'middle',width:'200px'},
        {title: '联系人电话', field: 'contactsPhone', visible: true, align: 'center', valign: 'middle',width:'150px'},
        {title: '取车地址', field: 'address', visible: true, align: 'center', valign: 'middle',width:'300px'},
        {title: '是否为首页推荐', field: 'firstPageShow', visible: true, align: 'center', valign: 'middle',width:'100px',
            formatter: function (value, row) {
                switch (value) {
                    case 1:
                        return '是';
                    case 2:
                        return '否';
                }
            }
        },
        {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',width:'100px',
            formatter: function (value, row) {
                switch (value) {
                    case 1:
                        return '待审核';
                    case 2:
                        return '上架中';
                    case 3:
                        return '已下架';
                    case 4:
                        return '待上架';
                    case 5:
                        return '已拒绝';
                }
            }
        }
    ];
};
 
/**
 * 检查是否选中
 */
SellingCar.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录!");
        return false;
    }else{
        SellingCar.seItem = selected[0];
        return true;
    }
};
 
/**
 * 点击添加车辆管理
 */
SellingCar.openAddSellingCar = function () {
    var index = layer.open({
        type: 2,
        title: '添加售卖车辆',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/sellingCar/sellingCar_add'
    });
    this.layerIndex = index;
};
 
SellingCar.showSellingCarInfo = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '售卖车辆详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/sellingCar/showSellingCarInfo?id=' + SellingCar.seItem.id
        });
        this.layerIndex = index;
    }
};
 
 
/**
 * 打开查看车辆管理详情
 */
SellingCar.openSellingCarDetail = function () {
    if (this.check()) {
        if(SellingCar.seItem.status == 2 || SellingCar.seItem.status ==5){
            Feng.info("不能编辑");
            return
        }
        var index = layer.open({
            type: 2,
            title: '编辑售卖车辆',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/sellingCar/sellingCar_update?id=' + SellingCar.seItem.id
        });
        this.layerIndex = index;
    }
};
 
/**
 * 删除车辆管理
 */
SellingCar.deleteSellingCar = function () {
    if (this.check()) {
        swal({
            title: "您是否确认删除该售车信息?",
            text: "请谨慎操作,删除后数据无法恢复!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            closeOnConfirm: true
        }, function () {
            var ajax = new $ax(Feng.ctxPath + "/sellingCar/deleteSellingCar", function (res) {
                if(res.code == 200){
                    swal("删除成功", "您已经成功删除了该租车信息。", "success");
                    SellingCar.table.refresh();
                }else{
                    Feng.error(res.msg);
                }
            }, function (data) {
                swal("删除失败", data.responseJSON.message+"!", "warning");
            });
            ajax.set("id",SellingCar.seItem.id);
            ajax.start();
        });
    }
};
 
/**
 * 上架
 */
SellingCar.onlineSellingCar = function () {
    if (this.check()) {
        if(SellingCar.seItem.status != 4 && SellingCar.seItem.status != 3){
            Feng.info("不允许发布");
            return
        }
        if(SellingCar.seItem.status == 2){
            Feng.info("不允许重复操作");
            return
        }
        var ajax = new $ax(Feng.ctxPath + "/sellingCar/onlineSellingCar", function (res) {
            if(res.code == 200){
                Feng.success("上架成功");
                SellingCar.table.refresh();
            }else{
                Feng.error(res.msg);
            }
        }, function (data) {
            swal("发布失败", data.responseJSON.message+"!", "warning");
        });
        ajax.set("id",SellingCar.seItem.id);
        ajax.start();
    }
};
 
/**
 * 下架
 */
SellingCar.offlineSellingCar = function () {
    if (this.check()) {
        if(SellingCar.seItem.status != 2){
            Feng.info("不允许下架");
            return
        }
        if(SellingCar.seItem.status == 3){
            Feng.info("不允许重复操作");
            return
        }
        var ajax = new $ax(Feng.ctxPath + "/sellingCar/offlineSellingCar", function (res) {
            if(res.code == 200){
                Feng.success("下架成功");
                SellingCar.table.refresh();
            }else{
                Feng.error(res.msg);
            }
        }, function (data) {
            swal("下架失败", data.responseJSON.message+"!", "warning");
        });
        ajax.set("id",SellingCar.seItem.id);
        ajax.start();
    }
};
 
/**
 * 设为首页推荐
 */
SellingCar.homeSellingCar = function () {
    if (this.check()) {
        if(SellingCar.seItem.firstPageShow == 1){
            Feng.info("不允许重复操作");
            return
        }
        if(SellingCar.seItem.status != 2){
            Feng.info("不允许设置");
            return
        }
        var ajax = new $ax(Feng.ctxPath + "/sellingCar/homeSellingCar", function (res) {
            if(res.code == 200){
                Feng.success("设置成功");
                SellingCar.table.refresh();
            }else{
                Feng.error(res.msg);
            }
        }, function (data) {
            swal("设置失败", data.responseJSON.message+"!", "warning");
        });
        ajax.set("id",SellingCar.seItem.id);
        ajax.start();
    }
};
 
/**
 * 取消推荐
 */
SellingCar.cancelHomeSellingCar = function () {
    if (this.check()) {
        if(SellingCar.seItem.firstPageShow == 2){
            Feng.info("不允许重复操作");
            return
        }
        var ajax = new $ax(Feng.ctxPath + "/sellingCar/cancelHomeSellingCar", function (res) {
            if(res.code == 200){
                Feng.success("设置成功");
                SellingCar.table.refresh();
            }else{
                Feng.error(res.msg);
            }
        }, function (data) {
            swal("设置失败", data.responseJSON.message+"!", "warning");
        });
        ajax.set("id",SellingCar.seItem.id);
        ajax.start();
    }
};
 
 
/**
 * 下载模板
 */
SellingCar.uploadSellingCarModel = function () {
    window.location.href = Feng.ctxPath + "/sellingCar/uploadSellingCarModel";
}
 
 
SellingCar.importSellingCar = function(){
    $('#file').click();
}
 
 
/**
 * 查询车辆管理列表
 */
SellingCar.search = function () {
    var queryData = {};
    queryData['createTime'] = $("#createTime").val();
    queryData['carLicensePlate'] = $("#carLicensePlate").val();
    queryData['brandId'] = $("#brandId").val();
    queryData['insertUser'] = $("#insertUser").val();
    queryData['status'] = $("#status").val();
    queryData['userType'] = $("#userType").val();
    SellingCar.table.setQueryParams({});
    SellingCar.table.refresh({query: queryData});
};
 
SellingCar.resetSearch = function () {
    $("#createTime").val("");
    $("#carLicensePlate").val("");
    $("#brandId").val("");
    $("#insertUser").val("");
    $("#status").val("");
    $("#userType").val("");
    SellingCar.search();
};
 
$(function () {
    var defaultColunms = SellingCar.initColumn();
    var table = new BSTable(SellingCar.id, "/sellingCar/list", defaultColunms);
    table.setPaginationType("server");
    SellingCar.table = table.init();
 
 
    $('#file').on('change', function () {
        let formData = new FormData()  //创建一个forData
        formData.append('file', $('#file')[0].files[0]) //把file添加进去  name命名为img
        layer.load(); //上传loading
        $.ajax({
            url: Feng.ctxPath + '/sellingCar/importSellingCar',
            data: formData,
            type: "POST",
            async: true,
            cache: false,
            contentType: false,
            processData: false,
            success: function(res) {
                layer.closeAll('loading'); //关闭loading
                $('#file').val('');
                if(res.code == 200){
                    Feng.success("导入成功");
                    CarRental.search();
                }else{
                    Feng.error(res.msg);
                }
 
            }
        })
    })
});