Showing
7 changed files
with
293 additions
and
2 deletions
@@ -59,8 +59,42 @@ exports.myDetails = (req, res, next) => { | @@ -59,8 +59,42 @@ exports.myDetails = (req, res, next) => { | ||
59 | }; | 59 | }; |
60 | 60 | ||
61 | indexModel.myDetails({ | 61 | indexModel.myDetails({ |
62 | - | 62 | + |
63 | }).then(result => { | 63 | }).then(result => { |
64 | res.render('personal-details', Object.assign(responseData, result)); | 64 | res.render('personal-details', Object.assign(responseData, result)); |
65 | }).catch(next); | 65 | }).catch(next); |
66 | }; | 66 | }; |
67 | + | ||
68 | +/** | ||
69 | + * 浏览记录 | ||
70 | + * @param req | ||
71 | + * @param res | ||
72 | + * @param next | ||
73 | + */ | ||
74 | + | ||
75 | +exports.record = (req, res, next) => { | ||
76 | + | ||
77 | + let headerData = headerModel.setNav({ | ||
78 | + navTitle: '浏览记录' | ||
79 | + }); | ||
80 | + | ||
81 | + let responseData = { | ||
82 | + pageHeader: headerData, | ||
83 | + module: 'home', | ||
84 | + page: 'browse-record', | ||
85 | + title: '浏览记录', | ||
86 | + pageFooter: true | ||
87 | + }; | ||
88 | + | ||
89 | + | ||
90 | + indexModel.record({ | ||
91 | + | ||
92 | + }).then(result => { | ||
93 | + console.log(Object.assign(responseData, result)); | ||
94 | + res.render('browse-record', Object.assign(responseData, result)); | ||
95 | + }).catch(next); | ||
96 | + | ||
97 | +}; | ||
98 | + | ||
99 | + | ||
100 | + |
@@ -11,6 +11,7 @@ const api = global.yoho.API; | @@ -11,6 +11,7 @@ const api = global.yoho.API; | ||
11 | const singleAPI = global.yoho.SingleAPI; | 11 | const singleAPI = global.yoho.SingleAPI; |
12 | const helpers = global.yoho.helpers; | 12 | const helpers = global.yoho.helpers; |
13 | const camelCase = global.yoho.camelCase; | 13 | const camelCase = global.yoho.camelCase; |
14 | +const _ = require('lodash'); | ||
14 | 15 | ||
15 | /** | 16 | /** |
16 | * 个人详情数据 | 17 | * 个人详情数据 |
@@ -127,6 +128,7 @@ const myDetails = (params) => { | @@ -127,6 +128,7 @@ const myDetails = (params) => { | ||
127 | result = camelCase(result); | 128 | result = camelCase(result); |
128 | if (result.data) { | 129 | if (result.data) { |
129 | return result.data; | 130 | return result.data; |
131 | + | ||
130 | // { | 132 | // { |
131 | // nickname: result.data.nickname, | 133 | // nickname: result.data.nickname, |
132 | // gender: result.data.gender, | 134 | // gender: result.data.gender, |
@@ -137,11 +139,54 @@ const myDetails = (params) => { | @@ -137,11 +139,54 @@ const myDetails = (params) => { | ||
137 | // } | 139 | // } |
138 | // } | 140 | // } |
139 | } | 141 | } |
142 | + | ||
140 | // return finalResult; | 143 | // return finalResult; |
141 | }); | 144 | }); |
142 | }; | 145 | }; |
143 | 146 | ||
147 | +/** | ||
148 | + * 浏览记录 | ||
149 | + * @param params | ||
150 | + */ | ||
151 | + | ||
152 | + | ||
153 | +const record = (params) => { | ||
154 | + | ||
155 | + return api.get('', { | ||
156 | + method: 'app.browse.product', | ||
157 | + uid: params.uid || 6228593, | ||
158 | + limit: 100, | ||
159 | + page: 1 | ||
160 | + }, {code: 200}).then((result) => { | ||
161 | + | ||
162 | + let resu = { | ||
163 | + recordResult: [] | ||
164 | + }; | ||
165 | + | ||
166 | + if (result && result.code === 200) { | ||
167 | + | ||
168 | + _.forEach(result.data.product_list, function(val) { | ||
169 | + let obj = {}; | ||
170 | + obj = _.assign(obj, { | ||
171 | + product_name: val.product_name, | ||
172 | + product_skn: val.product_skn, | ||
173 | + invalidGoods: val.status === 0, | ||
174 | + storage: val.storage | ||
175 | + }); | ||
176 | + resu.recordResult.push(obj); | ||
177 | + | ||
178 | + }); | ||
179 | + | ||
180 | + } | ||
181 | + | ||
182 | + // console.log(resu); | ||
183 | + return resu; | ||
184 | + }); | ||
185 | +}; | ||
186 | + | ||
187 | + | ||
144 | module.exports = { | 188 | module.exports = { |
145 | index, | 189 | index, |
146 | - myDetails | 190 | + myDetails, |
191 | + record | ||
147 | }; | 192 | }; |
@@ -39,6 +39,7 @@ router.get('/orderDetail', orderDetailController.orderDetail); // 订å•è¯¦æƒ…é¡ | @@ -39,6 +39,7 @@ router.get('/orderDetail', orderDetailController.orderDetail); // 订å•è¯¦æƒ…é¡ | ||
39 | 39 | ||
40 | router.get('/', homeController.index); // 个人中心首页 | 40 | router.get('/', homeController.index); // 个人中心首页 |
41 | router.get('/mydetails', homeController.myDetails); // 个人基本资料页面 | 41 | router.get('/mydetails', homeController.myDetails); // 个人基本资料页面 |
42 | +router.get('/record', homeController.record); // 浏览记录 | ||
42 | 43 | ||
43 | // 我的收藏 | 44 | // 我的收藏 |
44 | router.get('/favorite', favorite.favorite); | 45 | router.get('/favorite', favorite.favorite); |
1 | +{{# browseRecord}} | ||
2 | + <a class="browse-record-good clearfix {{#if invalidGoods}}invalidGoods{{/if}}" data-skn="{{product_skn}}" href="{{link}}"> | ||
3 | + <img class="thumb lazy" data-original="{{image}}"> | ||
4 | + <div class="deps clearfix"> | ||
5 | + <p class="name row">{{product_name}}</p> | ||
6 | + <p class="price row"> | ||
7 | + <span class="sale-price{{#unless market_price}} original-price{{/unless}}">¥{{sales_price}}</span> | ||
8 | + | ||
9 | + {{#if market_price}} | ||
10 | + <span class="market-price">¥{{market_price}}</span> | ||
11 | + {{/if}} | ||
12 | + </p> | ||
13 | + <p class="sold-out row"> | ||
14 | + {{#unless storage}} | ||
15 | + <span class="sold-out-tag">已售罄</span> | ||
16 | + {{/unless}} | ||
17 | + </p> | ||
18 | + <span class="iconfont del-icon"></span> | ||
19 | + </div> | ||
20 | + </a> | ||
21 | + | ||
22 | +{{/ browseRecord}} | ||
23 | + | ||
24 | +{{#if noRecord}} | ||
25 | + <div class="no-record"> | ||
26 | + <div class="icon"></div> | ||
27 | + <span>暂无浏览记录</span> | ||
28 | + <a class="walk-way" href="{{walkwayUrl}}">随便逛逛</a> | ||
29 | + </div> | ||
30 | +{{/if}} |
apps/home/views/action/browse-record.hbs
0 → 100644
1 | +<div class="browse-record-page yoho-page"> | ||
2 | + <div class="records"> | ||
3 | + | ||
4 | + {{# browseRecord}} | ||
5 | + <a class="browse-record-good clearfix {{#if invalidGoods}}invalidGoods{{/if}}" data-skn="{{product_skn}}" href="{{link}}"> | ||
6 | + <img class="thumb lazy" data-original="{{image}}"> | ||
7 | + <div class="deps clearfix"> | ||
8 | + <p class="name row">{{product_name}}</p> | ||
9 | + <p class="price row"> | ||
10 | + <span class="sale-price{{#unless market_price}} original-price{{/unless}}">¥{{sales_price}}</span> | ||
11 | + | ||
12 | + {{#if market_price}} | ||
13 | + <span class="market-price">¥{{market_price}}</span> | ||
14 | + {{/if}} | ||
15 | + </p> | ||
16 | + <p class="sold-out row"> | ||
17 | + {{#unless storage}} | ||
18 | + <span class="sold-out-tag">已售罄</span> | ||
19 | + {{/unless}} | ||
20 | + </p> | ||
21 | + <span class="iconfont del-icon"></span> | ||
22 | + </div> | ||
23 | + </a> | ||
24 | + | ||
25 | + {{/ browseRecord}} | ||
26 | + | ||
27 | + {{#if noRecord}} | ||
28 | + <div class="no-record"> | ||
29 | + <div class="icon"></div> | ||
30 | + <span>暂无浏览记录</span> | ||
31 | + <a class="walk-way" href="{{walkwayUrl}}">随便逛逛</a> | ||
32 | + </div> | ||
33 | + {{/if}} | ||
34 | + | ||
35 | + </div> | ||
36 | + <div class="load-more hide"> | ||
37 | + <span class="more">正在加载...</span> | ||
38 | + <span class="no-more hide">没有更多了</span> | ||
39 | + </div> | ||
40 | +</div> |
public/js/home/browse-record.page.js
0 → 100644
1 | +/** | ||
2 | + * 浏览记录 | ||
3 | + * @author: xuqi<qi.xu@yoho.cn> | ||
4 | + * @date: 2015/11/28 | ||
5 | + */ | ||
6 | +var $ = require('yoho-jquery'); | ||
7 | + | ||
8 | +var lazyLoad = require('yoho-jquery-lazyload'), | ||
9 | + load = require('../plugin/loading'), | ||
10 | + tip = require('../plugin/tip'); | ||
11 | + | ||
12 | +var dialog = require('../plugin/dialog'); | ||
13 | + | ||
14 | +var $page = $('.records'); | ||
15 | + | ||
16 | +var $loadMore = $('.load-more'), | ||
17 | + $more = $loadMore.children('.more'), | ||
18 | + $noMore = $loadMore.children('.no-more'); | ||
19 | + | ||
20 | +var page = 0; | ||
21 | + | ||
22 | +var end = false, | ||
23 | + loading = false; | ||
24 | + | ||
25 | +var winH = $(window).height(); | ||
26 | + | ||
27 | +require('../common'); | ||
28 | +load.init(); | ||
29 | +function moreRecord(cb) { | ||
30 | + var count = $page.children('.browse-record-good').length; | ||
31 | + | ||
32 | + if (loading) { | ||
33 | + return; | ||
34 | + } | ||
35 | + | ||
36 | + if (page === 1) { | ||
37 | + $loadMore.removeClass('hide'); | ||
38 | + } | ||
39 | + | ||
40 | + loading = true; | ||
41 | + $.ajax({ | ||
42 | + type: 'GET', | ||
43 | + url: '/home/recordContent', | ||
44 | + data: { | ||
45 | + page: page + 1 | ||
46 | + }, | ||
47 | + success: function(data) { | ||
48 | + if (data === ' ') { | ||
49 | + end = true; | ||
50 | + | ||
51 | + $more.addClass('hide'); | ||
52 | + $noMore.removeClass('hide'); | ||
53 | + } else { | ||
54 | + | ||
55 | + if (count === 0) { | ||
56 | + $page.html(data); | ||
57 | + | ||
58 | + lazyLoad(); | ||
59 | + } else { | ||
60 | + $page.append(data); | ||
61 | + | ||
62 | + lazyLoad($page.find('.browse-record-good:gt(' + (count - 1) + ') .lazy')); | ||
63 | + } | ||
64 | + window.rePosFooter(); | ||
65 | + page++; | ||
66 | + | ||
67 | + if (cb) { | ||
68 | + cb(); | ||
69 | + } | ||
70 | + } | ||
71 | + }, | ||
72 | + complete: function() { | ||
73 | + loading = false; | ||
74 | + } | ||
75 | + }); | ||
76 | +} | ||
77 | + | ||
78 | +load.showLoadingMask(); | ||
79 | +moreRecord(load.hideLoadingMask); | ||
80 | + | ||
81 | +$(window).scroll(function() { | ||
82 | + if (end) { | ||
83 | + return; | ||
84 | + } | ||
85 | + | ||
86 | + if (winH + $(window).scrollTop() > $(document).height() - 0.25 * $page.height()) { | ||
87 | + moreRecord(); | ||
88 | + } | ||
89 | +}); | ||
90 | + | ||
91 | +$page.on('touchstart', '.del-icon', function() { | ||
92 | + var $good = $(this).closest('.browse-record-good'), | ||
93 | + skn = $good.data('skn'); | ||
94 | + | ||
95 | + dialog.showDialog({ | ||
96 | + dialogText: '确定删除此条浏览记录吗?', | ||
97 | + hasFooter: { | ||
98 | + leftBtnText: '取消', | ||
99 | + rightBtnText: '确定' | ||
100 | + } | ||
101 | + }, function() { | ||
102 | + | ||
103 | + $.ajax({ | ||
104 | + type: 'GET', | ||
105 | + url: '/home/delRecord', | ||
106 | + data: { | ||
107 | + skn: skn | ||
108 | + }, | ||
109 | + success: function(data) { | ||
110 | + if (data.code === 200) { | ||
111 | + dialog.showDialog({ | ||
112 | + dialogText: '删除浏览记录成功', | ||
113 | + autoHide: 2000, | ||
114 | + fast: true | ||
115 | + }); | ||
116 | + setTimeout(function() { | ||
117 | + window.history.go(0); | ||
118 | + }, 1200); | ||
119 | + } | ||
120 | + } | ||
121 | + }); | ||
122 | + }); | ||
123 | +}); | ||
124 | + | ||
125 | +$('.deps').on('touchstart', 'span', function() { | ||
126 | + $(this).css('background', '#eee'); | ||
127 | +}).on('touchend touchcancel', 'span', function() { | ||
128 | + $(this).css('background', 'transparent'); | ||
129 | +}); | ||
130 | + | ||
131 | +$('.invalidGoods').on('touchstart touchend', function(e) { | ||
132 | + var $this = $(e.target).closest('span'); | ||
133 | + | ||
134 | + if ($this.hasClass('del-icon')) { | ||
135 | + return; | ||
136 | + } | ||
137 | + tip.show('商品已下架'); | ||
138 | + return false; | ||
139 | +}); |
@@ -14,6 +14,8 @@ var $userAvatar = $('.user-avatar'); | @@ -14,6 +14,8 @@ var $userAvatar = $('.user-avatar'); | ||
14 | var myImage = new Image(), | 14 | var myImage = new Image(), |
15 | avatar; | 15 | avatar; |
16 | 16 | ||
17 | +require('../common'); | ||
18 | + | ||
17 | // 部分老用户没有头像,显示默认头像 | 19 | // 部分老用户没有头像,显示默认头像 |
18 | avatar = $userAvatar.data('avatar'); | 20 | avatar = $userAvatar.data('avatar'); |
19 | myImage.src = avatar; | 21 | myImage.src = avatar; |
-
Please register or login to post a comment