Authored by lijing

开发完成

@@ -27,7 +27,7 @@ exports.index = (req, res, next) => { @@ -27,7 +27,7 @@ exports.index = (req, res, next) => {
27 }).catch(next); 27 }).catch(next);
28 }; 28 };
29 29
30 -exports.grow = (req, res) => { 30 +exports.grow = (req, res, next) => {
31 let responseData = { 31 let responseData = {
32 module: 'home', 32 module: 'home',
33 page: 'grade-new', 33 page: 'grade-new',
@@ -40,5 +40,23 @@ exports.grow = (req, res) => { @@ -40,5 +40,23 @@ exports.grow = (req, res) => {
40 pageFooter: true 40 pageFooter: true
41 }; 41 };
42 42
43 - res.render('grade-new/grow', responseData); 43 + let params = {
  44 + uid: req.user.uid,
  45 + page: 1
  46 + };
  47 +
  48 + req.ctx(gradeNewModel).grow(params).then(result => {
  49 + res.render('grade-new/grow', Object.assign(responseData, result));
  50 + }).catch(next);
  51 +};
  52 +
  53 +exports.getHis = (req, res, next) => {
  54 + let params = {
  55 + uid: req.user.uid,
  56 + page: req.query.page
  57 + };
  58 +
  59 + req.ctx(gradeNewModel).getHisAjax(params).then(result => {
  60 + res.json(result);
  61 + }).catch(next);
44 }; 62 };
@@ -3,6 +3,12 @@ @@ -3,6 +3,12 @@
3 const api = global.yoho.API; 3 const api = global.yoho.API;
4 const helpers = global.yoho.helpers; 4 const helpers = global.yoho.helpers;
5 const _ = require('lodash'); 5 const _ = require('lodash');
  6 +const moment = require('moment');
  7 +
  8 +// 格式年月日
  9 +const _formatDay = (day) => {
  10 + return moment(day).format('YYYY-MM-DD');
  11 +};
6 12
7 /** 13 /**
8 * 会员等级 14 * 会员等级
@@ -49,11 +55,45 @@ module.exports = class extends global.yoho.BaseModel { @@ -49,11 +55,45 @@ module.exports = class extends global.yoho.BaseModel {
49 }); 55 });
50 } 56 }
51 57
  58 + getGrowthVip(uid) {
  59 + let options = {
  60 + data: {
  61 + method: 'app.passport.growthvip',
  62 + uid: uid
  63 + },
  64 + param: {
  65 + code: 200
  66 + }
  67 + };
  68 +
  69 + return this.get(options).then(result => {
  70 + return result;
  71 + });
  72 + }
  73 +
  74 + getHis(params) {
  75 + let options = {
  76 + data: {
  77 + method: 'app.passport.growthhistory',
  78 + uid: params.uid,
  79 + page: params.page
  80 + },
  81 + param: {
  82 + code: 200
  83 + }
  84 + };
  85 +
  86 + return this.get(options).then(result => {
  87 + return result;
  88 + });
  89 + }
  90 +
52 index(param) { 91 index(param) {
53 if (param.uid) { 92 if (param.uid) {
54 return api.all([ 93 return api.all([
55 this.getGradeGrade(param.uid, param.channel), 94 this.getGradeGrade(param.uid, param.channel),
56 - this.getGradeUser(param.uid, param.channel) 95 + this.getGradeUser(param.uid, param.channel),
  96 + this.getGrowthVip(param.uid)
57 ]).then((result) => { 97 ]).then((result) => {
58 98
59 let resu = { 99 let resu = {
@@ -106,31 +146,9 @@ module.exports = class extends global.yoho.BaseModel { @@ -106,31 +146,9 @@ module.exports = class extends global.yoho.BaseModel {
106 146
107 } 147 }
108 148
109 - let upg = (1 * (result[0].data.upgrade_need_cost)).toFixed(2);  
110 -  
111 obj = _.assign(obj, { 149 obj = _.assign(obj, {
112 - costOfThisYear: result[0].data.current_year_cost,  
113 - sumCost: result[0].data.current_total_cost,  
114 - allUrl: helpers.urlFormat('/home/privilege'),  
115 - costGap: upg 150 + allUrl: helpers.urlFormat('/home/privilege')
116 }); 151 });
117 -  
118 - if (result[0].data.next_need_cost === 0 || result[0].data.next_need_cost === '') {  
119 - // 当vip等级升至顶级时,进度条满格  
120 - obj = _.assign(obj, {  
121 - percent: 100  
122 - });  
123 - } else {  
124 -  
125 - let perf = (100 * (result[0].data.current_year_cost /  
126 - result[0].data.next_need_cost)).toFixed(2);  
127 -  
128 - obj = _.assign(obj, {  
129 - percent: perf  
130 - });  
131 -  
132 - }  
133 -  
134 } 152 }
135 153
136 if (result[1] && result[1].data) { 154 if (result[1] && result[1].data) {
@@ -140,12 +158,104 @@ module.exports = class extends global.yoho.BaseModel { @@ -140,12 +158,104 @@ module.exports = class extends global.yoho.BaseModel {
140 }); 158 });
141 } 159 }
142 160
143 - resu.vipGrade.push(obj); 161 + if (result[2] && result[2].data) {
  162 + let nowGrowth = parseInt(result[2].data.current_total_growth, 10);
  163 + let nextGrowth = parseInt(result[2].data.upgrade_need_growth, 10) || 0;
144 164
  165 + obj = _.assign(obj, {
  166 + nowGrowth: nowGrowth,
  167 + nextGrowth: nextGrowth,
  168 + percent: nowGrowth < 7000 ? nowGrowth / 70 : 100
  169 + });
  170 + }
  171 + resu.vipGrade.push(obj);
145 return resu; 172 return resu;
146 }); 173 });
147 } else { 174 } else {
148 return Promise.resolve({}); 175 return Promise.resolve({});
149 } 176 }
150 } 177 }
  178 +
  179 + grow(param) {
  180 + return api.all([
  181 + this.getGrowthVip(param.uid),
  182 + this.getHis(param)
  183 + ]).then((result) => {
  184 + let resu = {
  185 + levelHis: [],
  186 + detailHis: []
  187 + };
  188 +
  189 + if (result) {
  190 + if (result[0] && result[0].data) {
  191 + let build = [];
  192 +
  193 + if (result[0].data.sliver_start_time) {
  194 + build.push({
  195 + tip: '普通升级为银卡',
  196 + time: _formatDay(result[0].data.sliver_start_time * 1000)
  197 + });
  198 + }
  199 +
  200 + if (result[0].data.gold_start_time) {
  201 + build.push({
  202 + tip: '银卡升级为金卡',
  203 + time: _formatDay(result[0].data.gold_start_time * 1000)
  204 + });
  205 + }
  206 +
  207 + if (result[0].data.whitegold_start_time) {
  208 + build.push({
  209 + tip: '金卡升级为白金',
  210 + time: _formatDay(result[0].data.whitegold_start_time * 1000)
  211 + });
  212 + }
  213 +
  214 + resu.levelHis = build;
  215 + }
  216 +
  217 + if (result[1] && result[1].data && result[1].data.data) {
  218 + let build = [];
  219 +
  220 + _.forEach(result[1].data.data, function(val) {
  221 + build.push({
  222 + title: val.typeDesc,
  223 + time: _formatDay(val.createTime),
  224 + value: val.growthValue
  225 + });
  226 + });
  227 +
  228 + resu.detailHis = build;
  229 + }
  230 + }
  231 +
  232 + return resu;
  233 + });
  234 + }
  235 +
  236 + getHisAjax(param) {
  237 + return api.all([
  238 + this.getHis(param)
  239 + ]).then((result) => {
  240 + let resu = {
  241 + detailHis: []
  242 + };
  243 +
  244 + if (result && result[0] && result[0].data) {
  245 + let build = [];
  246 +
  247 + _.forEach(result[0].data.data, function(val) {
  248 + build.push({
  249 + title: val.typeDesc,
  250 + time: _formatDay(val.createTime),
  251 + value: val.growthValue
  252 + });
  253 + });
  254 +
  255 + resu.detailHis = build;
  256 + }
  257 +
  258 + return resu;
  259 + });
  260 + }
151 }; 261 };
@@ -145,5 +145,6 @@ router.get('/logistic', auth, orderDetailController.logistic); // 瘚 @@ -145,5 +145,6 @@ router.get('/logistic', auth, orderDetailController.logistic); // 瘚
145 145
146 router.get('/gradeNew/index', auth, gradeNew.index); // 会员等级 146 router.get('/gradeNew/index', auth, gradeNew.index); // 会员等级
147 router.get('/gradeNew/grow', auth, gradeNew.grow); // 成长记录 147 router.get('/gradeNew/grow', auth, gradeNew.grow); // 成长记录
  148 +router.get('/gradeNew/getHis', gradeNew.getHis); // 成长记录
148 149
149 module.exports = router; 150 module.exports = router;
@@ -5,72 +5,25 @@ @@ -5,72 +5,25 @@
5 </div> 5 </div>
6 <div class="tab-item"> 6 <div class="tab-item">
7 <div class="ul-detail"> 7 <div class="ul-detail">
  8 + {{# detailHis}}
8 <div class="li-item"> 9 <div class="li-item">
9 <div class="text"> 10 <div class="text">
10 - <p>登录</p>  
11 - <p>2017-04-27</p> 11 + <p>{{title}}</p>
  12 + <p>{{time}}</p>
12 </div> 13 </div>
13 - <div class="num">+7</div>  
14 - </div>  
15 - <div class="li-item">  
16 - <div class="text">  
17 - <p>登录</p>  
18 - <p>2017-04-27</p>  
19 - </div>  
20 - <div class="num">+7</div>  
21 - </div>  
22 - <div class="li-item">  
23 - <div class="text">  
24 - <p>登录</p>  
25 - <p>2017-04-27</p>  
26 - </div>  
27 - <div class="num">+7</div>  
28 - </div>  
29 - <div class="li-item">  
30 - <div class="text">  
31 - <p>登录</p>  
32 - <p>2017-04-27</p>  
33 - </div>  
34 - <div class="num">+7</div>  
35 - </div>  
36 - <div class="li-item">  
37 - <div class="text">  
38 - <p>登录</p>  
39 - <p>2017-04-27</p>  
40 - </div>  
41 - <div class="num">+7</div>  
42 - </div>  
43 - <div class="li-item">  
44 - <div class="text">  
45 - <p>登录</p>  
46 - <p>2017-04-27</p>  
47 - </div>  
48 - <div class="num">+7</div> 14 + <div class="num">+{{value}}</div>
49 </div> 15 </div>
  16 + {{/ detailHis}}
50 </div> 17 </div>
51 </div> 18 </div>
52 <div class="tab-item hide"> 19 <div class="tab-item hide">
53 <div class="ul-detail"> 20 <div class="ul-detail">
  21 + {{# levelHis}}
54 <div class="li-item"> 22 <div class="li-item">
55 - <div class="title">金卡升级为白金</div>  
56 - <div class="date">2017-04-20</div>  
57 - </div>  
58 - <div class="li-item">  
59 - <div class="title">金卡升级为白金</div>  
60 - <div class="date">2017-04-20</div>  
61 - </div>  
62 - <div class="li-item">  
63 - <div class="title">金卡升级为白金</div>  
64 - <div class="date">2017-04-20</div>  
65 - </div>  
66 - <div class="li-item">  
67 - <div class="title">金卡升级为白金</div>  
68 - <div class="date">2017-04-20</div>  
69 - </div>  
70 - <div class="li-item">  
71 - <div class="title">金卡升级为白金</div>  
72 - <div class="date">2017-04-20</div> 23 + <div class="title">{{tip}}</div>
  24 + <div class="date">{{time}}</div>
73 </div> 25 </div>
  26 + {{/ levelHis}}
74 </div> 27 </div>
75 </div> 28 </div>
76 </div> 29 </div>
@@ -26,15 +26,19 @@ @@ -26,15 +26,19 @@
26 <div class="intro"> 26 <div class="intro">
27 <div class="name">{{name}},您好!</div> 27 <div class="name">{{name}},您好!</div>
28 <div class="level"> 28 <div class="level">
29 - <span class="now">我的成长值:<span class="val">2250</span> </span>  
30 - <span class="next">下次升级还需:<span class="val">2750</span></span> 29 + <span class="now">我的成长值:<span class="val">{{nowGrowth}}</span></span>
  30 + {{#if nextGrowth}}
  31 + <span class="next">下次升级还需:<span class="val">{{nextGrowth}}</span></span>
  32 + {{/if}}
31 </div> 33 </div>
32 </div> 34 </div>
33 {{/ vipGrade}} 35 {{/ vipGrade}}
34 </div> 36 </div>
35 <div class="level-process clearfix"> 37 <div class="level-process clearfix">
36 <div class="line-c"> 38 <div class="line-c">
37 - <div class="line"></div> 39 + {{# vipGrade}}
  40 + <div class="line"{{#if percent}} style="width:{{percent}}%"{{/if}}></div>
  41 + {{/ vipGrade}}
38 <div class="point"> 42 <div class="point">
39 <div class="point-item"> 43 <div class="point-item">
40 <div class="level-text"> 44 <div class="level-text">
@@ -64,7 +68,7 @@ @@ -64,7 +68,7 @@
64 </div> 68 </div>
65 </div> 69 </div>
66 </div> 70 </div>
67 - <a class="big-top"> 71 + <a class="big-top" href="//m.yohobuy.com/home/helpDetail?code=20111130-152124&name=如何成为VIP会员">
68 会员等级介绍 72 会员等级介绍
69 <span class="iconfont">&#xe604;</span> 73 <span class="iconfont">&#xe604;</span>
70 <span class="s-title">了解等级规则</span> 74 <span class="s-title">了解等级规则</span>
  1 +{{# detailHis}}
  2 +<div class="li-item">
  3 + <div class="text">
  4 + <p>{{title}}</p>
  5 + <p>{{time}}</p>
  6 + </div>
  7 + <div class="num">+{{value}}</div>
  8 +</div>
  9 +{{/ detailHis}}
@@ -5,13 +5,41 @@ import { @@ -5,13 +5,41 @@ import {
5 } from 'yoho-mvc'; 5 } from 'yoho-mvc';
6 6
7 import { 7 import {
8 - TabView 8 + TabView,
  9 + GetContent
9 } from './view'; 10 } from './view';
10 11
  12 +import {
  13 + globalSearch as search
  14 +} from './model';
  15 +
  16 +let hisContent = require('home/grade-new.hbs');
  17 +let tip = require('plugin/tip');
  18 +
11 class GradeController extends Controller { 19 class GradeController extends Controller {
12 constructor() { 20 constructor() {
13 super(); 21 super();
14 this.tabView = new TabView(); 22 this.tabView = new TabView();
  23 + this.content = new GetContent();
  24 + this.content.on('search', this.doSearch.bind(this));
  25 + this.page = 1;
  26 + }
  27 +
  28 + doSearch() {
  29 + if (!this.end) {
  30 + this.page ++;
  31 + this.search(this.page);
  32 + }
  33 + }
  34 +
  35 + search(page) {
  36 + search('//m.yohobuy.com/home/gradeNew/getHis', {page: page}).then(data => {
  37 + $('.ul-detail:first').append(hisContent(data));
  38 + if (data.detailHis <= 0) {
  39 + this.end = true;
  40 + tip.show('没有更多了~~');
  41 + }
  42 + }).catch(() => {});
15 } 43 }
16 } 44 }
17 45
  1 +'use strict';
  2 +
  3 +import {
  4 + http
  5 +} from 'yoho-mvc';
  6 +
  7 +function globalSearch(url, data) {
  8 + return http({
  9 + url: location.protocol + url,
  10 + data: data,
  11 + });
  12 +}
  13 +
  14 +export {
  15 + globalSearch
  16 +};
@@ -5,6 +5,7 @@ import { @@ -5,6 +5,7 @@ import {
5 class TabView extends View { 5 class TabView extends View {
6 constructor() { 6 constructor() {
7 super('.tab'); 7 super('.tab');
  8 + this.end = false;
8 this.on('touchend touchcancel', 'span', this.tabClick.bind(this)); 9 this.on('touchend touchcancel', 'span', this.tabClick.bind(this));
9 } 10 }
10 11
@@ -16,10 +17,29 @@ class TabView extends View { @@ -16,10 +17,29 @@ class TabView extends View {
16 17
17 $this.addClass('active').siblings('span').removeClass('active'); 18 $this.addClass('active').siblings('span').removeClass('active');
18 $('.tab-item:eq(' + $index + ')').removeClass('hide').siblings('.tab-item').addClass('hide'); 19 $('.tab-item:eq(' + $index + ')').removeClass('hide').siblings('.tab-item').addClass('hide');
  20 + window.rePosFooter();
  21 + }
  22 + }
  23 +}
  24 +
  25 +class GetContent extends View {
  26 + constructor() {
  27 + super('.grade-new-c');
  28 +
  29 + // srcoll to load more
  30 + $(window).scroll(() => {
  31 + window.requestAnimationFrame(this.scrollHandler.bind(this));
  32 + });
  33 + }
  34 +
  35 + scrollHandler() {
  36 + if (($(window).scrollTop() + $(window).height() >= $(document).height()) && $('.ul-detail').length > 0) {
  37 + this.emit('search');
19 } 38 }
20 } 39 }
21 } 40 }
22 41
23 export { 42 export {
24 - TabView 43 + TabView,
  44 + GetContent
25 }; 45 };
@@ -126,7 +126,7 @@ @@ -126,7 +126,7 @@
126 } 126 }
127 127
128 .line { 128 .line {
129 - width: 80%; 129 + width: 0;
130 height: 100%; 130 height: 100%;
131 max-width: 100%; 131 max-width: 100%;
132 background-color: #444; 132 background-color: #444;
@@ -146,12 +146,27 @@ @@ -146,12 +146,27 @@
146 background-size: auto 100%; 146 background-size: auto 100%;
147 background-repeat: no-repeat; 147 background-repeat: no-repeat;
148 float: left; 148 float: left;
149 - margin-right: 177px;  
150 position: relative; 149 position: relative;
151 } 150 }
152 151
153 - .point-item:last-child {  
154 - margin-right: 0; 152 + .point-item:nth-child(1) {
  153 + margin-right: 57px;
  154 +
  155 + .level-text {
  156 + margin-left: -80px;
  157 + }
  158 + }
  159 +
  160 + .point-item:nth-child(2) {
  161 + margin-right: 167px;
  162 +
  163 + .level-text {
  164 + margin-left: -40px;
  165 + }
  166 + }
  167 +
  168 + .point-item:nth-child(3) {
  169 + margin-right: 307px;
155 } 170 }
156 171
157 .level-text { 172 .level-text {