coupon.page.js
4.06 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
/* 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 $form = $('#uploadForm')[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() {
alert('导入成功');//eslint-disable line
}
});
}
};
const fetchRender = (pageNo, pageSize) => {
$.ajax({
url: '/admin/api/coupon/list',
data: {
pageNo,
pageSize
}
})
.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 = '不用码';
}
html += `
<tr class="even pointer">
<td class="">${item.id}</td>
<td class="">${item.couponName}</td>
<td class="">${item.couponDesc}</td>
<td class="">${item.shopName}</td>
<td class=""><img src="${item.shopLogoUrl}" width="100%"/></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" enctype="multipart/form-data">
<div class="x_title form-group">
<input id="up_excel" name="up_excel" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" style="display: inline-block; width: 80%;" type="file">
<button type="button" class="btn btn-danger btn-import" style="display: inline-block;" data-id="${item.id}">导入券码</button>
<div class="clearfix"></div>
</div>
</form>
<button class="btn btn-danger btn-export-no" data-id="${item.id}">导出券码
</button>
<a class="btn btn-danger btn-update" href="/admin/coupon/update?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);
});
};
fetchRender(1, 20);
}
(function() {
bind_table_pagination();
}());