lisy
2023-08-18 87d3a050867e17b0dd9b47263d59c496622e860a
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
/**
 * 初始化车辆管理详情对话框
 */
var language=1;
var TGoodsInfoDlg = {
    tGoodsInfoData : {},
    validateFields: {
    },
    goodsPicArray:[],
    storeIds: [],
 
};
 
/**
 * 验证数据是否为空
 */
TGoodsInfoDlg.validate = function () {
    $('#carInfoForm').data("bootstrapValidator").resetForm();
    $('#carInfoForm').bootstrapValidator('validate');
    return $("#carInfoForm").data('bootstrapValidator').isValid();
};
 
/**
 * 清除数据
 */
TGoodsInfoDlg.clearData = function() {
    this.tGoodsInfoData = {};
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TGoodsInfoDlg.set = function(key, val) {
    this.tGoodsInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TGoodsInfoDlg.get = function(key) {
    return $("#" + key).val();
}
 
/**
 * 关闭此对话框
 */
TGoodsInfoDlg.close = function() {
    parent.layer.close(window.parent.TPointProducts.layerIndex);
}
 
 
/**
 * 收集数据
 */
TGoodsInfoDlg.collectData = function() {
    this
    .set('id')
    .set('isPlatCar')
    .set('companyId')
    .set('franchiseeId')
    .set('carColor')
    .set('carModelId')
    .set('carBrandId')
    .set('carLicensePlate')
    .set('carPhoto')
    .set('drivingLicenseNumber')
    .set('drivingLicensePhoto')
    .set('annualInspectionTime')
    .set('commercialInsuranceTime')
    .set('createTime')
    .set('state')
    .set('addType')
    .set('addObjectId')
    .set('plateColor')
    .set('vehicleType')
    .set('ownerName')
    .set('engineId')
    .set('VIN')
    .set('certifyDateA')
    .set('fuelType')
    .set('engineDisplace')
    .set('certificate')
    .set('transAgency')
    .set('transArea')
    .set('transDateStart')
    .set('transDateStop')
    .set('certifyDateB')
    .set('fixState')
    .set('nextFixDate')
    .set('checkState')
    .set('feePrintId')
    .set('GPSBrand')
    .set('GPSModel')
    .set('GPSIMEI')
    .set('GPSInstallDate')
    .set('registerDate')
    .set('commercialType');
}
function storeList(){
    var index = layer.open({
        type: 2,
        title: '门店列表',
        area: ['80%', '80%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tGoods/storeList'
    });
    this.layerIndex = index;
}
TGoodsInfoDlg.selecUserOpt = function (arrays){
    console.log(arrays)
    //获取所有的值
    var subArr= this.storeIds;
    $(".timeClass").each(function () {
        subArr.push($(this).find("input[name*='id']").val());
    });
    var str = '';
    for(var i in arrays){
        var b = true;
        for(var j in subArr){
            if(arrays[i].id === Number(subArr[j])){
                b = false;
                break
            }
        }
        if(b){
            this.storeIds.push(arrays[i].id)
            str += '<tr class="timeClass">' +
                '<td><input type="hidden" id="id" name="id" value="'+arrays[i].id+'"><input type="hidden" id="provinceCity" name="provinceCity" value="'+arrays[i].provinceCity+'">' + arrays[i].provinceCity + '</td>' +
                '<td><input type="hidden" id="accountName" name="accountName" value="'+arrays[i].accountName+'">' + arrays[i].accountName + '</td>' +
                '<td><input type="hidden" id="name" name="name" value="'+arrays[i].name+'">' + arrays[i].name + '</td><td><button onclick="deleteSub(this)">移除</button></td></tr>';
        }
    }
    $("#coun").append(str);
    console.log('storeIds',this.storeIds)
}
function deleteSub(e) {
    console.log(e);
    var row = $(e).closest('tr');
    var value = row.find('#id').val();
    TGoodsInfoDlg.storeIds.splice(TGoodsInfoDlg.storeIds.indexOf(parseInt(value)), 1)
    $(e).parent().parent().remove();
    console.log('storeIds',TGoodsInfoDlg.storeIds)
}
TGoodsInfoDlg.delete = function (o) {
    $(o).parent("div").remove()
}
var num = 0;
TGoodsInfoDlg.addBranch = function () {
    num=num+1;
    var a= "";
    a = "<div style=\'margin-left: 25%\' class=\"col-sm-9 control-label\">\n" +
        "                            <select class=\"col-sm-1\"  id=\'provinceData"+num+"\' style=\"margin-top: 1%;width: 25%\" onchange=\'changeCity("+num+")\'>\n" +
        "                                <option value=\"\">请选择</option>\n" +
        "                            </select>\n" +
        "                            <label class=\"col-sm-1\"  style=\"width: 9%;margin-top: 7px\">省</label>\n" +
        "                            <select  class=\"col-sm-1\" style=\"margin-top: 1%;width: 25%\" id=\'cityData"+num+"\'>\n" +
        "                                <option value=\"\">请选择</option>\n" +
        "                            </select>\n" +
        "                            <label class=\"col-sm-1\" style=\"width: 7%;margin-top: 7px\">市</label>\n" +
        "                            <label name=\"addBranch\" class=\"col-sm-1\" onclick=\"TGoodsInfoDlg.delete(this)\" style=\"border: 0px;cursor: pointer;margin-top: 1%\"><i class=\"fa fa-trash\"></i></label>"+
        "                        </div>";
    $("#cityDemo").append($(a));
    getProvince(num);
}
function changeCity(n){
 
    var provinceSelect = null;
    if (n === undefined || n === null || n === ''){
        provinceSelect = document.getElementById("provinceData");
    }else {
        provinceSelect = document.getElementById("provinceData"+n);
    }
 
    var citySelect = null;
    if (n === undefined || n === null || n === ''){
        citySelect = document.getElementById("cityData");
    }else {
        citySelect = document.getElementById("cityData"+n);
    }
 
    var selectedProvince = provinceSelect.value;
    // 清空城市下拉框
    citySelect.innerHTML = '<option value="">请选择</option>';
    if (selectedProvince === "") {
        return;
    }
    var ajax = new $ax(Feng.ctxPath + "/tCouponManage/getCity", function(data){
        data.forEach(province => {
            var option = document.createElement("option");
            option.value = province.id;  // 根据你的数据结构确定省份的id字段
            option.text = province.name;  // 根据你的数据结构确定省份的name字段
            citySelect.appendChild(option);
        });
    },function(data){
        console.log('data:',data)
        Feng.error("获取失败!" + data.responseJSON.message + "!");
    });
    ajax.set('province',selectedProvince);
    ajax.start();
}
function getProvince(n){
    var ajax = new $ax(Feng.ctxPath + "/tCouponManage/getProvince", function(data){
        console.log(data)
        var provinceSelect = null;
        if (n === undefined || n === null || ''){
            provinceSelect = document.getElementById("provinceData");
        }else {
            provinceSelect = document.getElementById("provinceData"+n);
        }
        data.forEach(province => {
            var option = document.createElement("option");
            option.value = province.id;  // 根据你的数据结构确定省份的id字段
            option.text = province.name;  // 根据你的数据结构确定省份的name字段
            provinceSelect.appendChild(option);
        });
    },function(data){
        Feng.error("下拉失败!" + data.responseJSON.message + "!");
    });
    ajax.start();
}
/**
 * 提交添加
 */
TGoodsInfoDlg.addSubmit = function() {
 
    this.clearData();
    this.collectData();
    if(!this.validate()){
        return ;
    }
 
    let pCode = $("#pCode").val()
    let cCode = $("#cCode").val()
    let name = $("#name").val()
    let phone = $("#phone").val()
 
    if(pCode==''){
        Feng.info("请选择省")
        return;
    }
    if(cCode==''){
        Feng.info("请选择市")
        return;
    }
    if(name==''){
        Feng.info("管理员姓名不能为空")
        return;
    }
    if(phone==''){
        Feng.info("管理员手机号不能为空")
        return;
    }
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tCity/add", function(data){
        if(data=="5001"){
            Feng.error("改账号已经存在");
        }else
        if(data.code == 200){
            if(language==1){
                Feng.success("添加成功!");
            }else if(language==2){
                Feng.success("Successfully added!");
            }else {
                Feng.success("Sangat berhasil ditambah!");
            }
            window.parent.TCompetition.table.refresh();
            TGoodsInfoDlg.close();
        }else{
            Feng.error(data.msg);
        }
 
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.tGoodsInfoData);
    ajax.set("provinceCode",pCode);
    ajax.set("cityCode",cCode);
    ajax.set("name",name);
    ajax.set("phone",phone);
    ajax.start();
}
 
/**
 * 删除图片的函数
 * @param e
 */
function delImg(e){
    $(e).parent().remove();
}
 
 
/**
 * 提交修改
 */
TGoodsInfoDlg.editSubmit = function() {
    let cover = $("#cover").val();
    let goodsId = $("#goodsId").val();
    var productImages = "";
    if (TGoodsInfoDlg.goodsPicArray.length > 0){
        productImages = TGoodsInfoDlg.goodsPicArray.join(',');
    }
    let quantityIssued = $("#quantityIssued").val();
    let pickUpQuantity = $("#pickUpQuantity").val();
    let editor = jQuery.trim(TGoodsInfoDlg.editor.getContent());
    console.log('editor:',editor)
 
    let sort = $("#sort").val();
 
    if (quantityIssued === undefined || quantityIssued === null || quantityIssued === ''){
        return Feng.error('发放数量不能为空!');
    }
    if (pickUpQuantity === undefined || pickUpQuantity === null || pickUpQuantity === ''){
        return Feng.error('限领数量不能为空!');
    }
    let quantityHas = $("#quantityHas").val();
    if (quantityIssued <= quantityHas){
        return Feng.error('发放数量小于已领数量!');
    }
 
 
    if (editor === undefined || editor === null || editor === ''){
        return Feng.error('兑换说明不能为空!');
    }
    if (sort === undefined || sort === null || sort === ''){
        return Feng.error('排序不能为空!');
    }
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tGoods/update", function(data){
        Feng.success("修改成功!");
        window.parent.TPointProducts.table.refresh();
        TGoodsInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set("pointMerchandiseId",goodsId);
    ajax.set("quantityIssued",quantityIssued);
    ajax.set("pickUpQuantity",pickUpQuantity);
    ajax.set("redemptionInstructions",editor);
    ajax.set("cover",cover);
    ajax.set("productImages",productImages);
    ajax.set("sort",sort);
    ajax.start();
}
 
$(function() {
    getProvince(null);
    Feng.initValidator("carInfoForm", TGoodsInfoDlg.validateFields);
    // 初始化图片上传
    var carPhoto = new $WebUpload("cover");
    carPhoto.setUploadBarId("progressBar");
    carPhoto.init();
    var drivingLicensePhoto = new $WebUpload("drivingLicensePhoto");
    drivingLicensePhoto.setUploadBarId("progressBar");
    drivingLicensePhoto.init();
    TGoodsInfoDlg.editor = UE.getEditor('editor');
});
 
/**
 * 选择分公司后执行
 */
TGoodsInfoDlg.oneChange = function (e) {
    var oneId=$(e).val();
    var ajax = new $ax(Feng.ctxPath + "/tCity/onChange", function(data){
        if(data!=null){
            if(language==1){
                var content='<option value="">选择市</option>';
            }else if(language==2){
                var content='<option value="">Choose your franchisee</option>';
            }else {
                var content='<option value="">Pilih franchisee Anda</option>';
            }
            $.each(data, function(k,v) {
                content += "<option value='"+v.code+"'>"+v.name+"</option>";
            });
            $("#cCode").empty().append(content);
        }
    });
    ajax.set("oneId",oneId);
    ajax.start();
}
 
/**
 * 类型改变执行
 * @param e
 */
TGoodsInfoDlg.companyTypeClick = function (e) {
    if (1 == e){
        $(".companyDiv").hide();
    } else if (2 == e){
        $(".companyDiv").show();
    }
}
 
/**
 * 车辆品牌改变时执行
 */
TGoodsInfoDlg.brandChange = function (e) {
    var carBrandId=$(e).val();
    var ajax = new $ax(Feng.ctxPath + "/tCar/brandChange", function(data){
        if(data!=null){
            if(language==1){
                var content='<option value="">选择车辆类型</option>';
            }else if(language==2){
                var content='<option value="">Please select the vehicle type</option>';
            }else {
                var content='<option value="">Pilih Jenis Kendaraan</option>';
            }
 
            $.each(data, function(k,v) {
                content += "<option value='"+v.id+"'>"+v.name+"</option>";
            });
            $("#carModelId").empty().append(content);
        }
    });
    ajax.set("carBrandId",carBrandId);
    ajax.start();
}
 
/**
 * 专车服务被点击
 */
TGoodsInfoDlg.zcServerClick = function () {
    var serverBox1 = $('#serverBox1').prop('checked');
    if (serverBox1){
        $("#zcModelDiv").show();
    } else {
        $("#zcModelDiv").hide();
    }
}
 
/**
 * 跨城服务被点击
 */
TGoodsInfoDlg.kcServerClick = function () {
    var serverBox3 = $('#serverBox3').prop('checked');
    if (serverBox3){
        $("#kcModelDiv").show();
    } else {
        $("#kcModelDiv").hide();
    }
}