无关风月
2025-03-20 2ad97245d64b65132507cab36ad89d968edb7705
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
/**
 * 用户详情对话框(可用于添加和修改对话框)
 */
var CouponInfo = {
    userInfoData: {},
    layerIndex: -1,
    exposureCrowd: $('#exposureCrowd').val()
};
 
var editor = null;
 
/**
 * 关闭此对话框
 */
CouponInfo.close = function () {
    parent.layer.close(window.parent.Coupon.layerIndex);
};
 
 
/**
 * 提交添加coupon
 */
CouponInfo.addSubmit = function () {
    const img = $('#img').val();
    const name = $('#name').val();
    const code = $('#code').val();
    const listDescribe = $('#listDescribe').val();
    const infoDescribe = $('#infoDescribe').val();
    const price = $('#price').val();
    const unitPrice = $('#unitPrice').val();
    const total = $('#total').val();
    const startNumber = $('#startNumber').val();
    const restrictedQuantity = $('#restrictedQuantity').val();
    const seckillState = $('#seckillState').val();
    const activityPrice = $('#activityPrice').val();
    const dateTime = $('#dateTime').val();
    const forwardShareState = $('#forwardShareState').val();
    const backgroundImg = $('#backgroundImg').val();
    const purchaseInstructions = editor.getContent();
 
    const number = $("#number").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());
    });
 
    if(null == img || '' == img){
        Feng.error("图片不能为空");
        return
    }
    if(null == name || '' == name){
        Feng.error("券包名称不能为空");
        return
    }
    if(null == code || '' == code){
        Feng.error("券包模板ID不能为空");
        return
    }
    if(null == listDescribe || '' == listDescribe){
        Feng.error("列表描述不能为空");
        return
    }
    if(null == infoDescribe || '' == infoDescribe){
        Feng.error("详情描述不能为空");
        return
    }
    if(null == price || '' == price){
        Feng.error("券包价值不能为空");
        return
    }
    if(null == number || '' == number){
        Feng.error("发放数量不能为空");
        return
    }
    if(number > 5){
        Feng.error("发放数量不能大于5张")
        return
    }
    if(null == unitPrice || '' == unitPrice){
        Feng.error("券包价格不能为空");
        return
    }
    if(null == total || '' == total){
        Feng.error("数量上限不能为空");
        return
    }
    if(null == startNumber || '' == startNumber){
        Feng.error("已购买起始人数不能为空");
        return
    }
    if(null == restrictedQuantity || '' == restrictedQuantity){
        Feng.error("单人限购不能为空");
        return
    }
    if(1 == seckillState && (null == activityPrice || '' == activityPrice)){
        Feng.error("活动价格不能为空");
        return
    }
    if(1 == seckillState && (null == dateTime || '' == dateTime)){
        Feng.error("活动时间周期不能为空");
        return
    }
    if(1 == forwardShareState && (null == backgroundImg || '' == backgroundImg)){
        Feng.error("分享页主页背景不能为空");
        return
    }
    if(null == purchaseInstructions || '' == purchaseInstructions){
        Feng.error("购买须知不能为空");
        return
    }
    let obj = {
        img: img,
        name: name,
        code: code,
        listDescribe: listDescribe,
        infoDescribe: infoDescribe,
        price: price,
        unitPrice: unitPrice,
        total: total,
        startNumber: startNumber,
        restrictedQuantity: restrictedQuantity,
        seckillState: seckillState,
        activityPrice: activityPrice,
        forwardShareState: forwardShareState,
        backgroundImg: backgroundImg,
        purchaseInstructions: purchaseInstructions,
        frequency: frequency,
        frequencyTime: JSON.stringify(frequencyTime),
        pointTime: JSON.stringify(pointTime),
        number: number,
        exposureCrowd: CouponInfo.exposureCrowd
    }
    if(null != dateTime && '' != dateTime){
        obj.activityStartTime = dateTime.split(' - ')[0];
        obj.activityEndTime = dateTime.split(' - ')[1];
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/coupon/addCoupon", function (data) {
        if(data.code == 200){
            Feng.success("添加成功!");
            window.parent.Coupon.table.refresh();
            CouponInfo.close();
        }else{
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(obj);
    ajax.start();
};
 
/**
 * 提交修改
 */
CouponInfo.editSubmit = function () {
    const img = $('#img').val();
    const name = $('#name').val();
    const code = $('#code').val();
    const listDescribe = $('#listDescribe').val();
    const infoDescribe = $('#infoDescribe').val();
    const price = $('#price').val();
    const unitPrice = $('#unitPrice').val();
    const total = $('#total').val();
    const startNumber = $('#startNumber').val();
    const restrictedQuantity = $('#restrictedQuantity').val();
    const seckillState = $('#seckillState').val();
    const activityPrice = $('#activityPrice').val();
    const dateTime = $('#dateTime').val();
    const forwardShareState = $('#forwardShareState').val();
    const backgroundImg = $('#backgroundImg').val();
    const purchaseInstructions = editor.getContent();
 
    const number = $("#number").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());
    });
 
    if(null == img || '' == img){
        Feng.error("图片不能为空");
        return
    }
    if(null == name || '' == name){
        Feng.error("券包名称不能为空");
        return
    }
    if(null == code || '' == code){
        Feng.error("券包模板ID不能为空");
        return
    }
    if(null == listDescribe || '' == listDescribe){
        Feng.error("列表描述不能为空");
        return
    }
    if(null == infoDescribe || '' == infoDescribe){
        Feng.error("详情描述不能为空");
        return
    }
    if(null == price || '' == price){
        Feng.error("券包价值不能为空");
        return
    }
    if(null == number || '' == number){
        Feng.error("发放数量不能为空");
        return
    }
    if(number > 5){
        Feng.error("发放数量不能大于5张")
        return
    }
 
    if(null == unitPrice || '' == unitPrice){
        Feng.error("券包价格不能为空");
        return
    }
    if(null == total || '' == total){
        Feng.error("数量上限不能为空");
        return
    }
    if(null == startNumber || '' == startNumber){
        Feng.error("已购买起始人数不能为空");
        return
    }
    if(null == restrictedQuantity || '' == restrictedQuantity){
        Feng.error("单人限购不能为空");
        return
    }
    if(1 == seckillState && (null == activityPrice || '' == activityPrice)){
        Feng.error("活动价格不能为空");
        return
    }
    if(1 == seckillState && (null == dateTime || '' == dateTime)){
        Feng.error("活动时间周期不能为空");
        return
    }
    if(1 == forwardShareState && (null == backgroundImg || '' == backgroundImg)){
        Feng.error("分享页主页背景不能为空");
        return
    }
    if(null == purchaseInstructions || '' == purchaseInstructions){
        Feng.error("购买须知不能为空");
        return
    }
    let obj = {
        id: $('#id').val(),
        img: img,
        name: name,
        code: code,
        listDescribe: listDescribe,
        infoDescribe: infoDescribe,
        price: price,
        unitPrice: unitPrice,
        total: total,
        startNumber: startNumber,
        restrictedQuantity: restrictedQuantity,
        seckillState: seckillState,
        activityPrice: activityPrice,
        forwardShareState: forwardShareState,
        backgroundImg: backgroundImg,
        purchaseInstructions: purchaseInstructions,
        frequency: frequency,
        frequencyTime: JSON.stringify(frequencyTime),
        pointTime: JSON.stringify(pointTime),
        number: number,
        exposureCrowd: CouponInfo.exposureCrowd
    }
    if(null != dateTime && '' != dateTime){
        obj.activityStartTime = dateTime.split(' - ')[0];
        obj.activityEndTime = dateTime.split(' - ')[1];
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/coupon/editCoupon", function (data) {
        if(data.code == 200){
            Feng.success("编辑成功!");
            window.parent.Coupon.table.refresh();
            CouponInfo.close();
        }else{
            Feng.error(data.msg);
        }
    }, function (data) {
        Feng.error("编辑失败!" + data.responseJSON.message + "!");
    });
    ajax.set(obj);
    ajax.start();
};
 
 
CouponInfo.showExposureCrowd = function(){
    var index = layer.open({
        type: 2,
        title: '用户标签设置',
        area: ['100%', '100%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/exposureCrowd/showExposureCrowd?objectType=2&id=' + $('#id').val() + "&page=CouponInfo"
    });
    this.layerIndex = index;
}
 
 
//投放时间点添加
CouponInfo.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="CouponInfo.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',
 
            });
        });
    });
}
 
