Authored by 王水玲

sale outlet 倒计时ajax获取

@@ -56,6 +56,13 @@ exports.activityDetail = (req, res, next) => { @@ -56,6 +56,13 @@ exports.activityDetail = (req, res, next) => {
56 }).catch(next); 56 }).catch(next);
57 }; 57 };
58 58
  59 +// 奥莱活动倒计时时间
  60 +exports.activityTime = (req, res, next) => {
  61 + outletModel.getActivityTime(req.query).then(times => {
  62 + res.json(times);
  63 + }).catch(next);
  64 +};
  65 +
59 // 奥莱活动频道列表页 66 // 奥莱活动频道列表页
60 exports.activityList = (req, res, next) => { 67 exports.activityList = (req, res, next) => {
61 let headerData = headerModel.setNav({ 68 let headerData = headerModel.setNav({
@@ -139,6 +139,14 @@ let discountDetail = (req, res, next) => { @@ -139,6 +139,14 @@ let discountDetail = (req, res, next) => {
139 }).catch(next); 139 }).catch(next);
140 }; 140 };
141 141
  142 +let getTime = (req, res, next) => {
  143 + let id = req.query.id;
  144 +
  145 + saleModel.getDiscountTime(id, req.yoho.channel).then((time) => {
  146 + res.json(time);
  147 + }).catch(next);
  148 +};
  149 +
142 /** 150 /**
143 * vip 会员专享 151 * vip 会员专享
144 * @param {[object]} req 152 * @param {[object]} req
@@ -222,5 +230,6 @@ module.exports = { @@ -222,5 +230,6 @@ module.exports = {
222 discountDetail, 230 discountDetail,
223 vip, 231 vip,
224 filter, 232 filter,
225 - search 233 + search,
  234 + getTime
226 }; 235 };
@@ -123,6 +123,7 @@ const _convertActicityData = (data) => { @@ -123,6 +123,7 @@ const _convertActicityData = (data) => {
123 discountText = 0; 123 discountText = 0;
124 124
125 data = data || []; 125 data = data || [];
  126 +
126 _.forEach(data, (item) => { 127 _.forEach(data, (item) => {
127 if (item.promotionName) { 128 if (item.promotionName) {
128 discountArr = item.promotionName.split('~'); 129 discountArr = item.promotionName.split('~');
@@ -254,8 +255,29 @@ const getRecentActivity = (type, categoryId) => { @@ -254,8 +255,29 @@ const getRecentActivity = (type, categoryId) => {
254 }); 255 });
255 }; 256 };
256 257
  258 +// pageCache 单独获取活动时间
  259 +const getActivityTime = (params) => {
  260 + return api.get('', _.assign({
  261 + method: 'app.outlets.activityGet',
  262 + platform: 3 // h5平台代号
  263 + }, params)).then(res => {
  264 + var times = [];
  265 +
  266 + if (res && res.code === 200) {
  267 + _.forEach(res.data, item => {
  268 + times.push(item.startLeftTime > 0 ? dateFormate(item.startTime) : item.endLeftTime);
  269 + });
  270 + return times;
  271 + } else {
  272 + log.error('the response code of "app.outlets.activityGet" is NOT 200', res);
  273 + return {};
  274 + }
  275 + });
  276 +};
  277 +
257 module.exports = { 278 module.exports = {
258 getContent: getContent, 279 getContent: getContent,
259 getActivity: getActivity, 280 getActivity: getActivity,
260 - getRecentActivity: getRecentActivity 281 + getRecentActivity: getRecentActivity,
  282 + getActivityTime: getActivityTime
261 }; 283 };
@@ -383,8 +383,9 @@ const getDiscountDetailData = (id, yhChannel) => { @@ -383,8 +383,9 @@ const getDiscountDetailData = (id, yhChannel) => {
383 title: res[0] && res[0].title, 383 title: res[0] && res[0].title,
384 productPool: res[0] && res[0].productPool, 384 productPool: res[0] && res[0].productPool,
385 activity: { 385 activity: {
386 - coverUrl: res[0] && res[0].coverUrl,  
387 - leftTime: res[0] && res[0].leftTime 386 + coverUrl: res[0] && res[0].coverUrl
  387 +
  388 + // leftTime: res[0] && res[0].leftTime
388 } 389 }
389 }; 390 };
390 } else { 391 } else {
@@ -394,6 +395,22 @@ const getDiscountDetailData = (id, yhChannel) => { @@ -394,6 +395,22 @@ const getDiscountDetailData = (id, yhChannel) => {
394 }); 395 });
395 }; 396 };
396 397
  398 +const getDiscountTime = (id, yhChannel) => {
  399 + let param = {
  400 + id: id,
  401 + yh_channel: channelType[yhChannel] || '1'
  402 + };
  403 +
  404 + return _discount(param).then((result) => {
  405 + if (result && result.code === 200) {
  406 + return result.data[0].left_time;
  407 + } else {
  408 + logger.error('get discount time code no 200');
  409 + return {};
  410 + }
  411 + });
  412 +};
  413 +
397 module.exports = { 414 module.exports = {
398 getSaleData, 415 getSaleData,
399 getBreakCodeData, 416 getBreakCodeData,
@@ -402,5 +419,6 @@ module.exports = { @@ -402,5 +419,6 @@ module.exports = {
402 getVipData, 419 getVipData,
403 getFilterData, 420 getFilterData,
404 getSearchData, 421 getSearchData,
405 - saleNav 422 + saleNav,
  423 + getDiscountTime
406 }; 424 };
@@ -63,12 +63,14 @@ router.get('/sale/discount', sale.discount); @@ -63,12 +63,14 @@ router.get('/sale/discount', sale.discount);
63 router.get('/sale/discount/detail', sale.discountDetail); 63 router.get('/sale/discount/detail', sale.discountDetail);
64 router.get('/sale/breakingYards', sale.breakingYards); 64 router.get('/sale/breakingYards', sale.breakingYards);
65 router.get('/sale/vip', sale.vip); 65 router.get('/sale/vip', sale.vip);
  66 +router.get('/sale/discount/getTime', sale.getTime);
66 67
67 router.get('/sale/search', sale.search); 68 router.get('/sale/search', sale.search);
68 router.get('/sale/filter', sale.filter); 69 router.get('/sale/filter', sale.filter);
69 70
70 router.get('/outlet', outlet.index); 71 router.get('/outlet', outlet.index);
71 router.get('/outlet/activity', outlet.activityDetail); 72 router.get('/outlet/activity', outlet.activityDetail);
  73 +router.get('/outlet/activityTime', outlet.activityTime);
72 74
73 router.get('/outlet/activityinfo', outlet.activityList); 75 router.get('/outlet/activityinfo', outlet.activityList);
74 76
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 7
8 {{# activity}} 8 {{# activity}}
9 <img src="{{image coverUrl 640 200}}"/> 9 <img src="{{image coverUrl 640 200}}"/>
10 - <p class="activity-time" data-time-s="{{leftTime}}"><i class="iconfont time-ico">&#xe603;</i><span></span></p> 10 + <p class="activity-time" data-time-s=""><i class="iconfont time-ico">&#xe603;</i><span></span></p>
11 {{/ activity}} 11 {{/ activity}}
12 12
13 </div> 13 </div>
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 * @date: 2016/5/20 4 * @date: 2016/5/20
5 */ 5 */
6 var $ = require('yoho-jquery'), 6 var $ = require('yoho-jquery'),
  7 + tip = require('../plugin/tip'),
7 lazyLoad = require('yoho-jquery-lazyload'); 8 lazyLoad = require('yoho-jquery-lazyload');
8 9
9 var countDown = require('../plugin/countdown'), 10 var countDown = require('../plugin/countdown'),
@@ -13,4 +14,24 @@ search.start(); @@ -13,4 +14,24 @@ search.start();
13 14
14 lazyLoad($('img.lazy')); 15 lazyLoad($('img.lazy'));
15 16
16 -countDown(); 17 +$.ajax({
  18 + type: 'GET',
  19 + url: '/product/sale/discount/getTime',
  20 + data: {
  21 + id: window.queryString.id
  22 + },
  23 + success: function(data) {
  24 + if (data) {
  25 + // $('.activity-time').attr('data-time-s', data);
  26 +
  27 + countDown({
  28 + endTime: [data]
  29 + });
  30 + }
  31 + },
  32 + error: function() {
  33 + tip.show('网络断开连接了~');
  34 + }
  35 +});
  36 +
  37 +
1 var $ = require('yoho-jquery'), 1 var $ = require('yoho-jquery'),
2 - Countdown = require('./outlet/countdown'); 2 +
  3 + // Countdown = require('./outlet/countdown'),
  4 + ajaxActivityTime = require('./outlet/ajaxActivityTime');
3 5
4 var search = require('./sale/search'); 6 var search = require('./sale/search');
5 7
6 -var el = $('.cd-lite'); 8 +// var el = $('.cd-lite');
7 9
8 search.start(); 10 search.start();
9 11
10 -new Countdown.Countdown({  
11 - el: el 12 +ajaxActivityTime({
  13 + sort: 1, // 接口规定传1
  14 + id: window.queryString.id,
  15 + type: 0 // 接口规定传0
12 }); 16 });
13 17
  18 +// new Countdown.Countdown({
  19 +// el: el
  20 +// });
  21 +
14 $('.back-ground-white').css('padding', '0'); 22 $('.back-ground-white').css('padding', '0');
@@ -2,27 +2,26 @@ @@ -2,27 +2,26 @@
2 * Created by runner on 16/6/14. 2 * Created by runner on 16/6/14.
3 */ 3 */
4 var $ = require('yoho-jquery'), 4 var $ = require('yoho-jquery'),
5 - Countdown = require('./outlet/countdown'),  
6 - iscroll = require('./outlet/nav'); 5 + iscroll = require('./outlet/nav'),
  6 + ajaxActivityTime = require('./outlet/ajaxActivityTime');
7 7
8 -var $el = $('.cd-lite'); 8 +var $el = $('.cd-lite'),
  9 + $indexNav = $('#index_nav');
9 10
10 require('../common'); 11 require('../common');
11 require('./outlet/set-backurl'); 12 require('./outlet/set-backurl');
12 13
13 if ($el.length > 0) { 14 if ($el.length > 0) {
14 - $el.each(function() {  
15 - new Countdown.Countdown({  
16 - el: $(this)  
17 - }); 15 + ajaxActivityTime({
  16 + type: window.queryString.type || 2
18 }); 17 });
19 } 18 }
20 19
21 // 导航滚动 20 // 导航滚动
22 -if ($('#index_nav').length > 0) { 21 +if ($indexNav.length > 0) {
23 iscroll({ 22 iscroll({
24 el: '#index_nav' 23 el: '#index_nav'
25 - }).goto($('#index_nav').find('.active').index()); 24 + }).goto($indexNav.find('.active').index());
26 } 25 }
27 26
28 if ($('.back-ground-white').length < 1) { 27 if ($('.back-ground-white').length < 1) {
@@ -5,23 +5,46 @@ var $ = require('yoho-jquery'), @@ -5,23 +5,46 @@ var $ = require('yoho-jquery'),
5 tip = require('../plugin/tip'), 5 tip = require('../plugin/tip'),
6 iscroll = require('./outlet/nav'); 6 iscroll = require('./outlet/nav');
7 7
  8 +var $bgw = $('.back-ground-white'),
  9 + $indexNav = $('#index_nav');
  10 +
8 require('../common'); 11 require('../common');
9 require('./outlet/set-backurl'); 12 require('./outlet/set-backurl');
10 13
11 // 导航滚动 14 // 导航滚动
12 -if ($('#index_nav').length > 0) { 15 +if ($indexNav.length > 0) {
13 iscroll({ 16 iscroll({
14 el: '#index_nav' 17 el: '#index_nav'
15 - }).goto($('#index_nav').find('.active').index()); 18 + }).goto($indexNav.find('.active').index());
16 } 19 }
17 20
18 -if ($('.back-ground-white').length < 1) { 21 +if ($bgw.length < 1) {
19 $('.empty').show(); 22 $('.empty').show();
20 } 23 }
21 24
22 -$('.back-ground-white').on('click', function() { 25 +$bgw.on('click', function() {
23 tip.show('活动即将开始,敬请期待!'); 26 tip.show('活动即将开始,敬请期待!');
24 return false; 27 return false;
25 }); 28 });
26 29
27 -$('.cd-medium').show(); 30 +$.ajax({
  31 + type: 'GET',
  32 + url: '/product/outlet/activityTime',
  33 + data: {
  34 + type: window.queryString.type || 3
  35 + },
  36 + success: function(data) {
  37 + var $cdMedium = $('.cd-medium');
  38 +
  39 + if (data) {
  40 + $cdMedium.each(function(key, item) {
  41 + $(item).html(data[key]);
  42 + });
  43 +
  44 + $cdMedium.show();
  45 + }
  46 + },
  47 + error: function() {
  48 + tip.show('网络断开连接了~');
  49 + }
  50 +});
1 var $ = require('yoho-jquery'), 1 var $ = require('yoho-jquery'),
2 Swiper = require('yoho-swiper'), 2 Swiper = require('yoho-swiper'),
3 lazyLoad = require('yoho-jquery-lazyload'), 3 lazyLoad = require('yoho-jquery-lazyload'),
4 - Countdown = require('./outlet/countdown'); 4 + ajaxActivityTime = require('./outlet/ajaxActivityTime');
5 5
6 var $el = $('.cd-lite'); 6 var $el = $('.cd-lite');
7 var $categoryNavItem = $('.outlet-category-nav a'); 7 var $categoryNavItem = $('.outlet-category-nav a');
@@ -39,10 +39,9 @@ function searchInitParam(dom) { @@ -39,10 +39,9 @@ function searchInitParam(dom) {
39 } 39 }
40 40
41 if ($el.length > 0) { 41 if ($el.length > 0) {
42 - $el.each(function() {  
43 - new Countdown.Countdown({  
44 - el: $(this)  
45 - }); 42 + ajaxActivityTime({
  43 + type: 0, // 获取全部奥莱活动列表, 不区分是否将开始或结束
  44 + yh_channel: window.queryString.yh_channel
46 }); 45 });
47 } 46 }
48 47
  1 +/**
  2 + * 获取奥莱活动时间
  3 + * @author: wsl<shuiling.wang@yoho.cn>
  4 + * @date: 2016/10/10
  5 + */
  6 +var $ = require('yoho-jquery'),
  7 + Countdown = require('../outlet/countdown'),
  8 + tip = require('../../plugin/tip');
  9 +
  10 +var $el = $('.cd-lite');
  11 +
  12 +module.exports = function(params) {
  13 + $.ajax({
  14 + type: 'GET',
  15 + url: '/product/outlet/activityTime',
  16 + data: params,
  17 + success: function(data) {
  18 + if (data) {
  19 +
  20 + $el.each(function(key, item) {
  21 + $(item).attr('data-config', '{"leftTime": ' + data[key] + ' }');
  22 +
  23 + new Countdown.Countdown({
  24 + el: $(item)
  25 + });
  26 + });
  27 + }
  28 + },
  29 + error: function() {
  30 + tip.show('网络断开连接了~');
  31 + }
  32 + });
  33 +};