puzhibing
2023-08-16 d5b3e5a413bcfccba294793ee093722f31b2448a
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
/**
 * 管理初始化
 */
var TBranchOffice = {
    id: "TBranchOfficeTable",    //表格id
    seItem: null,        //选中的条目
    table: null,
    layerIndex: -1
};
 
/**
 * 初始化表格的列
 */
TBranchOffice.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '主键', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '代理商id', field: 'agentId', visible: false, align: 'center', valign: 'middle'},
        {title: '添加时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'},
        {title: '分公司名称', field: 'branchOfficeName', visible: true, align: 'center', valign: 'middle'},
        {title: '负责人姓名', field: 'principal', visible: true, align: 'center', valign: 'middle'},
        {title: '负责人电话', field: 'principalPhone', visible: true, align: 'center', valign: 'middle'},
        {title: '邮箱', field: 'email', visible: false, align: 'center', valign: 'middle'},
        {title: '代理区域省编号', field: 'provinceCode', visible: false, align: 'center', valign: 'middle'},
        {title: '代理区域省名称', field: 'provinceName', visible: false, align: 'center', valign: 'middle'},
        {title: '代理区域市编号', field: 'cityCode', visible: false, align: 'center', valign: 'middle'},
        {title: '代理区域市名称', field: 'cityName', visible: false, align: 'center', valign: 'middle'},
        {title: '代理区域区编号', field: 'districtCode', visible: false, align: 'center', valign: 'middle'},
        {title: '代理区域区名称', field: 'districtName', visible: false, align: 'center', valign: 'middle'},
 
        {title: '订单数量', field: 'orderCount', visible: true, align: 'center', valign: 'middle'},
        {title: '有效订单', field: 'effectiveOrderCount', visible: true, align: 'center', valign: 'middle'},
        {title: '已发放优惠券', field: 'totalCount', visible: true, align: 'center', valign: 'middle'},
        {title: '已使用优惠券', field: 'usedCount', visible: true, align: 'center', valign: 'middle'},
        {title: '累计优惠券金额', field: 'orderPriceCount', visible: true, align: 'center', valign: 'middle'},
 
        {title: '经营业务', field: 'operatingBusiness', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row) {
                if (row.operatingBusiness === 1){
                    return '<span>司机代驾</span>'
                }
            }
        },
 
        {title: '司机数', field: 'driverCount', visible: true, align: 'center', valign: 'middle'},
        {title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle',
            formatter: function (value, row) {
                if (row.status === 1){
                    return '<span>正常</span>'
                }else if(row.status === 2){
                    return '<span>冻结</span>'
                }else if (row.status === 3){
                    return '<span>已删除</span>'
                }
            }
        },
        {title: '操作', visible: true, align: 'center', valign: 'middle',width:150,
            formatter: function (value, row) {
                if(row.userType !== 1){
                    return '<a href="#" onclick="TBranchOffice.searchTBranchOfficeDetail('+row.id+')" style="color:blue">详情</a>'
                }else {
                    return '<a href="#" onclick="TBranchOffice.searchTBranchOfficeDetail('+row.id+')" style="color:blue">详情</a>' +'&nbsp;' +
                        '<a href="#" onclick="TBranchOffice.delete('+row.id+')" style="color:red">删除</a>'
                }
            }
        }
    ];
};
 
/**
 * 检查是否选中
 */
TBranchOffice.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录!");
        return false;
    }else{
        TBranchOffice.seItem = selected[0];
        return true;
    }
};
 
/**
 * 点击添加
 */
TBranchOffice.openAddTBranchOffice = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tBranchOffice/tBranchOffice_add'
    });
    this.layerIndex = index;
};
 
/**
 * 打开查看详情
 */
TBranchOffice.openTBranchOfficeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['100%', '100%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tBranchOffice/tBranchOffice_update/' + TBranchOffice.seItem.id
        });
        this.layerIndex = index;
    }
};
/**
 * 打开查看详情(使用中)
 */
TBranchOffice.searchTBranchOfficeDetail = function (id) {
    var index = layer.open({
        type: 2,
        title: '详情',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tBranchOffice/tBranchOfficeDetail?tBranchOfficeId=' + id
    });
    this.layerIndex = index;
};
 
/**
 * 删除
 */