//投放时间点删除
CouponInfo.subtractPointTime = function(e){
    $(e).parent().parent().remove();
}
 
$(function () {
    // 初始化头像上传
    var avatarUp = new $WebUpload("img");
    avatarUp.setUploadBarId("progressBar");
    avatarUp.init();
    var avatarUp = new $WebUpload("backgroundImg");
    avatarUp.setUploadBarId("progressBar");
    avatarUp.init();
 
    editor = UE.getEditor('editor');
    // 手动指定上传文件调用的接口(不同文件类型不同接口)
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        // 这里很重要,很重要,很重要,要和配置中的imageActionName值一样
        if(action == 'uploadimage'){
            // 这里调用后端我们写的图片上传接口
            return '/ueditor/uploadImageData';
        }else if(action == 'uploadfile'){
            return '/ueditor/uploadFileData';
        }else{
            return this._bkGetActionUrl.call(this, action);
        }
    }
 
 
    $('#seckillState').on('change', function () {
        const v = $(this).val();
        if(v == 0){
            $('#seckill').hide();
            $('#activityPrice').val('');
            $('#dateTime').val('');
        }
        if(v == 1){
            $('#seckill').show();
        }
    })
    $('#forwardShareState').on('change', function () {
        const v = $(this).val();
        if(v == 0){
            $('#forwardShare').hide();
        }
        if(v == 1){
            $('#forwardShare').show();
            var avatarUp = new $WebUpload("backgroundImg");
            avatarUp.setUploadBarId("progressBar");
            avatarUp.init();
        }
    })
 
    if($('#id').val() != ''){
        editor.ready(function() {
            editor.setContent($('#purchaseInstructions').val())
        });
    }
 
    //投放频率切换
    $('#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();
        }
    })
    //编辑回显投放频率类型
    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 );
});