Authored by OF1706

购物车

... ... @@ -20,6 +20,13 @@ const getProductInfo = (req, res, next) => {
}).catch(next);
};
const getProductData = (req, res, next) => {
let pid = req.query.productId || '';
service.getProductInfoAsync(pid).then((result) => {
return res.send(result);
}).catch(next);
};
/**
* 设置购物车COOKIE信息
... ... @@ -306,6 +313,7 @@ const getIncreasePurchase = (req, res) => {
module.exports = {
getProductInfo,
getProductData,
cart,
cartAdd,
cartTotal,
... ...
... ... @@ -33,41 +33,6 @@ const index = (req, res, next) => {
}).catch(next);
};
// 获取地址列表
const addressList = (req, res, next) => {
oeModel.addressList(req.user.uid).then(data => {
res.send(data);
}).catch(next);
};
// 获取区域列表
const getAreaList = (req, res, next) => {
oeModel.areaList(req.query.id).then(data => {
res.send(data);
}).catch(next);
};
// 地址删除
const delAddress = (req, res, next) => {
oeModel.delAddress(req.user.uid, req.body.id).then(data => {
res.send(data);
}).catch(next);
};
// 地址/更新新增
const saveAddress = (req, res, next) => {
oeModel.saveAddress(req.user.uid, req.body).then(data => {
res.send(data);
}).catch(next);
};
// 设置默认地址
const setDefault = (req, res, next) => {
oeModel.setDefault(req.user.uid, req.body.id).then(data => {
res.send(data);
}).catch(next);
};
// 获取优惠券列表
const getCoupons = (req, res, next) => {
oeModel.getCoupons(req.user.uid).then(data => {
... ... @@ -77,9 +42,10 @@ const getCoupons = (req, res, next) => {
// 订单金额计算
const compute = (req, res, next) => {
let cartType = req.query.cartType === '2' ? 'advance' : 'ordinary';
let params = req.body;
let cartType = params.cartType === '2' ? 'advance' : 'ordinary';
oeModel.compute(req.user.uid, cartType, req.query).then(data => {
oeModel.compute(req.user.uid, cartType, params).then(data => {
res.send(data);
}).catch(next);
};
... ... @@ -103,11 +69,6 @@ const submit = (req, res, next) => {
module.exports = {
index,
addressList,
getAreaList,
delAddress,
saveAddress,
setDefault,
getCoupons,
compute,
submit
... ...
... ... @@ -7,6 +7,12 @@
const api = global.yoho.API;
/**
* 购物车结算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
* @param yohoCoinMode [number] 是否使用yoho币,1使用,0不使用
*/
const getOrderPaymentAsync = (uid, cartType, yohoCoinMode) => api.get('', {
method: 'app.Shopping.payment',
cart_type: cartType,
... ... @@ -15,6 +21,15 @@ const getOrderPaymentAsync = (uid, cartType, yohoCoinMode) => api.get('', {
});
/**
* 获取用户优惠券信息API
* @param uid [number] uid
*/
const getUesrCouponAsync = (uid) => api.get('', {
method: 'app.Shopping.listCoupon',
uid: uid
});
/**
* 订单计算API
* @param uid [number] uid
* @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
... ... @@ -93,7 +108,8 @@ const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, p
delivery_way: deliveryWay,
payment_type: paymentType,
payment_id: paymentId,
is_print_price: printPrice
is_print_price: printPrice,
is_continue_buy: other.continueBuy ? 'Y' : 'N'
};
// 发票
... ... @@ -139,6 +155,7 @@ const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, p
module.exports = {
getOrderPaymentAsync,
getUesrCouponAsync,
getOrderComputeAsync,
orderSubmitAsync
};
... ...
... ... @@ -38,36 +38,7 @@ const index = (uid, cartType) => {
};
// 获取优惠券列表
// const getCoupons = (uid) => api.get('', {
// method: 'app.Shopping.listCoupon',
// uid: uid
// }).then(result => {
// if (result.code === 200) {
// let unuse = [];
// let use = [];
// _.forEach(result.data.unusable_coupons, i => {
// unuse.push({
// code: i.coupon_code,
// name: i.coupon_name,
// value: i.coupon_value,
// canuse: false
// });
// });
// _.forEach(result.data.usable_coupons, i => {
// use.push({
// code: i.coupon_code,
// name: i.coupon_name,
// value: i.coupon_value
// });
// });
// result.data = _.concat(use, unuse);
// }
// return result;
// });
const getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid);
// 订单计算
const compute = (uid, cartType, pa) => {
... ... @@ -110,8 +81,7 @@ const submit = (uid, cartType, p) => {
module.exports = {
index,
// getCoupons,
getCoupons,
compute,
submit
};
... ...
... ... @@ -15,6 +15,7 @@ const easypay = require(`${cRoot}/easypay`);
const ensure = require(`${cRoot}/order-ensure`);
router.get('/index/getProductInfo', cart.getProductInfo);
router.get('/index/getProductData', cart.getProductData);
router.get('/address/list', address.getList); // 省市区列表信息
router.get('/address/area', address.getArea); // 省市区列表信息
... ... @@ -23,6 +24,8 @@ router.post('/address/save', address.saveAddress); // 新增地址/更新地址
router.post('/address/setdefault', address.setDefault); // 设置默认地址
router.get('/ensure', ensure.index); // 限购商品快捷结算页
router.get('/ensure/coupons', ensure.getCoupons); // 限购商品快捷结算页
router.post('/ensure/compute', ensure.compute); // 价格重新计算
router.get('/easypay', easypay.index); // 限购商品快捷结算页
router.post('/easypay/compute', easypay.compute); // 价格重新计算
... ...
... ... @@ -120,19 +120,83 @@
<label id="modify-invoice">修改</label>
</div>
</div>
{{# shoppingCartData}}
<div class="extra-wrap">
<dl>
<dt>使用YOHO币</dt>
<dd></dd>
<dt>使用红包</dt>
<dd></dd>
<dt>添加备注信息</dt>
<dd></dd>
<dt id="use-coupons" class="use-coupons">
<span class="iconfont locker-switch">&#xe645;</span>使用优惠券/优惠码
<div class="tip-box right">
<p>优惠码不可与优惠券同时使用</p>
<p class="coupon-err-tip"></p>
</div>
</dt>
<dd>
<div class="coupon-opt-title">
<label class="radio-btn on">使用优惠券</label>
<label class="radio-btn code">使用优惠码</label>
<span class="ticket-use-tip hide">
已成功使用<em class="red num">1</em>张优惠券,<em class="red price"></em>
<b class="cancel-use-ticket">取消使用</b>
</span>
<div class="opt-area right">
<input type="text" class="coupon-code">
<label class="sure-use-code">直接使用</label>
<label class="sure-use-ticket">确定</label>
</div>
</div>
<div class="coupon-list-wrap"></div>
</dd>
<dt><span class="iconfont locker-switch">&#xe645;</span>使用YOHO币</dt>
<dd id="yoho-coin-box" class="yoho-coin-box" data-coin="{{usedCoinNum}}" data-max={{canUseCoinNum}}>
<div class="outer-view">
<p class="coin-err-tip">{{coinErrorTip}}</p>
<p>有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>
<i class="iconfont help-icon">&#xe628;</i>
<div class="coin-tip-help">
<p>有货币使用提示:</p>
<p>
1.订单金额大于20元(含20元)<br>
2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含{{yoho_coin_pay_rule.num_limit}}个) <br>
3.有货币支付上限为每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}
</p>
<p class="rs-text">备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
</div>
</div>
<div class="coin-main-view">
<p>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span></p>
<p class="grey">您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span class="red">{{canUseCoinNum}}</span></p>
<label class="coin-cancel-btn">取消使用</label>
<label class="coin-use-btn">确定</label>
</div>
</dd>
{{#if red_envelopes}}
<dt><span class="iconfont locker-switch">&#xe645;</span>使用红包</dt>
<dd id="red-packet-box" class="red-packet-box">
<div>
<label class="radio-btn"></label>
使用红包支付(当前账户红包金额:<em class="red">¥ {{red_envelopes}}</em>
<label class="sure-btn" data-num="{{red_envelopes}}">确定</label>
</div>
</dd>
{{/if}}
<dt><span class="iconfont locker-switch">&#xe645;</span>添加备注信息</dt>
<dd id="remark-box" class="remark-box">
<div class="note-text-box">
<p class="tip-text">声明:备注中有关收货人信息、支付方式、配送方式、发票信息等购买要求一律以上面的选择为准,备注无效。</p>
<textarea class="note-text"></textarea>
</div>
<p class="pp-area">是否打印价格:
<label class="radio-btn on"></label>
<label class="radio-btn unprint"></label>
<span>(如:送朋友的商品可不打印价格哦!)</span>
</p>
</dd>
</dl>
</div>
{{# shoppingCartData}}
<div class="balance-wrap">
<ul class="balance-detail">
<ul id="balance-detail" class="balance-detail">
{{#each promotion_formula_list}}
<li class="promotion-item">
{{#if @first}}
... ... @@ -149,7 +213,7 @@
</div>
<div class="sum-wrap">
应付金额:<span class="price">¥ {{last_order_amount}}</span>
应付金额:<span id="order-price" class="price">¥ {{round last_order_amount 2}}</span>
<button id="order-submit">提交订单</button>
</div>
{{/ shoppingCartData}}
... ...
<script id="address-tpl" type="text/html">
<div class="title">\{{title}}</div>
<p class="prompt">\{{title}}、电话为选填项,其他均为必填项</p>
... ... @@ -138,3 +136,70 @@
</ul>
</div>
</script>
<script id="coupons-tpl" type="text/html">
\{{#if usable_coupons}}
<ul class="usable-list">
<li class="useable-title">可用优惠券</li>
\{{#each usable_coupons}}
<li>
<span class="title">\{{coupon_name}}</span>
<span class="time">\{{coupon_validity}}</span>
<span class="money">¥ \{{round coupon_value 2}}</span>
<span class="coupon-radio" data-id="\{{coupon_code}}" data-price="\{{round coupon_value 2}}"></span>
</li>
\{{/each}}
</ul>
\{{^}}
<p class="empty-tip">暂无可用优惠券~</p>
\{{/if}}
\{{#if unusable_coupons}}
<ul class="unusable-list">
<li class="unuseable-title">未满足使用条件的优惠券</li>
\{{#each unusable_coupons}}
<li>
<span class="title">\{{coupon_name}}</span>
<span class="time">\{{coupon_validity}}</span>
<span class="money">¥ \{{round coupon_value 2}}</span>
</li>
\{{/each}}
</ul>
\{{/if}}
</script>
<script id="yoho-coin-tpl" type="text/html">
<div class="outer-view">
<p class="coin-err-tip">\{{coinErrorTip}}</p>
<p>有货币满<span class="red">\{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span class="red">\{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>
<i class="iconfont help-icon">&#xe628;</i>
<div class="coin-tip-help">
<p>有货币使用提示:</p>
<p>
1.订单金额大于20元(含20元)<br>
2.有货币数量大于\{{yoho_coin_pay_rule.num_limit}}个(含\{{yoho_coin_pay_rule.num_limit}}个) <br>
3.有货币支付上限为每笔订单应付金额的\{{yoho_coin_pay_rule.max_pay_rate_desc}}
</p>
<p class="rs-text">备注:使用有货币数量为\{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
</div>
</div>
<div class="coin-main-view">
<p>本次使用有货币<span class="red">\{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥\{{yoho_coin}}</span></p>
<p class="grey">您当前共有有货币 <span class="red">\{{total_yoho_coin_num}}</span> 个,可用 <span class="red">\{{canUseCoinNum}}</span> 个</p>
<label class="coin-cancel-btn">取消使用</label>
<label class="coin-use-btn">确定</label>
</div>
</script>
<script id="promotion-list-tpl" type="text/html">
\{{#each promotion_formula_list}}
<li class="promotion-item">
\{{#if @first}}
<a class="gain-coin-tip" href="/help/?category_id=87" target="_blank"></a>
<span class="back-coin">共返YOHO币:\{{../gain_yoho_coin}}个</span>
<span class="total-num"><i>\{{../selected_goods_count}}</i>件商品</span>
\{{/if}}
<span class="promotion-name">\{{promotion}}:</span>
<em class="promotion-val">\{{promotion_amount}}</em>
</li>
\{{/each}}
</script>
... ...
No preview for this file type
... ... @@ -2,7 +2,11 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>
<<<<<<< HEAD
Created by FontForge 20120731 at Fri Dec 30 17:59:57 2016
=======
Created by FontForge 20120731 at Fri Jan 6 16:35:29 2017
>>>>>>> 01504b9ffb57840ea020ad6141c7b32753e14078
By admin
</metadata>
<defs>
... ... @@ -239,11 +243,14 @@ d="M512 832q-91 0 -174 -35.5t-143 -95.5t-95 -143t-35 -174t35 -174t95 -142.5t143
<glyph glyph-name="jia" unicode="&#xe645;"
d="M512 832q-91 0 -174 -35.5t-143 -95.5t-95.5 -142.5t-35.5 -173.5t35.5 -173.5t95.5 -142.5t143 -95.5t174 -35.5t174 35.5t143 95.5t95.5 142.5t35.5 173.5t-35.5 173.5t-95.5 142.5t-143 95.5t-174 35.5v0zM753 351h-207v-207h-68v207h-207v68h207v207h68v-207h207v-68
v0zM753 351z" />
<<<<<<< HEAD
=======
<glyph glyph-name="focus" unicode="&#xe68e;" horiz-adv-x="1122"
d="M793 798q92 0 150.5 -65t58.5 -161q0 -82 -54 -145l-398 -413l-399 413q-53 63 -53 145q0 96 58 161t150 65q43 0 90 -22t79 -52t53.5 -58.5t21.5 -42.5q0 14 21 42.5t53.5 58.5t79 52t89.5 22zM793 896q-63 0 -127 -30t-116 -78q-53 48 -117 78t-127 30
q-131 0 -218.5 -92.5t-87.5 -231.5q0 -118 76 -208l3 -3l2 -2l398 -413l71 -73l70 73l398 413l3 2l2 3q76 90 76 208q0 139 -87.5 231.5t-218.5 92.5v0z" />
<glyph glyph-name="focused" unicode="&#xe68f;" horiz-adv-x="1122"
d="M793 896q-63 0 -127 -30t-116 -78q-53 48 -117 78t-127 30q-131 0 -218.5 -92.5t-87.5 -231.5q0 -118 76 -208l3 -3l2 -2l398 -413l71 -73l70 73l398 413l3 2l2 3q76 90 76 208q0 139 -87.5 231.5t-218.5 92.5v0z" />
>>>>>>> 01504b9ffb57840ea020ad6141c7b32753e14078
<glyph glyph-name="wenhao1" unicode="&#xe628;"
d="M512 886q-102 0 -195 -39.5t-160.5 -107t-107 -160.5t-39.5 -195t39.5 -195t107 -160.5t160.5 -107t195 -39.5t195 39.5t160.5 107t107 160.5t39.5 195t-39.5 195t-107 160.5t-160.5 107t-195 39.5zM521 -15q-34 0 -58.5 24t-24.5 58.5t24.5 58.5t58.5 24t58 -24t24 -58
q1 -34 -23.5 -58.5t-58.5 -24.5zM738 477q-17 -34 -67 -83q-45 -43 -60 -61q-12 -16 -17 -35q-6 -22 -6 -61l1 -31h-142v30q0 56 9 90q11 38 30 64q17 23 62 71q43 44 52 60q8 13 8 44q0 28 -20 51q-20 21 -61 21q-29 0 -48.5 -9.5t-28.5 -27.5t-12.5 -36t-3.5 -43v-30h-142
... ... @@ -266,6 +273,8 @@ d="M947 179q31 0 54 -23t23 -53.5t-23 -53.5t-54 -23h-51q31 0 54 -23t23 -54t-23 -5
q0 -136 -26 -205h256q31 0 54 -23t23 -53.5t-23 -53.5t-54 -23h51q31 0 54 -23t23 -54t-23 -54t-54 -23zM102.5 -128q-42.5 0 -72.5 30t-30 72v410q0 42 30 72t72.5 30t72.5 -30t30 -72v-410q0 -42 -30 -72t-72.5 -30z" />
<glyph glyph-name="juxingkaobei" unicode="&#xe6bc;"
d="M186 2l391 382l-391 382l131 130l521 -512l-521 -512z" />
<<<<<<< HEAD
=======
<glyph glyph-name="shang" unicode="&#xe6c0;"
d="M958 179q0 -15 -10.5 -25.5t-25.5 -10.5t-26 10l-384 384l-384 -384q-11 -10 -26 -10t-25.5 10.5t-10.5 25.5t11 26l409 410q11 10 26 10t26 -10l409 -410q11 -11 11 -26z" />
<glyph glyph-name="xia" unicode="&#xe6c1;"
... ... @@ -301,5 +310,6 @@ q-42 -57 -105.5 -93.5t-135.5 -46.5q-72 -9 -141 9t-126 61q-19 14 -44 10.5t-39 -23
<glyph glyph-name="yz" unicode="&#xe6d2;"
d="M255 743q113 85 252.5 96.5t262.5 -51.5l83 83q25 25 63 12q18 0 28.5 -15t10.5 -36v-248q0 -24 -17 -40.5t-41 -16.5h-254q-38 0 -57 38q-12 48 12 64l70 70q-79 35 -174 22t-169 -73q-78 -59 -115.5 -148.5t-26 -186t71.5 -174.5q43 -57 106.5 -93.5t135.5 -46.5
q71 -9 140 9t127 61q19 14 43.5 10.5t39 -23t10.5 -44t-23 -38.5q-133 -102 -293 -102q-44 0 -63 6q-97 15 -179.5 62t-139.5 123q-78 106 -92.5 235t35.5 248t153 197z" />
>>>>>>> 01504b9ffb57840ea020ad6141c7b32753e14078
</font>
</defs></svg>
... ...
No preview for this file type
No preview for this file type

2.96 KB | W: | H:

283 Bytes | W: | H:

  • 2-up
  • Swipe
  • Onion skin

3.03 KB | W: | H:

360 Bytes | W: | H:

  • 2-up
  • Swipe
  • Onion skin

47.4 KB | W: | H:

48.1 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -9,24 +9,54 @@ var Alert = Dialog.Alert;
var $cartnewTips = $('.cartnew-tips'),
$payWapper = $('.pay-wapper'),
$cartnewSum = $('.cartnew-sum'),
selectArray = [],
hasPromotion = false,
countJSON;
CART_ITEM_DEL_URL = '/cart/index/remove',
CART_ITEM_FAV_URL = '/cart/index/fav',
selColorWinTpl = require('hbs/cart/select-color-panel.hbs');
// 关闭温馨提示
$cartnewTips.find('.btn_close').click(function() {
$cartnewTips.fadeOut();
});
// 滚动到第一个选中的商品
function scrollToFirst() {
var $selected = $payWapper.find('li[data-role="pitem"] .cart-item-check.cart-item-checked:eq(0)');
var top = 0;
if ($selected.length > 0) {
top = $selected.offset().top - 36;
$('html,body').scrollTop(top);
}
return false;
}
function toggleCheckAllPros() {
}
// checkbox提交ajax
function choiceOut(data) {
$.ajax({
function choiceOut(items) {
var skuList = $.isArray(items) ? items : [items];
var hasPromotion = false;
$.each(skuList, function(idx, it) {
if (it.promotion_id) {
hasPromotion = true;
return false;
}
});
return $.ajax({
type: 'POST',
dataType: 'json',
url: '/cart/index/select',
data: data,
data: {
skuList: JSON.stringify(skuList),
hasPromotion: hasPromotion
},
beforeSend: function() {
$('.loading').css({
top: $(document).scrollTop() + 200
... ... @@ -40,123 +70,32 @@ function choiceOut(data) {
});
}
// 单选提交
$payWapper.one('click', 'li[data-role="pitem"] .cart-item-check', function() {
var $this = $(this);
var selected = $this.hasClass('cart-item-checked') ? 'Y' : 'N';
var $pitem = $this.closest('li[data-role="pitem"]');
var item = {
product_sku: $pitem.data('id'),
selected: selected,
buy_number: $pitem.data('productnum'),
goods_type: $pitem.data('goodstype'),
promotion_id: $pitem.data('promotionid') ? $pitem.data('promotionid') : 0
};
if (item.promotion_id) {
hasPromotion = true;
} else {
hasPromotion = false;
}
selectArray.push(item);
var dataJSON = {
skuList: JSON.stringify(selectArray),
hasPromotion: hasPromotion
};
choiceOut(dataJSON);
});
// 全选提交
$cartnewSum.one('click', '.cart-item-check', function() {
var $this = $(this);
var dataJSON = {};
var selected = $this.hasClass('cart-item-checked') ? 'Y' : 'N';
$payWapper.find('.cart-item-check').each(function() {
var $t = $(this);
if ($t.data('promotionid')) {
hasPromotion = true;
}
if ($t.data('id')) {
selectArray.push({
product_sku: $t.data('id'),
selected: selected,
buy_number: $t.data('productnum'),
goods_type: $t.data('goodstype'),
promotion_id: $t.data('promotionid') ? $t.data('promotionid') : 0
});
}
});
dataJSON = {
skuList: JSON.stringify(selectArray),
hasPromotion: hasPromotion
};
choiceOut(dataJSON);
});
// 滚动到第一个选中的商品
function scrollToFirst() {
var $selected = $payWapper.find('li[data-role="pitem"] .cart-item-check.cart-item-checked:eq(0)');
var top = 0;
if ($selected.length > 0) {
top = $selected.offset().top - 36;
$('html,body').scrollTop(top);
}
/*
* 1. 删除购物车商品,把删除的商品移入cookie中
* 2. 移到收藏夹
* data: 数据
* tpe: true - 删除,默认 移入收藏夹
*/
function cartItemDel(items, type, cookieList) {
return false;
}
var selList = $.isArray(items) ? items : [items];
var hasPromotion = false;
/*
function isCheck(obj, className) {
selectArray = [];
dataJSON = {};
selected = obj.attr('checked') ? 'Y' : 'N';
$('.' + className).each(function() {
if ($(this).data('promotionid')) {
$.each(selList, function(idx, it) {
if (it.promotion_id) {
hasPromotion = true;
} else {
hasPromotion = false;
}
if ($(this).data('id')) {
selectArray.push({
product_sku: $(this).data('id'),
selected: selected,
buy_number: $(this).data('productnum'),
goods_type: $(this).data('goodstype'),
promotion_id: $(this).data('promotionid') ? $(this).data('promotionid') : 0
});
return false;
}
});
dataJSON = {
skuList: JSON.stringify(selectArray),
hasPromotion: hasPromotion
};
choiceOut(dataJSON);
}*/
/* $('.per-list').on('click', 'input[type="checkbox"]', function() {
isCheck($(this), 'pre-sell-box');
});
$('.common-list').on('click', 'input[type="checkbox"]', function() {
isCheck($(this), 'common-sell-box');
});*/
// 删除购物车商品,把删除的商品移入cookie中
function cartItemDel(data, delUrl, cookieList) {
$.ajax({
return $.ajax({
type: 'POST',
dataType: 'json',
url: delUrl,
data: dataJSON,
url: type === true ? CART_ITEM_DEL_URL : CART_ITEM_FAV_URL,
data: {
skuList: JSON.stringify(selList),
hasPromotion: hasPromotion
},
beforeSend: function() {
$('.loading').css({
top: $(document).scrollTop() + 200
... ... @@ -183,142 +122,540 @@ function cartItemDel(data, delUrl, cookieList) {
});
}
// 购物车商品增减
var cartItemNumChg = (function(data) {
// 删除商品
$payWapper.on('click', '.cart-del-btn', function() {
var countBusy = false; // 保证一次只请求完成前不能再次发起
var $this = $(this);
var $item = $this.closest('li[data-role="pitem"]');
var dataJSON = {};
var selectArray = [];
var promotionId = $item.data('promotionid') ? $item.data('promotionid') : 0;
selectArray.push({
product_sku: $item.data('id'),
buy_number: $item.data('productnum'),
promotion_id: promotionId
});
return function(data) {
if (promotionId) {
hasPromotion = true;
} else {
hasPromotion = false;
}
if (countBusy) {
return;
}
dataJSON = {
skuList: JSON.stringify(selectArray),
hasPromotion: hasPromotion
countBusy = true;
$.ajax({
type: 'POST',
dataType: 'json',
url: '/cart/index/modify',
data: data
}).then(function(d) {
if (d.code === 200) {
window.history.go(0);
} else {
new Alert(d.message === '' ? '加入购物车失败哦~~' : d.message).show();
}
countBusy = false;
});
};
content = '<div><span></span>删除商品</div><p>确定从购物车中删除此商品?</p>';
if (!$this.data('gift')) {
countJSON = {
productPrice: $item.find('.productPrice').text(),
productTitle: $item.find('.pay-pro-info a').text(),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
promotionId: $item.data('promotionid')
};
})();
function getProductInfo(pid, skn) {
return $.ajax({
type: 'GET',
url: '/cart/index/getProductData', // '/product/item/getProductInfo',
data: {
productId: pid,
skn: skn
}
}).done(function(res) {
return res;
});
}
// 加入购物车,弹出框中加入购物车
function addcart(data, cookieList) {
$.ajax({
type: 'POST',
url: '/cart/index/add',
data: data
}).then(function(d) {
if (d.code === 200) {
window.history.go(0);
if (cookieList) {
window.setCookie('cart-del-list', JSON.stringify(cookieList), {
domain: '.yohobuy.com',
path: '/'
});
}
} else {
new Alert(d.message === '' ? '加入购物车失败哦~~' : d.message).show();
}
});
}
function parseProductInfo(productInfo, defaultInfo) {
var index = 0;
var colors;
var colorsLen;
var color;
// 前端处理后的集合
var filterSet = [];
var sizeIdx;
var curColor;
var curSize;
var hasActiveColor = false;
var defaultColor = defaultInfo.color;
var defaultSize = defaultInfo.size;
var defaultImg;
// 没有res.code
if (productInfo.colors) {
// 获取成功
colors = productInfo.colors;
colorsLen = colors.length;
for (index; index < colorsLen; index++) {
color = colors[index];
// 迭代每一种颜色
filterSet.push({
proId: res.id,
color: color.color,
sizes: color.sizes,
pic: color.thumbs[0],
selectable: color.total > 0,
rgb: color.rgb
});
}
}
delUrl = '/cart/index/remove';
new Confirm({
content: content,
cb: function() {
cartItemDel(dataJSON, delUrl, countJSON);
// 默认选中用户选择的sku,若已售罄或下架,则选中列表中第一个非售罄的sku
for (index = 0; index < filterSet.length; index++) {
curColor = filterSet[index];
if (!hasActiveColor && curColor.color === defaultInfo.color) {
curColor.active = true;
curColor.hasActiveColor = hasActiveColor = true;
defaultImg = curColor.pic;
}
}).show();
});
// 移入收藏夹
$payWapper.on('click', '.cart-remove-btn', function() {
curSize = curColor.sizes;
for (sizeIdx = 0; sizeIdx < curSize.length; sizeIdx++) {
if (curColor.hasActiveColor && curSize[sizeIdx].name === defaultInfo.size) {
curSize[sizeIdx].sizeFocus = true;
break;
}
}
}
var $this = $(this);
var $item = $this.closest('li[data-role="pitem"]');
dataJSON = {};
selectArray = [];
var promotionId = $item.data('promotionid') ? $item.data('promotionid') : 0;
selectArray.push({
product_sku: $item.data('id'),
buy_number: $item.data('productnum'),
promotion_id: promotionId
});
// 若无对应颜色,则选中第一个颜色
if (!hasActiveColor) {
filterSet[0].active = true;
defaultColor = filterSet[0].color;
if (promotionId) {
hasPromotion = true;
} else {
hasPromotion = false;
defaultImg = filterSet[0].pic;
}
dataJSON = {
skuList: JSON.stringify(selectArray),
hasPromotion: hasPromotion
return {
colors: filterSet,
defaultColor: defaultColor,
defaultSize: defaultSize,
defaultImg: defaultImg
};
}
cartItemDel(dataJSON, '/cart/index/fav');
});
function renderAndShowSelWin($edit, pinfo) {
$edit.find('.goods-choose-box').remove();
var $selWin = selColorWinTpl(pinfo).appendTo($edit);
$selWin.show();
}
// 批量删除商品
$cartnewSum.on('click', '.delAll', function() {
dataJSON = {};
countJSON = {};
selectArray = [];
PromotionArray = [];
var Cart = {
addToCart: function(params) {
<<<<<<< HEAD
$payWapper.find('.cart-item-check').each(function() {
var $item = $(this);
var $chk = $item.find('.cart-item-check');
if ($chk.hasClass('cart-item-checked')) {
=======
},
toggleSelectOne: function() { // 单选
var $this = $(this);
var $pitem = $this.closest('li[data-role="pitem"]');
var item = {
product_sku: $pitem.data('id'),
selected: $this.hasClass('cart-item-checked') ? 'Y' : 'N',
buy_number: $pitem.data('productnum'),
goods_type: $pitem.data('goodstype'),
promotion_id: $pitem.data('promotionid') ? $pitem.data('promotionid') : 0
};
>>>>>>> 3a2b8fa435f608cc40704e327ea3ee303f3c3da4
var promotionId = $item.data('promotionid') ? $item.data('promotionid') : 0;
return choiceOut(item);
},
toggleSelectAll: function() { // 全选
if (promotionId) {
hasPromotion = true;
}
var $this = $(this);
var selected = $this.hasClass('cart-item-checked') ? 'Y' : 'N';
var selectArray = [];
if ($item.data('id')) {
$payWapper.find('.cart-item-check').each(function() {
var $t = $(this);
if ($t.data('id')) {
selectArray.push({
product_sku: $item.data('id'),
buy_number: $item.data('productnum'),
promotion_id: promotionId
product_sku: $t.data('id'),
selected: selected,
buy_number: $t.data('productnum'),
goods_type: $t.data('goodstype'),
promotion_id: $t.data('promotionid') || 0
});
countJSON = {
productPrice: $item.find('.productPrice').text(),
productTitle: $item.find('.pay-pro-info a').text(),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
promotionId: $item.data('promotionid')
};
PromotionArray.push(countJSON);
}
});
choiceOut(selectArray);
},
del: function() {
var $this = $(this);
var $item = $this.closest('li[data-role="pitem"]');
var selectArray = [];
var content = '<div><span></span>删除商品</div><p>确定从购物车中删除此商品?</p>';
var countJSON;
selectArray.push({
product_sku: $item.data('id'),
buy_number: $item.data('productnum'),
promotion_id: $item.data('promotionid') || 0
});
if (!$this.data('gift')) {
countJSON = {
productPrice: $item.find('.productPrice').text(),
productTitle: $item.find('.pay-pro-info a').text(),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
promotionId: $item.data('promotionid')
};
}
});
delUrl = '/cart/index/remove';
content = '<div><span></span>删除商品</div><p>确定从购物车中删除所有选中商品?</p>';
dataJSON = {
skuList: JSON.stringify(selectArray),
hasPromotion: hasPromotion
};
if (!$.isEmptyObject(selectArray)) {
new Confirm({
content: content,
cb: function() {
cartitemDel(dataJSON, delUrl, PromotionArray);
cartItemDel(selectArray, true, countJSON);
}
}).show();
} else {
new Alert('请至少选择一件商品').show();
},
delAll: function() {
var selectArray = [];
var PromotionArray = [];
var content = '<div><span></span>删除商品</div><p>确定从购物车中删除所有选中商品?</p>';
$payWapper.find('.cart-item-check').each(function() {
var $item = $(this);
var $chk = $item.find('.cart-item-check');
if ($chk.hasClass('cart-item-checked')) {
if ($item.data('id')) {
selectArray.push({
product_sku: $item.data('id'),
buy_number: $item.data('productnum'),
promotion_id: $item.data('promotionid') || 0
});
PromotionArray.push({
productPrice: $item.find('.productPrice').text(),
productTitle: $item.find('.pay-pro-info a').text(),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
promotionId: $item.data('promotionid')
});
}
}
});
if (!$.isEmptyObject(selectArray)) {
new Confirm({
content: content,
cb: function() {
cartItemDel(selectArray, true, PromotionArray);
}
}).show();
} else {
new Alert('请至少选择一件商品').show();
}
},
toFav: function() {
var $this = $(this);
var $item = $this.closest('li[data-role="pitem"]');
var item = {
product_sku: $item.data('id'),
buy_number: $item.data('productnum'),
promotion_id: $item.data('promotionid') ? $item.data('promotionid') : 0
};
cartItemDel(item);
},
toFavAll: function() {
var selectArray = [];
$payWapper.find('.cart-item-check').each(function() {
var $item = $(this);
var $chk = $item.find('.cart-item-check');
if ($chk.hasClass('cart-item-checked')) {
if ($item.data('id')) {
selectArray.push({
product_sku: $(this).data('id'),
buy_number: $(this).data('productnum'),
promotion_id: $item.data('promotionid') || 0
});
}
}
});
if (!$.isEmptyObject(selectArray)) {
cartItemDel(selectArray);
} else {
new Alert('请至少选择一件商品').show();
}
},
modNum: function() {
var $this = $(this);
var countJSON = {};
var oprType = $this.hasClass('minus') ? 'decreaseNum' : 'increaseNum';
countJSON[oprType] = 1;
if ($this.siblings('input').val() === '1' && $this.hasClass('minus')) {
return false;
}
cartItemNumChg($.extend(countJSON, {
sku: $this.closest('li[data-role="pitem"]').data('id')
}));
},
cleanAllDisable: function() {
var selectArray = [];
var PromotionArray = [];
var content = '<div><span></span>删除商品</div><p>确定从购物车中删除所有选中商品?</p>';
$payWapper.find('.cart-item-check').each(function() {
var $item = $(this);
var $chk = $item.find('.cart-item-check');
if ($chk.hasClass('cart-item-checked')) {
if ($item.data('id')) {
selectArray.push({
product_sku: $item.data('id'),
buy_number: $item.data('productnum'),
promotion_id: $item.data('promotionid') || 0
});
PromotionArray.push({
productPrice: $item.find('.productPrice').text(),
productTitle: $item.find('.pay-pro-info a').text(),
link: $item.find('.pay-pro-info a').attr('href'),
productNum: $item.data('productnum'),
productSku: $item.data('id'),
promotionId: $item.data('promotionid')
});
}
}
});
if (!$.isEmptyObject(selectArray)) {
new Confirm({
content: content,
cb: function() {
cartItemDel(selectArray, true, PromotionArray);
}
}).show();
} else {
new Alert('请至少选择一件商品').show();
}
},
showColorSizePanel: function() {
var $this = $(this);
var $item = $this.closest('li[data-role="pitem"]');
var pinfo = $this.data('_p_info');
var $selWin = $this.find('.goods-choose-box');
var pid = $item.data('pid');
var skn = $item.data('skn');
var defaultInfo = {
color: $this.find('.default-color').text(),
size: $this.find('.default-size').text(),
pid: pid,
skn: skn
};
if ($selWin && $selWin.length && $selWin.is(':visible')) {
$selWin.hide();
return;
}
if (!pinfo) {
getProductInfo(pid, skn).done(function(productInfo) {
pinfo = parseProductInfo(productInfo, defaultInfo);
$this.data('_p_info', pinfo);
renderAndShowSelWin($this, pinfo);
}).fail(function() {
new Alert('此商品无法编辑颜色和尺寸').show();
});
return;
}
renderAndShowSelWin($this, pinfo);
},
editColorOrSize: function(productId, skn, defaultColor, defaultSize, editTarget) {
},
submit: function() {
/* understock = '';
if ($('.pay-wapper input:checked').parents('tr').find('.tipNoStore').length > 0) {
shopName = $('.pay-wapper input:checked').parents('tr').find('.tipNoStore');
$.each(shopName.parents('tr').find('.pay-pro-info a'), function() {
understock += $(this).html();
});
new Alert(understock + '库存不足').show();
} else {
if ($('.zp').length > 0 && !$(this).attr('title')) {
$(this).attr('title', '1');
new Alert('您有赠品没有选择,请选择完再结算!').show();
} else {
if ($('input:checked').length > 0) {
// 添加埋点
var productId = [];
$('.pay-wapper input:checked').parents('tr').each(function() {
if ($(this).attr('data-pid')) {
productId.push($(this).attr('data-pid'));
}
});
// 结算点击埋点
window.addPoint('YB_SC_TOBUY_CLICK', {PRD_ID: productId.join(',')});
if ($('.pre-sell-box input:checked').length > 0) {
window.location.href = '/cart/index/orderEnsure?type=2';
} else {
window.location.href = '/cart/index/orderEnsure?type=1';
}
} else {
new Alert('请至少选择一件商品').show();
}
}
}*/
}
};
module.exports = Cart;
$payWapper.one('click', 'li[data-role="pitem"] .cart-item-check', Cart.toggleSelectOne); // 单选
$cartnewSum.one('click', '.cart-item-check', Cart.toggleSelectAll); // 全选
$payWapper.on('click', '.cart-del-btn', Cart.del); // 删除商品
$cartnewSum.on('click', '.delAll', Cart.delAll); // 批量删除商品
$payWapper.on('click', '.cart-remove-btn', Cart.toFav); // 移入收藏夹
$cartnewSum.on('click', '.removeAll', Cart.toFavAll); // 批量移入收藏夹商品
$payWapper.on('click', '.minus, .plus', Cart.modNum); // 修改购物车数量
$cartnewSum.on('click', '.clean-all-disable', Cart.cleanAllDisable);
$('.btn_account').on('click', Cart.submit); // 结算
$payWapper.on('click', 'li[data-role="pitem"] .pay-pro-detail', Cart.showColorSizePanel);
// / 绑定颜色尺码弹窗事件 begin
/*
oldProductSku = editTarget.find('.current').attr('data-sku');
// rebind events(Tips依赖接口数据,so 不能delegate)
editTarget.find('#confirm').click(function(e) {
e.preventDefault();
newProductSku = editTarget.find('.current-sizes .active').attr('data-sku');
// 没有重新选择颜色-尺码,则不用重新请求显示
if (!oldProductSku || !newProductSku || newProductSku === oldProductSku) {
editTarget.find('.edit-color-size').remove();
return false;
}
Util.ajax({
url: '/shopping/cart/updateProduct',
type: 'PUT',
data: {
swapData: JSON.stringify([{
buy_number: '1',
selected: 'Y',
new_product_sku: newProductSku,
old_product_sku: oldProductSku
}])
},
success: function(newCartData) {
editTarget.find('.edit-color-size').remove();
Util.refreshCart(newCartData);
setEditable();
}
});
return false;
});
editTarget.find('#cancel').click(function(e) {
e.preventDefault();
editTarget.find('.edit-color-size').remove();
setEditable();
return false;
});
editTarget.find('.edit-color-size').click(function(e) {
e.preventDefault();
return false;
});
editTarget.find('.color-item').click(function(e) {
e.preventDefault();
selectColor = $(this);
if (!selectColor.hasClass('current-color')) {
selectColor.addClass('current-color').siblings().removeClass('current-color');
selectColor.parent().siblings('.current-sizes').hide().removeClass('current-sizes');
editTarget.find('#' + selectColor.attr('data-target')).show().addClass('current-sizes')
.end()
.find('.right img').attr({
src: selectColor.attr('data-imageurl'),
title: selectColor.attr('data-title')
})
.end()
.find('.selected-color').text(selectColor.attr('data-title'));
}
return false;
});
editTarget.find('.size-item').click(function() {
var $this = $(this);
if ($this.hasClass('active') || $this.hasClass('disabled')) {
return;
}
$(this).addClass('active').siblings('.active').removeClass('active');
});
// 初始化size list选中项(其他颜色中第一个尺码)
editTarget.find('.sizes-list.mb10').each(function() {
if ($(this).find('.active').length === 0) {
$(this).find('.size-item:not(.disabled)').first().addClass('active');
}
});*/
// / 绑定颜色尺码弹窗事件 end
// 显示赠品
var giftBtn = '[data-role=gift-view-btn],[data-role=gift-resel-btn],[data-role=gift-sel-btn]';
... ...
... ... @@ -86,7 +86,7 @@ $('.bottom-tab-slide').on('click', '.bottom-title', function() {
});
//删除购物车商品,把删除的商品移入cookie中
// 删除购物车商品,把删除的商品移入cookie中
function cartDel(data, delUrl, cookieList) {
$.ajax({
type: 'POST',
... ... @@ -119,6 +119,7 @@ function cartDel(data, delUrl, cookieList) {
});
}
<<<<<<< HEAD
//购物车表单 删除商品
$payWapper.on('click', '.cart-del-btn', function() {
// new Confirm({
... ... @@ -140,6 +141,8 @@ $payWapper.on('click', '.cart-del-btn', function() {
);
});
=======
>>>>>>> 3a2b8fa435f608cc40704e327ea3ee303f3c3da4
// 凑单图片懒加载
var togetherDialog = {};
var dialogTpl = require('hbs/cart/cart-togetherGoods.hbs');
... ... @@ -286,6 +289,7 @@ $cartGoodsDetail.on('click', '.btn-favCount', function() {
// 购物车列表 赠品
<<<<<<< HEAD
//购物车列表 显示
$('.shop-cart').on('click', '.gift-sell .btn-clear', function() {
... ... @@ -293,6 +297,9 @@ $('.shop-cart').on('click', '.gift-sell .btn-clear', function() {
showPromotion(tid);
});
=======
// 购物车列表 显示
>>>>>>> 3a2b8fa435f608cc40704e327ea3ee303f3c3da4
function showPromotion(id) {
if (!id) {
... ... @@ -312,7 +319,8 @@ function showPromotion(id) {
dialog.show();
}
//购物车列表 大小图切换
// 购物车列表 大小图切换
$('body').on('click', '.piclist li', function() {
pacList = $(this).index();
$('.detail-bigpic:not(.none) .piclist li').removeClass('active');
... ... @@ -415,9 +423,15 @@ $goodsChoose.on('click', '.choose-color .dt', function() {
$('.bigImg').addClass('none').eq($(this).index()).removeClass('none');
});
<<<<<<< HEAD
//结算
$paySum.on('click','.btn-account', function() {
=======
// 结算
$paySum.on('click', '.btn-account', function() {
>>>>>>> 3a2b8fa435f608cc40704e327ea3ee303f3c3da4
understock = '';
// if ($('.pay-wapper .cart-item-checked').parents('.tr').find('.tipNoStore').length > 0) {
// shopName = $('.pay-wapper .cart-item-checked').parents('.tr').find('.tipNoStore');
// $.each(shopName.parents('.tr').find('.pay-pro-info a'), function() {
... ... @@ -444,7 +458,7 @@ $paySum.on('click','.btn-account', function() {
// }
// } else {
new Alert('请至少选择一件商品').show();
new Alert('请至少选择一件商品').show();
// }
// }
... ... @@ -465,4 +479,8 @@ $('.shop-cart').on('click', giftBtn, function() {
console.log(htmlJson);
});
<<<<<<< HEAD
=======
>>>>>>> 3a2b8fa435f608cc40704e327ea3ee303f3c3da4
require('./cart-action');
... ...
... ... @@ -5,14 +5,105 @@
*/
var $ = require('yoho-jquery');
var Hbs = require('yoho-handlebars');
var order = {};
var $balanceDetail = $('#balance-detail'),
$orderPrice = $('#order-price');
var order = {
printPrice: 'Y'
},
iconCode = {
on: '&#xe643;',
off: '&#xe645;'
};
var payWay,
deliveryWay;
deliveryWay,
coupon,
yohoCoin;
var address = require('./order-new/address'),
invoice = require('./order-new/invoice');
var coinTpl = Hbs.compile($('#yoho-coin-tpl').html());
var promotionTpl = Hbs.compile($('#promotion-list-tpl').html());
require('../common');
order.cartType = window.queryString().type || 1;
// FE Helper
Hbs.registerHelper('round', function(num, precision) {
precision = parseFloat('0' + precision, 10) || 2;
return (+num).toFixed(precision);
});
// 订单计算
// 传有货币数量则使用有货币,否者不使用,更改订单总价有货币使用数量重置为0
function compute(coin) {
var reqData = {
cartType: order.cartType,
coin: coin ? coin : 0
};
require('./order-new/address');
require('./order-new/invoice');
order.coin = reqData.coin;
// 支付方式
if (order.paymentType) {
reqData.paymentType = order.paymentType;
}
// 配送方式
if (order.deliveryWay) {
reqData.deliveryWay = order.deliveryWay;
}
// 优惠券
if (order.couponCode) {
reqData.couponCode = order.couponCode;
}
// 红包
if (order.redEnvelopes) {
reqData.redEnvelopes = order.redEnvelopes;
}
$.ajax({
type: 'POST',
url: '/cart/ensure/compute',
data: reqData
}).then(function(data) {
var res;
if (data.code === 200) {
res = data.data;
// update yoho coin max use num
yohoCoin.maxCoin = res.canUseCoinNum;
// update yoho coin using
yohoCoin.$el.html(coinTpl(res));
if (!reqData.coin) {
yohoCoin.$el.removeClass('used');
}
// update last order amount
$orderPrice.html('¥ ' + res.last_order_amount);
// update promotion formula list
$balanceDetail.html(promotionTpl(res));
} else if (data.code === 317) {
if (coupon.$errorTip) {
coupon.$errorTip.text(data.message);
if (order.couponCode) {
delete order.couponCode;
}
}
}
});
}
// 支付方式
payWay = {
... ... @@ -53,6 +144,9 @@ payWay = {
// 更新订单支付数据
that.updateOrder($this.data());
// 重新计算订单价格
compute();
});
},
updateOrder: function(info) {
... ... @@ -116,6 +210,9 @@ deliveryWay = {
// 更新订单配送方式数据
that.updateOrder({way: $this.data('id')});
// 重新计算订单价格
compute();
});
this.$deliveryTime.click(function() {
... ... @@ -146,5 +243,239 @@ deliveryWay = {
}
};
coupon = {
$el: $('#use-coupons'),
init: function() {
if (!this.$el.length) {
return;
}
this.$couponWrap = this.$el.next();
this.$errorTip = $('.coupon-err-tip', this.$el);
this.$ticketUseTip = $('.ticket-use-tip', this.$couponWrap);
this.$couponCode = $('.coupon-code', this.$couponWrap);
this.$couponList = $('.coupon-list-wrap', this.$couponWrap);
this.couponsTpl = Hbs.compile($('#coupons-tpl').html());
this.getList();
this.eventBind();
},
getList: function() {
var that = this;
$.ajax({
type: 'GET',
url: '/cart/ensure/coupons'
}).then(function(data) {
if (data.code === 200) {
$('.coupon-list-wrap', that.$couponWrap).html(that.couponsTpl(data.data));
that.$radios = that.$couponWrap.find('.coupon-radio');
}
});
},
eventBind: function() {
var that = this;
this.$couponWrap.on('click', '.radio-btn', function() {
var $this = $(this);
if ($this.hasClass('on')) {
return;
}
$this.siblings('.radio-btn.on').removeClass('on');
$this.addClass('on').parent().toggleClass('using-code');
if ($this.hasClass('code')) {
that.cancelTicketUse();
that.$couponList.slideUp();
} else {
that.cancelCodeUse();
that.$couponList.slideDown();
}
}).on('click', '.cancel-use-ticket', function() {
that.cancelTicketUse();
}).on('change', '.coupon-code', function() {
that.$errorTip.empty();
}).on('click', '.opt-area > label', function() {
var $this = $(this);
var couponId, data;
if ($this.hasClass('sure-use-ticket')) {
data = that.$radios.filter('.on').data();
if (data) {
that.$ticketUseTip.find('.price').text('- ¥' + data.price);
that.$ticketUseTip.removeClass('hide');
couponId = data.id;
}
} else {
couponId = $this.siblings('.coupon-code').val();
}
if (couponId) {
order.couponCode = couponId;
// 重新计算订单价格
compute();
}
}).on('click', '.coupon-radio', function() {
var $this = $(this);
if ($this.hasClass('on')) {
return;
}
if (that.$radios) {
that.$radios.filter('.on').removeClass('on');
}
$this.addClass('on');
});
},
cancelTicketUse: function() {
if (order.couponCode) {
this.$ticketUseTip.addClass('hide');
this.$radios.filter('.on').removeClass('on');
delete order.couponCode;
compute(); // 重新计算订单价格
}
},
cancelCodeUse: function() {
this.$errorTip.empty();
this.$couponCode.val('');
if (order.couponCode) {
delete order.couponCode;
compute(); // 重新计算订单价格
}
}
};
yohoCoin = {
$el: $('#yoho-coin-box'),
init: function() {
var data;
if (!this.$el.length) {
return;
}
data = this.$el.data();
if (data) {
order.coin = data.coin || 0;
this.maxCoin = data.max;
}
this.eventBind();
},
eventBind: function() {
var that = this;
this.$el.on('click', '.coin-use-btn', function() {
if (order.coin * 1 === this.maxCoin * 1) {
return;
}
compute(that.maxCoin);
}).on('click', '.coin-cancel-btn', function() {
if (order.coin * 1 === 0) {
return;
}
compute();
});
}
};
$('.locker-switch').click(function() {
var $this = $(this),
$par = $this.parent();
$par.toggleClass('open');
if ($par.hasClass('open')) {
$this.html(iconCode.on);
} else {
$this.html(iconCode.off);
}
});
$('#red-packet-box').on('click', '.radio-btn', function() {
$(this).toggleClass('on');
}).on('click', '.sure-btn', function() {
var $this = $(this),
num = $this.data('num');
if (!num) {
return;
}
if ($this.siblings('.on').length) {
order.redEnvelopes = num;
} else if (order.redEnvelopes) {
delete order.redEnvelopes;
}
compute(); // 重新计算订单价格
});
$('#remark-box').on('keyup', '.note-text', function() {
var $this = $(this);
var val = $.trim($this.val());
if (val) {
$this.addClass('has-text');
if (val.length > 100) {
val = val.substring(0, 99);
$this.val(val);
}
order.remark = val;
} else {
$this.removeClass('has-text');
}
}).on('click', '.radio-btn', function() {
var $this = $(this);
if ($this.hasClass('on')) {
return;
}
if ($this.hasClass('unprint')) {
order.printPrice = 'N';
} else {
order.printPrice = 'Y';
}
$this.siblings('.on').removeClass('on');
$this.addClass('on');
});
$('#order-submit').click(function() {
var invoiceInfo = invoice.getInvoice();
order.addressId = address.getAddress();
// 发票信息
if (invoiceInfo) {
$.extend(order, invoiceInfo);
}
$.ajax({
type: 'POST',
url: '/cart/ensure/submit',
data: order
}).then(function(data) {
if (data.code === 200) {
location.href = data.data.url;
}
});
});
payWay.init();
deliveryWay.init();
coupon.init();
yohoCoin.init();
... ...
... ... @@ -22,6 +22,8 @@ var addressTpl = hbs.compile($('#address-tpl').html()),
var addrList = {},
addrDefault = '';
var addrSelect;
$('.addr-item').each(function() {
var data = $(this).data();
... ... @@ -168,6 +170,7 @@ function setShowDeliveryAddr(data) {
}
if (data) {
addrSelect = data.id;
_h = '寄送至:' + data.area + '&nbsp;&nbsp;&nbsp;&nbsp;' + data.address +
'<br>收货人:' + data.consignee + '&nbsp;&nbsp;&nbsp;&nbsp;' + data.mobile;
}
... ... @@ -377,3 +380,8 @@ $('.addr-opt').on('click', 'span', function() {
});
setShowDeliveryAddr();
// 获取地址信息
exports.getAddress = function() {
return addrSelect;
};
... ...
/**
* 订单结算页
* 订单结算页-发票
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/12/29
*/
... ...
... ... @@ -483,11 +483,351 @@
border: 1px solid $borderColor;
border-bottom-color: #fff;
dt {
line-height: 40px;
> .iconfont {
font-size: 18px;
margin-right: 10px;
vertical-align: top;
cursor: pointer;
}
}
dd {
display: none;
}
.open + dd {
display: block;
}
}
.use-coupons {
.tip-box {
width: 60%;
color: $red;
position: relative;
text-align: right;
display: none;
}
.coupon-err-tip {
width: 100%;
background-color: #fff;
position: absolute;
top: 0;
}
&.open > .tip-box {
display: block;
}
}
.coupon-opt-title {
height: 50px;
line-height: 50px;
padding: 0 30px;
background-color: #f0f0f0;
.ticket-use-tip {
margin-left: 20px;
.red {
color: $red;
}
.cancel-use-ticket {
color: #1987cf;
margin-left: 20px;
cursor: pointer;
}
}
.opt-area {
line-height: 1;
margin-top: 13px;
border: 1px solid #000;
background-color: #fff;
> input {
width: 174px;
line-height: 24px;
border: none;
padding: 0 10px;
font-size: 14px;
display: none;
}
> label {
color: #fff;
background-color: #000;
width: 78px;
height: 24px;
line-height: 24px;
text-align: center;
cursor: pointer;
display: none;
}
.sure-use-code {
float: right;
}
.sure-use-ticket {
display: inline-block;
}
}
&.using-code .opt-area {
> * {
display: inline-block;
}
.sure-use-ticket {
display: none;
}
}
}
.coupon-list-wrap {
padding: 0 30px;
border: 1px solid #e8e8e8;
line-height: 18px;
.empty-tip {
line-height: 24px;
padding-top: 10px;
}
li {
padding: 6px 0;
}
.unusable-list {
color: #999;
border-top: 1px solid #e8e8e8;
margin: 10px 0;
}
.useable-title,
.unuseable-title {
color: #444;
line-height: 30px;
margin-top: 6px;
}
.title {
width: 340px;
display: inline-block;
}
.time {
width: 340px;
display: inline-block;
}
.money {
width: 170px;
display: inline-block;
}
.coupon-radio {
display: inline-block;
width: 15px;
height: 15px;
margin-right: 6px;
background-image: url(/cart/radio-off.png);
display: inline-block;
vertical-align: middle;
position: relative;
top: -1px;
cursor: pointer;
&.on {
background-image: url(/cart/radio-check.png);
}
}
}
.yoho-coin-box {
line-height: 24px;
padding: 10px 30px;
background-color: #f0f0f0;
position: relative;
.grey {
color: #a9a9a9;
}
.red {
color: $red;
}
.outer-view {
width: 70%;
position: absolute;
right: 0;
top: -32px;
padding-right: 20px;
text-align: right;
.help-icon {
position: absolute;
right: 0;
top: 0;
cursor: pointer;
&:hover + .coin-tip-help {
display: block;
}
}
}
.help-icon {
position: absolute;
right: 0;
top: 0;
cursor: pointer;
&:hover + .coin-tip-help {
display: block;
}
}
.coin-tip-help {
width: 304px;
padding: 6px 10px;
line-height: 2;
border: 1px solid #000;
background-color: #fff;
text-align: left;
position: absolute;
top: 28px;
right: -8px;
display: none;
&:before {
content: '';
width: 12px;
height: 6px;
background-image: url('/cart/row.png');
display: block;
position: absolute;
top: -6px;
right: 10px;
}
> p:first-child {
font-weight: 700;
}
.rs-text {
color: #999;
}
}
.coin-main-view {
> * {
display: inline-block;
}
> label {
width: 76px;
height: 22px;
line-height: 22px;
display: inline-block;
border: 1px solid #000;
background-color: #fff;
text-align: center;
cursor: pointer;
float: right;
}
p:first-child {
margin-right: 40px;
}
.coin-cancel-btn {
color: #fff;
background-color: #000;
margin-left: 18px;
> span {
display: none;
}
}
}
}
.red-packet-box {
padding: 10px 10px;
background-color: #f0f0f0;
line-height: 24px;
.radio-btn {
margin-right: 0;
}
.sure-btn {
width: 78px;
float: right;
background-color: #000;
color: #fff;
text-align: center;
margin-right: 20px;
cursor: pointer;
}
}
.remark-box {
padding: 30px 20px 0;
background-color: #f0f0f0;
.note-text-box {
border: 1px solid #e0e0e0;
background-color: #fff;
overflow: hidden;
.tip-text {
padding: 10px;
color: #a9a9a9;
}
}
.note-text {
width: 888px;
height: 84px;
padding: 8px 10px;
font-size: 14px;
line-height: 1.5;
border: none;
resize: none;
background: none;
margin-top: -34px;
}
.has-text {
background-color: #fff;
}
.pp-area {
line-height: 50px;
padding-bottom: 4px;
> span {
color: #a9a9a9;
}
}
}
.balance-wrap {
font-size: 13px;
line-height: 2;
... ... @@ -645,17 +985,6 @@
position: absolute;
padding-left: 94px;
line-height: 1.5;
/* &:before {
content: '';
width: 16px;
height: 16px;
margin-right: 6px;
background: url('/cart/error-ico.png');
display: inline-block;
position: relative;
top: 4px;
}*/
}
.area-box {
... ...