lisy
2023-08-07 aca52db249c7ddcd84e1d4125573a6bb3524670f
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
/**
 * 初始化详情对话框
 */
var couponInfoDlg = {
    couponInfoData: {},
    goodsPicArray: [], //商品图片数组
    goodsCover: '', //商品封面图
    storeIds: [],
};
 
/**
 * 清除数据
 */
couponInfoDlg.clearData = function () {
    this.couponInfoData = {};
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
couponInfoDlg.set = function (key, val) {
    this.couponInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
couponInfoDlg.get = function (key) {
    return $("#" + key).val();
}
 
/**
 * 关闭此对话框
 */
couponInfoDlg.close = function () {
    parent.layer.close(window.parent.TCoupon.layerIndex);
}
 
 
/**
 * 兑换方式1
 */
function exchangeMethod1() {
    $("#needAmount").hide();
    $("#needIntegral").show();
    $('#requiredPoints').val('');
    $('#requiredCash').val('');
}
 
/**
 * 兑换方式2
 */
function exchangeMethod2() {
    $("#needAmount").show();
    $("#needIntegral").show();
    $('#requiredPoints').val('');
    $('#requiredCash').val('');
}
 
/**
 * 兑换方式3
 */
function exchangeMethod3() {
    $("#needAmount").show();
    $("#needIntegral").hide();
    $('#requiredPoints').val('');
    $('#requiredCash').val('');
}
 
/**
 * 全国通用
 */
function scopeOfApplication1() {
    $("#storeSelect").hide();
    $("#citySelect").hide();
}
/**
 * 指定城市
 */
function scopeOfApplication2() {
    $("#storeSelect").hide();
    $("#citySelect").show();
}
/**
 * 指定门店
 */
function scopeOfApplication3() {
    $("#storeSelect").show();
    $("#citySelect").hide();
}
 
/**
 * 满减券
 */
function radio1() {
    $("#conditionalAmount").removeAttr("disabled");
    $("#deductionAmount").removeAttr("disabled");
 
    $("#voucherAmount").val('')
    $("#voucherAmount").attr('disabled', 'disabled');
 
    $("#experienceName").val('')
    $("#experienceName").attr('disabled', 'disabled');
}
 
/**
 * 代金券
 */
function radio2() {
    $("#voucherAmount").removeAttr("disabled");
 
    $("#conditionalAmount").val('')
    $("#deductionAmount").val('')
    $("#deductionAmount").attr('disabled', 'disabled');
    $("#conditionalAmount").attr('disabled', 'disabled');
 
    $("#experienceName").val('')
    $("#experienceName").attr('disabled', 'disabled');
 
}
 
/**
 * 体验券
 */
function radio3() {
    $("#experienceName").removeAttr("disabled");
 
    $("#conditionalAmount").val('')
    $("#deductionAmount").val('')
    $("#deductionAmount").attr('disabled', 'disabled');
    $("#conditionalAmount").attr('disabled', 'disabled');
 
    $("#voucherAmount").val('')
    $("#voucherAmount").attr('disabled', 'disabled');
 
}
 
 
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){
        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();
}
 
function storeList(){
    var index = layer.open({
        type: 2,
        title: '门店列表',
        area: ['80%', '80%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/tCouponManage/storeList'
    });
    this.layerIndex = index;
}
 
 
var num = 0;
couponInfoDlg.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=\"couponInfoDlg.delete(this)\" style=\"border: 0px;cursor: pointer;margin-top: 1%\"><i class=\"fa fa-trash\"></i></label>"+
        "                        </div>";
    $("#cityDemo").append($(a));
    getProvince(num);
}
 
 
 
couponInfoDlg.delete = function (o) {
    $(o).parent("div").remove()
}
 
/**
 * 提交
 */
couponInfoDlg.addSubmit = function () {
 
    var cityIds = [];
    // 优惠券名称
    var couponName = $('#name').val();
    // 优惠券类型
    var prescription = $('#prescription').val();
    // 说明
    var illustrate = $('#illustrate').val();
    // 发放方式
    var distributionMethod = $('#distributionMethod').val();
    // 所需积分
    var requiredPoints = $('#requiredPoints').val();
    // 用户人群
    let userGroup = $(':radio[name="userGroup"]:checked').val();
 
    // 发放数量
    var quantityIssued = $('#quantityIssued').val();
    // 限领数量
    var pickUpQuantity = $('#pickUpQuantity').val();
    // 有效期
    var periodOfValidity = $('#periodOfValidity').val();
 
    let exchangeMethod = $(':radio[name="exchangeMethod"]:checked').val();
 
    var requiredCash = $('#requiredCash').val();
 
    var company = $('#company').val();
    if (company === '2'){
        var myselect=document.getElementById('cityData');
        var seCity = myselect.options[myselect.selectedIndex].value;
        if (seCity === null || seCity === undefined || seCity === ''){
            return Feng.error('请选中一个省市');
        }
        cityIds.push(seCity);
        if (this.num > 0){
            for (let i = 1; i <= num; i++) {
                var insSelect=document.getElementById('cityData'+i);
                var inData = insSelect.options[insSelect.selectedIndex].value;
                if (inData !== undefined || inData !== null ||  inData !== ''){
                    cityIds.push(inData);
                }
            }
        }
    }
 
    if (company === '3'){
 
    }
 
    console.log('11111111')
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tCouponManage/commitData", function (data) {
        Feng.success("添加成功!");
        window.parent.TCoupon.table.refresh();
        couponInfoDlg.close();
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set("userType",1);
    ajax.set("cityManagerId",1);
    ajax.set("couponName",couponName);
    ajax.set("prescription",prescription);
    ajax.set("condition",$('#conditionalAmount').val());
    ajax.set("subtraction",$('#deductionAmount').val());
    ajax.set("discount",$('#voucherAmount').val());
    ajax.set("experience",$('#experienceName').val());
    ajax.set("illustrate",illustrate);
    ajax.set("distributionMethod",distributionMethod);
    ajax.set("requiredPoints",requiredPoints);
    ajax.set("requiredCash",requiredCash);
    ajax.set("userGroup",userGroup);
    ajax.set("quantityIssued",quantityIssued);
    ajax.set("pickUpQuantity",pickUpQuantity);
    ajax.set("periodOfValidity",periodOfValidity);
    ajax.set("exchangeMethod",exchangeMethod);
    ajax.set("goodImg",this.goodsCover);
    ajax.set("goodImgs",this.goodsPicArray);
    ajax.set("company",$('#company').val());
    ajax.set("cityIds",cityIds);
    ajax.set("storeIds",this.storeIds);
    ajax.start();
 
}
 
/**
 * 收集数据
 */
couponInfoDlg.collectData = function () {
    this
        .set('couponId')
        .set('name')
        .set('type')
        .set('typeName')
        .set('times')
        .set('sheetsNum')
        .set('auditStatus')
        .set('reason')
        .set('remark')
        .set('startTime')
        .set('endTime')
        .set('activityId')
        .set('createId')
        .set('createTime')
        .set('timeType')
        .set('expDay')
        .set('couponCode')
        .set('instructions')
        .set('belongs')
        .set('useTimes');
}
 
 
$(function () {
    getProvince(null);
    radio1();
    var userType = $('#userType').val();
    if (userType === '1'){
        // 兑换方式
        $('#exchangeType').show();
        $('#needAmount').show();
        $('#needIntegral').show();
        // 图片
        $('#app').show();
        $('#app1').show();
        // 适用范围
        $('#belongsCon').show();
        $('#belongsNationwide').show();
        $('#belongsCity').show();
        $('#belongsStore').show();
    }
    if (userType === '2'){
        $('#needIntegral').show();
        $('#belongsCon').show();
        $('#belongsStore').show();
        $('#storeSelect').show();
    }
});