couponList.js
9.44 KB
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
/**
* Created by ty on 2016/5/24.
*/
'use strict';
var $ = require('jquery'),
common = require('../common/common');
/**
* 全局变量
* departments 部门
* couponTypes 优惠券类型
* customTypes 用户类型
* ENUM tab参数
* @type {string[]}
*/
var departments = ["渠道二部", "渠道一部", "零售部", "品牌资源部", "店铺运营部", "类目运营部", "营销部", "市场部", "会员部 ", "客服部", "内容营销部"];
var couponTypes = ["A券", "B券", "公开券", "生日券", "免邮券"];
var useLimitTypes = ["无限制", "货物件数限制", "订单金额限制"];
var customTypes = ["新客户", "银卡会员", "金卡会员", "白金卡会员", "普通用户(不含新客)"];
var ENUM = {
status: {0: '待审核', 1: '审核通过', 2: '驳回', '-1': '过期', 3: '作废'},//全部
tips: {"0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "all": 0}
};
var columnname = "all";
/**
* 初始化下拉框
*/
new common.dropDown({el: '#filter-dep'});
common.util.__ajax({
url: "/coupon/queryList",//获取所有优惠券ID
data: {size: 1000}
}, function (res) {
$("#couponsIds").html(common.util.__template2($("#search-coupon").html(), res));
new common.dropDown({el: "#choose-coupon"});
}, true);
/**
* tab分页
*/
var t = new common.tab({
el: "#basicTab",
click: function () {
columnname = $(this).find('a').attr('columnname');
g.options.columns[6].hidden = true;
g.options.columns[7].hidden = true;
switch (columnname) {
case "1":
{
g.options.columns[8].hidden = true;
}
break;
case "2":
{
g.options.columns[6].hidden = false;
g.options.columns[8].hidden = true;
}
break;
case "3":
{
g.options.columns[7].hidden = false;
g.options.columns[8].hidden = true;
}
break;
case "all":
{
g.options.columns[8].hidden = false;
}
break;
}
g.init("/coupon/queryCouponList");
},
columns: [
{name: "all", display: "全部"},
{name: "1", display: "已通过"},
{name: "0", display: "待审核"},
{name: "2", display: "已驳回"},
{name: "3", display: "已作废"},
{name: "-1", display: "已过期"}
]
}).init(ENUM.tips);
/**
* 列表
* @type {common.grid}
*/
var g = new common.grid({
el: '#basicTable',
parms: function () {
return {
couponId: common.util.__input("choose-coupon"),
couponName: common.util.__input("filter-couponName"),
department: common.util.__input("filter-dep"),
status: t.active
};
},
columns: [
{display: "优惠券ID", name: "id"},
{
display: "基本信息", render: function (item) {
var arr = [];
arr.push("<p>名称:" + item.couponName + "</p>");
arr.push("<p>类型:" + couponTypes[item.couponType - 1] + "</p>");
arr.push("<p>优惠结果:" + item.couponAmount + "</p>");
arr.push("<p>数量:" + item.couponNum + "</p>");
arr.push("<p>部门:" + departments[item.department - 1] + "</p>");
return arr.join('');
}
},
{
display: "使用期限", render: function (item) {
var startTime = Bll.getTime(item.startTime);
var endTime = Bll.getTime(item.endTime);
return startTime + "</br> 至 " + endTime;
}
},
{
display: "使用条件", render: function (item) {
var str = "无限制";
if (item.useLimitType == 1) {
str = "件数满:" + item.useLimit;
} else if (item.useLimitType == 2) {
str = "金额满:" + item.useLimit;
}
return '<p style="max-width: 200px;word-wrap: break-word;">' + str + '</p>';
}
},
{display: "优惠券说明", name: "explains"},
{display: "申请人", name: "proposer"},
{
display: "驳回理由", hidden: true, name: "rejectReason", render: function (item) {
return "<p style='color: red'>" + item.rejectReason + "</p>"
}
},
{
display: "作废理由", hidden: true, name: "invalidReason", render: function (item) {
return "<p style='color: red'>" + item.invalidReason + "</p>"
}
},
{
display: '状态', render: function (item) {
var html = ENUM.status[item.status] || '全部';
if (item.reason) {
if (item.status == 2 || item.status == 4) {
html += '<p style="color:red;word-wrap: break-word;">(' + item.reason + ')</p>';
}
}
return html;
}
},
{
display: "操作", render: function (item) {
var HtmArr = [];
HtmArr = Bll.getButtons(item.__index, item.id, item.options);
return HtmArr.join('');
}
}
]
});
g.init("/coupon/queryCouponList");
/**
* 通用方法
* @type {{getTime: Function, toast: Function, toastInfo: Function}}
*/
var Bll = {
getTime: function (time) {
var t = new Date(time * 1000);
return common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
},
toast: function (content, url, data) {
common.dialog.confirm("温馨提示", content, function () {
common.util.__ajax({
url: url,
data: data()
}, function () {
g.reload();
},true);
});
},
toastPass: function (content, url, data) {
common.dialog.confirm("温馨提示", content, function () {
common.util.__ajax({
url: url,
data: data
}, function () {
g.reload();
},true);
});
},
toastInfo: function (item, hint) {
common.dialog({
title: hint,
content: common.util.__template2($("#templateInfo").html(), item),
width: "40%",
button: [{
value: '取消',
css: "btn btn-primary"
}
]
})
},
getButtons: function (index, id, array) {
var btns = [];
var buttons = [
'<a class="btn btn-warning btn-xs apply-back" data-index="' + index + '" >驳回</a>',
'<a class="btn btn-primary btn-xs apply-success" data-index="' + index + '" >通过</a>',
'<a class="btn btn-info btn-xs coupon-info" data-index="' + index + '">查看详情</a>',
'<a class="btn btn-info btn-xs apply-modify" data-index="' + index + '" href="/market/couponList/update/' + id + '">修改</a>',
'<a class="btn btn-danger btn-xs apply-cancel" data-index="' + index + '" >作废</a>'
];
for (var i = 0; i < array.length; i++) {
btns.push(buttons[array[i]])
}
return btns;
}
};
/**
* 筛选
*/
$("#filter-btn").click(function () {
g.reload(1);
});
//审核通过
$(document).on('click', '.apply-success', function () {
var item = g.rows[$(this).data("index")];
var data = {
couponId: item.id
};
Bll.toastPass("确定要通过该申请吗?", "/coupon/approve", data);
});
//驳回
$(document).on('click', '.apply-back', function () {
var item = g.rows[$(this).data("index")];
var data = function () {
var reason = $('#reason').val();
if (reason === '' || $.trim(reason) === '') {
return "请填写驳回原因";
}
return {
couponId: item.id,
rejectReason: reason
};
};
Bll.toast(common.util.__template2($("#template").html(), {name: "你确定要驳回该申请吗?"}), "/coupon/reject", data);
});
//作废
$(document).on('click', '.apply-cancel', function () {
var item = g.rows[$(this).data("index")];
var data = function () {
var reason = $('#reason').val();
if (reason == '' || $.trim(reason) == '') {
return "请填写作废原因";
}
return {
couponId: item.id,
invalidReason: reason
};
};
Bll.toast(common.util.__template2($("#template").html(), {name: "你确定要作废此限购码吗?"}), "/coupon/invalid", data);
});
/**
* 查看详情
*/
$(document).on('click', '.coupon-info', function () {
var item = g.rows[$(this).data("index")];
var item1 = $.extend(true, {}, item);
item1.createTime = Bll.getTime(item1.createTime);
item1.startTime = Bll.getTime(item1.startTime);
item1.endTime = Bll.getTime(item1.endTime);
item1.couponType = couponTypes[item1.couponType - 1];
item1.department = departments[item1.department - 1];
item1.useLimitType = useLimitTypes[item1.useLimitType];
if (item1.customType) {
item1.customType = item1.customType.split(",");
var typeLen = item1.customType.length;
var types = [];
if (typeLen == 5) {
item1.customType = "全部"
}
else {
for (var i = 0; i < typeLen; i++) {
types.push(customTypes[item1.customType[i] - 1]);
}
item1.customType = types.join(",");
}
}else {
item1.customType="无";
}
Bll.toastInfo(item1, '优惠券详情');
});