Authored by 郭成尧

del-old-code

// 优惠券 by acgpiano
'use strict';
const headerModel = require('../../../doraemon/models/header'), // 头部model
model = require('../models/coupons');
// status为使用状态
const index = (req, res, next) => {
req.ctx(model).couponData({
method: 'app.coupons.li',
uid: req.user.uid,
status: req.body.status || 0,
page: req.body.page || 1,
limit: 10,
}).then(result => {
let options = {
module: 'home',
page: 'coupons',
pageHeader: headerModel.setNav({
navTitle: '优惠券'
}),
title: '优惠券',
pageFooter: true,
list: result,
localCss: true
};
res.render('coupons', options);
}).catch(next);
};
const couponsAjax = (req, res, next) => {
req.ctx(model).couponData({
method: 'app.coupons.li',
uid: req.user.uid,
status: parseInt(req.body.status || 0, 10),
page: parseInt(req.body.page || 1, 10),
limit: 10,
}).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index,
couponsAjax
};
// 优惠券 by acgpiano
'use strict';
const helpers = global.yoho.helpers;
class couponsModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
couponData(params) {
return this.get({data: params}).then(result => {
if (result && result.data && result.data.couponList) {
let status0 = params.status === 0;
let status1 = params.status === 1;
return result.data.couponList.map(function(elem) {
delete elem.id;
if (status0) {
elem.bestowLink = helpers.urlFormat('/product/index/index',
{
coupon_id: elem.couponId,
coupon_code: elem.couponCode,
title: '优惠活动商品',
intro_text: `以下商品可使用【${elem.couponDetailInfomation}】优惠券`
}
);
} else if (status1) {
delete elem.overState;
elem.employbg = true;
}
return elem;
});
}
return [];
});
}
}
module.exports = couponsModel;
<div class="yoho-page my-coupon-page">
<div class="coupon-tab">
<ul>
<li class="activate">未使用</li>
<li>已使用</li>
</ul>
</div>
{{!--coupon-list start--}}
<div class="coupon-list coupon-tab1">
{{#each list}}
<div class="coupon-group{{#isEqualOr couponType '5'}} usable-frees{{/isEqualOr}}" data-coupon-id={{couponId}}>
<div class="coupon-header">{{couponDetailInfomation}}</div>
<div class="coupon-content">
<div class="coupon-content-group1">
<p class="coupon-money">{{couponValue}}</p>
<p>{{rule4ShortName}}</p>
</div>
<div class="coupon-content-group2">
<div class="coupon-content-group2-table">
<div>
{{couponValidity}}
{{#if overState}}<span class="coupon-soon-expire">{{overState}}</span>{{/if}}
</div>
<div>
<div class="left down info-btn">详细信息<i class="iconfont"></i></div>
<div class="right">
{{#if employbg}}
<span class="employ"></span>
{{else if bestowLink}}
<a href="javascript:void(0);" data-link="{{bestowLink}}" class="btn">立即使用</a>
{{/if}}
</div>
</div>
</div>
</div>
</div>
<div class="coupon-footer hide">
{{#notes}}
<p>{{.}}</p>
{{/notes}}
</div>
</div>
{{/each}}
</div>
{{!--coupon-list end--}}
<div class="coupon-list coupon-tab2"></div>
<div class="coupon-list coupon-tab3"></div>
</div>
<input type="hidden" id="no-download">
<div class="coupon-not-result">
<i></i>
<p>您还没有优惠券!</p>
<a href="/product/new">随便逛逛</a>
</div>
{{#each list}}
<div class="coupon-group{{#is-equal-or couponType '5'}} usable-frees{{/is-equal-or}}" data-coupon-id={{couponId}}>
<div class="coupon-header">{{couponDetailInfomation}}</div>
<div class="coupon-content">
<div class="coupon-content-group1">
<p class="coupon-money">{{couponValue}}</p>
<p>{{rule4ShortName}}</p>
</div>
<div class="coupon-content-group2">
<div class="coupon-content-group2-table">
<div>
{{couponValidity}}
{{#if overState}}<span class="coupon-soon-expire">{{overState}}</span>{{/if}}
</div>
<div>
<div class="left down info-btn">详细信息<i class="iconfont"></i></div>
<div class="right">
{{#if employbg}}
<span class="employ"></span>
{{else if bestowLink}}
<a href="javascript:void(0);" data-link="{{bestowLink}}" class="btn">立即使用</a>
{{/if}}
</div>
</div>
</div>
</div>
</div>
<div class="coupon-footer hide">
{{#notes}}
<p>{{.}}</p>
{{/notes}}
</div>
</div>
{{/each}}
// 不要使用es6
'use strict';
require('home/coupons.page.css');
require('common');
let $ = require('yoho-jquery'),
couponsListHbs = require('home/coupons-list.hbs'),
notResultHbs = require('home/coupon-not-result.hbs');
let $couponTab1 = $('.coupon-tab1'),
$couponTab2 = $('.coupon-tab2'),
$couponTab3 = $('.coupon-tab3'),
$couponUl = $('.coupon-tab'),
page = 1,
indexNum,
couponFun,
scrollHandler,
$tabDom;
$('body').css({'background-color': '#f2f2f2'});
couponFun = function() {
$tabDom = $couponUl.find('li.activate');
if (!$tabDom) {
return false;
}
if ($tabDom.data('AjaxFlag')) {
return false;
}
$tabDom.data('AjaxFlag', true);
page = $tabDom.data('page') || 1;
indexNum = $tabDom.index() * 1;
// 首屏渲染page = 2
if (indexNum === 0 && !$tabDom.data('page')) {
page = 2;
}
$.ajax({
type: 'POST',
url: '/home/couponsAjax',
dataType: 'json',
data: {
status: indexNum,
page: page
},
success: function(data) {
let $activeDom;
if (indexNum === 1) {
$activeDom = $couponTab2;
} else if (indexNum === 2) {
$activeDom = $couponTab3;
} else {
$activeDom = $couponTab1;
}
if (page <= 1 && data.length <= 0) {
$activeDom.html(notResultHbs());
return false;
}
if (data.length <= 0) {
return false;
}
$tabDom.data('page', ++page);
$tabDom.data('AjaxFlag', false);
$activeDom.append(couponsListHbs({list: data}));
window.rePosFooter(); // 重新计算底部位置
}
});
};
scrollHandler = function() {
if ($(window).scrollTop() + $(window).height() > $('body').height() - 100) {
couponFun();
return;
}
};
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
// tab 事件
$couponUl.on('click', 'li', function() {
$(this).addClass('activate').siblings().removeClass('activate');
$('.coupon-list').addClass('hide').eq($(this).index()).removeClass('hide');
couponFun();
window.rePosFooter(); // 重新计算底部位置
});
// 详细信息事件
$('.coupon-list').on('click', '.info-btn', function() {
let $this = $(this);
if ($this.hasClass('down')) {
$this.removeClass('down').addClass('up');
$this.closest('.coupon-group').find('.coupon-footer').removeClass('hide');
} else {
$this.removeClass('up').addClass('down');
$this.closest('.coupon-group').find('.coupon-footer').addClass('hide');
}
// 优惠券埋点
window._yas && window._yas.sendCustomInfo && window._yas.sendCustomInfo({
op: 'YB_COUPON_DETAIL_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')] || 1,
COUPON_ID: $this.closest('.coupon-group').data('coupon-id')
})
}, true);
window.rePosFooter(); // 重新计算底部位置
});
// 立即使用
$('.coupon-list').on('click', 'a.btn', function() {
let $this = $(this);
// 优惠券埋点
window._yas && window._yas.sendCustomInfo && window._yas.sendCustomInfo({
op: 'YB_COUPON_IMMEDIATE_USE_C',
param: JSON.stringify({
C_ID: window._ChannelVary[window.cookie('_Channel')] || 1,
COUPON_ID: $this.closest('.coupon-group').data('coupon-id')
})
}, true);
document.location.href = $this.data('link');
});
// 首屏渲染无结果判断
if ($('.coupon-tab1').find('.coupon-group').length <= 0) {
$('.coupon-tab1').html(notResultHbs());
window.rePosFooter(); // 重新计算底部位置
}