Authored by 郭成尧

order-info-conflict

... ... @@ -15,7 +15,6 @@ const paymentProcess = require(`${utils}/payment-process`);
const crypto = global.yoho.crypto;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const camelCase = global.yoho.camelCase;
// cookie 参数
const actCkOpthn = {
... ... @@ -110,8 +109,8 @@ class BuyNowController {
return res.render('buynow/order-ensure', {
pageHeader: headerData,
module: 'buynow',
page: 'order-ensure',
module: 'cart',
page: 'buynow-order-ensure',
title: '确认订单',
width750: true,
localCss: true,
... ... @@ -232,8 +231,8 @@ class BuyNowController {
});
res.render('select-address', {
module: 'buynow',
page: 'select-address',
module: 'cart',
page: 'buynow-select-address',
pageHeader: headerData,
pageFooter: true,
moreUrl,
... ... @@ -274,8 +273,8 @@ class BuyNowController {
res.render('select-invoice', _.assign(returnData, {
pageHeader: headerData,
module: 'buynow',
page: 'select-invoice',
module: 'cart',
page: 'buynow-select-invoice',
localCss: true,
addressMore: helpers.urlFormat('/cart/index/buynow/orderensure', {
product_sku: product_sku,
... ... @@ -295,8 +294,8 @@ class BuyNowController {
});
res.render('select-coupon', {
module: 'buynow',
page: 'select-coupon',
module: 'cart',
page: 'buynow-select-coupon',
title: '选择优惠券',
selectCouponPage: true,
pageHeader: headerData,
... ... @@ -312,17 +311,57 @@ class BuyNowController {
* @param {*} next
*/
listCoupon(req, res, next) {
let orderInfo;
try {
orderInfo = JSON.parse(req.cookies.buynow_info);
} catch (e) {
logger.info(`orderEnsure: get buynow-order-info from cookie error:${JSON.stringify(e)}`);
orderInfo = {};
res.clearCookie('buynow_info', actCkOpthn);
}
let delivery_way = orderInfo.deliveryId || 1;
co(function* () {
let result = yield req.ctx(BuyNowModel).listCoupon({
uid: req.user.uid,
product_sku: req.query.product_sku,
sku_type: req.query.sku_type,
buy_number: req.query.buy_number
buy_number: req.query.buy_number,
is_group_frees: 'Y', // 运费券是否分组
delivery_way: delivery_way,
});
let finalResult = _.get(result, 'data', {});
res.json(camelCase(finalResult));
let finalResult = {
availableCoupons: [],
usableFreesCoupons: [],
notAvailableCoupons: [],
};
let usableCoupons = _.get(result, 'data.usable_coupons', []);
let freesCoupons = _.get(result, 'data.usable_frees_coupons', []);
let unusableCoupons = _.get(result, 'data.unusable_coupons', []);
let orderInfoUsableUsualCode = _.get(orderInfo, 'usable_usual_code', '');
let orderInfoUsableFreeCode = _.get(orderInfo, 'usable_free_code', '');
let procCouponsData = coupon => {
return {
couponCode: coupon.coupon_code,
couponDetailInfomation: coupon.coupon_name,
couponValue: coupon.coupon_value,
couponValidity: coupon.coupon_validity,
checked: coupon.coupon_code === orderInfoUsableUsualCode ||
coupon.coupon_code === orderInfoUsableFreeCode
};
};
finalResult.availableCoupons = usableCoupons.map(procCouponsData); // 可用优惠券
finalResult.usableFreesCoupons = freesCoupons.map(procCouponsData); // 运费券
finalResult.notAvailableCoupons = unusableCoupons.map(procCouponsData); // 不可用优惠券
res.json(finalResult);
})().catch(next);
}
... ...
... ... @@ -278,7 +278,7 @@ exports.selectCoupon = (req, res) => {
title: '选择优惠券',
selectCouponPage: true,
pageHeader: headerData,
pageFooter: true,
pageFooter: false,
localCss: true
});
};
... ... @@ -287,29 +287,42 @@ exports.selectCoupon = (req, res) => {
* 购物车结算--获取优惠券列表
*/
exports.couponList = (req, res, next) => {
let uid = req.user.uid;
let orderInfo;
try {
orderInfo = JSON.parse(req.cookies['order-info']);
} catch (e) {
logger.info(`orderEnsure: get orderInfo from cookie error:${JSON.stringify(e)}`);
orderInfo = {};
res.clearCookie('order-info', actCkOpthn);
}
let delivery_way = orderInfo.deliveryId || 1;
if (req.xhr) {
return cartModel.getCouponList(uid)
.then(data => {
res.json(data);
}).catch(next);
return cartModel.getCouponList({
uid: req.user.uid,
delivery_way: delivery_way,
is_group_frees: 'Y', // 运费券是否分组
orderInfo: orderInfo
}).then(data => {
res.json(data);
}).catch(next);
} else {
return next();
}
};
/**
* 购物车输入优惠券码使用优惠券
*/
exports.couponSearch = (req, res, next) => {
exports.useCouponCode = (req, res, next) => {
let couponCode = req.body.couponCode || '';
let uid = req.user.uid;
co(function* () {
if (req.xhr) {
let result = yield cartModel.searchCoupon(uid, couponCode);
let result = yield cartModel.useCouponCode(uid, couponCode);
res.json(result);
} else {
... ...
... ... @@ -34,7 +34,9 @@ class BuyNowModel extends global.yoho.BaseModel {
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number
buy_number: params.buy_number,
is_group_frees: params.is_group_frees,
delivery_way: params.delivery_way
}, {cache: false});
}
... ...
... ... @@ -247,36 +247,45 @@ exports.orderSub = (uid, addressId, cartType, deliveryTime,
* @param int $uid 用户ID
* @return array|mixed 处理之后的优惠券数据
*/
exports.getCouponList = uid => {
exports.getCouponList = params => {
let result = {
availableCoupons: [],
usableFreesCoupons: [],
notAvailableCoupons: [],
coupons: []
};
return shoppingAPI.listCoupon(uid)
.then(coupons => {
let unusableCoupons = _.get(coupons, 'data.unusable_coupons', []);
let usableCoupons = _.get(coupons, 'data.usable_coupons', []);
let procCouponsData = coupon => {
return {
couponCode: coupon.coupon_code,
couponDetailInfomation: coupon.coupon_name,
couponValue: coupon.coupon_value,
couponValidity: coupon.coupon_validity
};
return shoppingAPI.listCoupon({
uid: params.uid,
delivery_way: params.delivery_way,
is_group_frees: params.is_group_frees
}).then(coupons => {
let usableCoupons = _.get(coupons, 'data.usable_coupons', []);
let freesCoupons = _.get(coupons, 'data.usable_frees_coupons', []);
let unusableCoupons = _.get(coupons, 'data.unusable_coupons', []);
let orderInfoUsableUsualCode = _.get(params, 'orderInfo.usable_usual_code', '');
let orderInfoUsableFreeCode = _.get(params, 'orderInfo.usable_free_code', '');
let procCouponsData = coupon => {
return {
couponCode: coupon.coupon_code,
couponDetailInfomation: coupon.coupon_name,
couponValue: coupon.coupon_value,
couponValidity: coupon.coupon_validity,
checked: coupon.coupon_code === orderInfoUsableUsualCode ||
coupon.coupon_code === orderInfoUsableFreeCode
};
};
result.notAvailableCoupons = unusableCoupons.map(procCouponsData);
result.coupons = usableCoupons.map(procCouponsData);
result.availableCoupons = usableCoupons.map(procCouponsData); // 可用优惠券
result.usableFreesCoupons = freesCoupons.map(procCouponsData); // 运费券
result.notAvailableCoupons = unusableCoupons.map(procCouponsData); // 不可用优惠券
return result;
},
() => result
);
return result;
});
};
exports.searchCoupon = (uid, couponCode) => {
exports.useCouponCode = (uid, couponCode) => {
let result = {code: 400, message: '出错啦~'};
if (!couponCode) {
... ...
... ... @@ -260,10 +260,12 @@ exports.getValidCouponCount = uid => {
* @param uid int 用户uid
* @return see doc
*/
exports.listCoupon = uid => {
exports.listCoupon = params => {
let param = {
method: 'app.Shopping.listCoupon',
uid
uid: params.uid,
delivery_way: params.delivery_way,
is_group_frees: params.is_group_frees
};
return api.get('', param);
... ...
... ... @@ -38,7 +38,7 @@ router.post('/index/new/orderCompute', authMW, order.orderCompute); // 结算页
router.post('/index/new/orderSub', authMW, order.orderSub); // 订单提交
router.get('/index/new/selectCoupon', authMW, order.selectCoupon); // 选择优惠券 页面
router.get('/index/new/couponList', order.couponList); // [ajax]获取优惠券列表
router.post('/index/new/couponSearch', order.couponSearch); // [ajax]购物车输入优惠券码使用优惠券
router.post('/index/new/useCouponCode', order.useCouponCode); // [ajax]购物车输入优惠券码使用优惠券
router.get('/index/new/selectAddress', authMW, order.selectAddress); // 选择地址
router.get('/index/new/invoiceInfo', authMW, order.invoiceInfo); // 发票信息
router.get('/index/new/jitDetail', authMW, order.jitDetail); // JIT 拆单配送信息
... ...
... ... @@ -94,27 +94,18 @@
<a href="{{selectCouponUrl}}">
<span class="title">优惠券/优惠券码</span>
{{# coupon}}
{{#if couponName}}
<span class="used coupon-use" data-name="{{couponName}}">
{{couponName}}
<i class="iconfont">&#xe614;</i>
</span>
{{^}}
{{#unless isLimit}}
<span class="coupon-count">
{{#if count}}
{{count}}张可用
{{else}}
无可用
{{#if isLimit}}
<span class="coupon-info pull-right">
该商品不可使用优惠券
<i class="iconfont">&#xe614;</i>
</span>
{{^}}
<span class="count">{{#if selectedAmount}}已选{{selectedAmount}}{{^}}{{count}}张可用{{/if}}</span>
<span class="coupon-info pull-right">
{{info}}
<i class="iconfont">&#xe614;</i>
</span>
{{/if}}
<i class="iconfont">&#xe614;</i>
</span>
{{/unless}}
<span class="not-used coupon-use">
{{#if isLimit}}该商品不可使用优惠券{{/if}}
<i class="iconfont">&#xe614;</i>
</span>
{{/if}}
{{/coupon}}
</a>
</li>
... ...
... ... @@ -94,27 +94,18 @@
<a href="{{#if isLimit}}javascript:void(0);{{else}}/cart/index/new/selectCoupon{{/if}}">
<span class="title">优惠券/优惠券码</span>
{{# coupon}}
{{#if couponName}}
<span class="used coupon-use" data-name="{{couponName}}">
{{couponName}}
<i class="iconfont">&#xe614;</i>
</span>
{{^}}
{{#unless isLimit}}
<span class="coupon-count">
{{#if count}}
{{count}}张可用
{{else}}
无可用
{{#if isLimit}}
<span class="coupon-info pull-right">
该商品不可使用优惠券
<i class="iconfont">&#xe614;</i>
</span>
{{^}}
<span class="count">{{#if selectedAmount}}已选{{selectedAmount}}{{^}}{{count}}张可用{{/if}}</span>
<span class="coupon-info pull-right">
{{info}}
<i class="iconfont">&#xe614;</i>
</span>
{{/if}}
<i class="iconfont">&#xe614;</i>
</span>
{{/unless}}
<span class="not-used coupon-use">
{{#if isLimit}}该商品不可使用优惠券{{/if}}
<i class="iconfont">&#xe614;</i>
</span>
{{/if}}
{{/coupon}}
</a>
</li>
... ...
<div class="yoho-page select-coupon-page my-coupon-page">
<form id="new-coupon" method="POST" action="">
<input type="text" name="couponCode" value="" placeholder="输入优惠券码">
<button type="submit" class="submit">确定</button>
</form>
<div class="coupon-wrap">
<div id="coupon-list" class="coupon-list"></div>
<div class="not-avaliable-coupon-line hide">不可使用的优惠券</div>
<div id="coupon-list-not" class="coupon-list"></div>
<div class="coupon-page-title">
<form id="new-coupon" class="new-coupon" method="POST" action="">
<input type="text" name="couponCode" value="" placeholder="输入优惠券码">
<button type="submit" class="submit">兑换</button>
</form>
<div class="coupon-use-manual">
说明:普通优惠券可以与运费券同时使用
</div>
<div class="coupon-tab">
<ul class="tab-navs" data-sticky>
<li class="tab-nav pull-left active">
<span data-target="#couponAvailable" data-trigger="tab" data-funHome>可用优惠券</span>
</li>
<em class="pull-left">|</em>
<li class="tab-nav pull-left">
<span data-target="#couponUnavailable" data-trigger="tab" data-funGetNewGoods>不可用优惠券</span>
</li>
</ul>
</div>
</div>
<div class="tab-panels coupon-wrap">
<div id="couponAvailable" class="coupon-list active"></div>
<div id="couponUnavailable" class="coupon-list"></div>
</div>
<div class="use-coupon-btn-group">
<button id="useCoupon" class="pull-left use">使用</button>
<button id="notUseCoupon" class="pull-right not-use">不使用</button>
</div>
</div>
<script id="tmpl-no-coupon" type="text/tmpl">
<div class="coupon-list">
<script id="tmplNoCoupon" type="text/tmpl">
<div class="null">
<i></i>
<p>您还没有优惠券!</p>
<p>没有可用优惠券!</p>
</div>
</div>
</script>
... ...
... ... @@ -9,7 +9,7 @@
{{!--coupon-list start--}}
<div class="coupon-list coupon-tab1">
{{#each list}}
<div class="coupon-group" data-coupon-id={{couponId}}>
<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">
... ...
{{# notAvailableCoupons}}
<div class="employ-main not-avaliable">
<span>{{ couponValue}}</span>
<p class="coupon-name">{{ couponDetailInfomation}}</p>
<p>有效期:{{ couponValidity}}</p>
</div>
{{/ notAvailableCoupons}}
\ No newline at end of file
{{#notAvailableCoupons}}
<section class="coupon not-available">
<div class="coupon-title">{{ couponDetailInfomation }}</div>
<div class="coupon-content">
<div class="content-left pull-left">
<div class="value">{{ couponValue }}</div>
<div class="requirement">使用条件</div>
</div>
<div class="content-middle pull-left">{{ couponValidity}}</div>
</div>
</section>
{{/notAvailableCoupons}}
\ No newline at end of file
... ...
{{#coupons}}
{{^ notAvailable}}
<a class="employ-main" data-coupon-code="{{ couponCode}}" data-coupon-name="{{ couponDetailInfomation}}" href="javascript:void(0);">
<span>{{ couponValue}}</span>
<p class="coupon-name">{{ couponDetailInfomation}}</p>
<p>有效期:{{ couponValidity}}</p>
</a>
{{/ notAvailable}}
{{/coupons}}
<a class="not-use" href="javascript:void(0);">不使用任何优惠券</a>
\ No newline at end of file
{{#availableCoupons}}
<section class="coupon usable-usual" data-code="{{ couponCode }}">
<div class="coupon-title">{{ couponDetailInfomation }}</div>
<div class="coupon-content">
<div class="content-left pull-left">
<div class="value">{{ couponValue }}</div>
<div class="requirement">使用条件</div>
</div>
<div class="content-middle pull-left">{{ couponValidity}}</div>
<div class="content-right pull-left">
<i class="iconfont checkbox{{#if checked}} icon-cb-radio{{^}} icon-radio{{/if}}"></i>
</div>
</div>
</section>
{{/availableCoupons}}
{{#usableFreesCoupons}}
<section class="coupon usable-free" data-code="{{ couponCode }}">
<div class="coupon-title">{{ couponDetailInfomation }}</div>
<div class="coupon-content">
<div class="content-left pull-left">
<div class="value">{{ couponValue }}</div>
<div class="requirement">使用条件</div>
</div>
<div class="content-middle pull-left">{{ couponValidity}}</div>
<div class="content-right pull-left">
<i class="iconfont checkbox{{#if checked}} icon-cb-radio{{^}} icon-radio{{/if}}"></i>
</div>
</div>
</section>
{{/usableFreesCoupons}}
\ No newline at end of file
... ...
... ... @@ -11,12 +11,11 @@ const qs = require('yoho-qs');
let tip = require('plugin/tip'),
loading = require('plugin/loading'),
order = require('./order-info'),
richTip = require('plugin/rich-tip'),
dialog = require('plugin/dialog');
dialog = require('plugin/dialog'),
order = require('cart/buynow/order-info'),
richTip = require('plugin/rich-tip');
let $invoice = $('.invoice'),
$couponUse = $('.coupon-use.used'),
$addressWrap = $('.address-wrap'),
$coinCheck = $('.coin-check'),
$coinLi = $('li.coin'),
... ... @@ -108,11 +107,6 @@ if (window.getUid() !== orderInfo('uid')) {
window.location.reload();
}
if ($couponUse.data('name') !== orderInfo('couponName')) {
orderInfo('coupon_code', null);
orderInfo('couponName', null);
}
isLimitGood() && (function() {
let a = [];
... ...
/*
* @Author: Targaryen
* @Date: 2017-06-23 11:43:18
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 11:43:18
* @Last Modified by: Targaryen
* @Last Modified time: 2017-07-21 11:06:16
*/
require('cart/select-address.page.css');
let $ = require('yoho-jquery'),
orderInfo = require('./order-info').orderInfo;
orderInfo = require('cart/buynow/order-info').orderInfo;
let $confim = $('.confim-mask'),
deleteId;
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-23 11:43:44
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-27 14:58:41
* @Last Modified time: 2017-07-24 17:49:36
*/
require('cart/select-coupon.page.css');
const qs = require('yoho-qs');
... ... @@ -12,17 +12,26 @@ let $ = require('yoho-jquery'),
tip = require('plugin/tip'),
conponTmpl = require('cart/select-coupon/coupon.hbs'),
conponNotAvaliableTmpl = require('cart/select-coupon/coupon-not-avaliable.hbs'),
orderInfo = require('./order-info').orderInfo;
orderInfo = require('cart/buynow/order-info').orderInfo;
require('plugin/tab');
let isGetData;
let $newCoupon = $('#new-coupon'),
linkUrl = document.referrer,
$couponList = $('#coupon-list');
linkUrl = document.referrer;
let $couponAvailable = $('#couponAvailable');
let $couponUnavailable = $('#couponUnavailable');
let $useCoupon = $('#useCoupon');
let $notUseCoupon = $('#notUseCoupon');
// let $couponUsableUsual;
// let $couponUsableFree;
let winH = $(window).height();
require('common');
require('cart/cartbuynow/select-coupon');
function fixedLayOut() {
let $null = $('.null'),
... ... @@ -48,6 +57,9 @@ function goToBack() {
}
}
/**
* 输入优惠券码兑换优惠券
*/
$newCoupon.on('submit', function() {
let $this = $(this);
let couponCode = $this.find('[name="couponCode"]').val();
... ... @@ -64,16 +76,14 @@ $newCoupon.on('submit', function() {
buy_number: qs.buy_number
}
}).then(function(res) {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
tip.show('优惠券可用');
// 实付金额发生变化,使用有货币为0
orderInfo('use_yoho_coin', 0);
orderInfo('coupon_code', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
goToBack();
} else {
tip.show(res.message);
setTimeout(function() {
location.reload();
}, 500);
}
}).fail(function() {
tip.show('网络错误');
... ... @@ -81,101 +91,108 @@ $newCoupon.on('submit', function() {
return false;
});
$couponList.on('touchstart', '.employ-main', function() {
let $this = $(this);
$this.siblings().removeClass('focus');
$this.addClass('focus');
}).on('touchend touchcancel', '.employ-main', function() {
let $this = $(this);
/**
* 使用优惠券
*/
$useCoupon.on('click', function() {
let couponCodeArray = [];
$this.siblings().removeClass('focus');
$this.removeClass('focus');
});
if (orderInfo('usable_usual_code')) {
couponCodeArray.push(orderInfo('usable_usual_code'));
}
$('body').on('touchend', '.not-use', function() {
orderInfo('coupon_code', null);
orderInfo('couponName', null);
if (orderInfo('usable_free_code')) {
couponCodeArray.push(orderInfo('usable_free_code'));
}
// 实付金额发生变化,使用有货币为0
orderInfo('use_yoho_coin', 0);
orderInfo('coupon_code', couponCodeArray.join(','));
goToBack();
});
$newCoupon.find('input').on('input', function() {
if ($(this).val() !== '') {
$newCoupon.find('.submit').css('background', '#444');
} else {
$newCoupon.find('.submit').css('background', '#b0b0b0');
}
/**
* 不使用优惠券
*/
$notUseCoupon.on('click', function() {
orderInfo('coupon_code', null);
orderInfo('usable_usual_code', null);
orderInfo('usable_free_code', null);
goToBack();
});
/**
* 优惠券列表处理
* @param {*} allCoupons
*/
function getCouponHandle(allCoupons) {
let notAvailableCoupons,
coupons;
// 把可用和不可用的优惠券分离出来
notAvailableCoupons = allCoupons.unusableCoupons;
coupons = allCoupons.usableCoupons;
// 没有优惠券
if (!(notAvailableCoupons.length || coupons.length)) {
$('.coupon-wrap').html($('#tmpl-no-coupon').html());
fixedLayOut();
return;
}
let availableCoupons = allCoupons.availableCoupons;
let usableFreesCoupons = allCoupons.usableFreesCoupons;
let notAvailableCoupons = allCoupons.notAvailableCoupons;
$.each(availableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$.each(coupons, function(i, coupon) {
$.each(usableFreesCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
coupon.couponDetailInfomation = coupon.couponName;
});
$.each(notAvailableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
coupon.couponDetailInfomation = coupon.couponName;
});
$couponUnavailable.append(conponNotAvaliableTmpl({
notAvailableCoupons: notAvailableCoupons
}));
// 没有优惠券
if (!(availableCoupons.length || usableFreesCoupons.length)) {
$('#couponAvailable').html($('#tmplNoCoupon').html());
fixedLayOut();
return false;
}
// 渲染可用的优惠券
$couponList.append(conponTmpl({
coupons: coupons
})).find('.employ-main').on('touchstart', function() {
let couponCode = $(this).data('coupon-code');
$.ajax({
method: 'POST',
url: '/cart/index/buynow/useCoupon',
data: {
product_sku: qs.product_sku,
buy_number: qs.buy_number,
coupon_code: couponCode
}
}).then(function(res) {
if (res.code === 200) {
orderInfo('coupon_code', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
// 实付金额发生变化,使用有货币为0
orderInfo('use_yoho_coin', 0);
goToBack();
} else if (res.message) {
tip.show(res.message);
$couponAvailable.append(conponTmpl({
availableCoupons: availableCoupons,
usableFreesCoupons: usableFreesCoupons
})).find('.coupon').on('touchstart', function() {
let $theCoupon = $(this);
let $theCouponCheckBox = $theCoupon.find('.checkbox');
let couponCode = $theCoupon.data('code');
// 操作前的选中状态
let beforeIsChecked = $theCouponCheckBox.hasClass('icon-cb-radio');
if ($theCoupon.hasClass('usable-usual')) {
if (beforeIsChecked) {
$theCouponCheckBox.removeClass('icon-cb-radio').addClass('icon-radio');
orderInfo('usable_usual_code', null);
} else {
$('.usable-usual').find('.checkbox').removeClass('icon-cb-radio').addClass('icon-radio');
$theCouponCheckBox.removeClass('icon-radio').addClass('icon-cb-radio');
orderInfo('usable_usual_code', couponCode);
}
}).fail(function() {
tip.show('网络错误');
});
});
} else if ($theCoupon.hasClass('usable-free')) {
if (beforeIsChecked) {
$theCouponCheckBox.removeClass('icon-cb-radio').addClass('icon-radio');
if (notAvailableCoupons.length) {
$('.not-avaliable-coupon-line').show();
}
$('#coupon-list-not').append(conponNotAvaliableTmpl({
notAvailableCoupons: notAvailableCoupons
}));
window.rePosFooter();
orderInfo('usable_free_code', null);
} else {
$('.usable-free').find('.checkbox').removeClass('icon-cb-radio').addClass('icon-radio');
$theCouponCheckBox.removeClass('icon-radio').addClass('icon-cb-radio');
orderInfo('usable_free_code', couponCode);
}
}
});
}
/**
* 获取优惠券列表
*/
function getCouponData() {
if (isGetData) {
... ... @@ -193,7 +210,9 @@ function getCouponData() {
buy_number: qs.buy_number
},
dataType: 'json'
}).then(getCouponHandle).always(function() {
}).then(getCouponHandle).fail(function() {
tip.show('加载优惠券失败');
}).always(function() {
isGetData = false;
loading.hideLoadingMask();
});
... ...
... ... @@ -8,7 +8,7 @@ require('cart/select-invoice.page.css');
let $ = require('yoho-jquery'),
tip = require('plugin/tip'),
dialog = require('plugin/dialog'),
order = require('./order-info');
order = require('cart/buynow/order-info');
let $invoiceNotice = $('.invoice-notice'),
$taxNumber = $('.tax-number'),
... ... @@ -26,7 +26,7 @@ let isModifyTel = false;
let C_ID = window._ChannelVary[window.cookie('_Channel')] || 1;
require('common');
require('cartbuynow/select-invoice');
require('cart/cartbuynow/select-invoice');
if (window.getUid() !== orderInfo('uid')) {
order.init();
... ...
... ... @@ -22,7 +22,6 @@ function init() {
use_yoho_coin: 0,
address_id: null,
coupon_code: null,
couponName: null,
invoice: null, // 是否选择了发票
invoices_type: null, // 发票类型: 电子 or 纸质
invoices_title: null, // 发票抬头
... ...
/*
* @Author: Targaryen
* @Date: 2017-06-27 17:18:56
* @Last Modified by: Targaryen
*/
$('.select-coupon-page').css('min-height', function() {
return $(window).height() - $('#yoho-header').height();
});
... ...
... ... @@ -15,7 +15,6 @@ let tip = require('plugin/tip'),
dialog = require('plugin/dialog');
let $invoice = $('.invoice'),
$couponUse = $('.coupon-use.used'),
$addressWrap = $('.address-wrap'),
$coinCheck = $('.coin-check'),
$coinLi = $('li.coin'),
... ... @@ -69,15 +68,11 @@ if (window.getUid() !== orderInfo('uid')) {
window.location.reload();
}
if ($couponUse.data('name') !== orderInfo('couponName')) {
orderInfo('couponCode', null);
orderInfo('couponName', null);
}
// 来自购物车的链接默认不使用优惠券
if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1) {
orderInfo('couponCode', null);
orderInfo('couponName', null);
orderInfo('usable_usual_code', null);
orderInfo('usable_free_code', null);
}
isLimitGood() && (function() {
... ...
... ... @@ -20,7 +20,6 @@ function init() {
yohoCoin: 0,
addressId: null,
couponCode: null,
couponName: null,
invoice: null,
invoices_title: null,
invoices_type: null,
... ...
... ... @@ -12,15 +12,24 @@ let $ = require('yoho-jquery'),
conponNotAvaliableTmpl = require('cart/select-coupon/coupon-not-avaliable.hbs'),
orderInfo = require('./order-info').orderInfo;
require('plugin/tab');
let isGetData;
let $newCoupon = $('#new-coupon'),
linkUrl = document.referrer,
$couponList = $('#coupon-list');
linkUrl = document.referrer;
let $couponAvailable = $('#couponAvailable');
let $couponUnavailable = $('#couponUnavailable');
let $useCoupon = $('#useCoupon');
let $notUseCoupon = $('#notUseCoupon');
// let $couponUsableUsual;
// let $couponUsableFree;
let winH = $(window).height();
require('common');
require('cart/cartbuynow/select-coupon');
function fixedLayOut() {
let $null = $('.null'),
... ... @@ -46,6 +55,9 @@ function goToBack() {
}
}
/**
* 输入优惠券码兑换优惠券
*/
$newCoupon.on('submit', function() {
let $this = $(this);
... ... @@ -55,7 +67,7 @@ $newCoupon.on('submit', function() {
}
$.ajax({
method: 'POST',
url: '/cart/index/new/couponSearch',
url: '/cart/index/new/useCouponCode',
data: $this.serialize()
}).then(function(res) {
if (res.message) {
... ... @@ -63,12 +75,9 @@ $newCoupon.on('submit', function() {
}
if (res.code === 200) {
tip.show('优惠券可用');
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
orderInfo('couponCode', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
goToBack();
setTimeout(function() {
location.reload();
}, 500);
}
}).fail(function() {
tip.show('网络错误');
... ... @@ -76,53 +85,48 @@ $newCoupon.on('submit', function() {
return false;
});
$couponList.on('touchstart', '.employ-main', function() {
let $this = $(this);
$this.siblings().removeClass('focus');
$this.addClass('focus');
}).on('touchend touchcancel', '.employ-main', function() {
let $this = $(this);
/**
* 使用优惠券
*/
$useCoupon.on('click', function() {
let couponCodeArray = [];
$this.siblings().removeClass('focus');
$this.removeClass('focus');
});
if (orderInfo('usable_usual_code')) {
couponCodeArray.push(orderInfo('usable_usual_code'));
}
$('body').on('touchend', '.not-use', function() {
orderInfo('couponCode', null);
orderInfo('couponName', null);
if (orderInfo('usable_free_code')) {
couponCodeArray.push(orderInfo('usable_free_code'));
}
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
orderInfo('couponCode', couponCodeArray.join(','));
goToBack();
});
$newCoupon.find('input').on('input', function() {
if ($(this).val() !== '') {
$newCoupon.find('.submit').css('background', '#444');
} else {
$newCoupon.find('.submit').css('background', '#b0b0b0');
}
/**
* 不使用优惠券
*/
$notUseCoupon.on('click', function() {
orderInfo('couponCode', null);
orderInfo('usable_usual_code', null);
orderInfo('usable_free_code', null);
goToBack();
});
/**
* 优惠券列表处理
* @param {*} allCoupons
*/
function getCouponHandle(allCoupons) {
let notAvailableCoupons,
coupons;
// 把可用和不可用的优惠券分离出来
notAvailableCoupons = allCoupons.notAvailableCoupons;
coupons = allCoupons.coupons;
// 没有优惠券
if (!(notAvailableCoupons.length || coupons.length)) {
$('.coupon-wrap').html($('#tmpl-no-coupon').html());
fixedLayOut();
return;
}
let availableCoupons = allCoupons.availableCoupons;
let usableFreesCoupons = allCoupons.usableFreesCoupons;
let notAvailableCoupons = allCoupons.notAvailableCoupons;
$.each(availableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$.each(coupons, function(i, coupon) {
$.each(usableFreesCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
... ... @@ -130,47 +134,60 @@ function getCouponHandle(allCoupons) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$couponUnavailable.append(conponNotAvaliableTmpl({
notAvailableCoupons: notAvailableCoupons
}));
// 没有优惠券
if (!(availableCoupons.length || usableFreesCoupons.length)) {
$('#couponAvailable').html($('#tmplNoCoupon').html());
fixedLayOut();
return false;
}
// 渲染可用的优惠券
$couponList.append(conponTmpl({
coupons: coupons
})).find('.employ-main').on('touchstart', function() {
let couponCode = $(this).data('coupon-code');
$.ajax({
method: 'POST',
url: '/cart/index/new/couponSearch',
data: {
couponCode: couponCode
}
}).then(function(res) {
if (res.code === 200) {
// tip.show('优惠券可用');
orderInfo('couponCode', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
goToBack();
} else if (res.message) {
tip.show(res.message);
$couponAvailable.append(conponTmpl({
availableCoupons: availableCoupons,
usableFreesCoupons: usableFreesCoupons
})).find('.coupon').on('touchstart', function() {
let $theCoupon = $(this);
let $theCouponCheckBox = $theCoupon.find('.checkbox');
let couponCode = $theCoupon.data('code');
// 操作前的选中状态
let beforeIsChecked = $theCouponCheckBox.hasClass('icon-cb-radio');
if ($theCoupon.hasClass('usable-usual')) {
if (beforeIsChecked) {
$theCouponCheckBox.removeClass('icon-cb-radio').addClass('icon-radio');
orderInfo('usable_usual_code', null);
} else {
$('.usable-usual').find('.checkbox').removeClass('icon-cb-radio').addClass('icon-radio');
$theCouponCheckBox.removeClass('icon-radio').addClass('icon-cb-radio');
orderInfo('usable_usual_code', couponCode);
}
}).fail(function() {
tip.show('网络错误');
});
});
} else if ($theCoupon.hasClass('usable-free')) {
if (beforeIsChecked) {
$theCouponCheckBox.removeClass('icon-cb-radio').addClass('icon-radio');
if (notAvailableCoupons.length) {
$('.not-avaliable-coupon-line').show();
}
$('#coupon-list-not').append(conponNotAvaliableTmpl({
notAvailableCoupons: notAvailableCoupons
}));
window.rePosFooter();
orderInfo('usable_free_code', null);
} else {
$('.usable-free').find('.checkbox').removeClass('icon-cb-radio').addClass('icon-radio');
$theCouponCheckBox.removeClass('icon-radio').addClass('icon-cb-radio');
orderInfo('usable_free_code', couponCode);
}
}
});
}
function getCouponDate() {
/**
* 获取优惠券列表
*/
function getCouponData() {
if (isGetData) {
return;
... ... @@ -184,18 +201,11 @@ function getCouponDate() {
url: '/cart/index/new/couponList',
dataType: 'json'
}).then(getCouponHandle).fail(function() {
// tip.show('加载优惠券失败');
tip.show('加载优惠券失败');
}).always(function() {
isGetData = false;
loading.hideLoadingMask();
});
}
getCouponDate();
// $(window).scroll(function() {
// if ($(window).scrollTop() + $(window).height() > $('body').height() * 0.9) {
// getCouponDate();
// }
// });
getCouponData();
... ...
... ... @@ -26,7 +26,7 @@ let isModifyTel = false;
let C_ID = window._ChannelVary[window.cookie('_Channel')] || 1;
require('common');
require('cartbuynow/select-invoice');
require('cart/cartbuynow/select-invoice');
if (window.getUid() !== orderInfo('uid')) {
order.init();
... ...
... ... @@ -518,6 +518,12 @@
color: #444;
}
.count {
background-color: #ff5558;
padding: 2px;
color: #fff;
}
.coupon-count {
margin-left: 20px;
color: #b0b0b0;
... ...
$couponRadius: 8px;
$rosyPink: #f06a6b;
$backgroudColor: #f2f2f2;
$fontColor: #444;
$fontGrayLight: #b0b0b0;
$fontSizeSmall: 16px;
@define-extend line {
content: "";
position: absolute;
... ... @@ -7,19 +14,27 @@
height: 0;
}
@define-extend page-padding {
padding-left: 30px;
padding-right: 30px;
}
.select-coupon-page {
margin-top: 30px;
margin-bottom: 30px;
background-color: $backgroudColor;
margin-top: 40px;
.coupon-page-title {
background-color: #fff;
}
.new-coupon {
@extend page-padding;
#new-coupon {
margin-bottom: 30px;
padding-left: 30px;
padding-right: 30px;
font-size: 24px;
input {
padding: 0 12px;
width: 384px;
width: 400px;
height: 80px;
border: 1px solid #b0b0b0;
border-radius: 0.1rem;
... ... @@ -38,50 +53,164 @@
}
}
.coupon-wrap {
padding-bottom: 100px;
}
.coupon-use-manual {
@extend page-padding;
color: $fontGrayLight;
font-size: $fontSizeSmall;
width: 100%;
margin-top: 30px;
}
.coupon-tab {
height: 60px;
line-height: 60px;
margin-top: 30px;
border-top: 1px solid $fontGrayLight;
li {
width: 315px;
text-align: center;
color: $fontGrayLight;
&.active {
color: $fontColor;
}
}
em {
color: $fontGrayLight;
width: 10px;
}
}
.coupon-list {
.employ-main:first-child {
margin-top: 0;
display: none;
.coupon {
border-radius: $couponRadius;
background-color: #fff;
margin: 30px;
height: 200px;
.coupon-title {
border-top-left-radius: $couponRadius;
border-top-right-radius: $couponRadius;
background-color: $rosyPink;
color: $backgroudColor;
font-size: 24px;
padding: 10px;
}
.coupon-content {
border-top: 4px dotted $rosyPink;
margin-top: -2px;
padding: 20px;
.content-left {
width: 120px;
border-right: 2px solid $fontColor;
}
.content-left > .value {
width: 100%;
text-align: center;
font-size: 48px;
color: $fontColor;
}
.content-left > .requirement {
text-align: center;
font-size: $fontSizeSmall;
color: $fontColor;
}
.content-middle {
width: 360px;
margin-left: 20px;
}
.content-right {
width: 40px;
padding-top: 36px;
}
.content-right > .checkbox {
font-size: 28px;
color: $fontColor;
}
}
}
.employ-main:last-child {
margin-bottom: 0;
.not-available {
.coupon-title {
background-color: $fontGrayLight;
}
.coupon-content {
border-top: 4px dotted $fontGrayLight;
}
}
.usable-free {
.coupon-title {
background-color: $fontColor;
}
.coupon-content {
border-top: 4px dotted $fontColor;
}
}
}
.not-use {
.active {
display: block;
width: 560px;
margin: 30px auto 0;
text-align: center;
font-size: 32px;
line-height: 2.5;
border: 1px solid #444;
border-radius: 4PX;
}
.not-avaliable-coupon-line {
position: relative;
margin-top: 30px;
margin-bottom: 30px;
font-size: 28px;
line-height: 2;
color: #b0b0b0;
text-align: center;
.use-coupon-btn-group {
@extend page-padding;
&:before {
@extend line;
width: 100%;
position: fixed;
left: 0;
bottom: 0;
z-index: 2;
background-color: #fff;
padding-top: 20px;
padding-bottom: 20px;
left: 60px;
}
button {
color: #fff;
width: 270px;
height: 70px;
border-radius: $couponRadius;
&:after {
@extend line;
&.use {
background-color: $fontColor;
}
right: 60px;
&.not-use {
background-color: $fontGrayLight;
}
}
}
.not-avaliable {
background-image: resolve("home/employ/employ-grey.jpg") !important;
.null {
position: absolute;
left: 50%;
transform: translateX(-50%);
i {
width: 100%;
height: 120px;
overflow: hidden;
display: block;
background: resolve("home/employ/not.png") center top no-repeat;
background-size: 100%;
}
}
}
... ...
@import "./select-coupon";
@import "home/coupons";
... ...
$coupon-content-background-color: #fff;
$coupon-header-backgroud-color: #f26968;
$font-color: #444;
$usable-frees-background-color: #444;
.my-coupon-page {
.coupon-tab {
height: 90px;
... ... @@ -24,7 +29,7 @@
.coupon-group {
background-color: #f2f2f2;
color: #f2f2f2;
color: $font-color;
margin: 20px 20px 0;
& > div {
... ... @@ -33,7 +38,8 @@
.coupon-header {
border-radius: 10px 10px 0 0;
background-color: #e53333;
background-color: $coupon-header-backgroud-color;
color: #fff;
height: 60px;
line-height: 60px;
overflow: hidden;
... ... @@ -48,7 +54,7 @@
border-top: 2px dashed #e53333;
display: table;
padding: 15px 0;
background-color: #f06a6b;
background-color: $coupon-content-background-color;
.coupon-content-group1 {
display: table-cell;
... ... @@ -70,7 +76,7 @@
.coupon-content-group2 {
display: table-cell;
font-size: 20px;
border-left: 1px solid #f1aeaf;
border-left: 1px solid $font-color;
padding-left: 20px;
padding-right: 20px;
width: 100%;
... ... @@ -91,7 +97,7 @@
.left {
float: left;
line-height: 45px;
color: #fff;
color: $font-color;
}
.left.down .iconfont:before {
... ... @@ -117,7 +123,7 @@
width: 120px;
height: 45px;
text-align: center;
background-color: #e53333;
background-color: $coupon-header-backgroud-color;
border-radius: 10px;
color: #fff;
}
... ... @@ -137,12 +143,26 @@
}
.coupon-footer {
background-color: #f06a6b;
background-color: $coupon-content-background-color;
padding: 20px;
font-size: 18px;
border-radius: 10px;
color: #fff;
border-top: 1px dashed #fff;
color: $font-color;
border-top: 1px dashed $font-color;
}
}
.usable-frees {
.coupon-header {
background-color: $usable-frees-background-color;
}
> .coupon-content {
border-top: 2px dashed $usable-frees-background-color;
> .coupon-content-group2 > .coupon-content-group2-table .btn {
background-color: $usable-frees-background-color;
}
}
}
... ...
... ... @@ -333,21 +333,29 @@ function tranformPayment(data, orderInfo, cartType, skuList, orderComputeData) {
*/
function coupon(count, orderInfo, orderComputeData) {
let coupons = {
couponName: '',
isCoupon: false,
count: count
count: count,
selectedAmount: 0,
info: ''
};
let couponAmount = _.get(orderComputeData, 'coupon_amount', false);
let shippingCost = _.get(orderComputeData, 'shipping_cost', false); // shipping_cost 是普通运费
if (couponAmount || (couponAmount === 0 && shippingCost === 0)) {
coupons.couponName = orderInfo.couponName;
if (_.get(orderInfo, 'usable_usual_code', null)) {
coupons.selectedAmount++;
}
// 选中已使用的优惠劵,则剩余多少张优惠劵,不提示
if (!coupons.couponName || coupons.count) {
coupons.isCoupon = true;
if (_.get(orderInfo, 'usable_free_code', null)) {
coupons.selectedAmount++;
}
if (count) {
if (coupons.selectedAmount) {
coupons.info = `-${couponAmount.toFixed(2)}`;
} else {
coupons.info = '未使用';
}
} else {
coupons.info = '无可用';
}
return coupons;
... ...