Showing
5 changed files
with
104 additions
and
19 deletions
@@ -23,11 +23,33 @@ const timeFormat = (time) => { | @@ -23,11 +23,33 @@ const timeFormat = (time) => { | ||
23 | 23 | ||
24 | const zeroBuy = { | 24 | const zeroBuy = { |
25 | zeroBuyList(req, res, next) { | 25 | zeroBuyList(req, res, next) { |
26 | + let params = req.query; | ||
27 | + | ||
28 | + const statusList = [ | ||
29 | + {name: '全部', status: ''}, | ||
30 | + {name: '关闭', status: 0}, | ||
31 | + {name: '开启', status: 1}, | ||
32 | + {name: '已开奖', status: 2}, | ||
33 | + ]; | ||
34 | + | ||
26 | req.ctx(ActivityModel).getZerobuyList(req.query).then(result => { | 35 | req.ctx(ActivityModel).getZerobuyList(req.query).then(result => { |
36 | + _.forEach(statusList, value => { | ||
37 | + if (+params.status === value.status) { | ||
38 | + value.active = true; | ||
39 | + } | ||
40 | + }); | ||
41 | + | ||
42 | + if (!_.find(statusList, 'active')) { | ||
43 | + statusList[0].active = true; | ||
44 | + } | ||
45 | + | ||
27 | res.render('activity/zero-buy-list', Object.assign(result, { | 46 | res.render('activity/zero-buy-list', Object.assign(result, { |
28 | bodyClass: 'nav-md', | 47 | bodyClass: 'nav-md', |
29 | module: 'admin', | 48 | module: 'admin', |
30 | - page: 'zero-buy' | 49 | + page: 'zero-buy', |
50 | + qsQuery: params.query, | ||
51 | + qsStatus: params.status, | ||
52 | + statusList | ||
31 | })); | 53 | })); |
32 | }).catch(next); | 54 | }).catch(next); |
33 | }, | 55 | }, |
@@ -395,17 +395,31 @@ class AdminModel extends global.yoho.BaseModel { | @@ -395,17 +395,31 @@ class AdminModel extends global.yoho.BaseModel { | ||
395 | const pageSize = 10; | 395 | const pageSize = 10; |
396 | const page = parseInt(params.page, 10) || 1; | 396 | const page = parseInt(params.page, 10) || 1; |
397 | 397 | ||
398 | + let where = ['act_id = :actId']; | ||
399 | + | ||
400 | + if (params.query) { | ||
401 | + where.push('name like :query'); | ||
402 | + } | ||
403 | + | ||
404 | + if (!_.isNaN(+params.status)) { | ||
405 | + where.push('status = :status'); | ||
406 | + } | ||
407 | + | ||
398 | return Promise.all([ | 408 | return Promise.all([ |
399 | mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} | 409 | mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} |
400 | - where act_id = :actId order by id desc | 410 | + where ${where.join(' and ')} order by id desc |
401 | limit :start,:end`, { | 411 | limit :start,:end`, { |
402 | actId, | 412 | actId, |
403 | start: (page - 1) * pageSize, | 413 | start: (page - 1) * pageSize, |
404 | - end: page * pageSize | 414 | + end: page * pageSize, |
415 | + query: `%${params.query}%`, | ||
416 | + status: params.status | ||
405 | }), | 417 | }), |
406 | mysqlCli.query(`select count(*) as total from ${TABLE_ACT_PRIZE_PRODUCT} | 418 | mysqlCli.query(`select count(*) as total from ${TABLE_ACT_PRIZE_PRODUCT} |
407 | - where act_id = :actId`, { | ||
408 | - actId | 419 | + where ${where.join(' and ')}`, { |
420 | + actId, | ||
421 | + query: `%${params.query}%`, | ||
422 | + status: params.status | ||
409 | }), | 423 | }), |
410 | ]).then(result => { | 424 | ]).then(result => { |
411 | let resData = {}; | 425 | let resData = {}; |
@@ -5,21 +5,24 @@ | @@ -5,21 +5,24 @@ | ||
5 | <div> | 5 | <div> |
6 | <a href="/admin/activity/zerobuy/edit" class="btn btn-primary">创建抽奖活动</a> | 6 | <a href="/admin/activity/zerobuy/edit" class="btn btn-primary">创建抽奖活动</a> |
7 | <div class="clearfix"></div> | 7 | <div class="clearfix"></div> |
8 | -{{!-- | ||
9 | - <input type="text" class="form-control" aria-label="..."> | ||
10 | - <div class="btn-group"> | ||
11 | - <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">全部 <span class="caret"></span></button> | ||
12 | - <ul class="dropdown-menu"> | ||
13 | - <li><a href="#">关闭</a></li> | ||
14 | - <li><a href="#">开启</a></li> | ||
15 | - <li><a href="#">已开奖</a></li> | ||
16 | - </ul> | ||
17 | - </div> | ||
18 | - | ||
19 | - <button type="button" class="btn btn-primary">筛选</button> | ||
20 | - <button type="button" class="btn btn-primary">全部</button> --}} | ||
21 | - | ||
22 | 8 | ||
9 | + <div class="search-wrap"> | ||
10 | + <input type="text" id="search-key" class="form-control" value="{{qsQuery}}"> | ||
11 | + <div class="btn-group"> | ||
12 | + <button type="button" id="status-switch" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-status="{{qsStatus}}"><span class="btn-text"> | ||
13 | + {{# statusList}} | ||
14 | + {{#if active}}{{name}}{{/if}} | ||
15 | + {{/ statusList}} | ||
16 | + </span> <span class="caret"></span></button> | ||
17 | + <ul class="dropdown-menu"> | ||
18 | + {{# statusList}} | ||
19 | + <li><a href="javascript:;" class="status-switch" data-status="{{status}}">{{name}}</a></li> | ||
20 | + {{/ statusList}} | ||
21 | + </ul> | ||
22 | + </div> | ||
23 | + <button type="button" id="search-btn" class="btn btn-primary">筛选</button> | ||
24 | + <a href="/admin/activity/zerobuy" class="btn btn-primary">全部</a> | ||
25 | + </div> | ||
23 | </div> | 26 | </div> |
24 | 27 | ||
25 | <table class="table table-bordered"> | 28 | <table class="table table-bordered"> |
@@ -55,6 +58,11 @@ | @@ -55,6 +58,11 @@ | ||
55 | </td> | 58 | </td> |
56 | </tr> | 59 | </tr> |
57 | {{/each}} | 60 | {{/each}} |
61 | + {{#unless list}} | ||
62 | + <tr> | ||
63 | + <td class="text-center" colspan="8">暂无数据</td> | ||
64 | + </tr> | ||
65 | + {{/unless}} | ||
58 | </tbody> | 66 | </tbody> |
59 | </table> | 67 | </table> |
60 | <div class="table-pagination article-pagination pull-right"> | 68 | <div class="table-pagination article-pagination pull-right"> |
@@ -6,6 +6,32 @@ const $alert = $('#alert-modal'); | @@ -6,6 +6,32 @@ const $alert = $('#alert-modal'); | ||
6 | const $confirm = $('#confirm-modal'); | 6 | const $confirm = $('#confirm-modal'); |
7 | 7 | ||
8 | function bindListPageEvent() { | 8 | function bindListPageEvent() { |
9 | + const $searchKey = $('#search-key'); | ||
10 | + const $statusSwitch = $('#status-switch'); | ||
11 | + | ||
12 | + const searchFn = function() { | ||
13 | + let val = $searchKey.val(); | ||
14 | + let status = $statusSwitch.data('status'); | ||
15 | + | ||
16 | + let qs = []; | ||
17 | + | ||
18 | + if (val) { | ||
19 | + qs.push(val ? 'query=' + val : ''); | ||
20 | + } | ||
21 | + | ||
22 | + if (!_.isNaN(+status)) { | ||
23 | + qs.push('status=' + status); | ||
24 | + } | ||
25 | + | ||
26 | + location.href = `?${qs.join('&')}`; | ||
27 | + }; | ||
28 | + | ||
29 | + const statusFn = function() { | ||
30 | + let $this = $(this); | ||
31 | + | ||
32 | + $statusSwitch.data('status', $this.data('status')).children('.btn-text').text($this.text()); | ||
33 | + } | ||
34 | + | ||
9 | const editFn = function() { | 35 | const editFn = function() { |
10 | window.open('/admin/activity/zerobuy/edit?id=' + | 36 | window.open('/admin/activity/zerobuy/edit?id=' + |
11 | $(this).data('id'), '_blank'); | 37 | $(this).data('id'), '_blank'); |
@@ -52,6 +78,9 @@ function bindListPageEvent() { | @@ -52,6 +78,9 @@ function bindListPageEvent() { | ||
52 | }); | 78 | }); |
53 | }; | 79 | }; |
54 | 80 | ||
81 | + $('#search-btn').on('click', searchFn); | ||
82 | + $('.status-switch').on('click', statusFn); | ||
83 | + | ||
55 | $('.btn-edit').on('click', editFn); | 84 | $('.btn-edit').on('click', editFn); |
56 | $('.btn-switch-open').on('click', switchFn); | 85 | $('.btn-switch-open').on('click', switchFn); |
57 | $('.btn-switch-close').on('click', switchFn); | 86 | $('.btn-switch-close').on('click', switchFn); |
1 | @import '~bootstrap-daterangepicker'; | 1 | @import '~bootstrap-daterangepicker'; |
2 | 2 | ||
3 | +.search-wrap { | ||
4 | + padding-bottom: 20px; | ||
5 | +} | ||
6 | + | ||
7 | +.search-wrap > * { | ||
8 | + display: inline-block; | ||
9 | + max-width: 50%; | ||
10 | + vertical-align: middle; | ||
11 | + margin-bottom: 0; | ||
12 | + margin-right: 20px; | ||
13 | +} | ||
14 | + | ||
3 | .cover-img { | 15 | .cover-img { |
4 | width: 160px; | 16 | width: 160px; |
5 | } | 17 | } |
-
Please register or login to post a comment