TBranchOffice.delete = function (id) {
 
    var userType = $('#userType').val()
    if(userType == 2){
        Feng.error("无权删除分公司!")
        return;
    }
 
    var ajax = new $ax(Feng.ctxPath + "/tBranchOffice/delete", function (data) {
        Feng.success("删除成功!");
        TBranchOffice.table.refresh();
    }, function (data) {
        Feng.error("删除失败!" + data.responseJSON.message + "!");
    });
    ajax.set("tBranchOfficeId",id);
    ajax.start();
};
 
/**
 * 提交冻结
 */
TBranchOffice.stop = function () {
    if(this.check()){
        if(2 == this.seItem.status){
            Feng.error("该条数据已冻结!");
            return;
        }
        var ajax = new $ax(Feng.ctxPath + "/tBranchOffice/stop?id="+this.seItem.id, function (data) {
            if(500 == data.code){
                Feng.error(data.message);
                return;
            }else {
                Feng.success("冻结成功!");
                TBranchOffice.table.refresh();
            }
        }, function (data) {
            Feng.error("冻结失败!" + data.message + "!");
        });
        ajax.start();
    }
};
 
/**
 * 提交启用
 */
TBranchOffice.start = function () {
    if(this.check()){
        if(1 == this.seItem.status){
            Feng.error("该条数据已启用!");
            return;
        }
        var ajax = new $ax(Feng.ctxPath + "/tBranchOffice/start?id="+this.seItem.id, function (data) {
            if(500 == data.code){
                Feng.error(data.message);
                return;
            }else {
                Feng.success("启用成功!");
                TBranchOffice.table.refresh();
            }
        }, function (data) {
            Feng.error("启用失败!" + data.message + "!");
        });
        ajax.start();
    }
};
 
/**
 * 打开区域选择页面新增
 */
