Authored by yyq

结算

... ... @@ -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
};
... ...
... ... @@ -23,6 +23,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,7 @@
<!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>
Created by FontForge 20120731 at Thu Dec 15 10:53:04 2016
Created by FontForge 20120731 at Fri Dec 30 17:59:57 2016
By admin
</metadata>
<defs>
... ... @@ -52,6 +52,8 @@ d="M384 640v-513l321 257z" />
d="M286 509l-46 -45l272 -272l272 272l-46 45l-226 -226z" />
<glyph glyph-name="chevron-right" unicode="&#xe60c;"
d="M387 158l45 -46l272 272l-272 272l-45 -46l226 -226z" />
<glyph glyph-name="shoucang" unicode="&#xe641;"
d="M896 294q66 69 66 166.5t-66 166.5q-68 71 -164 69q-37 -1 -91.5 -29.5t-90.5 -57.5l-37 -28q-6 4 -15.5 12t-38.5 28t-55.5 35t-59 27.5t-56.5 12.5q-93 0 -159 -69t-66 -166.5t66 -166.5l383 -399z" />
<glyph glyph-name="duihao" unicode="&#xe605;"
d="M903 577l-68 69l-388 -388l-231 230l-68 -68l299 -298l65 65v0z" />
<glyph glyph-name="tongzhi" unicode="&#xe63f;"
... ... @@ -103,6 +105,9 @@ q5 37 20 66t39 49t55 31q31 10 66 10q33 0 63 -9.5t53 -28.5t36 -46.5t13 -64.5q0 -2
q-12 0 -23.5 4.5t-20.5 12.5q-8 7 -13 18t-5 23z" />
<glyph glyph-name="add" unicode="&#xe644;"
d="M960 262h-410v-410h-76v410h-410v76h410v410h76v-410h410v-76z" />
<glyph glyph-name="search1" unicode="&#xe640;"
d="M968 47l-163 164q69 108 69 234q0 119 -57.5 219t-157 158.5t-216 58.5t-216 -58.5t-157 -158.5t-57.5 -218.5t57.5 -219t157 -158.5t216.5 -58q124 0 231 69l163 -164q27 -28 65 -28t65 27.5t27 66t-27 66.5zM443.5 134q-127.5 0 -217.5 91.5t-90 220t90 219.5t217.5 91
t217.5 -91t90 -219.5t-90 -220t-217.5 -91.5z" />
<glyph glyph-name="xiangxia" unicode="&#xe61d;"
d="M888 620q12 12 28.5 12t28.5 -12v0q12 -12 12 -28.5t-12 -28.5l-406 -405q-12 -12 -28.5 -12t-27.5 12v0q-12 11 -12 27.5t12 28.5zM539 214q11 -12 11 -28.5t-11 -27.5v0q-12 -12 -28.5 -12t-28.5 12l-406 405q-11 12 -11 28.5t11 28.5v0q12 12 28.5 12t28.5 -12z
M539 214z" />
... ... @@ -124,6 +129,9 @@ d="M569 607q-28 66 -74 108.5t-95 56.5t-100 2.5t-91.5 -45t-66 -94t-26.5 -137.5q0
q0 76 -26.5 136t-67 92t-92 42.5t-101 -4t-94.5 -56t-72 -104.5z" />
<glyph glyph-name="logincheckbutton1" unicode="&#xe616;"
d="M877 896h-730q-61 0 -104 -43t-43 -104v-730q0 -61 43 -104t104 -43h730q61 0 104 43t43 104v730q0 61 -43 104t-104 43zM939 19q0 -26 -18 -44t-44 -18h-730q-26 0 -44 18t-18 44v730q0 26 18 44t44 18h730q26 0 44 -18t18 -44v-730z" />
<glyph glyph-name="like" unicode="&#xe642;"
d="M703 695q-113 0 -191 -81q-79 81 -191 81t-191 -79t-79 -190q0 -31 6.5 -59.5t20.5 -56t23 -42t26 -39.5q42 -60 127.5 -138t142 -120.5t71.5 -51.5q21 -14 44 -14q25 0 44 14q10 7 30.5 22t66 51t87 72t86 81.5t71.5 83.5q17 25 26 39.5t23 42t20.5 56t6.5 59.5
q0 111 -79 190t-191 79z" />
<glyph glyph-name="aaa" unicode="&#xe601;"
d="M505 337l2 -2q2 -1 3.5 -1t3.5 1l430 364q2 2 1 5.5t-5 3.5h-435h-424q-4 0 -5 -3.5t1 -5.5zM72 669q-3 2 -6 0.5t-3 -4.5v-584q0 -4 3.5 -5t5.5 1l288 346zM953 669.5q-3 1.5 -5 -0.5l-288 -246l287 -346q3 -2 6 -1t3 5v584q0 3 -3 4.5zM641 406l-131 -111l-5 5
l-125 103l-275 -328q-2 -3 -1 -6t5 -3h396h407q4 0 5 3t-1 6z" />
... ... @@ -222,6 +230,11 @@ t-34 14t-14 34t14 34l192 191l-192 192q-14 14 -14 34t14 34t34 14t34 -14l192 -192l
d="M611 55h-39q-10 0 -10 -9q0 -21 -14.5 -36t-35.5 -15t-35.5 15t-14.5 36q0 9 -10 9h-40q-9 0 -9 -9q0 -45 32.5 -77t76.5 -32t76.5 32t32.5 77q0 9 -10 9v0zM920 105q0 6 -3 11q-6 48 -31.5 89t-65.5 69v170q0 96 -55 175t-145 113q-3 42 -34.5 70.5t-73.5 28.5
t-73.5 -28.5t-35.5 -70.5q-89 -34 -144 -113t-55 -175v-170q-40 -28 -65.5 -69t-31.5 -89q-4 -8 -2 -16q-1 -7 -1 -15q0 -9 10 -9h796q10 0 10 9q0 7 -1 15q1 3 1 5v0zM569 686q20 -5 39 -12q69 -29 111 -92.5t42 -137.5v-198q0 -6 5 -9q66 -33 87 -102h-682q21 70 87 102
q5 3 5 9v198q0 85 54 153.5t137 88.5q8 2 8 9v27q0 21 15 35.5t35 14.5t35 -14.5t15 -35.5v-27q0 -7 7 -9v0zM569 686z" />
<glyph glyph-name="jian" unicode="&#xe643;"
d="M512 832q-91 0 -174 -35.5t-143 -95.5t-95 -143t-35 -174t35 -174t95 -142.5t143 -95t174 -35.5t174 35.5t143 95t95.5 142.5t35.5 174t-35.5 174t-95.5 143t-143 95.5t-174 35.5v0zM753 350h-206v0h-69v0h-207v69h207v0v0h69h206v-69v0zM753 350z" />
<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" />
<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
... ... @@ -231,5 +244,14 @@ d="M562 224h109v-111h-109v111zM889 224h109v-111h-109v111zM562 113h109v-110h-109v
h222v-111h-222v111zM889 334h109v-111h-109v111zM780 113h109v-111h-109v111zM562 2h218v-110h-218v110zM889 2h109v-110h-109v110z" />
<glyph glyph-name="subtract" unicode="&#xe63c;"
d="M928 418h-832q-13 0 -22.5 -9.5t-9.5 -23t9.5 -22.5t22.5 -9h832q13 0 22.5 9t9.5 22.5t-9.5 23t-22.5 9.5z" />
<glyph glyph-name="shiliangzhinengduixiang" unicode="&#xe6ba;"
d="M875 747q-99 98 -231 133t-263.5 0t-229.5 -133q-98 -99 -133 -231t0 -263.5t133 -229.5q73 -74 167 -112.5t194 -38.5q101 0 195 38t168 111q73 74 111 170t38 193t-38 193t-111 170zM810 86q-60 -61 -139.5 -92.5t-159.5 -31.5t-159.5 31.5t-140.5 92.5
q-80 81 -108 189.5t1 217t110 189.5q61 61 138 93t160 32t160 -32t138 -93q81 -81 110 -189.5t0 -217t-110 -189.5zM786 595l-485 -485q67 -52 149.5 -67t164 10t142.5 86q93 93 101 224t-72 232zM723 658q-90 71 -211 71q-69 0 -132.5 -26t-112.5 -76q-61 -62 -86 -143
t-10 -163.5t67 -150.5z" />
<glyph glyph-name="xingzhuangkaobei" unicode="&#xe6bb;"
d="M947 179q31 0 54 -23t23 -53.5t-23 -53.5t-54 -23h-51q31 0 54 -23t23 -54t-23 -54t-54 -23h-563q-31 0 -54 23t-23 54v461q0 20 5 30q8 20 28.5 33t43.5 13q128 96 128 205q0 71 0.5 99.5t5.5 58.5t15.5 38.5t29.5 8.5q21 0 46 -11t50 -33.5t41.5 -64.5t16.5 -96
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" />
</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

48.9 KB | W: | H:

49.2 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -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 {
... ...