Authored by 郭成尧

Merge remote-tracking branch 'origin/master' into release/180427

Showing 61 changed files with 2059 additions and 1581 deletions
... ... @@ -52,6 +52,26 @@ class BuyNowController {
res.clearCookie('buynow_info', actCkOpthn);
}
// 是否需要重新计算
let needReComputer = orderInfo && !_.isEmpty(orderInfo) &&
(orderInfo.yohoCoin || orderInfo.coupon_code);
let computerPromise = null;
if (needReComputer) {
computerPromise = req.ctx(BuyNowModel).compute({
uid: uid,
product_sku: product_sku,
sku_type: req.query.sku_type,
buy_number: buy_number,
payment_type: orderInfo.payment_type,
delivery_way: orderInfo.delivery_way,
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10),
coupon_code: orderInfo.coupon_code,
gift_card_code: orderInfo.gift_card_code,
promotion_code: orderInfo.promotion_code
});
}
co(function * () {
let [userProfile, address, result, computeData, validCouponCount, validGiftCardCount] =
yield Promise.all([
... ... @@ -64,23 +84,13 @@ class BuyNowController {
buy_number: buy_number,
yoho_coin_mode: parseInt(orderInfo.use_yoho_coin, 10) > 0 ? 1 : 0
}),
req.ctx(BuyNowModel).compute({
uid: uid,
product_sku: product_sku,
sku_type: req.query.sku_type,
buy_number: buy_number,
payment_type: orderInfo.payment_type,
delivery_way: orderInfo.delivery_way,
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10),
coupon_code: orderInfo.coupon_code,
gift_card_code: orderInfo.gift_card_code,
promotion_code: orderInfo.promotion_code
}),
computerPromise,
req.ctx(BuyNowModel).countUsableCoupon({
uid: uid,
product_sku: req.query.product_sku,
sku_type: req.query.sku_type,
buy_number: buy_number
buy_number: buy_number,
delivery_way: orderInfo.delivery_way
}),
req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量
]);
... ... @@ -89,6 +99,7 @@ class BuyNowController {
let mobile = _.get(userProfile, 'data.mobile', '');
let orderAddress = _.get(result, 'address', []);
let addressList = _.get(address, 'data', []);
let autoSelectCouponCodeStr = _.get(result, 'data.coupon_pay.coupon_code', '');
let orderEnsure = {};
if (result.code !== 200 && result.message) {
... ... @@ -101,6 +112,11 @@ class BuyNowController {
}
});
if (orderInfo.user_check_coupon !== 'Y' && autoSelectCouponCodeStr) {
orderInfo.coupon_code = autoSelectCouponCodeStr;
res.cookie('buynow_info', JSON.stringify(orderInfo), actCkOpthn);
}
// 兼容原有的数据格式
orderInfo.deliveryId = orderInfo.delivery_way;
orderInfo.deliveryTimeId = orderInfo.delivery_time;
... ... @@ -109,13 +125,16 @@ class BuyNowController {
orderInfo.paymentType = orderInfo.payment_type;
orderEnsure = _.assign(
paymentProcess.tranformPayment(_.get(result, 'data', {}), orderInfo, null, null, computeData.data),
paymentProcess.tranformPayment(
_.get(result, 'data', {}), orderInfo, null, null,
_.get(computeData, 'data', {})),
{
coupon: paymentProcess.coupon(
_.get(validCouponCount, 'data.count', 0),
orderInfo,
computeData.data
),
coupon: paymentProcess.handleCoupons({
paymentApiCouponData: _.get(result, 'data.coupon_pay', {}),
validCouponCount: _.get(validCouponCount, 'data.count', 0),
orderComputeCouponPay: _.get(computeData, 'data.coupon_pay'),
userCheckCoupon: orderInfo.user_check_coupon
}),
selectAddressUrl: helpers.urlFormat('/cart/index/buynow/selectAddress', {
product_sku: product_sku,
buy_number: buy_number
... ... @@ -128,7 +147,7 @@ class BuyNowController {
choseGiftCard: helpers.urlFormat('/cart/index/buynow/selectGiftcard'),
giftCards: paymentProcess.handleGiftCards({
validGiftCardCount: _.get(validGiftCardCount, 'data.count', 0),
orderCompute: computeData.data
orderCompute: _.get(computeData, 'data', {})
})
}
);
... ... @@ -159,26 +178,51 @@ class BuyNowController {
* @param {*} next
*/
orderCompute(req, res, next) {
co(function * () {
let result = yield req.ctx(BuyNowModel).compute({
uid: req.user.uid,
cart_type: req.body.cart_type,
delivery_way: req.body.delivery_way,
payment_type: req.body.payment_type,
product_sku: req.body.product_sku,
buy_number: req.body.buy_number,
coupon_code: req.body.coupon_code,
gift_card_code: req.body.gift_card_code,
use_yoho_coin: req.body.use_yoho_coin
});
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);
}
co(function* () {
let [result, validCouponCount] = yield Promise.all([
req.ctx(BuyNowModel).compute({
uid: req.user.uid,
cart_type: req.body.cart_type,
delivery_way: req.body.delivery_way,
payment_type: req.body.payment_type,
product_sku: req.body.product_sku,
buy_number: req.body.buy_number,
coupon_code: req.body.coupon_code,
gift_card_code: req.body.gift_card_code,
use_yoho_coin: req.body.use_yoho_coin
}),
req.ctx(BuyNowModel).countUsableCoupon({
uid: req.user.uid,
product_sku: req.body.product_sku,
sku_type: req.body.sku_type,
buy_number: req.body.buy_number,
delivery_way: req.body.delivery_way
})
]);
let finalResult = _.get(result, 'data', {});
if (finalResult) {
_.set(finalResult, 'use_yoho_coin', paymentProcess.transPrice(_.get(result, 'data.use_yoho_coin')));
_.set(finalResult, 'yohoCoinCompute', paymentProcess.yohoCoinCompute(result.data));
_.set(finalResult, 'coupon', paymentProcess.handleCoupons({
paymentApiCouponData: {},
validCouponCount: _.get(validCouponCount, 'data.count', 0),
orderComputeCouponPay: _.get(finalResult, 'coupon_pay'),
userCheckCoupon: orderInfo.user_check_coupon
}));
}
return res.json(result.data);
return res.json(finalResult);
})().catch(next);
}
... ... @@ -363,21 +407,70 @@ class BuyNowController {
selectCoupon(req, res) {
let headerData = headerModel.setNav({
navTitle: '选择优惠券',
myConponPageNavBtn: true,
navBtn: false
});
res.render('select-coupon', {
res.render('select-coupons-page', {
module: 'cart',
page: 'buynow-select-coupon',
page: 'buynow-select-coupons',
title: '选择优惠券',
selectCouponPage: true,
pageHeader: headerData,
pageFooter: false,
localCss: true
localCss: true,
width750: true
});
}
/**
* 获取用户可用和不可用优惠券列表
*/
couponList(req, res, next) {
let uid = req.user.uid;
let delivery_way = req.body.delivery_way || 1;
let coupon_code = req.body.coupon_code || '';
let product_sku = req.body.product_sku;
let buy_number = req.body.buy_number;
let sku_type = req.body.sku_type;
co(function* () {
let couponApi = yield req.ctx(BuyNowModel).listCoupon({
uid,
delivery_way,
coupon_code,
product_sku,
buy_number,
sku_type
});
let result = paymentProcess.couponProcess(_.get(couponApi, 'data', {}));
res.render('select-coupons', {
pageFooter: false,
result: result,
layout: false
});
})().catch(next);
}
/**
* 输入优惠券码使用优惠券
*/
useCouponCode(req, res, next) {
co(function* () {
let result = yield req.ctx(BuyNowModel).usePromotionCode({
uid: req.user.uid,
product_sku: req.body.product_sku,
sku_type: req.body.sku_type,
buy_number: req.body.buy_number,
promotion_code: req.body.promotion_code
});
res.json(result);
})().catch(next);
}
/**
* 选择礼品卡页面
*/
selectGiftcard(req, res, next) {
... ... @@ -426,104 +519,6 @@ class BuyNowController {
});
})().catch(next);
}
/**
* 获取用户可用和不可用优惠券列表
* @param {*} req
* @param {*} res
* @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,
is_group_frees: 'Y', // 运费券是否分组
delivery_way: delivery_way,
});
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);
}
/**
* 使用优惠券
* @param {*} req
* @param {*} res
* @param {*} next
*/
useCoupon(req, res, next) {
co(function* () {
let result = yield req.ctx(BuyNowModel).useCoupon({
uid: req.user.uid,
product_sku: req.body.product_sku,
sku_type: req.body.sku_type,
buy_number: req.body.buy_number,
coupon_code: req.body.coupon_code
});
res.json(result);
})().catch(next);
}
/**
* 输入优惠券码使用优惠券
*/
usePromotionCode(req, res, next) {
co(function* () {
let result = yield req.ctx(BuyNowModel).usePromotionCode({
uid: req.user.uid,
product_sku: req.body.product_sku,
sku_type: req.body.sku_type,
buy_number: req.body.buy_number,
promotion_code: req.body.promotion_code
});
res.json(result);
})().catch(next);
}
}
module.exports = new BuyNowController();
... ...
... ... @@ -90,6 +90,7 @@ exports.orderEnsure = (req, res, next) => {
let userProfile = result[1];
let address = result[2];
let isNewUser = result[3];
let autoSelectCouponCodeStr = _.get(order, 'coupon.couponCode', '');
if (!_.isUndefined(isNewUser)) {
if (isNewUser) {
... ... @@ -99,6 +100,11 @@ exports.orderEnsure = (req, res, next) => {
}
}
if (orderInfo.user_check_coupon !== 'Y' && autoSelectCouponCodeStr) {
orderInfo.coupon_code = autoSelectCouponCodeStr;
res.cookie('order-info', JSON.stringify(orderInfo), actCkOpthn);
}
if (req.xhr) {
logger.info(`orderEnsure: ajax request, return json:${JSON.stringify(order)}`);
return res.json(order);
... ... @@ -157,6 +163,15 @@ exports.orderCompute = (req, res, next) => {
let uid = req.user.uid;
let skuList = req.body.skuList;
let type = req.body.type;
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);
}
if (type !== 'tickets') {
let params = {
... ... @@ -179,7 +194,8 @@ exports.orderCompute = (req, res, next) => {
}).catch(next);
} else {
req.ctx(cartModel).orderCompute(_.assign(params, {
product_sku_list: skuList
product_sku_list: skuList,
userCheckCoupon: orderInfo.user_check_coupon
})).then(result => {
res.json(result);
}).catch(next);
... ... @@ -324,27 +340,52 @@ exports.orderSub = (req, res, next) => {
};
/**
* 下单流程 选择优惠券
* 下单流程-选择优惠券页面
*/
exports.selectCoupon = (req, res) => {
exports.selectCouponsPage = (req, res) => {
let headerData = headerModel.setNav({
navTitle: '选择优惠券',
myConponPageNavBtn: true,
navBtn: false
});
res.render('select-coupon', {
res.render('select-coupons-page', {
module: 'cart',
page: 'select-coupon',
page: 'select-coupons',
title: '选择优惠券',
selectCouponPage: true,
pageHeader: headerData,
pageFooter: false,
localCss: true
localCss: true,
width750: true
});
};
/**
* 下单流程--获取优惠券列表
*/
exports.couponList = (req, res, next) => {
let uid = req.user.uid;
let delivery_way = req.body.delivery_way || 1;
let coupon_code = req.body.coupon_code || '';
co(function* () {
let couponApi = yield req.ctx(shoppingModel).listCoupon({
uid: uid,
delivery_way: delivery_way,
coupon_code: coupon_code
});
let result = paymentProcess.couponProcess(_.get(couponApi, 'data', {}));
res.render('select-coupons', {
pageFooter: false,
result: result,
layout: false
});
})().catch(next);
};
/**
* 选择礼品卡页面
*/
exports.selectGiftcard = (req, res, next) => {
... ... @@ -396,36 +437,6 @@ exports.selectGiftcard = (req, res, next) => {
};
/**
* 购物车结算--获取优惠券列表
*/
exports.couponList = (req, res, next) => {
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 req.ctx(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.useCouponCode = (req, res, next) => {
... ...
... ... @@ -20,7 +20,8 @@ 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,
delivery_way: params.delivery_way
},
param: {
cache: false
... ... @@ -35,15 +36,14 @@ class BuyNowModel extends global.yoho.BaseModel {
listCoupon(params) {
return this.post({
data: {
method: 'app.Buynow.listCoupon',
method: 'app.Buynow.selectCoupon',
uid: params.uid,
delivery_way: params.delivery_way,
coupon_code: params.coupon_code,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number,
is_group_frees: params.is_group_frees,
delivery_way: params.delivery_way
},
param: {cache: false}
sku_type: params.sku_type || 'I',
}
});
}
... ... @@ -54,7 +54,7 @@ class BuyNowModel extends global.yoho.BaseModel {
payment(params) {
let finalParams = {
data: {
method: 'app.Buynow.payment',
method: 'app.Buynow.enhancedPayment',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
... ...
... ... @@ -33,17 +33,22 @@ class cartModel extends global.yoho.BaseModel {
result.isLimit = true;
}
// cookie保存的数据
if (params.orderInfo && !_.isEmpty(params.orderInfo)) {
params.orderInfo.paymentType = params.orderInfo.paymentType ? params.orderInfo.paymentType : '';
let orderInfoCookie = _.get(params, 'orderInfo', null);
// 是否需要重新计算
let needReComputer = orderInfoCookie && !_.isEmpty(orderInfoCookie) &&
(orderInfoCookie.yohoCoin || orderInfoCookie.user_check_coupon === 'Y');
if (needReComputer) {
orderInfoCookie.paymentType = orderInfoCookie.paymentType ? orderInfoCookie.paymentType : '';
orderComputeAPI = this.ctx.req.ctx(shoppingModel).orderComputeAPI({
uid: params.uid,
cart_type: params.cartType,
delivery_way: params.orderInfo.deliveryId,
payment_type: params.orderInfo.paymentType,
coupon_code: params.orderInfo.couponCode,
gift_card_code: params.orderInfo.gift_card_code,
use_yoho_coin: params.orderInfo.yohoCoin,
delivery_way: orderInfoCookie.deliveryId,
payment_type: orderInfoCookie.paymentType,
coupon_code: orderInfoCookie.coupon_code,
gift_card_code: orderInfoCookie.gift_card_code,
use_yoho_coin: orderInfoCookie.yohoCoin,
product_sku_list: skuList,
activityInfo: params.activityInfo
});
... ... @@ -54,11 +59,11 @@ class cartModel extends global.yoho.BaseModel {
let cartPayAPIParams = {
uid: params.uid,
cart_type: params.cartType,
delivery_way: params.orderInfo.deliveryId,
payment_type: params.orderInfo.paymentType,
coupon_code: params.orderInfo.couponCode,
gift_card_code: params.orderInfo.gift_card_code,
use_yoho_coin: params.orderInfo.yohoCoin,
delivery_way: orderInfoCookie.deliveryId,
payment_type: orderInfoCookie.paymentType,
coupon_code: orderInfoCookie.couponCode,
gift_card_code: orderInfoCookie.gift_card_code,
use_yoho_coin: orderInfoCookie.yohoCoin,
product_sku_list: skuList,
activityInfo: params.activityInfo
};
... ... @@ -74,15 +79,18 @@ class cartModel extends global.yoho.BaseModel {
return Promise.all([
cartPayAPI, // 0. 订单数据
orderComputeAPI,
this.ctx.req.ctx(shoppingModel).getValidCouponCount(params.uid), // 2. 有效优惠券
this.ctx.req.ctx(shoppingModel).getValidCouponCount({
uid: params.uid,
delivery_way: orderInfoCookie.deliveryId
}), // 2. 有效优惠券
this.ctx.req.ctx(shoppingModel).countUsableGiftCard(params.uid) // 3 可用礼品卡数量
]).then(res => {
let pay = res[0];
let orderCompute = _.get(res[1], 'data', {});
let validCouponCount = _.get(res[2], 'data.count', 0);
let validGiftCardCount = _.get(res[3], 'data.count', 0);
let goodsList = _.get(pay, 'data.goods_list', []);
let paymentApiCouponData = _.get(pay, 'data.coupon_pay', {});
if (_.isEmpty(goodsList)) {
logger.info(`orderEnsure: goodsList is empty, isLimitGoods: ${isLimitGoods}`);
... ... @@ -99,13 +107,16 @@ class cartModel extends global.yoho.BaseModel {
return result;
}
result = Object.assign(
_.assign(
result,
paymentProcess.tranformPayment(pay.data, params.orderInfo, params.cartType, skuList, orderCompute),
{
coupon: paymentProcess.coupon(validCouponCount, params.orderInfo, orderCompute),
},
paymentProcess.tranformPayment(pay.data, orderInfoCookie, params.cartType, skuList, orderCompute),
{
coupon: paymentProcess.handleCoupons({
paymentApiCouponData,
validCouponCount: validCouponCount,
orderComputeCouponPay: orderCompute.coupon_pay,
userCheckCoupon: orderInfoCookie.user_check_coupon
}),
giftCards: paymentProcess.handleGiftCards({
validGiftCardCount: validGiftCardCount,
orderCompute: orderCompute
... ... @@ -120,11 +131,26 @@ class cartModel extends global.yoho.BaseModel {
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
*/
orderCompute(params) {
return this.ctx.req.ctx(shoppingModel).orderComputeAPI(params).then(result => {
if (result && result.data) {
result.data.use_yoho_coin = paymentProcess.transPrice(result.data.use_yoho_coin);
result.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(result.data);
return result.data;
return Promise.all([
this.ctx.req.ctx(shoppingModel).orderComputeAPI(params),
this.ctx.req.ctx(shoppingModel).getValidCouponCount({
uid: params.uid,
delivery_way: params.delivery_way
})
]).then(result => {
let computerResult = result[0];
let validCouponCount = _.get(result[1], 'data.count', 0);
if (computerResult && computerResult.data) {
computerResult.data.use_yoho_coin = paymentProcess.transPrice(computerResult.data.use_yoho_coin);
computerResult.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(computerResult.data);
computerResult.data.coupon = paymentProcess.handleCoupons({
paymentApiCouponData: {},
validCouponCount: validCouponCount,
orderComputeCouponPay: _.get(computerResult, 'data.coupon_pay'),
userCheckCoupon: params.user_check_coupon
});
return computerResult.data;
} else {
return {};
}
... ...
... ... @@ -16,7 +16,7 @@ class shoppingModel extends global.yoho.BaseModel {
}
let param = {
method: params.activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
method: params.activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.enhancedPayment',
enable_red_envelopes: 0, // h5不返回红包
cart_type: params.cart_type,
yoho_coin_mode: params.yoho_coin_mode || 0,
... ... @@ -234,10 +234,11 @@ class shoppingModel extends global.yoho.BaseModel {
* @param uid int 用户uid
* @return see doc
*/
getValidCouponCount(uid) {
getValidCouponCount(params) {
let param = {
method: 'app.Shopping.countUsableCoupon',
uid
uid: params.uid,
delivery_way: params.delivery_way || 1
};
return this.get({data: param});
... ... @@ -246,19 +247,23 @@ class shoppingModel extends global.yoho.BaseModel {
/**
* 获取用户优惠券列表,可用和不可用
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
* @param uid int 用户uid
* @return see doc
*/
listCoupon(params) {
let param = {
method: 'app.Shopping.listCoupon',
method: 'app.Shopping.selectCoupon',
uid: params.uid,
delivery_way: params.delivery_way,
is_group_frees: params.is_group_frees
coupon_code: params.coupon_code
};
return this.get({data: param});
return this.get({
data: param,
param: {
cache: false
}
});
}
/**
... ... @@ -269,7 +274,7 @@ class shoppingModel extends global.yoho.BaseModel {
*/
useCoupon(uid, couponCode) {
let param = {
method: 'app.Shopping.useCoupon',
method: 'app.coupons.bindPCoupon',
coupon_code: couponCode,
uid
};
... ...
... ... @@ -36,8 +36,9 @@ router.get('/index/new/pay/alipayresult', authMW, payController.payAli);// 支
router.get('/index/new/orderEnsure', authMW, disableBFCache, order.orderEnsure); // 订单结算
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.get('/index/new/selectCoupon', authMW, order.selectCouponsPage); // 选择优惠券 页面 New!
router.post('/index/new/couponList', order.couponList); // [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); // 发票信息
... ... @@ -70,9 +71,8 @@ router.post('/index/buynow/ordersub', authMW, BuyNowController.orderSub); // 立
router.get('/index/buynow/selectAddress', authMW, BuyNowController.selectAddress); // 选择地址
router.get('/index/buynow/selectInvoice', authMW, BuyNowController.selectInvoice); // 发票信息
router.get('/index/buynow/selectCoupon', authMW, BuyNowController.selectCoupon); // 选择优惠券页面
router.post('/index/buynow/useCoupon', BuyNowController.useCoupon); // [ajax]使用优惠券
router.post('/index/buynow/usePromotionCode', BuyNowController.usePromotionCode); // [ajax]输入优惠券码使用优惠券
router.get('/index/buynow/listCoupon', BuyNowController.listCoupon); // [ajax]获取优惠券列表
router.post('/index/buynow/useCouponCode', BuyNowController.useCouponCode); // [ajax]输入优惠券码使用优惠券
router.post('/index/buynow/couponList', BuyNowController.couponList); // [ajax]获取优惠券列表
router.get('/index/buynow/selectGiftcard', authMW, BuyNowController.selectGiftcard); // 选择礼品卡页面
... ...
... ... @@ -98,20 +98,7 @@
{{#if isOrdinaryCart}}
<li class="coupon">
<a href="{{selectCouponUrl}}">
<span class="title">优惠券/优惠券码</span>
{{# coupon}}
{{#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}}
{{/coupon}}
{{> cart/coupon-info}}
</a>
</li>
{{/if}}
... ... @@ -120,7 +107,7 @@
<li class="coin" data-yoho-coin="{{yohoCoinCompute.yohoCoin}}" data-yoho-coin-click={{yohoCoinCompute.yohoCoinClick}}>
<span class="title">有货币</span>
<span class="desc msg">{{yohoCoinCompute.yohoCoinMsg}}</span>
<span class="yoho-coin-help">?</span>
<span class="iconfont icon-wenhao yoho-coin-help"></span>
{{#if yohoCoinCompute.useYohoCoin}}
<span class="coin-check">
<i class="iconfont checkbox icon-cb-radio"></i>
... ... @@ -225,6 +212,9 @@
{{/if}}
<input type="hidden" id="product-sku" name="product-sku" value="{{sku}}">
{{#if couponPayRule}}
{{> cart/coupon-dialog}}
{{/if}}
{{#with seckill}}
<input type="hidden" id="activity-id" name="activity-id" value="{{activityId}}">
{{/with}}
... ...
... ... @@ -103,20 +103,7 @@
{{#if isOrdinaryCart}}
<li class="coupon">
<a href="{{#if isLimit}}javascript:void(0);{{else}}/cart/index/new/selectCoupon{{/if}}">
<span class="title">优惠券</span>
{{# coupon}}
{{#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{{#isEqualOr info '无可用'}} no-can-use{{/isEqualOr}}">
{{info}}<i class="iconfont">&#xe614;</i>
</span>
{{/if}}
{{/coupon}}
{{> cart/coupon-info}}
</a>
</li>
{{/if}}
... ... @@ -125,7 +112,7 @@
<li class="coin" data-yoho-coin="{{yohoCoinCompute.yohoCoin}}" data-yoho-coin-click={{yohoCoinCompute.yohoCoinClick}}>
<span class="title">有货币</span>
<span class="desc msg">{{yohoCoinCompute.yohoCoinMsg}}</span>
<span class="yoho-coin-help">?</span>
<span class="iconfont icon-wenhao yoho-coin-help"></span>
{{#if yohoCoinCompute.useYohoCoin}}
<span class="coin-check">
<i class="iconfont checkbox icon-cb-radio"></i>
... ... @@ -223,6 +210,9 @@
</div>
<input type="hidden" id="product-sku" name="product-sku" value="{{sku}}">
{{#if couponPayRule}}
{{> cart/coupon-dialog}}
{{/if}}
{{#with seckill}}
<input type="hidden" id="activity-id" name="activity-id" value="{{activityId}}">
{{/with}}
... ...
<div class="yoho-page select-coupon-page my-coupon-page">
<div class="coupon-page-title">
<form id="new-coupon" class="new-coupon clearfix" 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-funCouponAvailable>可用优惠券</span>
</li>
<em class="pull-left">|</em>
<li class="tab-nav pull-left">
<span data-target="#couponUnavailable" data-trigger="tab" data-funCouponUnavailable>不可用优惠券</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="tmplNoCoupon" type="text/tmpl">
<div class="null">
<i></i>
<p>没有可用优惠券!</p>
</div>
</script>
<div class="select-coupons-page">
</div>
... ...
{{#result}}
<section>
<div class="filter-box">
<span class="filter-btn valid active" data-num="{{usableCouponNumStr}}">可用{{#notEqualEither usableCouponNumStr '0'}}({{usableCouponNumStr}}){{/notEqualEither}}</span>
<span class="filter-btn invalid" data-num="{{unusableCouponNumStr}}">不可用{{#notEqualEither unusableCouponNumStr '0'}}({{unusableCouponNumStr}}){{/notEqualEither}}</span>
</div>
<div class="exchange-box">
<input type="text" name="couponCodeInput" placeholder="请输入优惠券码">
<button id="exchangeCouponBtn" class="exchange-coupon-btn">兑换</button>
</div>
<div class="tip-box{{#if noShowTips}} hide{{/if}}">
<div class="tips">
{{{headMsg}}}
</div>
<div class="tip-close">
<span class="iconfont">&#xe623;</span>
</div>
</div>
<div class="coupon-list usable">
{{#usableCouponsList}}
{{#each ./coupons}}
<div class="coupon{{#isEqualOr is_selected_support 'N'}} no-support-selected{{^}}{{#isEqualOr catalog 200}} coupon-activity{{/isEqualOr}}
{{#isEqualOr catalog 300}} coupon-freight{{/isEqualOr}}
{{#isEqualOr catalog 100}} coupon-shop{{/isEqualOr}}{{/isEqualOr}}" data-code="{{coupon_code}}">
<div class="coupon-left">
<p class="value">
<span>{{coupon_value_str}}</span>
</p>
<p class="threshold">{{use_rule}}</p>
</div>
<div class="coupon-right">
<div class="info">
<p class="title">
<span class="catalog-name">[{{catalog_name}}]</span> {{coupon_name}}</p>
<p class="time">{{coupon_validity}}</p>
{{#isEqualOr is_selected_support 'N'}}
<p class="desc">{{desc}}</p>
{{/isEqualOr}}
</div>
<div class="check">
{{#isEqualOr is_selected_support 'Y'}}
<span class="iconfont checkbox{{#isEqualOr selected 'Y'}} icon-cb-radio{{^}} icon-radio{{/isEqualOr}}"></span>
{{^}}
<span class="iconfont icon-point1"></span>
{{/isEqualOr}}
</div>
</div>
{{#isEqualOr is_overdue_soon 'Y'}}
<span class="top-tip"></span>
{{/isEqualOr}}
</div>
{{/each}}
{{/ usableCouponsList}}
{{#isEqualOr usableCouponNumStr '0'}}
<div class="no-conpon-now">
<div class="icon-not"></div>
<p>暂无优惠券</p>
</div>
{{/isEqualOr}}
</div>
<div class="coupon-list unusable hide">
{{#unusableCouponsList}}
{{#if ./name}}
<div class="coupon-list-type"><hr><span>{{./name}}</span><hr></div>
{{/if}}
{{#each ./coupons}}
<div class="coupon{{#isEqualOr catalog 200}} coupon-activity{{/isEqualOr}}
{{#isEqualOr catalog 300}} coupon-freight{{/isEqualOr}}
{{#isEqualOr catalog 100}} coupon-shop{{/isEqualOr}}">
<div class="coupon-left">
<p class="value">
<span>{{coupon_value_str}}</span>
</p>
<p class="threshold">{{use_rule}}</p>
</div>
<div class="coupon-right">
<div class="info">
<p class="title">
<span class="catalog-name">[{{catalog_name}}]</span> {{coupon_name}}</p>
<p class="time">{{coupon_validity}}</p>
<p class="desc unusable-desc">{{desc}}</p>
</div>
</div>
{{#isEqualOr is_overdue_soon 'Y'}}
<span class="top-tip"></span>
{{/isEqualOr}}
</div>
{{/each}}
{{/ unusableCouponsList}}
{{#isEqualOr unusableCouponNumStr '0'}}
<div class="no-conpon-now">
<div class="icon-not"></div>
<p>暂无优惠券</p>
</div>
{{/isEqualOr}}
</div>
<div class="use-now{{#isEqualOr usableCouponNumStr '0'}} hide{{/isEqualOr}}" id="useNowBox">
{{#couponPay}}
<div class="left-info">
<p>已选择
<span class="nums">{{coupon_count}}</span> 张,共优惠
<span class="nums">{{coupon_amount_str}}</span></p>
<p>待支付
<span class="nums">{{to_pay_amount_str}}</span></p>
</div>
{{/ couponPay}}
<button class="use-now-btn" id="useNowBtn">确认</button>
</div>
{{/ result}}
</section>
... ...
<div id="conponDialogWrapper" class="dialog-wrapper conpon-diaalog-wrapper">
<div class="dialog-box" style="top: 50%; margin-top: -119px;">
<div class="dialog-header">优惠券使用规则</div>
<div class="dialog-content">{{{couponPayRule}}}</div>
<div class="dialog-footer">
<span class="dialog-center-btn tap-hightlight" id="conponDialogCancel">知道了</span>
</div>
</div>
</div>
... ...
<span class="title">优惠券</span>
{{# coupon}}
{{#if isLimit}}
<span class="coupon-info pull-right">
该商品不可使用优惠券
<i class="iconfont">&#xe614;</i>
</span>
{{^}}
<span class="count">
{{showText}}
</span>
<span class="coupon-info pull-right{{#isEqualOr info '无可用'}} no-can-use{{/isEqualOr}}">
<span class="coupon-price-info">{{priceText}}</span>
<i class="iconfont">&#xe614;</i>
</span>
{{/if}}
{{/coupon}}
<span class="iconfont icon-wenhao coupon-help"></span>
... ...
const co = Promise.coroutine;
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const CouponNewModel = require('../models/coupon-new');
const helpers = global.yoho.helpers;
/**
* 优惠券数据处理
*/
const _couponProcess = (couponList, type) => {
_.map(couponList, coupon => {
if (type === 'use') {
coupon.is_used = true;
}
if (type === 'use' || coupon.is_overtime === 'Y' || coupon.is_invalid === 'Y') {
coupon.usedOvertimeOrInValid = true;
}
coupon.useNowLink = helpers.urlFormat(`/list/cc${coupon.coupon_code}-cd${coupon.coupon_id}?intro_text=以下商品可使用【${coupon.coupon_name}】优惠券&title=优惠活动商品`, '', null); // eslint-disable-line
return coupon;
});
return couponList;
};
class CouponNew {
page(req, res, next) {
let uid = req.user.uid;
co(function* () {
let [couponsApi, couponNumApi] = yield Promise.all([
req.ctx(CouponNewModel).couponGet({ uid }),
req.ctx(CouponNewModel).getCouponNums({ uid })
]);
let pageData = _.get(couponsApi, 'data', {});
let couponNum = _.get(couponNumApi, 'data', null);
let couponNumStr = {
notuse: '0',
use: '0',
overtime: '0'
};
let couponList = _.get(pageData, 'couponList', []);
if (couponList && couponList.length) {
pageData.couponList = _couponProcess(couponList);
}
if (couponNum) {
if (couponNum.notuse > 99) {
couponNumStr.notuse = '99+';
} else {
couponNumStr.notuse = couponNum.notuse + '';
}
if (couponNum.use > 99) {
couponNumStr.use = '99+';
} else {
couponNumStr.use = couponNum.use + '';
}
if (couponNum.overtime > 99) {
couponNumStr.overtime = '99+';
} else {
couponNumStr.overtime = couponNum.overtime + '';
}
}
res.render('coupons/page', {
module: 'home',
page: 'coupon-new',
localCss: true,
width750: true,
pageData,
couponNumStr,
pageHeader: headerModel.setNav({
navTitle: '优惠券',
myConponPageNavBtn: true,
navBtn: false
})
});
})().catch(next);
}
/**
* 优惠券数据
*/
coupons(req, res, next) {
let uid = req.user.uid;
let type = req.body.type;
let filter = req.body.filter;
let page = req.body.page;
co(function* () {
let couponApi = yield req.ctx(CouponNewModel).couponGet({
uid, type, filter, page
});
let couponsList = _.get(couponApi, 'data.couponList', []);
if (couponsList && couponsList.length) {
couponsList = _couponProcess(couponsList, type);
res.render('coupons/coupons', {
couponsList,
layout: false
});
} else {
res.json([]);
}
})().catch(next);
}
}
module.exports = new CouponNew();
... ...
// 优惠券 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
};
class CouponNewModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 优惠券数据
*/
couponGet(params) {
return this.get({
data: {
method: 'app.coupons.get',
uid: params.uid,
type: params.type || 'notuse',
filter: params.filter || 0,
limit: 20,
page: params.page || 1
},
param: {
cache: false
}
});
}
/**
* 优惠券数量
*/
getCouponNums(params) {
return this.get({
data: {
method: 'app.coupons.getCouponNums',
uid: params.uid
}
});
}
}
module.exports = CouponNewModel;
... ...
// 优惠券 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;
... ... @@ -18,7 +18,6 @@ class qrcodeModel extends global.yoho.BaseModel {
order_code: id,
uid: uid
}}).then(result => {
console.log(result);
if (result && result.code === 200) {
return result.data;
} else {
... ...
... ... @@ -24,7 +24,9 @@ const favorite = require(`${cRoot}/favorite`);
const orderController = require(`${cRoot}/order`);
const orderDetailController = require(`${cRoot}/orderDetail`);
const currencyController = require(`${cRoot}/myCurrency`);
const coupons = require(`${cRoot}/coupons`);
// const coupons = require(`${cRoot}/coupons`);
const couponNew = require(`${cRoot}/coupon-new`);
const suggest = require(`${cRoot}/suggest`);
const message = require(`${cRoot}/message`);
const onlineService = require(`${cRoot}/onlineService`);
... ... @@ -92,8 +94,8 @@ router.get('/favBrand', auth, favorite.favfavBrand);// 收藏的品牌
router.post('/favoriteDel', auth, favorite.favoriteDelete);// 取消收藏
// 优惠券
router.use('/coupons', auth, coupons.index);
router.use('/couponsAjax', coupons.couponsAjax);
router.get('/coupons', auth, couponNew.page);
router.post('/couponsList', couponNew.coupons);
// 意见反馈
router.get('/suggest', suggest.suggestData);
... ...
<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">
{{#couponsList}}
{{> coupons/coupon}}
{{/ couponsList}}
... ...
<div class="coupon-new-page cpage-padding284">
{{#couponNumStr}}
<div class="filter-box">
<span class="filter-btn-box">
<span class="filter-btn no-used active" data-num="{{notuse}}">未使用{{#notEqualEither notuse '0'}}({{notuse}}){{/notEqualEither}}</span>
<span class="iconfont icon-down show-filter-btn active"></span>
</span>
<span class="filter-btn-box">
<span class="filter-btn used" data-num="{{use}}">已使用{{#notEqualEither use '0'}}{{use}}{{/notEqualEither}}</span>
</span>
<span class="filter-btn-box">
<span class="filter-btn invalid" data-num="{{overtime}}">已失效{{#notEqualEither overtime '0'}}{{overtime}}{{/notEqualEither}}</span>
</span>
</div>
{{/ couponNumStr}}
{{#pageData}}
<div class="filter-item hide">
{{#filters}}
<button data-id="{{filter_id}}">{{filter_name}}</button>
{{/ filters}}
</div>
<div class="exchange-box">
<input type="text" name="couponCodeInput" placeholder="请输入优惠券码">
<button id="exchangeCouponBtn" class="exchange-coupon-btn">兑换</button>
</div>
<div class="coupon-list" id="couponList">
{{#couponList}}
{{> coupons/coupon}}
{{/ couponList}}
</div>
<div class="used-tip hide">
<hr>
<span class="used">以上是近期已使用的优惠券</span>
<span class="invalid">以上是近期已失效的优惠券</span>
<hr>
</div>
<div class="no-conpon-now{{#if couponList}} hide{{/if}}">
<div class="icon-not"></div>
<p>暂无优惠券</p>
</div>
{{/ pageData}}
</div>
<input type="hidden" id="no-download">
... ...
<section class="coupon-section" data-code="{{coupon_code}}" data-id="{{coupon_id}}">
<div class="coupon{{#isEqualOr is_overtime 'Y'}} coupon-overtime{{/isEqualOr}}{{#if is_used}} coupon-used{{/if}}{{#isEqualOr is_invalid 'Y'}} coupon-invalid{{/isEqualOr}}">
<div class="coupon-left{{#unless usedOvertimeOrInValid}}{{#isEqualOr catalog 200}} coupon-left-activity{{/isEqualOr}}{{#isEqualOr catalog 300}} coupon-left-freight{{/isEqualOr}}{{#isEqualOr catalog 100}} coupon-left-shop{{/isEqualOr}}{{/unless}}">
<p class="value"><span>{{coupon_value_str}}</span></p>
{{#if use_rule}}
<p class="threshold">{{use_rule}}</p>
{{/if}}
</div>
<div class="coupon-right">
<p class="title">
<span class="{{#isEqualOr catalog 200}}type-activity{{/isEqualOr}}{{#isEqualOr catalog 300}}type-freight{{/isEqualOr}}{{#isEqualOr catalog 100}}type-shop{{/isEqualOr}}">[{{catalog_name}}]</span> {{coupon_name}}</p>
<p class="time">{{coupon_validity}}</p>
{{#if notes}}
<p class="use-intro">
<span class="show-intro-btn">使用说明</span>
<span class="iconfont icon-down show-intro-btn show-intro-arrow"></span>
</p>
{{/if}}
<span class="tip"></span>
</div>
{{#if usedOvertimeOrInValid}}
{{#isEqualOr is_overtime 'Y'}}
<div class="stamp overtime-stamp"></div>
{{/isEqualOr}}
{{#isEqualOr is_invalid 'Y'}}
<div class="stamp invalid-stamp"></div>
{{/isEqualOr}}
{{#if is_used}}
<div class="stamp used-stamp"></div>
{{/if}}
{{^}}
<a href="{{useNowLink}}" class="use-now">立即使用</a>
{{#isEqualOr is_overdue_soon 'Y'}}
<span class="top-tip"></span>
{{/isEqualOr}}
{{/if}}
</div>
<ul class="coupon-intro hide">
{{#notes}}
<li>{{.}}</li>
{{/ notes}}
</ul>
</section>
... ...
... ... @@ -24,6 +24,9 @@
{{#installmentPage}}
<a href="/service/qaDetail?keyword=%E6%9C%89%E8%B4%A7%E5%88%86%E6%9C%9F&sonId=179" class="iconfont nav-home">&#xe639;</a>
{{/installmentPage}}
{{#myConponPageNavBtn}}
<a href="/service/qaDetail?keyword=%E4%BC%98%E6%83%A0%E5%88%B8&sonId=181" class="iconfont nav-home">&#xe639;</a>
{{/myConponPageNavBtn}}
{{#navPhone}}
<a href="{{.}}" class="iconfont nav-home">&#xe641;</a>
{{/navPhone}}
... ...
{
"name": "yohobuywap-node",
"version": "6.5.36",
"version": "6.5.40",
"private": true,
"description": "A New Yohobuy Project With Express",
"repository": {
... ...
<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}}
... ... @@ -2,8 +2,9 @@ import 'activity/grade-detail.page.css';
import $ from 'yoho-jquery';
import echarts from 'echarts/lib/echarts';
import 'echarts/lib/chart/line';
import 'echarts/lib/component/dataZoom';
import 'echarts/lib/component/markLine';
// import 'echarts/lib/component/dataZoom';
// import 'echarts/lib/component/markLine';
import Page from 'yoho-page';
import graphOptions from './graph-options';
import yoho from 'yoho-app';
... ... @@ -42,9 +43,10 @@ class GradeDetailPage extends Page {
});
this.eGradeGraph = echarts.init(this.view.gradeGraph[0]);
this.eGradeGraph.on('click', this.monthDetailInit.bind(this));
this.view.navBack.on('click', this.goBack.bind(this));
this.eGradeGraph.on('dataZoom', this.dataZoomEvent.bind(this));
// this.eGradeGraph.on('click', this.monthDetailInit.bind(this));
// this.view.navBack.on('click', this.goBack.bind(this));
// this.eGradeGraph.on('dataZoom', this.dataZoomEvent.bind(this));
this.beforeScroll = document.body.scrollTop;
this.year = 0;
... ...
... ... @@ -17,14 +17,15 @@ export default (graphData) => {
tooltip: {
trigger: 'none'
},
dataZoom: [{
type: 'inside',
start: graphData.start,
end: 100,
zoomLock: true,
zoomOnMouseWheel: false,
filterMode: 'none'
}],
// dataZoom: [{
// type: 'inside',
// start: graphData.start,
// end: 100,
// zoomLock: true,
// zoomOnMouseWheel: false,
// filterMode: 'none'
// }],
xAxis: {
type: 'category',
boundaryGap: false,
... ... @@ -46,6 +47,8 @@ export default (graphData) => {
color: ['#A59075'],
symbol: 'circle',
symbolSize: 10,
clipOverflow: false,
hoverAnimation: false,
type: 'line',
label: {
normal: {
... ...
... ... @@ -131,6 +131,8 @@ function orderCompute() {
$('.price-cost span').html('¥' + res.last_order_amount);
$('.bill span').html('¥' + res.last_order_amount);
$('.total').html(total);
$('.coupon .count').html(res.coupon.showText);
$('.coupon .coupon-price-info').html(res.coupon.priceText);
}
updateDeliverWay(deliver_way);
... ...
/*
* @Author: Targaryen
* @Date: 2017-06-23 11:43:44
* @Last Modified by: Targaryen
*/
require('cart/select-coupon.page.css');
const qs = require('yoho-qs');
let $ = require('yoho-jquery'),
loading = require('plugin/loading'),
tip = require('plugin/tip'),
conponTmpl = require('cart/select-coupon/coupon.hbs'),
conponNotAvaliableTmpl = require('cart/select-coupon/coupon-not-avaliable.hbs'),
orderInfo = require('cart/buynow/order-info').orderInfo;
let isGetData;
let $newCoupon = $('#new-coupon');
let $couponAvailable = $('#couponAvailable');
let $couponUnavailable = $('#couponUnavailable');
let $useCoupon = $('#useCoupon');
let $notUseCoupon = $('#notUseCoupon');
let winH = $(window).height();
let linkUrl = document.referrer;
require('common');
require('cart/cartbuynow/select-coupon');
function fixedLayOut() {
let $null = $('.null'),
navH = $('.nav-title').height(),
nullH = $null.height();
if ($null.length === 0) {
return false;
}
$null.css({
top: winH / 2 - nullH / 2 + navH
});
}
function goToBack() {
if (linkUrl) {
window.location.href = linkUrl;
} else {
history.go(-1);
}
}
/**
* 输入优惠券码兑换优惠券
*/
$newCoupon.on('submit', function() {
let $this = $(this);
let couponCode = $this.find('[name="couponCode"]').val();
if (!couponCode) {
tip.show('请输入优惠券码');
return false;
}
$.ajax({
method: 'POST',
url: '/cart/index/buynow/useCoupon',
data: {
coupon_code: couponCode,
buy_number: qs.buy_number,
product_sku: qs.product_sku
}
}).then(function(res) {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
orderInfo('usable_usual_code', res.data.coupon_code);
tip.show('优惠券可用');
setTimeout(function() {
location.reload();
}, 500);
}
}).fail(function() {
tip.show('网络错误');
});
return false;
});
/**
* 使用优惠券
*/
$useCoupon.on('click', function() {
let couponCodeArray = [];
if (orderInfo('usable_usual_code')) {
couponCodeArray.push(orderInfo('usable_usual_code'));
}
if (orderInfo('usable_free_code')) {
couponCodeArray.push(orderInfo('usable_free_code'));
}
orderInfo('coupon_code', couponCodeArray.join(','));
if (couponCodeArray.length > 0) {
goToBack();
} else {
tip.show('请选择优惠券');
}
});
/**
* 不使用优惠券
*/
$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 availableCoupons = allCoupons.availableCoupons;
let usableFreesCoupons = allCoupons.usableFreesCoupons;
let notAvailableCoupons = allCoupons.notAvailableCoupons;
$.each(availableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$.each(usableFreesCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$.each(notAvailableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$couponUnavailable.append(conponNotAvaliableTmpl({
notAvailableCoupons: notAvailableCoupons
}));
// 没有优惠券
if (!(availableCoupons.length || usableFreesCoupons.length)) {
$('#couponAvailable').html($('#tmplNoCoupon').html());
fixedLayOut();
return false;
}
// 渲染可用的优惠券
$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);
}
} else if ($theCoupon.hasClass('usable-free')) {
if (beforeIsChecked) {
$theCouponCheckBox.removeClass('icon-cb-radio').addClass('icon-radio');
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) {
return;
}
loading.showLoadingMask();
isGetData = true;
$.ajax({
type: 'GET',
url: '/cart/index/buynow/listCoupon',
data: {
product_sku: qs.product_sku,
buy_number: qs.buy_number
},
dataType: 'json'
}).then(getCouponHandle).fail(function() {
tip.show('加载优惠券失败');
}).always(function() {
isGetData = false;
loading.hideLoadingMask();
});
}
getCouponData();
import 'cart/select-coupons.page.css';
import SelectCouponsController from '../cartbuynow/select-coupons';
import { orderInfo } from 'cart/buynow/order-info';
new SelectCouponsController({
orderInfo: orderInfo,
couponListUrl: '/cart/index/buynow/couponList',
useCouponCodeUrl: '/cart/index/buynow/useCouponCode',
isBuyNowPage: true
});
... ...
export default {
path: '/cart/index'
};
... ...
... ... @@ -13,7 +13,10 @@ class OrderEnsure extends Page {
this.selector = {
invoice: $('.invoice'),
invoiceType: $('.invoice-type'),
userMobile: $('.user-mobile')
userMobile: $('.user-mobile'),
couponHelp: $('.coupon-help'),
conponDialogWrapper: $('#conponDialogWrapper'),
conponDialogCancel: $('#conponDialogCancel')
};
this.init();
... ... @@ -29,6 +32,26 @@ class OrderEnsure extends Page {
bindEvents() {
this.selector.invoice.on('click', '.checkbox', this.needInvoice.bind(this));
this.selector.couponHelp.on('click', this.showCouponHelp.bind(this));
this.selector.conponDialogCancel.on('click', this.cancelCouponHelp.bind(this));
}
/**
* 展示优惠券帮助弹窗
*/
showCouponHelp(e) {
this.selector.conponDialogWrapper.show();
e.preventDefault();
e.stopPropagation();
}
/**
* 关闭优惠券帮助弹窗
*/
cancelCouponHelp(e) {
this.selector.conponDialogWrapper.hide();
e.preventDefault();
e.stopPropagation();
}
/**
... ...
/*
* @Author: Targaryen
* @Date: 2017-06-27 17:18:56
* @Last Modified by: Targaryen
*/
const $couponCodeInput = $('input[name=couponCode]');
const $submit = $('.submit');
const $useCouponBtnGroup = $('.use-coupon-btn-group');
let Tab = require('plugin/tab');
Tab.prototype.couponavailable = () => {
$useCouponBtnGroup.removeClass('disable');
};
Tab.prototype.couponunavailable = () => {
$useCouponBtnGroup.addClass('disable');
};
$('.select-coupon-page').css('min-height', function() {
return $(window).height() - $('#yoho-header').height() + 20;
});
/**
* 优惠券码输入监听
*/
$couponCodeInput.bind('input', () => {
if ($couponCodeInput.val()) {
$submit.addClass('active');
} else {
$submit.removeClass('active');
}
});
import $ from 'yoho-jquery';
import qs from 'yoho-qs';
import Page from 'yoho-page';
import tip from 'plugin/tip';
import cookie from 'yoho-cookie';
import cookieOption from './cookie-option';
class SelectCouponController extends Page {
constructor(params) {
super();
this.linkUrl = document.referrer;
this.orderInfo = params.orderInfo;
this.couponListUrl = params.couponListUrl;
this.useCouponCodeUrl = params.useCouponCodeUrl;
this.selectCouponCodes = [];
this.isBuyNowPage = params.isBuyNowPage || false;
this.closeCouponRuleTipbyUser = cookie.get('close_coupon_rule_tip_by_user') || 'N';
if (this.orderInfo('coupon_code')) {
this.selectCouponCodes = this.orderInfo('coupon_code').split(',');
}
this.page = $('.select-coupons-page');
this.renderPage();
}
/**
* 渲染页面
*/
renderPage() {
let couponCodeStr = this.selectCouponCodes.length > 0 ? this.selectCouponCodes.join(',') : '';
let postData = {
delivery_way: this.orderInfo('deliveryId'),
coupon_code: couponCodeStr
};
if (this.isBuyNowPage) {
postData.product_sku = qs.product_sku;
postData.buy_number = qs.buy_number;
}
this.ajax({
type: 'POST',
url: this.couponListUrl,
data: postData
}).then(result => {
this.orderInfo('coupon_code', couponCodeStr);
let resultHtml = $(result);
this.bindEvents(resultHtml);
this.page.html(resultHtml);
});
}
/**
* 事件绑定处理
*/
bindEvents(resultHtml) {
this.view = {
filterBtn: resultHtml.find('.filter-btn'),
coupon: resultHtml.find('.coupon'),
checkbox: resultHtml.find('.checkbox'),
tipBox: resultHtml.find('.tip-box'),
tipClose: resultHtml.find('.tip-close'),
usableCouponList: resultHtml.find('.usable'),
unusableCouponList: resultHtml.find('.unusable'),
useNowBtn: resultHtml.find('#useNowBtn'),
exchangeCouponBtn: resultHtml.find('#exchangeCouponBtn'),
couponCodeInput: resultHtml.find('input[name=couponCodeInput]'),
exchangeBox: resultHtml.find('.exchange-box'),
useNowBox: resultHtml.find('#useNowBox')
};
this.view.filterBtn.on('click', this.tabChange.bind(this));
this.view.coupon.on('click', '.checkbox', this.check.bind(this));
this.view.tipClose.on('click', this.closeTip.bind(this));
this.view.useNowBtn.on('click', this.useCoupon.bind(this));
this.view.exchangeCouponBtn.on('click', this.exchangeCoupon.bind(this));
this.view.couponCodeInput.on('input', this.changeExchangeBtnStatus.bind(this));
if (this.closeCouponRuleTipbyUser === 'Y') {
this.view.tipBox.addClass('hide');
}
}
/**
* 改变兑换按钮状态
*/
changeExchangeBtnStatus() {
if (this.view.couponCodeInput.val().length > 0) {
this.view.exchangeCouponBtn.addClass('active');
} else {
this.view.exchangeCouponBtn.removeClass('active');
}
}
/**
* 使用优惠券码
*/
exchangeCoupon() {
let couponCode = this.view.couponCodeInput.val();
if (!couponCode) {
tip.show('请输入优惠券码');
return false;
}
this.ajax({
method: 'POST',
url: this.useCouponCodeUrl,
data: {
couponCode: couponCode
}
}).then(res => {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
this.selectCouponCodes.push(couponCode);
setTimeout(() => {
location.reload();
}, 500);
}
});
}
/**
* 使用优惠券
*/
useCoupon() {
if (this.linkUrl) {
window.location.href = this.linkUrl;
} else {
history.go(-1);
}
}
/**
* tab 切换
*/
tabChange(event) {
let itemClicked = $(event.currentTarget);
// Tab 按钮状态
if (!itemClicked.hasClass('active')) {
this.view.filterBtn.removeClass('active');
itemClicked.addClass('active');
}
// 优惠券列表切换,兑换模块、立即使用模块显示控制
if (itemClicked.hasClass('valid')) {
this.view.unusableCouponList.addClass('hide');
this.view.usableCouponList.removeClass('hide');
this.view.exchangeBox.removeClass('hide');
if (itemClicked.data('num') === 0) {
this.view.useNowBox.addClass('hide');
} else {
this.view.useNowBox.removeClass('hide');
}
} else {
this.view.usableCouponList.addClass('hide');
this.view.unusableCouponList.removeClass('hide');
this.view.exchangeBox.addClass('hide');
this.view.useNowBox.addClass('hide');
}
// Tip 控制
if (this.closeCouponRuleTipbyUser === 'Y' || itemClicked.hasClass('invalid')) {
this.view.tipBox.addClass('hide');
} else {
if (itemClicked.data('num') === 0) {
this.view.tipBox.addClass('hide');
} else {
this.view.tipBox.removeClass('hide');
}
}
}
/**
* 优惠券勾选处理
*/
check(e) {
let theCouponCheck = $(e.currentTarget);
let theCoupon = $(e.delegateTarget);
let theCouponData = theCoupon.data();
if (!this.orderInfo('user_check_coupon')) {
this.orderInfo('user_check_coupon', 'Y');
}
if (theCouponCheck.hasClass('icon-cb-radio')) {
this.selectCouponCodes.splice($.inArray(theCouponData.code, this.selectCouponCodes), 1);
theCouponCheck.removeClass('icon-cb-radio').addClass('icon-radio');
} else {
this.selectCouponCodes.push(theCouponData.code);
theCouponCheck.removeClass('icon-radio').addClass('icon-cb-radio');
}
this.renderPage();
}
/**
* 关闭提示框
*/
closeTip() {
this.closeCouponRuleTipbyUser = 'Y';
cookie.set('close_coupon_rule_tip_by_user', 'Y', cookieOption);
this.view.tipBox.hide();
}
}
export default SelectCouponController;
... ...
... ... @@ -55,7 +55,7 @@ function isLimitGood() {
// 来自购物车的链接默认不使用优惠券
if (cookie.get('ensure_from') === 'cart') {
orderInfo('couponCode', null);
orderInfo('coupon_code', null);
orderInfo('usable_usual_code', null);
orderInfo('usable_free_code', null);
cookie.removeSpecific('ensure_from', actCkOpthn);
... ... @@ -121,7 +121,7 @@ function orderCompute() {
cartType: orderInfo('cartType') || 'ordinary',
deliveryId: orderInfo('deliveryId'),
paymentType: orderInfo('paymentType'),
couponCode: orderInfo('couponCode'),
couponCode: orderInfo('coupon_code'),
gift_card_code: orderInfo('gift_card_code'),
yohoCoin: yohoCoin,
skuList: isLimitGood() ? orderInfo('skuList') : void 0
... ... @@ -173,6 +173,8 @@ function orderCompute() {
$('.price-cost span').html('¥' + res.last_order_amount);
$('.bill span').html('¥' + res.last_order_amount);
$('.total').html(total);
$('.coupon .count').html(res.coupon.showText);
$('.coupon .coupon-price-info').html(res.coupon.priceText);
}
updateDeliverId(deliverId);
... ... @@ -213,7 +215,7 @@ function submitOrder(verifyCode) {
isPrintPrice: orderInfo('isPrintPrice'),
paymentTypeId: orderInfo('paymentTypeId'),
paymentType: orderInfo('paymentType'), // 支付方式
couponCode: orderInfo('couponCode'),
couponCode: orderInfo('coupon_code'),
gift_card_code: orderInfo('gift_card_code'),
verifyCode: verifyCode || null,
yohoCoin: orderInfo('yohoCoin'),
... ...
... ... @@ -3,8 +3,8 @@
* @author: bikai<kai.bi@yoho.cn>
* @date: 2015/12/14
*/
require('common');
let info = window.cookie('order-info');
const cookie = require('yoho-cookie');
let info = cookie.get('order-info');
// cookie 参数
let actCkOpthn = {
... ... @@ -19,7 +19,7 @@ function init() {
paymentTypeId: 1,
yohoCoin: 0,
addressId: null,
couponCode: null,
coupon_code: null,
invoice: null,
invoices_title: null,
invoices_type: null,
... ... @@ -29,25 +29,21 @@ function init() {
msg: null,
cartType: 'ordinary'
};
window.setCookie('order-info', JSON.stringify(info), actCkOpthn);
cookie.set('order-info', JSON.stringify(info), actCkOpthn);
}
// info 必须是 JSON 字符串
try {
info = JSON.parse(info);
// 2015/12/31 hf: fixes bug to 购物车页面调用该JS, 会导致有有货币,值却没有传给服务端. 因此需要再设置一下
// info['yohoCoin'] = $('.coin').data('yoho-coin') || 0;
} catch (e) {
init();
}
exports.init = init;
exports.orderInfo = function(key, value) {
if (typeof value === 'undefined') {
return info[key];
}
info[key] = value;
window.setCookie('order-info', JSON.stringify(info), actCkOpthn);
cookie.set('order-info', JSON.stringify(info), actCkOpthn);
};
... ...
... ... @@ -70,13 +70,13 @@ if (window.getUid() !== orderInfo('uid')) {
}
if ($couponUse.data('name') !== orderInfo('couponName')) {
orderInfo('couponCode', null);
orderInfo('coupon_code', null);
orderInfo('couponName', null);
}
// 来自购物车的链接默认不使用优惠券
if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1) {
orderInfo('couponCode', null);
orderInfo('coupon_code', null);
orderInfo('couponName', null);
}
... ...
/**
* 优惠券选择
* @author: bikai<kai.bi@yoho.cn>
* @date: 2015/12/10
*/
require('cart/select-coupon.page.css');
let $ = require('yoho-jquery'),
loading = require('plugin/loading'),
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;
let isGetData;
let $newCoupon = $('#new-coupon');
let $couponAvailable = $('#couponAvailable');
let $couponUnavailable = $('#couponUnavailable');
let $useCoupon = $('#useCoupon');
let $notUseCoupon = $('#notUseCoupon');
let winH = $(window).height();
let linkUrl = document.referrer;
require('common');
require('cart/cartbuynow/select-coupon');
function fixedLayOut() {
let $null = $('.null'),
navH = $('.nav-title').height(),
nullH = $null.height();
if ($null.length === 0) {
return false;
}
$null.css({
top: winH / 2 - nullH / 2 + navH
});
}
function goToBack() {
if (linkUrl) {
window.location.href = linkUrl;
} else {
history.go(-1);
}
}
/**
* 输入优惠券码兑换优惠券
*/
$newCoupon.on('submit', function() {
let $this = $(this);
if (!$this.find('[name="couponCode"]').val()) {
tip.show('请输入优惠券码');
return false;
}
$.ajax({
method: 'POST',
url: '/cart/index/new/useCouponCode',
data: $this.serialize()
}).then(function(res) {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
orderInfo('usable_usual_code', res.data.coupon_code);
tip.show('优惠券可用');
setTimeout(function() {
location.reload();
}, 500);
}
}).fail(function() {
tip.show('网络错误');
});
return false;
});
/**
* 使用优惠券
*/
$useCoupon.on('click', function() {
let couponCodeArray = [];
if (orderInfo('usable_usual_code')) {
couponCodeArray.push(orderInfo('usable_usual_code'));
}
if (orderInfo('usable_free_code')) {
couponCodeArray.push(orderInfo('usable_free_code'));
}
orderInfo('couponCode', couponCodeArray.join(','));
if (couponCodeArray.length > 0) {
goToBack();
} else {
tip.show('请选择优惠券');
}
});
/**
* 不使用优惠券
*/
$notUseCoupon.on('click', function() {
orderInfo('couponCode', null);
orderInfo('usable_usual_code', null);
orderInfo('usable_free_code', null);
goToBack();
});
/**
* 优惠券列表处理
* @param {*} allCoupons
*/
function getCouponHandle(allCoupons) {
let availableCoupons = allCoupons.availableCoupons;
let usableFreesCoupons = allCoupons.usableFreesCoupons;
let notAvailableCoupons = allCoupons.notAvailableCoupons;
$.each(availableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$.each(usableFreesCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$.each(notAvailableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
});
$couponUnavailable.append(conponNotAvaliableTmpl({
notAvailableCoupons: notAvailableCoupons
}));
// 没有优惠券
if (!(availableCoupons.length || usableFreesCoupons.length)) {
$('#couponAvailable').html($('#tmplNoCoupon').html());
fixedLayOut();
return false;
}
// 渲染可用的优惠券
$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);
}
} else if ($theCoupon.hasClass('usable-free')) {
if (beforeIsChecked) {
$theCouponCheckBox.removeClass('icon-cb-radio').addClass('icon-radio');
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) {
return;
}
loading.showLoadingMask();
isGetData = true;
$.ajax({
type: 'GET',
url: '/cart/index/new/couponList',
dataType: 'json'
}).then(getCouponHandle).fail(function() {
tip.show('加载优惠券失败');
}).always(function() {
isGetData = false;
loading.hideLoadingMask();
});
}
getCouponData();
import 'cart/select-coupons.page.css';
import SelectCouponsController from '../cartbuynow/select-coupons';
import { orderInfo } from 'cart/order-info';
new SelectCouponsController({
orderInfo: orderInfo,
couponListUrl: '/cart/index/new/couponList',
useCouponCodeUrl: '/cart/index/new/useCouponCode'
});
... ...
import $ from 'yoho-jquery';
import tip from 'plugin/tip';
import Page from 'yoho-page';
class ConponController extends Page {
constructor() {
super();
this.couponType = 'notuse';
this.couponFilter = 0;
this.page = 1;
this.view = {
page: $('.coupon-new-page'),
filterBtn: $('.filter-btn'),
filterItem: $('.filter-item'),
showFilterBtn: $('.show-filter-btn'),
couponList: $('#couponList'),
couponSection: $('.coupon-section'),
noConponNow: $('.no-conpon-now'),
exchangeCouponBtn: $('#exchangeCouponBtn'),
couponCodeInput: $('input[name=couponCodeInput]'),
usedTip: $('.used-tip'),
exchangeBox: $('.exchange-box')
};
this.view.filterBtn.on('click', this.tabChange.bind(this));
this.view.showFilterBtn.on('click', this.showFilter.bind(this));
this.view.filterItem.on('click', 'button', this.filterCoupons.bind(this));
this.view.couponSection.on('click', '.show-intro-btn', this.showIntro.bind(this));
this.view.exchangeCouponBtn.on('click', this.exchangeCoupon.bind(this));
this.view.couponCodeInput.on('input', this.changeExchangeBtnStatus.bind(this));
this.loading = false;
this.loadEnd = false;
this.beforeScroll = $(window).scrollTop(); // 滚动前位置记录
this.afterScroll; // 滚动后的位置
window.onscroll = () => {
if (this.loading || this.loadEnd) {
return;
}
setTimeout(() => {
this.afterScroll = $(window).scrollTop();
if (this.afterScroll - this.beforeScroll > 0) {
window.requestAnimationFrame(() => {
this.scrollHandler();
});
}
this.beforeScroll = this.afterScroll;
}, 100);
};
}
/**
* 改变兑换按钮状态
*/
changeExchangeBtnStatus() {
if (this.view.couponCodeInput.val().length > 0) {
this.view.exchangeCouponBtn.addClass('active');
} else {
this.view.exchangeCouponBtn.removeClass('active');
}
}
/**
* 使用优惠券码
*/
exchangeCoupon() {
let couponCode = this.view.couponCodeInput.val();
if (!couponCode) {
tip.show('请输入优惠券码');
return false;
}
this.ajax({
method: 'POST',
url: '/cart/index/new/useCouponCode',
data: {
couponCode: couponCode
}
}).then(res => {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
setTimeout(() => {
location.reload();
}, 500);
}
});
}
/**
* 滚动处理
*/
scrollHandler() {
let conponListHeight = this.view.couponList.height();
if ($(window).scrollTop() > conponListHeight * 0.6) {
this.renderCoupons(true);
}
}
/**
* 筛选优惠券
*/
filterCoupons(evt) {
let currentTarget = $(evt.currentTarget);
let currentTargetData = currentTarget.data();
this.couponType = 'notuse';
this.page = 0;
this.couponFilter = currentTargetData.id;
this.view.filterItem.find('button').removeClass('active');
currentTarget.addClass('active');
this.view.filterItem.addClass('hide');
this.view.showFilterBtn.removeClass('icon-up').addClass('icon-down');
this.renderCoupons();
}
/**
* 获取优惠券
*/
renderCoupons(scroll) {
if (this.loading) {
return;
}
this.loading = true;
this.page++;
this.ajax({
type: 'POST',
url: '/home/couponsList',
data: {
type: this.couponType,
filter: this.couponFilter,
page: this.page
},
}).then(result => {
this.loading = false;
let noResult = !result || !result.length;
if (scroll && noResult) {
this.loadEnd = true;
return;
}
if (noResult) {
this.view.noConponNow.removeClass('hide');
} else {
this.view.noConponNow.addClass('hide');
}
let couponValidHbsHtml = $(result);
couponValidHbsHtml.on('click', '.show-intro-btn', this.showIntro.bind(this));
if (scroll) {
this.view.couponList.append(couponValidHbsHtml);
} else {
this.view.couponList.html(couponValidHbsHtml);
}
});
}
/**
* tab 切换
*/
tabChange(event) {
this.page = 0;
this.couponFilter = 0;
this.loadEnd = false;
let itemClicked = $(event.currentTarget);
let itemCouponNum = itemClicked.data('num');
// 筛选参数更改
if (itemClicked.hasClass('no-used')) {
this.couponType = 'notuse';
this.view.usedTip.addClass('hide');
this.view.usedTip.find('span').addClass('hide');
} else if (itemClicked.hasClass('used')) {
this.couponType = 'use';
if (itemCouponNum !== 0) {
this.view.usedTip.removeClass('hide');
this.view.usedTip.find('.used').removeClass('hide');
this.view.usedTip.find('.invalid').addClass('hide');
} else {
this.view.usedTip.addClass('hide');
}
} else if (itemClicked.hasClass('invalid')) {
this.couponType = 'overtime';
if (itemCouponNum !== 0) {
this.view.usedTip.removeClass('hide');
this.view.usedTip.find('.invalid').removeClass('hide');
this.view.usedTip.find('.used').addClass('hide');
} else {
this.view.usedTip.addClass('hide');
}
} else {
tip.show('未知券类型');
}
// 筛选框控制按钮状态、优惠券码兑换输入框状态管理
if (itemClicked.hasClass('no-used')) {
this.view.page.addClass('cpage-padding284').removeClass('cpage-padding194');
this.view.showFilterBtn.addClass('active');
this.view.exchangeBox.removeClass('hide');
} else {
this.view.page.addClass('cpage-padding194').removeClass('cpage-padding284');
this.view.showFilterBtn.removeClass('icon-up').addClass('icon-down');
this.view.showFilterBtn.removeClass('active');
this.view.exchangeBox.addClass('hide');
}
// 筛选项面板和筛选项状态重置
this.view.filterItem.addClass('hide');
this.view.filterItem.find('button').removeClass('active');
if (!itemClicked.hasClass('active')) {
this.view.filterBtn.removeClass('active');
itemClicked.addClass('active');
this.renderCoupons();
}
}
/**
* 展示筛选器
*/
showFilter(e) {
let currentTarget = $(e.currentTarget);
if (!currentTarget.hasClass('active')) {
return;
}
if (this.view.filterItem.hasClass('hide')) {
this.view.filterItem.removeClass('hide');
this.view.showFilterBtn.removeClass('icon-down').addClass('icon-up');
} else {
this.view.filterItem.addClass('hide');
this.view.showFilterBtn.removeClass('icon-up').addClass('icon-down');
}
}
/**
* 展示优惠券介绍
*/
showIntro(e) {
let delegateTarget = $(e.delegateTarget);
let couponIntro = delegateTarget.find('.coupon-intro');
let showIntroIcon = delegateTarget.find('.show-intro-btn');
if (couponIntro.hasClass('hide')) {
couponIntro.removeClass('hide');
showIntroIcon.eq(1).removeClass('icon-down').addClass('icon-up');
} else {
couponIntro.addClass('hide');
showIntroIcon.eq(1).removeClass('icon-up').addClass('icon-down');
}
}
}
export default ConponController;
... ...
import 'home/conpon-new.page.css';
import ConponController from './controller';
new ConponController();
... ...
// 不要使用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(); // 重新计算底部位置
}
... ... @@ -477,16 +477,6 @@
text-align: right;
}
/* .fill-text {
padding: 0.05rem 0.3rem;
color: #fff;
font-size: 0.625rem;
line-height: 0.75rem;
border-radius: 0.75rem;
display: inline-block;
background-color: #e01;
} */
.price {
color: #e01;
}
... ... @@ -533,9 +523,11 @@
.count {
background-color: #ff575c;
margin-left: 9px;
margin-left: 12px;
padding: 4px 15px;
color: #fff;
font-size: 22px;
font-weight: 300;
}
.coupon-count {
... ... @@ -752,17 +744,14 @@
}
}
.coupon-help {
color: #b0b0b0;
margin-left: 30px;
}
.yoho-coin-help {
display: inline-block;
background-color: #b0b0b0;
border-radius: 28px;
width: 28px;
height: 28px;
line-height: 36px;
text-align: center;
color: #fff;
font-size: 22px;
margin-left: 10px;
color: #b0b0b0;
margin-left: 16px;
}
.yoho-coin-help-dialog-bg {
... ... @@ -893,3 +882,13 @@
}
}
}
.conpon-diaalog-wrapper {
> .dialog-box > .dialog-content {
padding-top: 0;
}
> .dialog-box > .dialog-footer > .dialog-center-btn {
font-weight: 500;
}
}
... ...
$couponRadius: 8px;
$rosyPink: #f06a6b;
$backgroudColor: #f2f2f2;
$fontColor: #444;
$fontGrayLight: #e0e0e0;
$fontSizeSmall: 16px;
@define-extend line {
content: "";
position: absolute;
top: 50%;
border-top: 1px solid $fontGrayLight;
width: 120px;
height: 0;
}
@define-extend page-padding {
padding-left: 30px;
padding-right: 30px;
}
.select-coupon-page {
background-color: $backgroudColor;
margin-top: 40px;
.coupon-page-title {
background-color: #fff;
}
.new-coupon {
@extend page-padding;
font-size: 24px;
input {
padding: 0 12px;
width: 400px;
height: 80px;
border: 1px solid #b0b0b0;
border-radius: 0.1rem;
outline: 0;
float: left;
}
.submit {
margin-left: 30px;
width: 130px;
height: 80px;
color: #fff;
background: #b0b0b0;
border-radius: 0.1rem;
border: none;
outline: 0;
float: left;
}
.active {
background: #444;
}
}
.coupon-wrap {
padding-bottom: 100px;
}
.coupon-use-manual {
@extend page-padding;
color: #b0b0b0;
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 {
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;
height: 100px;
border-right: 2px solid $fontColor;
}
.content-left > .value {
width: 100%;
height: 76px;
text-align: center;
font-size: 52px;
line-height: 100px;
color: $fontColor;
}
.content-middle {
width: 360px;
margin-left: 20px;
}
.content-right {
width: 40px;
padding-top: 36px;
}
.content-right > .checkbox {
font-size: 28px;
color: $fontColor;
}
}
}
.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;
}
}
}
.active {
display: block;
}
.use-coupon-btn-group {
@extend page-padding;
width: 100%;
position: fixed;
left: 0;
bottom: 0;
z-index: 2;
background-color: #fff;
padding-top: 20px;
padding-bottom: 20px;
button {
color: #fff;
width: 270px;
height: 70px;
border-radius: $couponRadius;
&.use {
background-color: $fontColor;
}
&.not-use {
background-color: $fontGrayLight;
}
}
}
.disable {
display: none;
}
.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%;
}
}
}
body {
background-color: #f0f0f0;
}
.select-coupons-page {
.filter-box {
height: 88px;
display: flex;
padding: 14px 0;
box-shadow: 0 0 16px 0 #eee;
background-color: #fff;
position: relative;
.valid,
.invalid {
flex: 1;
line-height: 60px;
text-align: center;
color: #b0b0b0;
}
.valid {
border-right: 1px solid #e0e0e0;
}
.show-filter-btn,
.active {
color: #444;
}
}
.filter-item {
display: flex;
width: 100%;
height: 130px;
justify-content: space-around;
align-items: center;
background-color: #fff;
button {
width: 150px;
height: 70px;
background-color: #fff;
color: #444;
font-size: 28px;
border: 1px solid #e0e0e0;
border-radius: 4px;
}
}
.exchange-box {
height: 90px;
padding: 16px 20px;
background-color: #fff;
input {
width: 570px;
height: 60px;
margin-right: 12px;
padding: 0 20px;
background-color: #f0f0f0;
border-radius: 4px;
border: none;
}
.exchange-coupon-btn {
width: 120px;
height: 60px;
border-radius: 4px;
font-size: 28px;
color: #fff;
background-color: #b0b0b0;
}
.active {
background-color: #444;
}
}
.tip-box {
width: 100%;
padding: 14px 20px;
display: flex;
justify-content: space-between;
align-items: center;
color: #fff;
font-size: 22px;
background-color: #ff8083;
}
.coupon-list {
padding: 20px;
margin-bottom: 80px;
.coupon-list-type {
width: 100%;
font-size: 24px;
color: #444;
margin-top: 10px;
margin-bottom: 30px;
display: flex;
hr {
width: 142px;
border: none;
border-bottom: 1px solid #e0e0e0;
}
}
.coupon {
width: 710px;
height: 200px;
margin-bottom: 20px;
position: relative;
.coupon-left {
width: 200px;
height: 200px;
background-image: resolve("home/coupon/overtime.png");
background-size: 100% 100%;
float: left;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.coupon-left > p {
color: #fc5960;
font-size: 24px;
> span {
font-size: 60px;
font-weight: 600;
}
}
.coupon-right {
width: 510px;
height: 200px;
background-color: #fff;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
float: right;
padding: 22px;
font-size: 22px;
color: #b0b0b0;
position: relative;
display: flex;
.info {
flex: 1;
position: relative;
}
.type-shop {
color: #efaf46;
}
.type-activity {
color: #fc5960;
}
.type-freight {
color: #222;
}
.info > .title {
width: 400px;
font-size: 24px;
color: #444;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.info > .title > .catalog-name {
font-weight: 500;
}
.info > .time {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.info > .desc {
width: 400px;
font-size: 20px;
color: #444;
position: absolute;
left: 0;
bottom: 0;
}
.info > .unusable-desc {
color: #b0b0b0;
}
.check {
width: 40px;
height: 40px;
position: absolute;
top: 50%;
right: 30px;
transform: translateY(-50%);
}
.check > .iconfont {
font-size: 40px;
color: #444;
}
.check > .icon-point1 {
color: #e0e0e0;
}
}
.top-tip {
width: 84px;
height: 84px;
background-image: resolve("home/coupon/top-tip.png");
background-size: 100% 100%;
position: absolute;
top: 0;
right: 0;
}
}
.coupon-activity {
> .coupon-left {
background-image: resolve("home/coupon/activity.png");
}
> .coupon-right .catalog-name {
color: #fc5960;
}
}
.coupon-freight {
> .coupon-left {
background-image: resolve("home/coupon/freight.png");
> p {
color: #000;
}
> p > span {
font-size: 48px;
font-weight: 600;
}
}
> .coupon-right .catalog-name {
color: #000;
}
}
.coupon-shop {
> .coupon-left {
background-image: resolve("home/coupon/shop.png");
> p {
color: #ffa72e;
}
}
> .coupon-right .catalog-name {
color: #ffa72e;
}
}
.no-support-selected {
> .coupon-left > p {
color: #b0b0b0;
}
> .coupon-right .info > .title {
color: #b0b0b0;
}
}
}
.use-now {
width: 100%;
height: 100px;
position: fixed;
left: 0;
bottom: 0;
background: #fff;
z-index: 3;
.left-info {
width: 510px;
height: 100px;
float: left;
padding: 12px 20px;
}
.use-now-btn {
width: 240px;
height: 100px;
background-color: #d0021b;
color: #fff;
font-size: 34px;
float: right;
}
p {
font-size: 24px;
text-align: right;
line-height: 42px;
}
.nums {
color: #d0021b;
font-weight: 500;
}
}
.hide {
display: none;
}
.no-conpon-now {
text-align: center;
padding-top: 262px;
color: #b0b0b0;
.icon-not {
width: 208px;
height: 130px;
background-image: resolve("home/employ/not.png");
background-size: 100% 100%;
margin: auto auto 30px;
}
p {
font-size: 28px;
}
}
}
... ...
body {
background-color: #f0f0f0;
}
.yoho-header {
position: fixed;
top: 0;
left: 0;
}
.cpage-padding284 {
padding-top: 284px;
}
.cpage-padding194 {
padding-top: 194px;
}
.coupon-new-page {
.filter-box {
width: 100%;
height: 88px;
display: flex;
padding: 14px 0;
box-shadow: 0 0 16px 0 #eee;
background-color: #fff;
position: fixed;
top: 106px;
left: 0;
z-index: 3;
.filter-btn-box {
flex: 1;
line-height: 60px;
text-align: center;
color: #b0b0b0;
border-right: 1px solid #e0e0e0;
}
.filter-btn-box:last-child {
border-right: none;
}
.show-filter-btn {
color: #b0b0b0;
}
.active {
color: #444;
}
}
.filter-item {
display: flex;
width: 100%;
height: 130px;
justify-content: space-around;
align-items: center;
background-color: #fff;
position: fixed;
top: 192px;
left: 0;
z-index: 3;
button {
width: 150px;
height: 70px;
background-color: #fff;
color: #444;
font-size: 28px;
border: 1px solid #e0e0e0;
border-radius: 4px;
&.active {
background-color: #444;
color: #fff;
border: 1px solid transparent;
}
}
}
.exchange-box {
height: 90px;
padding: 16px 20px;
background-color: #fff;
position: fixed;
top: 194px;
left: 0;
z-index: 2;
input {
width: 570px;
height: 60px;
margin-right: 12px;
padding: 0 20px;
background-color: #f0f0f0;
border-radius: 4px;
border: none;
}
.exchange-coupon-btn {
width: 120px;
height: 60px;
border-radius: 4px;
font-size: 28px;
color: #fff;
background-color: #b0b0b0;
}
.active {
background-color: #444;
}
}
.coupon-list {
padding: 20px;
.coupon-section {
margin-bottom: 20px;
}
.coupon {
position: relative;
width: 710px;
height: 200px;
.coupon-left {
width: 200px;
height: 200px;
background-image: resolve("home/coupon/overtime.png");
background-size: 100% 100%;
float: left;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.coupon-left > p {
color: #fc5960;
font-size: 24px;
> span {
font-size: 60px;
font-weight: 600;
}
}
.coupon-left-activity {
background-image: resolve("home/coupon/activity.png");
}
.coupon-left-freight {
background-image: resolve("home/coupon/freight.png");
> p {
color: #000;
}
> p > span {
font-size: 48px;
font-weight: 600;
}
}
.coupon-left-shop {
background-image: resolve("home/coupon/shop.png");
> p {
color: #ffa72e;
}
}
.coupon-right {
width: 510px;
height: 200px;
background-color: #fff;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
float: left;
padding: 22px;
font-size: 22px;
color: #b0b0b0;
position: relative;
.type-shop,
.type-activity,
.type-freight {
font-weight: 500;
}
.type-shop {
color: #efaf46;
}
.type-activity {
color: #fc5960;
}
.type-freight {
color: #222;
}
.title {
width: 370px;
font-size: 24px;
color: #444;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.time {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.use-intro {
position: absolute;
bottom: 22px;
}
.tip {
position: absolute;
top: 0;
right: 0;
}
}
.use-now {
font-size: 22px;
position: absolute;
width: 130px;
height: 50px;
line-height: 50px;
text-align: center;
border: 1px solid #444;
border-radius: 25px;
background-color: #fff;
color: #444;
bottom: 20px;
right: 20px;
}
.stamp {
position: absolute;
width: 126px;
height: 114px;
right: 20px;
top: 50%;
transform: translateY(-50%);
background-size: 100% 100%;
}
.overtime-stamp {
background-image: resolve("home/coupon/timeout.png");
}
.used-stamp {
background-image: resolve("home/coupon/used.png");
}
.invalid-stamp {
background-image: resolve("home/coupon/invalid.png");
}
.top-tip {
width: 84px;
height: 84px;
background-image: resolve("home/coupon/top-tip.png");
background-size: 100% 100%;
position: absolute;
top: 0;
right: 0;
}
}
.freight-coupon {
> .coupon-left {
font-size: 48px;
}
}
.coupon-invalid,
.coupon-used,
.coupon-overtime {
> .coupon-left > p {
color: #b0b0b0;
}
> .coupon-right > .title {
color: #b0b0b0;
& > .type-activity {
color: #b0b0b0;
}
& > .type-freight {
color: #b0b0b0;
}
& > .type-shop {
color: #b0b0b0;
}
}
}
.coupon-intro {
background: rgba(255, 255, 255, 0.7);
margin-top: -12px;
padding: 36px 22px 22px;
li {
font-size: 22px;
color: #444;
}
}
}
.no-conpon-now {
text-align: center;
padding-top: 262px;
color: #b0b0b0;
.icon-not {
width: 208px;
height: 130px;
background-image: resolve("home/employ/not.png");
background-size: 100% 100%;
margin: auto auto 30px;
}
p {
font-size: 28px;
}
}
.used-tip {
display: flex;
span {
color: #b0b0b0;
font-size: 24px;
}
hr {
width: 160px;
border: none;
border-bottom: 1px solid #e0e0e0;
}
}
.hide {
display: none;
}
}
... ...
$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;
padding: 25px 0;
text-align: center;
background-color: #fff;
font-size: 32px;
color: #b0b0b0;
ul li {
float: left;
width: 50%;
border-right: 1px solid #b0b0b0;
&.activate {
color: #444;
}
&:last-child {
border: none;
}
}
}
.coupon-list {
margin-bottom: 40px;
}
.coupon-group {
background-color: #f2f2f2;
color: $font-color;
margin: 20px 20px 0;
& > div {
padding: 0 15px;
}
.coupon-header {
border-radius: 10px 10px 0 0;
background-color: $coupon-header-backgroud-color;
color: #fff;
height: 60px;
line-height: 60px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 28px;
}
.coupon-content {
border-radius: 0 0 10px 10px;
height: 140px;
border-top: 2px dashed #e53333;
display: table;
padding: 15px 0;
background-color: $coupon-content-background-color;
.coupon-content-group1 {
display: table-cell;
text-align: center;
vertical-align: middle;
font-size: 20px;
p {
width: 200px;
overflow: hidden;
min-height: 28px;
}
.coupon-money {
font-size: 80px;
}
}
.coupon-content-group2 {
display: table-cell;
font-size: 20px;
border-left: 1px solid $font-color;
padding-left: 20px;
padding-right: 20px;
width: 100%;
.coupon-content-group2-table {
display: table;
overflow: hidden;
height: 100%;
width: 100%;
line-height: 45px;
}
.coupon-content-group2-table > div {
display: table-row;
height: 100%;
}
.left {
float: left;
line-height: 45px;
color: $font-color;
}
.left.down .iconfont:before {
font-size: 12px;
content: "\e609";
}
.left.up .iconfont:before {
font-size: 12px;
content: "\e608";
}
.right {
float: right;
}
.coupon-soon-expire {
color: $coupon-header-backgroud-color;
}
.btn {
display: inline-block;
width: 120px;
height: 45px;
text-align: center;
background-color: $coupon-header-backgroud-color;
border-radius: 10px;
color: #fff;
}
.employ {
width: 171px;
height: 146px;
position: absolute;
display: block;
z-index: 2;
right: 37px;
margin-top: -95px;
background-image: resolve("home/employ.png");
background-size: cover;
}
}
}
.coupon-footer {
background-color: $coupon-content-background-color;
padding: 20px;
font-size: 18px;
border-radius: 10px;
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;
}
}
}
.coupon-not-result {
width: 100%;
height: auto;
overflow: hidden;
position: fixed;
left: 0;
top: 50%;
margin-top: -162px;
i {
width: 100%;
height: 120px;
overflow: hidden;
display: block;
background: resolve("home/employ/not.png") center top no-repeat;
background-size: auto 100%;
}
p {
width: 100%;
height: auto;
overflow: hidden;
padding: 20px 0 0;
font-size: 32px;
text-align: center;
color: #444;
}
a {
width: 73.75%;
height: 80px;
overflow: hidden;
font-size: 36px;
line-height: 80px;
display: block;
background: #444;
color: #fff;
text-align: center;
margin: 60px auto 0;
border-radius: 0.2rem;
}
}
}
... ... @@ -210,6 +210,22 @@ button {
content: "\e646";
}
.icon-up:before {
content: "\e608";
}
.icon-down:before {
content: "\e609";
}
.icon-wenhao:before {
content: "\e699";
}
.icon-point1:before {
content: "\e60c";
}
.wx-footer-c {
margin-top: 30px;
}
... ...
... ... @@ -180,6 +180,27 @@ module.exports = {
return opt.inverse(this); // eslint-disable-line
}
},
notEqualEither: function() {
let args = Array.prototype.slice.call(arguments);
let v1 = args[0];
let opt = args[args.length - 1];
let isTrue = false;
for (let i = 1; i < args.length - 1; i++) {
if (v1 === args[i]) {
isTrue = true;
break;
}
}
if (!isTrue) {
return opt.fn(this); // eslint-disable-line
} else {
return opt.inverse(this); // eslint-disable-line
}
},
ifand: function() {
let args = Array.prototype.slice.call(arguments);
let opt = args[args.length - 1];
... ...
... ... @@ -327,45 +327,101 @@ function tranformPayment(data, orderInfo, cartType, skuList, orderComputeData) {
orderInfo.msg && (result.msg = orderInfo.msg);
result.isPrintPrice = true; // 是否不打印价格,默认不勾选,预留
// 优惠券
let couponPayRule = _.get(data, 'coupon_pay_rule.desc', null);
if (couponPayRule) {
result.couponPayRule = _.replace(couponPayRule, '\n', '<br>');
}
return result;
}
/**
* 优惠券数据
* @param count int 用户有效优惠券
* @param orderComputeData obj app.Shopping.compute返回的data数据
* @param orderInfo cookie中的数据
* @return obj
* 下单页面处理优惠券数据
*/
function coupon(count, orderInfo, orderComputeData) {
let coupons = {
count: count,
selectedAmount: 0,
info: ''
};
function handleCoupons(params) {
let orderComputeCouponPay = _.get(params, 'orderComputeCouponPay', {});
let couponData = _.get(params, 'paymentApiCouponData', {});
let validCouponCount = _.get(params, 'validCouponCount');
let couponCode = couponData.coupon_code;
let showText = '';
let priceText = '';
// 重新计算过后取重新计算的值
if (!_.isEmpty(orderComputeCouponPay)) {
couponData = orderComputeCouponPay;
}
let couponAmount = _.get(orderComputeData, 'coupon_amount', 0);
if (!couponData.coupon_count) {
showText = `${validCouponCount}张可用`;
}
if (_.get(orderInfo, 'usable_usual_code', null)) {
coupons.selectedAmount++;
if (validCouponCount && couponData.coupon_count) {
showText = `${validCouponCount}张可用 已推荐${couponData.coupon_count}张`;
priceText = `-${couponData.coupon_amount_str}`;
}
if (_.get(orderInfo, 'usable_free_code', null)) {
coupons.selectedAmount++;
if (validCouponCount &&
couponData.coupon_count &&
params.userCheckCoupon === 'Y') {
showText = `已选${couponData.coupon_count}张`;
priceText = `-${couponData.coupon_amount_str}`;
}
if (count) {
if (coupons.selectedAmount) {
coupons.info = `-${couponAmount.toFixed(2)}`;
return {
showText, priceText, couponCode
};
}
/**
* 选择优惠券页面数据处理
*/
const couponProcess = conponData => {
let usableCouponsList = _.get(conponData, 'usable_coupon_catalogs.list', []);
let unusableCouponsList = _.get(conponData, 'unusable_coupon_catalogs.list', []);
let usableCouponNum = _.get(usableCouponsList, '[0].coupons.length', 0);
let unusableCouponNum = 0;
let couponPay = _.get(usableCouponsList, '[0].coupon_pay');
let headMsg = _.replace(_.get(conponData, 'usable_coupon_catalogs.head_msg', []), '\n', '<br>');
let usableCouponNumStr = '';
let unusableCouponNumStr = '';
let noShowTips = false;
_.forEach(unusableCouponsList, listItem => {
if (listItem.coupons && listItem.coupons.length) {
unusableCouponNum += listItem.coupons.length;
} else {
coupons.info = '未使用';
listItem.name = '';
}
});
if (usableCouponNum > 99) {
usableCouponNumStr = '99+';
} else {
coupons.info = '无可用';
usableCouponNumStr = usableCouponNum + '';
}
return coupons;
}
if (unusableCouponNum > 99) {
unusableCouponNumStr = '99+';
} else {
unusableCouponNumStr = unusableCouponNum + '';
}
if (!usableCouponNum) {
noShowTips = true;
}
return {
usableCouponNumStr,
unusableCouponNumStr,
usableCouponsList,
unusableCouponsList,
couponPay,
headMsg,
noShowTips
};
};
/**
* 选择礼品卡页面礼品卡数据处理
... ... @@ -517,7 +573,8 @@ module.exports = {
transPrice,
tranformPayment,
yohoCoinCompute,
coupon,
handleCoupons,
couponProcess,
handleGiftCards,
handleGiftCardsRender,
transformJit,
... ...