coupon.page.js
6.02 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
/* eslint-disable eqeqeq */
require('admin/user.page.css');
require('bootpag/lib/jquery.bootpag.min');
const _ = require('lodash');
function bind_table_pagination() {
const $ul = $('.coupon-list');
const $up = $('.coupon-pagination');
let uploadFn = function() {
let id = $(this).data('id');
let $form = $('#uploadForm_' + id)[0];
let formData = new FormData($form);
formData.append('id', $(this).data('id'));
if ($form) {
$.ajax({
url: '/admin/api/coupon/batchAddNo',
data: formData,
method: 'POST',
cache: false,
processData: false,
contentType: false,
success: function(data) {
if (!data.result) {
alert(data.message);
} else {
alert('导入成功');// eslint-disable line
}
}
});
}
};
let statusParam = null;
const fetchRender = (pageNo, pageSize) => {
let param = {pageNo, pageSize};
if (statusParam != null) {
param.status = statusParam;
}
$.ajax({
url: '/admin/api/coupon/list',
data: param
})
.then(result => {
const list = result.data;
const totalPage = result.totalPage;
let html = '';
_.each(list, item => {
if (item.status) {
item.statusText = '已上架';
} else {
item.statusText = '已下架';
}
if (item.type == 1) {
item.typeText = '通用码';
} else if (item.type == 2) {
item.typeText = '一人一码';
} else if (item.type == 3) {
item.typeText = '不用码';
}
let status = item.status ? `<a class="btn btn-danger btn-status" data-id="${item.id}" data-status="0">下架</a>` : `<a class="btn btn-success btn-status" data-id="${item.id}" data-status="1">上架</a>`;
html += `
<tr class="even pointer">
<td class="">${item.id}</td>
<td class="">${item.couponName}</td>
<td class="">${item.shopName}</td>
<td class=""><img src="${item.shopLogoUrl}" width="100" height="50"/></td>
<td class="">${item.statusText}</td>
<td class="">${item.typeText}</td>
<td class="">${item.sort}</td>
<td class="">${item.createTime}</td>
<td class="">
<form id="uploadForm_${item.id}" enctype="multipart/form-data">
<input id="up_excel" name="up_excel" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" style="display: inline-block; width: 80%;" type="file">
</form>
<button type="button" class="btn btn-primary btn-import" style="display: inline-block;" data-id="${item.id}">导入券码</button>
<button class="btn btn-primary btn-export-no" data-id="${item.id}">导出领取信息
</button>
<a class="btn btn-info btn-update" href="/admin/coupon/update?id=${item.id}">修改</a>
` + status + `
<a class="btn btn-danger btn-delete" data-id="${item.id}">删除</a>
</td>
</tr>`;
});
$ul.html(html);
if (pageNo === 1) {
$up.bootpag({
total: totalPage,
page: 1,
maxVisible: 10,
}).on('page', function(event, num) {
fetchRender(num, 20);
});
}
$('.btn-export-no').on('click', function() {
let id = $(this).attr('data-id');
window.location = '/admin/api/coupon/downloadNo?id=' + id;
});
$('.btn-import').on('click', uploadFn);
$('.btn-delete').click(function() {
let id = $(this).attr('data-id');
$.ajax({
url: '/admin/api/coupon/delete?id=' + id,
method: 'get',
cache: false,
processData: false,
contentType: false,
success: function(data) {
if (!data.result) {
alert(data.message);
} else {
window.location.reload();
}
}
});
});
$('.btn-status').click(function() {
$.ajax({
url: '/admin/api/coupon/modify',
method: 'post',
data: {
id: $(this).attr('data-id'),
status: parseInt($(this).attr('data-status'))
},
success: function() {
window.location.reload();
}
});
});
});
};
$('.dropdown-menu li').click(function() {
let status = $(this).attr('data-status');
if (status) {
statusParam = parseInt(status);
} else {
statusParam = null;
}
$('#dropdown-toggle-txt').text($(this).text() + ' ');
fetchRender(1, 20);
});
fetchRender(1, 20);
}
(function() {
bind_table_pagination();
}());