puzhibing
2023-11-28 7b726d5ff439e7b8bb66369ecc5881e370286bc8
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 IconInfo = {
    userInfoData: {},
    layerIndex: -1,
    exposureCrowd: $('#exposureCrowd').val()
};
 
 
/**
 * 关闭此对话框
 */
IconInfo.close = function () {
    parent.layer.close(window.parent.Icon.layerIndex);
};
 
 
/**
 * 提交添加banner
 */
IconInfo.addSubmit = function () {
    const name = $('#name').val();
    const imgOneUrl = $('#imgOneUrl').val();
    const imgTwoUrl = $('#imgTwoUrl').val();
    const dateTime = $('#dateTime').val();
    const jumpType = $('#jumpType').val();
    const content = $('#content').val();
    const sort = $('#sort').val();
    const objecCode = $('#objecCode').val();
    const appid = $('#appid').val();
    const isLogin = $('#isLogin').val();
 
    const position = $('#position').val();
    const jumpClassification = $('#jumpClassification').val();
    const frequency = $('#frequency').val();
    const zhouSelectpicker = $('#zhouSelectpicker').find("select").val();
    const yueSelectpicker = $('#yueSelectpicker').find("select").val();
    var frequencyTime="";
    if(frequency==1){//周
        frequencyTime=zhouSelectpicker==null?[]:zhouSelectpicker;
    }else {
        frequencyTime=yueSelectpicker==null?[]:yueSelectpicker;
    }
    var pointTime = [];
    $(".pointTime").each(function(){
        pointTime.push($(this).val());
    });
    var exposureProvince = $('#province').find("option:selected").text();
    var exposureProvinceCode = $('#province').find("option:selected").attr("code");
    var exposureCity =$('#city').find("option:selected").text();
    var exposureCityCode =$('#city').find("option:selected").attr("code");
    var exposureDistrict = $('#district').find("option:selected").text();
    var exposureDistrictCode = $('#district').find("option:selected").attr("code");
    if(exposureProvince=="请选择"){
        exposureProvince='';
    }
    if(exposureCity=="请选择"){
        exposureCity='';
    }
    if(exposureDistrict=="请选择"){
        exposureDistrict='';
    }
 
    if(null == name || '' == name){
        Feng.error("icon名称不能为空");
        return
    }
    if(null == imgOneUrl || '' == imgOneUrl){
        Feng.error("icon图片1不能为空");
        return
    }
    if(null == imgTwoUrl || '' == imgTwoUrl){
        Feng.error("icon图片2不能为空");
        return
    }
    if(null == dateTime || '' == dateTime){
        Feng.error("生效周期不能为空");
        return
    }
    /*if(null == frequencyTime || '' == frequencyTime){
        Feng.error("投放频率不能为空");
        return
    }*/
    if((jumpType == 11) && content == ''){
        Feng.error("链接不能为空");
        return
    }
    if((jumpType == 6 || jumpType == 7) && objecCode == ''){
        Feng.error("数据ID不能为空");
        return
    }
    if(jumpType == 12 && content == ''){
        Feng.error("小程序链接不能为空");
        return
    }
    if(jumpType == 12 && appid == ''){
        Feng.error("小程序APPID不能为空");
        return
    }
    if(null == sort || '' == sort){
        Feng.error("权重排序不能为空");
        return
    }
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/icon/addIcon", function (data) {
        if(data.code == 200){
            Feng.success("添加成功!");
            window.parent.Icon.table.refresh();
            IconInfo.close();
        }else{
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set({
        name: name,
        imgOneUrl: imgOneUrl,
        imgTwoUrl: imgTwoUrl,
        startTime: dateTime.split(' - ')[0],
        endTime: dateTime.split(' - ')[1],
        jumpType: jumpType,
        content: content,
        appid: appid,
        sort: sort,
        isLogin: isLogin,
        objecCode: objecCode,
        position: position,
        jumpClassification: jumpClassification,
        frequency: frequency,
        frequencyTime: JSON.stringify(frequencyTime),
        pointTime: JSON.stringify(pointTime),
        exposureProvinceCode: exposureProvinceCode,
        exposureCityCode: exposureCityCode,
        exposureDistrictCode: exposureDistrictCode,
        exposureProvince: exposureProvince,
        exposureCity: exposureCity,
        exposureDistrict: exposureDistrict,
        exposureCrowd: IconInfo.exposureCrowd
    });
    ajax.start();
};
 
/**
 * 提交修改
 */
IconInfo.editSubmit = function () {
 
    const name = $('#name').val();
    const imgOneUrl = $('#imgOneUrl').val();
    const imgTwoUrl = $('#imgTwoUrl').val();
    const dateTime = $('#dateTime').val();
    const jumpType = $('#jumpType').val();
    const content = $('#content').val();
    const sort = $('#sort').val();
    const objecCode = $('#objecCode').val();
    const appid = $('#appid').val();
    const isLogin = $('#isLogin').val();
    const position = $('#position').val();
    const jumpClassification = $('#jumpClassification').val();
    const frequency = $('#frequency').val();
    const zhouSelectpicker = $('#zhouSelectpicker').find("select").val();
    const yueSelectpicker = $('#yueSelectpicker').find("select").val();
    var frequencyTime="";
    if(frequency==1){//周
        frequencyTime=zhouSelectpicker==null?[]:zhouSelectpicker;
    }else {
        frequencyTime=yueSelectpicker==null?[]:yueSelectpicker;
    }
    var pointTime = [];
    $(".pointTime").each(function(){
        pointTime.push($(this).val());
    });
    var exposureProvince = $('#province').find("option:selected").text();
    var exposureProvinceCode = $('#province').find("option:selected").attr("code");
    var exposureCity =$('#city').find("option:selected").text();
    var exposureCityCode =$('#city').find("option:selected").attr("code");
    var exposureDistrict = $('#district').find("option:selected").text();
    var exposureDistrictCode = $('#district').find("option:selected").attr("code");
    if(exposureProvince=="请选择"){
        exposureProvince='';
    }
    if(exposureCity=="请选择"){
        exposureCity='';
    }
    if(exposureDistrict=="请选择"){
        exposureDistrict='';
    }
    if(null == name || '' == name){
        Feng.error("icon名称不能为空");
        return
    }
    if(null == imgOneUrl || '' == imgOneUrl){
        Feng.error("icon图片1不能为空");
        return
    }
    if(null == imgTwoUrl || '' == imgTwoUrl){
        Feng.error("icon图片2不能为空");
        return
    }
    if(null == dateTime || '' == dateTime){
        Feng.error("生效周期不能为空");
        return
    }
    /*if(null == frequencyTime || '' == frequencyTime){
        Feng.error("投放频率不能为空");
        return
    }*/
    if((jumpType == 11) && content == ''){
        Feng.error("链接不能为空");
        return
    }
    if((jumpType == 6 || jumpType == 7) && objecCode == ''){
        Feng.error("数据ID不能为空");
        return
    }
    if(jumpType == 12 && content == ''){
        Feng.error("小程序链接不能为空");
        return
    }
    if(jumpType == 12 && appid == ''){
        Feng.error("小程序APPID不能为空");
        return
    }
    if(null == sort || '' == sort){
        Feng.error("权重排序不能为空");
        return
    }
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/icon/editIcon", function (data) {
        if(data.code == 200){
            Feng.success("添加成功!");
            window.parent.Icon.table.refresh();
            IconInfo.close();
        }else{
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set({
        id: $('#id').val(),
        name: name,
        imgOneUrl: imgOneUrl,
        imgTwoUrl: imgTwoUrl,
        startTime: dateTime.split(' - ')[0],
        endTime: dateTime.split(' - ')[1],
        jumpType: jumpType,
        content: content,
        appid: appid,
        sort: sort,
        isLogin: isLogin,
        objecCode: objecCode,
        position: position,
        jumpClassification: jumpClassification,
        frequency: frequency,
        frequencyTime: JSON.stringify(frequencyTime),
        pointTime: JSON.stringify(pointTime),
        exposureProvinceCode: exposureProvinceCode,
        exposureCityCode: exposureCityCode,
        exposureDistrictCode: exposureDistrictCode,
        exposureProvince: exposureProvince,
        exposureCity: exposureCity,
        exposureDistrict: exposureDistrict,
        exposureCrowd: IconInfo.exposureCrowd
    });
    ajax.start();
};
 
IconInfo.showExposureCrowd = function(){
    var index = layer.open({
        type: 2,
        title: '用户标签设置',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/exposureCrowd/showExposureCrowd?objectType=3&id=' + $('#id').val() + "&page=IconInfo"
    });
    this.layerIndex = index;
}
 
 
//投放时间点添加
IconInfo.addPointTime = function(){
    var pointTimeDiv='<div class="form-group">\n' +
        '                        <label class="col-sm-3 control-label"></label>\n' +
        '                        <div class="col-sm-2">\n' +
        '                            <input class="form-control pointTime">\n' +
        '                        </div>\n' +
        '                        <div class="col-sm-1">\n' +
        '                            <i class="fa fa-minus-square" onclick="BannerInfo.subtractPointTime(this)" style="font-size:24px"></i>\n' +
        '                        </div>\n' +
        '                    </div>';
    $(".pointTime").last().parent().parent().after(pointTimeDiv);
    //初始化时间选择器
    $('.pointTime').each(function (e, i) {
        layui.use('laydate', function() {
            var laydate = layui.laydate;
            laydate.render({
                // 绑定元素
                elem: i,
                // 类型:时间
                type: 'time',
                range:true,
                // 格式:时分秒
                format: 'HH:mm:ss',
 
            });
        });
    });
}
 
//投放时间点删除
IconInfo.subtractPointTime = function(e){
    $(e).parent().parent().remove();
}
 
 
//选择城市
IconInfo.selectCity=function(e,name,val){
    var parentId=$(e).val();
    var ajax = new $ax(Feng.ctxPath + "/region/cityList", function(data){
        if(data!=null){
            var content="<option value='-1'>请选择</option>";
            $.each(data, function(k,v) {
                if(val==v.name){
                    content += "<option value='"+v.id+"' code='"+v.code+"' selected>"+v.name+"</option>";
                }else{
                    content += "<option value='"+v.id+"' code='"+v.code+"' >"+v.name+"</option>";
                }
 
            });
            $("#"+name+"").empty().append(content);
        }
    });
    ajax.set("parentId",parentId);
    ajax.start();
}
 
 
$(function () {
    // 初始化头像上传
    var avatarUp = new $WebUpload("imgOneUrl");
    avatarUp.setUploadBarId("progressBarOne");
    avatarUp.init();
 
    // 初始化头像上传
    var avatarUp = new $WebUpload("imgTwoUrl");
    avatarUp.setUploadBarId("progressBarTwo");
    avatarUp.init();
 
    $('#jumpType').on('change', function () {
        const v = $(this).val();
        if(v == 0 || v == 1 || v == 2 || v == 3 || v == 4 || v == 9 || v == 10 || v == 13 || v == 14){
            $('#link').hide();
            $('#appidDiv').hide();
            $('#dataCode').hide();
            $('#link input').val('');
            $('#dataCode input').val('');
            $('#appidDiv input').val('');
        }
        if(v == 5 || v == 6 || v == 7 || v == 15){
            $('#link').hide();
            $('#appidDiv').hide();
            $('#dataCode').show();
            $('#link input').val('');
            $('#appidDiv input').val('');
            if(v == 6 || v == 7){
                $('#dataCode').find('label').empty().append('<span style="color: red">*</span>数据ID');
            }else {
                $('#dataCode').find('label').text('数据ID');
            }
        }
        if(v == 11){
            $('#link').show();
            $('#appidDiv').hide();
            $('#dataCode').hide();
            $('#appidDiv input').val('');
            $('#dataCode input').val('');
        }
        if(v == 12){
            $('#link').show();
            $('#appidDiv').show();
            $('#dataCode').hide();
            $('#dataCode input').val('');
        }
        if(v == 8){
            $('#link').hide();
            $('#appidDiv').hide();
            $('#dataCode').show();
            $('#link input').val('');
            $('#appidDiv input').val('');
            $('#dataCode').find('label').text('商品编码');
        }
    })
 
 
    if($('#id').val() != ''){
        $('#jumpType').change();
    }
 
    //投放频率切换
    $('#frequency').on('change', function () {
        var  frequencyVal = $(this).val();
        $(".selectpicker").selectpicker('val',"");
        if(frequencyVal==2){
            $("#zhouSelectpicker").hide();
            $("#yueSelectpicker").show();
            $("#nullSelectpicker").hide();
        }else if(frequencyVal==1){
            $("#zhouSelectpicker").show();
            $("#yueSelectpicker").hide();
            $("#nullSelectpicker").hide();
        }else{
            $("#zhouSelectpicker").hide();
            $("#yueSelectpicker").hide();
            $("#nullSelectpicker").show();
        }
    })
    //跳转类型切换
    $('#jumpClassification').on('change', function () {
        var  jumpClassificationVal = $(this).val();
        var jumpHtml = "";
        var jumpTypeInput = $("#jumpTypeInput").val();
        if(jumpClassificationVal==1){
            jumpHtml =
                '                            <option value="5">券包</option>\n' +
                '                            <option value="6">促销活动</option>\n' +
                '                            <option value="7">集点活动</option>\n' +
                '                            <option value="15">领券活动</option>';
        }else if(jumpClassificationVal==2){
            jumpHtml =
                '                            <option value="1">签到</option>\n' +
                '                            <option value="2">会员权益</option>\n' +
                '                            <option value="3">任务中心</option>\n' +
                '                            <!--<option value="4">我的</option>-->\n' +
                '                            <!--<option value="16">我的优惠券</option>-->\n' +
                '                            <option value="17">我的任务</option>\n' +
                '                            <option value="18">我的订单</option>';
        }else if(jumpClassificationVal==3){
            jumpHtml =
                '                            <option value="8">积分商城</option>\n' +
                '                            <option value="9">我的优惠券列表</option>\n' +
                '                            <option value="10">加油站首页</option>\n' +
                '                            <option value="13">一键加油</option>\n' +
                '                            <option value="14">开发票</option>\n' +
                '                            <option value="11">外部H5</option>\n' +
                '                            <option value="12">外部小程序</option>';
        }else if(jumpClassificationVal==4){
            jumpHtml = '<option value="0">不跳转</option>';
        }
        $("#jumpType").empty().append(jumpHtml);
        $("#jumpType option[value="+jumpTypeInput+"]").prop("selected","selected");
        $("#jumpType").trigger("change");
    })
    $("#jumpClassification").trigger("change");
    $("#jumpType").trigger("change");
    //省市区初始化
    IconInfo.selectCity($("#province"),"province",$('#provinceInput').val());
    $("#province").trigger("change");
    $("#city").trigger("change");
    //编辑回显投放频率类型
    var frequencyInput = $('#frequencyInput').val();
    if(frequencyInput==2){
        $("#zhouSelectpicker").hide();
        $("#yueSelectpicker").show();
        $("#nullSelectpicker").hide();
    }else if(frequencyInput==1){
        $("#zhouSelectpicker").show();
        $("#yueSelectpicker").hide();
        $("#nullSelectpicker").hide();
    }else{
        $("#zhouSelectpicker").hide();
        $("#yueSelectpicker").hide();
        $("#nullSelectpicker").show();
    }
    //编辑回显投放频率时间
    var obj = eval('(' + $("#frequencyTimeInput").val() + ')');
    $(".selectpicker").selectpicker('val',obj );
});