TBranchOffice.areaAdd = function () {
 
    var area = $("#area").val();
    var areaId = $("#areaId").val();
 
    var index = layer.open({
        type: 2,
        title: '区域选择',
        area: ['1000px', '270px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tBranchOffice/areaPageAdd?area='+area+'&areaId='+areaId
    });
    this.layerIndex = index;
}
 
/**
 * 打开区域选择页面编辑
 */
TBranchOffice.areaUpdate = function () {
 
    var area = $("#area").val();
    var areaId = $("#areaId").val();
 
    var index = layer.open({
        type: 2,
        title: '区域选择',
        area: ['1000px', '270px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tBranchOffice/areaPageUpdate?area='+area+'&areaId='+areaId
    });
    this.layerIndex = index;
}
 
/**
 * 查询市
 */
TBranchOffice.areaCity = function () {
 
    //监听第一个下拉菜单的变动操作
    $("#province").change(function(){
        //当第一级下拉列表没选择值时,将二级下拉列表和三级同时设置为空
        if(this.value==""){
            $("#city").empty();//二级联动设为空设为空
            $("#city").append('<option value="">请选择</option>');
            //region
            $("#district").empty();//三级联动设为空设为空
            $("#district").append('<option value="">请选择</option>');
 
        }
        if(this.value!=""){//第一级下拉菜单选择了值
            $("#city").empty();//先行置空,防止上次选择留下的元素影响效果
            $("#city").append('<option value="">请选择</option>')//设置初始选项
            $("#district").empty();//三级联动设为空设为空
            $("#district").append('<option value="">请选择</option>');
            var province = document.getElementById('province');
            var index= province.selectedIndex ;
            var id = province.options[index].id;
            var ajax = new $ax(Feng.ctxPath + "/tBranchOffice/areaCity?parentId="+id, function (data) {
                for(var i=0,n=data.length;i<n;i++){//遍历
                    $("#city").append('<option value="'+data[i].id+'">'+data[i].name+'</option>');//创造元素
                }
            }, function (data) {
                Feng.error("查询失败!" + data.responseJSON.message + "!");
            });
            ajax.start();
        }
    });
 
    /*var province = document.getElementById('province');
    var index= province.selectedIndex ;
    var id = province.options[index].id;
    var ajax = new $ax(Feng.ctxPath + "/tBranchOffice/areaCity?parentId="+id, function (data) {
        /!*var opts=document.getElementById('city').options;
        opts.length=0;// 这一句是清空原有列表项
        for(var i=0,n=data.length;i<n;i++){
            var data1=data[i];
            var opt=new Option(data1.name,data1.id,true,true);
            opts.add(opt);
        }*!/
    }, function (data) {
        Feng.error("查询失败!" + data.responseJSON.message + "!");
    });
    ajax.start();*/
}
 
/**
 * 查询区
 */
TBranchOffice.areaDistrict = function () {
    //监听第二个下拉菜单的变动操作
    $("#city").change(function(){
        if(this.value==""){//第二级菜单为空,则将第三级菜单也置为空
            $("#district").empty();
            $("#district").append('<option value="">请选择</option>');
        }
        if(this.value!=""){//第二级菜单不为空,则将第三级菜单动态生成
            $("#district").empty();
            $("#district").append('<option value="">请选择</option>');
 
            var city = document.getElementById('city');
            var cityIndex= city.selectedIndex ;
            var id = city.options[cityIndex].id;
            if(id == ""){
                id = city.options[cityIndex].value;
            }
            var ajax = new $ax(Feng.ctxPath + "/tBranchOffice/areaCity?parentId="+id, function (data) {
                for(var i=0,n=data.length;i<n;i++){//对区数据进行遍历,动态生成
                    $("#district").append('<option value="'+data[i].id+'">'+data[i].name+'</option>');
                }
            }, function (data) {
                Feng.error("查询失败!" + data.responseJSON.message + "!");
            });
            ajax.start();
        }
    })
 
    /*var city = document.getElementById('city');
    var cityIndex= city.selectedIndex ;
    var id = city.options[cityIndex].value;
    var ajax = new $ax(Feng.ctxPath + "/tBranchOffice/areaCity?parentId="+id, function (data) {
        var opts=document.getElementById('district').options;
        opts.length=0;// 这一句是清空原有列表项
        for(var i=0,n=data.length;i<n;i++){
            var data1=data[i];
            var opt=new Option(data1.name,data1.id,true,true);
            opts.add(opt);
        }
    }, function (data) {
        Feng.error("查询失败!" + data.responseJSON.message + "!");
    });
    ajax.start();*/
}
 
/**
 * 选择省市
 */
TBranchOffice.submitArea = function () {
    var province = document.getElementById('province');
    var provinceIndex= province.selectedIndex ;
    var provinceId = province.options[provinceIndex].value;
    var provinceName = province.options[provinceIndex].innerText;
    console.log(provinceId)
    console.log(provinceName)
 
    if(provinceName == null || provinceName == ''){
        Feng.error("请选择省份!")
        return;
    }
 
    var city = document.getElementById('city');
    var cityIndex= city.selectedIndex ;
    var cityId = city.options[cityIndex].value;
    var cityName = city.options[cityIndex].innerText;
    console.log(cityId)
    console.log(cityName)
    if(cityName == null || cityName == '' || cityName =='请选择'){
        Feng.error("请选择市区!")
        return;
    }
 
    var district = document.getElementById('district');
    var districtIndex= district.selectedIndex ;
    var districtId = district.options[districtIndex].value;
    var districtName = district.options[districtIndex].innerText;
    console.log(districtId)
    console.log(districtName)
 
    if(districtName == '' || districtName == null || districtName == '请选择'){
        parent.$("#area").val(provinceName+'/'+cityName)
        parent.$("#areaId").val(provinceId+'/'+cityId)
    }else {
        parent.$("#area").val(provinceName+'/'+cityName+'/'+districtName)
        parent.$("#areaId").val(provinceId+'/'+cityId+'/'+districtId)
    }
    console.log($("#area").val())
    console.log($("#areaId").val())
    TBranchOfficeInfoDlg.close();
}
 
/**
 * 查询列表
 */
TBranchOffice.search = function () {
    var queryData = {};
    queryData['branchOfficeName'] = $("#branchOfficeName").val();
    queryData['principal'] = $("#principal").val();
    queryData['principalPhone'] = $("#principalPhone").val();
    queryData['operatingBusiness'] = $("#operatingBusiness").val();
    queryData['status'] = $("#status").val();
    TBranchOffice.table.refresh({query: queryData});
};
 
/**
 * 重置
 */
TBranchOffice.resetSearch = function (){
    $("#branchOfficeName").val('');
    $("#principal").val('');
    $("#principalPhone").val('');
    $("#operatingBusiness").val('');
    $("#status").val('');
    TBranchOffice.search();
}
 
$(function () {
    var defaultColunms = TBranchOffice.initColumn();
    var table = new BSTable(TBranchOffice.id, "/tBranchOffice/list", defaultColunms);
    table.setPaginationType("client");
    TBranchOffice.table = table.init();
});