yanghb
2023-04-10 b2f678ad387ca24e05a11100ea4583f0f2f730f0
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
/**
 * 初始化车辆品牌管理详情对话框
 */
 
var ids = null;
 
var tdArrList = new Array();
var couponData = [];
 
var MerchantActivityInfoDlg = {
    merchantActivityInfoData: {},
    validateFields: {
        name: {
            validators: {
                notEmpty: {
                    message: '活动标题不能为空'
                }
            }
        },
    }
};
 
 
/**
 * 验证数据是否为空
 */
MerchantActivityInfoDlg.validate = function () {
    $('#merchantActivityForm').data("bootstrapValidator").resetForm();
    $('#merchantActivityForm').bootstrapValidator('validate');
    return $("#merchantActivityForm").data('bootstrapValidator').isValid();
};
 
/**
 * 清除数据
 */
MerchantActivityInfoDlg.clearData = function () {
    this.merchantActivityInfoData = {};
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
MerchantActivityInfoDlg.set = function (key, val) {
    this.merchantActivityInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
MerchantActivityInfoDlg.get = function (key) {
    return $("#" + key).val();
}
 
/**
 * 关闭此对话框
 */
MerchantActivityInfoDlg.close = function () {
 
    if (window.parent.MerchantActivity != null) {
        parent.layer.close(window.parent.MerchantActivity.layerIndex);
    } else
        parent.layer.close(window.parent.MerchantActivityExamine.layerIndex);
 
}
 
/**
 * 收集数据
 */
MerchantActivityInfoDlg.collectData = function () {
    this
        .set('id')
        .set('name')
        .set('merchantId')
        .set('companyType')
        .set('companyId')
        .set('activityType')
        .set('name')
        .set('orderType')
        .set('type')
        .set('orderAmountFull')
        .set('orderNumber')
        .set('effectiveDays')
        .set('auditStatus')
        .set('auditNote')
        .set('auditUserId')
        .set('auditTime')
        .set('status')
        .set('state')
        .set('state')
        .set('merchantActivitySlaveList')
        .set('merchantAll')
        .set('createTime');
}
 
/**
 * 提交添加
 */
MerchantActivityInfoDlg.addSubmit = function () {
 
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    var merchantIds = "";
    var merchantIdAll = $("#merchantIdAll").val();
    if (merchantIdAll == null) {
        Feng.error("请选择商家");
        return
    }
    for (var i = 0; i < merchantIdAll.length; i++) {
        if (i > 0) {
            merchantIds += ",";
        }
        merchantIds += merchantIdAll[i]
    }
    this.set("merchantIds", merchantIds);
 
 
    var orderTypeAll = $("#orderType").val();
    if (orderTypeAll == null) {
        Feng.info("请选择叫车类型");
        return;
    }
    var orderType = "";
    for (var i = 0; i < orderTypeAll.length; i++) {
        if (i > 0) {
            orderType += ",";
        }
        orderType += orderTypeAll[i];
    }
    this.set("orderType", orderType);
 
 
    this.set("merchantActivitySlaveList", tdArrList);
    this.set("type", $("#type").val());
 
    var orderAmountFull = $("#orderAmountFull").val();
    var orderNumber = $("#orderNumber").val();
 
    if ((orderAmountFull == null || orderAmountFull == "") && (orderNumber == null || orderNumber == "")) {
        Feng.info("请填写完成订单金额或者完成订单数量");
        return;
    }
    var effectiveDays = $("#effectiveDays").val();
    if (effectiveDays == null || effectiveDays == "") {
        Feng.info("请输入活动有效天数");
        return;
    }
    if (!priceParameter()) {
        return
    }
    var data = this.merchantActivityInfoData;
    $.ajax({
        url: Feng.ctxPath + "/merchantActivity/add",
        type: "post",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(data),
        success: function (json) {
            if (json.code == 200) {
                Feng.success("添加成功!");
                window.parent.MerchantActivity.table.refresh();
                MerchantActivityInfoDlg.close();
            } else {
                Feng.error("修改失败!" + json.message + "!");
            }
        }
    });
}
 
/**
 * 提交修改
 */
MerchantActivityInfoDlg.editSubmit = function () {
 
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    var merchantId = $("#merchantId").valueOf();
    if ("" == merchantId) {
        Feng.info("请选择商家");
        return;
    }
    MerchantActivityInfoDlg.set("content", MerchantActivityInfoDlg.editor.getContent());
    //提交信息
 
    var ajax = new $ax(Feng.ctxPath + "/merchantActivity/update", function (data) {
        Feng.success("修改成功!");
        window.parent.MerchantActivity.table.refresh();
        MerchantActivityInfoDlg.close();
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.merchantActivityInfoData);
    ajax.start();
}
 
 
MerchantActivityInfoDlg.choiceCouponAll = function (val, type) {
    ids = "";
    couponData = [];
    for (var i = 0; i < val.length; i++) {
        if (i > 0) {
            ids += ",";
        }
        ids += val[i].id;
    }
    couponData = val;
 
    initializeTable(type, val);
};
 
/**
 * 表格数据展示
 * @param type
 * @param val
 */
function initializeTable(type, val) {
    var str = "";
    if (type == 1) {
        for (var i in val) {
            str += '<tr><td style="display: none">' + val[i].id + '</td>' +
                '<td style="display: none">' + val[i].merchantId + '</td>' +
                '<td>' + val[i].merchantName + '</td>' +
                '<td>' + val[i].name + '</td>' +
                '<td>' + "满" + val[i].fullAmount + "减" + val[i].discount + "券" + '</td>' +
                '<td><input id="num+' + i + '" type=\"number\" style="width: 100px;text-align: center" /> </td>' +
                '</tr>';
        }
        $("#table").html("<th>所属商家</th><th>商家券名称</th><th>优惠金额</th><th>张数</th>");
        $("#tableList").html(str);
    }
    if (type == 2) {
        for (var i in val) {
            str += '<tr><td style="display: none">' + val[i].id + '</td>' +
                '<td style="display: none">' + val[i].merchantId + '</td>' +
                '<td>' + val[i].merchantName + '</td>' +
                '<td>' + val[i].name + '</td>' +
                '<td><input id="num+' + i + '" type=\"number\" style="width: 100px;text-align: center" /> </td>' +
                '</tr>';
        }
        $("#table").html("<th>所属商家</th><th>商家券名称</th><th>张数</th>");
        $("#tableList").html(str);
    }
}
 
/**
 * 跳转选择商家券/商品券
 * @param type
 */
MerchantActivityInfoDlg.choiceCoupon = function (type) {
    var merchantIds = "";
 
    if (ids == null || ids == "undefined") {
        ids = 0;
    }
    var merchantIdAll = $("#merchantIdAll").val();
    if (merchantIdAll == null) {
        Feng.error("请选择商家");
        return
    }
 
    for (var i = 0; i < merchantIdAll.length; i++) {
        if (i > 0) {
            merchantIds += ",";
        }
        merchantIds += merchantIdAll[i]
    }
    var title = "商家券选择";
    if (type == 2) {
        title = "商品券选择";
    }
    var index = layer.open({
        type: 2,
        title: title,
        fix: false, //不固定
        area: ['80%', '80%'], //宽高
        maxmin: true,
        content: Feng.ctxPath + '/merchantActivity/choiceCoupon?ids=' + ids + "&type=" + type + "&merchantIds=" + merchantIds
    });
    this.layerIndex = index;
};
 
 
function priceParameter() {
 
    var trList = $("#tableList").children("tr");
    if (trList.length < 1) {
        Feng.error("请选择商家券");
        return false;
    }
 
    for (var i = 0; i < trList.length; i++) {
        var num = "";
        var tdArr = new Array();
        var tdArr = trList.eq(i).find("td");
 
        var id = tdArr.eq(0).text();//id
        var merchantId = tdArr.eq(1).text();//merchantId
        var value1 = tdArr.eq(4).find('input').val();//数量
        var value = tdArr.eq(5).find('input').val();//数量
 
        if ($("#type").val() == 1) {
            num = value;
            if (value == null || value == '') {
                Feng.error("请输入优惠券的张数");
                return false;
            }
        }
        if ($("#type").val() == 2) {
            num = value1;
            if (value1 == null || value1 == '') {
                Feng.error("请输入优惠券的张数");
                return false;
            }
        }
        var data = {
            "merchantCouponId": id,//商家卷Id
            "merchantId": merchantId,//商家卷Id
            "totalNumber": num//数量
        };
        tdArrList.push(data)
    }
    return true;
}
 
/**
 * 选择商家重置商家券数据
 */
function merchantChoice() {
    var merchantIds = [];
    var merchantIdAll = $("#merchantIdAll").val();
    for (var i = 0; i < merchantIdAll.length; i++) {
        merchantIds.push(merchantIdAll[i])
    }
    var dataList = [];
    for (var i = 0; i < merchantIds.length; i++) {
        for (var j = 0; j < couponData.length; j++) {
            if (merchantIds[i] == couponData[j].merchantId) {
                dataList.push(couponData[j]);
            }
        }
    }
    couponData = dataList;
    if (dataList.length > 0) {
        MerchantActivityInfoDlg.choiceCouponAll(dataList, dataList[0].type)
    }
}
 
/**
 * 选择券类型——重置表格数据
 */
function typeChoice() {
 
    var vs = $("#type").val();
 
    if (vs == 1) {
        couponData=[];
 
        $("#volume1").show();
        $("#volume2").hide();
        $(".volume2").hide();
 
        ids = null;
        $("#table").html("<th>所属商家</th><th>商家券名称</th><th>优惠金额</th><th>张数</th>");
        $("#tableList").html("");
    }
    if (vs == 2) {
        couponData=[];
 
        $("#volume2").show();
        $(".volume2").show();
        $("#volume1").hide();
 
        ids = null;
        $("#table").html("<th>所属商家</th><th>商家券名称</th><th>张数</th>");
        $("#tableList").html("");
    }
}
 
 
$(function () {
 
    Feng.initValidator("merchantActivityForm", MerchantActivityInfoDlg.validateFields);
 
    $("#merchantId").val($("#merchantId_").val())
 
    $("#orderType").val($("#asList").val())
 
});