guochao.page.js
3.68 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
/* eslint-disable eqeqeq */
require('admin/user.page.css');
require('bootpag/lib/jquery.bootpag.min');
const _ = require('lodash');
let obj = {where: {}, order: []};
function bind_table_pagination() {
const $ul = $('.guochao-list');
const fetchRender = () => {
$.ajax({
url: '/admin/api/guochao/list',
method: 'post',
contentType: 'application/json',
data: JSON.stringify(obj)
}).then(result => {
const list = result;
let html = '';
_.each(list, item => {
if (item.place) {
item.placeText = '下';
} else {
item.placeText = '上';
}
let str = item.place ? `<a class="btn btn-info btn-update btn-place-up" data-id="${item.id}">更变到上方</a>` : `<a class="btn btn-info btn-success btn-place-down" data-id="${item.id}">更变到下方</a>`;
html += `
<tr class="even pointer">
<td class="">${item.id}</td>
<td class=""><img src="${item.logo}" style="background: #000000" width="100" height="50"/></td>
<td class="">${item.shop_name}</td>
<td class=""><input class="sort" data-id="${item.id}" value="${item.sort}"/></td>
<td class="">${item.placeText}</td>
<td class="">${item.collect_count}</td>
<td class="">
${str}
</td>
</tr>`;
});
$ul.html(html);
$('.sort').blur(function() {
let num = parseInt($(this).val());
if (typeof num != 'number') {
return alert('请输入数字');
}
$.ajax({
method: 'post',
url: '/admin/api/guochao/update',
contentType: 'application/json',
data: JSON.stringify({id: $(this).attr('data-id'), sort: $(this).val()})
}).then(() => {
fetchRender();
});
});
$('.btn-place-up').click(function() {
$.ajax({
method: 'post',
contentType: 'application/json',
url: '/admin/api/guochao/update',
data: JSON.stringify({id: $(this).attr('data-id'), place: 0})
}).then(() => {
fetchRender();
});
});
$('.btn-place-down').click(function() {
$.ajax({
method: 'post',
url: '/admin/api/guochao/update',
contentType: 'application/json',
data: JSON.stringify({id: $(this).attr('data-id'), place: 1})
}).then(() => {
fetchRender();
});
});
});
};
$('.btn_collect_desc').click(function() {
obj.order = ['collect_count', 'desc'];
fetchRender();
obj = {where: {}, order: []};
});
$('.btn_up_query').click(function() {
obj.where = {place: 0};
fetchRender();
obj = {where: {}, order: []};
});
$('.btn_down_query').click(function() {
obj.where = {place: 1};
fetchRender();
obj = {where: {}, order: []};
});
$('.btn_name_query').click(function() {
obj.where = {shop_name: $('.shop_name').val()};
fetchRender();
obj = {where: {}, order: []};
});
fetchRender();
}
(function() {
bind_table_pagination();
}());