index.js
7.48 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
/**
* 限购码列表页
*/
'use strict';
var $ = require('jquery'),
Handlebars = require('yoho.handlebars'),
grid=require('../common/grid'),
dropDown = require('../common/dropDown');
require('yoho.bootstrap')
exports.init = function() {
//下拉框
new dropDown({el: '#filter-dep'});
/**
* 状态数据转换为中文显示
* @param: $element(转换的节点), status(转换的状态字符串)
*/
function statusConvert(status) {
var status = parseInt(status);
switch (status) {
case 0:
return '待审核';
break;
case 1:
return '审核通过';
break;
case 2:
return '驳回';
break;
case 3:
return '过期';
break;
case 4:
return '作废';
break;
default:
return '全部';
break;
}
}
var btnAuthority = JSON.parse($("#btnAuthority").val());
var g = new grid({
el: '#basicTable',
tabUrl: $('#tabUrl').val(),
tabConvert: statusConvert,
size: 10,
parms:function(){
return {
batchNo: $.trim($('#filter-id').val()) ||"",
name: $.trim($('#filter-name').val()) ||"",
reqDepartment:$.trim($('#filter-dep').val()) ||""
};
},
columns:[
{display:"批次号", name:"batchNo", render: function(item) {
return '<a href="/coupon/info/' + item.id + '">' + item.batchNo + '</a>';
}},
{display:"基本信息",name:"name", render: function(item) {
return '<p>名称:' + item.name + '</p><p>次数' + item.limitTimes + '</p><p>部门:' + item.reqDepartment + '</p>';
}},
{display: '使用期限', name: "limit", render: function(item) {
return '<p class="audit-time">' + item.limitDateFrom + '</p><p>' + item.limitDateTo + '</p>'
}},
{display: '限购码说明', hidden:btnAuthority.couponDes, name: "describe"},
{display: '优惠码说明', hidden:btnAuthority.limitDes, name: "describe"},
{display: '申请记录', name: "staff"},
{display: '状态', name: "status", render: function(item) {
var html = statusConvert(item.status);
if (item.reason) {
html += '<p style="color:red;">(' + item.reason + ')</p>';
}
return html;
}},
{display:"操作",name:"operate",render:function(items){
var HtmArr=[];
if(btnAuthority.look){
HtmArr.push('<a href="/coupon/info/'+ items.id+'" class="btn btn-info btn-xs">查看详情</a>');
}
if(items.status == 0){
HtmArr.push('<a class="btn btn-primary btn-xs apply-success" data-id="'+ items.id+'" href="javascript:;">通过</a>');
HtmArr.push('<a class="btn btn-warning btn-xs apply-back" data-id="'+ items.id+'" href="javascript:;">驳回</a>');
HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-id="'+ items.id+'" href="javascript:;">作废</a>');
}
if(items.status == 1){
HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-id="'+ items.id+'" href="javascript:;">作废</a>');
}
if(items.status == 2){
HtmArr.push('<a class="btn btn-info btn-xs apply-modify" data-id="'+ items.id+'" href="/coupon/update/'+ items.id+'">修改</a>');
}
return HtmArr.join('');
}}
]
})
g.init($("#gridurl").val());
$("#filter-btn").click(function(){
g.reload();
});
//作废事件
$('#basicTable').on('click', '.apply-cancel', function() {
var that = this,
applyId = $(this).data('id');
$('#cancel-modal').modal();
$('#cancel-modal').on('click', '.btn-primary', function() {
var reason = $('#cancel-reason').val();
if (reason === '' || $.trim(reason) === '') {
alert('请填写作废原因');
return;
}
$.ajax({
type: 'post',
dataType: 'json',
url: '{{auditUrl}}',
data: {
id: applyId,
status: 4,
reason: reason
},
success: function(data) {
$('#cancel-modal').modal('hide');
g.reload();
}
})
});
});
//通过事件
$('#basicTable').on('click', '.apply-success', function() {
var that = this,
$listBtn,
applyId = $(this).data('id'),
applyState = $(this).data('state');
$('#success-modal').modal();
$('#success-modal').on('click', '.btn-primary', function() {
$.ajax({
type: 'post',
dataType: 'json',
url: '{{auditUrl}}',
data: {
id: applyId,
status: 1 //审核通过
},
success: function(data) {
$('#success-modal').modal('hide');
g.reload();
}
})
});
$listBtn = $('#success-modal').find('.btn-info');
//发放列表点击事件
$listBtn.off('click.sendPromotion').on('click.sendPromotion', function() {
var auditTime = $(that).parents('td').siblings().find('.audit-time').text();
$.ajax({
type: 'post',
dataType: 'json',
url: '{{sendUrl}}',
data: {
auditTime: auditTime
},
success: function(res) {
var data = res.data.data.list;
if (data.length === 0) {
alert('暂无时间交叉的优惠码');
} else {
$('#send-modal').modal({
width: 1000
});
var tpl = Handlebars.compile($('#send-tpl').html());
$('#send-modal tbody').html(tpl({
data: data
}));
}
}
})
});
});
//驳回事件
$('#basicTable').on('click', '.apply-back', function() {
var that = this,
applyId = $(this).data('id');
$('#back-modal').modal();
$('#back-modal').on('click', '.btn-primary', function() {
var reason = $('#back-reason').val();
if (reason === '' || $.trim(reason) === '') {
alert('请填写驳回原因');
return;
}
$.ajax({
type: 'post',
dataType: 'json',
url: '{{auditUrl}}',
data: {
id: applyId,
status: 2,
reason: reason
},
success: function(data) {
$('#back-modal').modal('hide');
g.reload();
}
})
})
});
}