Authored by 毕凯

下单流程 增加优惠券页面

  1 +var $ = require('jquery'),
  2 + Handlebars = require('yoho.handlebars'),
  3 + ellipsis = require('mlellipsis'),
  4 + loading = require('../plugin/loading'),
  5 + tip = require('../plugin/tip');
  6 +
  7 +var page = 1,
  8 + canGetCoupon = true,
  9 + isGetData;
  10 +
  11 +var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()),
  12 + conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html());
  13 +
  14 +ellipsis.init();
  15 +
  16 +function getCouponDate() {
  17 + if (!canGetCoupon) {
  18 + return;
  19 + }
  20 +
  21 + if (isGetData) {
  22 + return;
  23 + }
  24 +
  25 + loading.showLoadingMask();
  26 + page += 1;
  27 + isGetData = true;
  28 +
  29 + $.ajax({
  30 + type: 'POST',
  31 + url: '/home/couponData',
  32 + dataType: 'html',
  33 + data: {
  34 + statuss: status,
  35 + page: page
  36 + }
  37 + }).then(function(coupons) {
  38 + var notAvailableCoupons = [];
  39 +
  40 + // 后端需要返回一个 coupons 列表,如下
  41 + // notAvailable 表示不可用的优惠券
  42 + coupons = [{
  43 + money: '99',
  44 + coupon_name: '满XX-减去吴悠右腿有益于有2222',
  45 + couponValidity: '20150129-20150430',
  46 + coupon_id: '22222'
  47 + }, {
  48 + money: '99',
  49 + coupon_name: '满XX-减去吴悠右腿有益于有2222',
  50 + couponValidity: '20150129-20150430',
  51 + coupon_id: '2222233'
  52 + }, {
  53 + money: '99',
  54 + coupon_name: 'NONO满XX-减去吴悠右腿有益于有2222',
  55 + couponValidity: '20150129-20150430',
  56 + coupon_id: '2222233',
  57 + notAvailable: 1
  58 + }];
  59 +
  60 + // coupons 是个列表,如果不是列表,可能是服务器错误,这次翻页加载不算
  61 + if (!$.isArray(coupons)) {
  62 + page--;
  63 + return;
  64 + }
  65 +
  66 + // 每页10张,当不足10张时,说明已经加载完
  67 + if (coupons.length < 10) {
  68 + canGetCoupon = false;
  69 + }
  70 +
  71 + // 第一页张数为 0 ,显示优惠券为空
  72 + if (!coupons.length && page === 2) {
  73 + $('.select-coupon-page').html($('#tmpl-no-coupon').html());
  74 + return;
  75 + }
  76 +
  77 + // 把不可用的优惠券分离出来
  78 + $.each(coupons, function(i, coupon) {
  79 + if (coupon.notAvailable) {
  80 + notAvailableCoupons.push(coupon);
  81 + }
  82 + })
  83 +
  84 + if (notAvailableCoupons.length) {
  85 + $('.not-avaliable-coupon-line').show();
  86 + }
  87 + $('#coupon-list').append(conponTmpl({
  88 + coupons: coupons
  89 + }));
  90 + $('#coupon-list-not').append(conponNotAvaliableTmpl({
  91 + notAvailableCoupons: notAvailableCoupons
  92 + }));
  93 + window.rePosFooter();
  94 + }).fail(function() {
  95 + page -= 1;
  96 + tip.show('加载优惠券失败');
  97 + }).always(function() {
  98 + isGetData = false;
  99 + loading.hideLoadingMask();
  100 + });
  101 +}
  102 +
  103 +getCouponDate();
  104 +
  105 +$(window).scroll(function() {
  106 + if ($(window).scrollTop() + $(window).height() > $('body').height() * 0.9) {
  107 + getCouponDate();
  108 + }
  109 +});
1 -.employ{ 1 +.my-coupon-page {
  2 + .employ{
2 width: 100%; 3 width: 100%;
3 height: 90rem / $pxConvertRem; 4 height: 90rem / $pxConvertRem;
4 5
@@ -22,16 +23,17 @@ @@ -22,16 +23,17 @@
22 color: #444444; 23 color: #444444;
23 } 24 }
24 } 25 }
25 -}  
26 -#employ{ 26 + }
  27 + .coupon-list{
27 width:100%; 28 width:100%;
28 height: auto; 29 height: auto;
29 overflow:hidden; 30 overflow:hidden;
30 .employ-main{ 31 .employ-main{
  32 + display: block;
31 width: 90.625%; 33 width: 90.625%;
32 height: 180rem / $pxConvertRem; 34 height: 180rem / $pxConvertRem;
33 overflow: hidden; 35 overflow: hidden;
34 - margin: 20rem / $pxConvertRem auto; 36 + margin: 30rem / $pxConvertRem auto;
35 background-image: image-url('me/employ/employ.jpg'); 37 background-image: image-url('me/employ/employ.jpg');
36 background-position: top center; 38 background-position: top center;
37 background-repeat:no-repeat; 39 background-repeat:no-repeat;
@@ -53,7 +55,7 @@ @@ -53,7 +55,7 @@
53 float: left; 55 float: left;
54 &:first-of-type{ 56 &:first-of-type{
55 margin-top: 0.75rem; 57 margin-top: 0.75rem;
56 - font-size: 18px; 58 + font-size: 16px;
57 height: auto; 59 height: auto;
58 min-height: 42px; 60 min-height: 42px;
59 display: -webkit-box; 61 display: -webkit-box;
@@ -115,7 +117,8 @@ @@ -115,7 +117,8 @@
115 } 117 }
116 } 118 }
117 119
118 -}  
119 -.none{ 120 + }
  121 + .none{
120 display: none; 122 display: none;
  123 + }
121 } 124 }
1 -@import "good", "chose-panel", "gift-advance-good", "order-ensure"; 1 +@import "good", "chose-panel", "gift-advance-good", "order-ensure", "select-coupon";
2 2
3 3
4 .icon-checkbox:before { content: "\e61c"; } 4 .icon-checkbox:before { content: "\e61c"; }
@@ -85,6 +85,10 @@ @@ -85,6 +85,10 @@
85 height: 90rem / $pxConvertRem; 85 height: 90rem / $pxConvertRem;
86 line-height: 90rem / $pxConvertRem; 86 line-height: 90rem / $pxConvertRem;
87 border-bottom: 1px solid #f7f7f7; 87 border-bottom: 1px solid #f7f7f7;
  88 +
  89 + a {
  90 + display: block;
  91 + }
88 } 92 }
89 93
90 .coupon-count { 94 .coupon-count {
  1 +.select-coupon-page {
  2 + margin-top: pxToRem(30px);
  3 + margin-bottom: pxToRem(30px);
  4 +
  5 + .coupon-list {
  6 + .employ-main:first-child {
  7 + margin-top: 0;
  8 + }
  9 + .employ-main:last-child {
  10 + margin-bottom: 0;
  11 + }
  12 + }
  13 +
  14 + %line {
  15 + content: '';
  16 + position: absolute;
  17 + top: 50%;
  18 + border-top: 1px solid #b0b0b0;
  19 + width: pxToRem(120px);
  20 + height: 0;
  21 + }
  22 +
  23 + .not-avaliable-coupon-line {
  24 + position: relative;
  25 + margin-top: pxToRem(30px);
  26 + margin-bottom: pxToRem(30px);
  27 + font-size: pxToRem(14px);
  28 + line-height: 2;
  29 + color: #b0b0b0;
  30 + text-align: center;
  31 +
  32 + &:before {
  33 + @extend %line;
  34 + left: pxToRem(60px);
  35 + }
  36 +
  37 + &:after {
  38 + @extend %line;
  39 + right: pxToRem(60px);
  40 + }
  41 + }
  42 +
  43 + .not-avaliable {
  44 + -webkit-filter: grayscale(100%);
  45 + }
  46 +}
1 {{> layout/header}} 1 {{> layout/header}}
2 -<div class="yoho-page"> 2 +<div class="yoho-page my-coupon-page">
3 <div class="employ"> 3 <div class="employ">
4 <span class="active">未使用</span> 4 <span class="active">未使用</span>
5 <span>已使用</span> 5 <span>已使用</span>
6 </div> 6 </div>
7 - <div id="employ"></div> 7 + <div id="employ" class="coupon-list"></div>
8 </div> 8 </div>
9 {{> layout/footer}} 9 {{> layout/footer}}
@@ -43,7 +43,8 @@ @@ -43,7 +43,8 @@
43 <ul class="sale-invoice"> 43 <ul class="sale-invoice">
44 {{# coupon}} 44 {{# coupon}}
45 <li class="coupon"> 45 <li class="coupon">
46 - <a href="{{url}}"> 46 + <a href="/shoppingCart/selectCoupon">
  47 + <!-- <a href="{{url}}"> -->
47 <span class="title">优惠券</span> 48 <span class="title">优惠券</span>
48 {{#if count}} 49 {{#if count}}
49 <span class="coupon-count"> 50 <span class="coupon-count">
  1 +{{> layout/header}}
  2 +<div class="yoho-page select-coupon-page my-coupon-page">
  3 + <div id="coupon-list" class="coupon-list"></div>
  4 + <div class="not-avaliable-coupon-line hide">不可使用的优惠券</div>
  5 + <div id="coupon-list-not" class="coupon-list"></div>
  6 +</div>
  7 +<script id="tmpl-coupon" type="text/tmpl">
  8 +\{{#coupons}}
  9 + \{{^ notAvailable}}
  10 + <a class="employ-main" href="/shoppingCart/orderEnsure?coupon_id={{ coupon_id}}">
  11 + <span>\{{ money}}</span>
  12 + <p class="coupon-name">\{{ coupon_name}}</p>
  13 + <p>有效期:\{{ couponValidity}}</p>
  14 + </a>
  15 + \{{/ notAvailable}}
  16 +\{{/coupons}}
  17 +</script>
  18 +<script id="tmpl-coupon-not-avaliable" type="text/tmpl">
  19 +\{{# notAvailableCoupons}}
  20 + <div class="employ-main not-avaliable">
  21 + <span>\{{ money}}</span>
  22 + <p class="coupon-name">\{{ coupon_name}}</p>
  23 + <p>有效期:\{{ couponValidity}}</p>
  24 + </div>
  25 +\{{/ notAvailableCoupons}}
  26 +</script>
  27 +<script id="tmpl-no-coupon" type="text/tmpl">
  28 +<div class="coupon-list">
  29 + <div class="null">
  30 + <i></i>
  31 + <p>您还没有优惠券!</p>
  32 + </div>
  33 +</div>
  34 +</script>
  35 +{{> layout/footer}}
@@ -218,6 +218,11 @@ @@ -218,6 +218,11 @@
218 seajs.use('js/shopping-cart/order-ensure'); 218 seajs.use('js/shopping-cart/order-ensure');
219 </script> 219 </script>
220 {{/if}} 220 {{/if}}
  221 +{{#if selectCouponPage}}
  222 +<script>
  223 + seajs.use('js/shopping-cart/select-coupon');
  224 +</script>
  225 +{{/if}}
221 {{!-- 个人中心 --}} 226 {{!-- 个人中心 --}}
222 {{#if myIndexPage}} 227 {{#if myIndexPage}}
223 <script> 228 <script>
@@ -218,6 +218,10 @@ class ShoppingCartController extends AbstractAction @@ -218,6 +218,10 @@ class ShoppingCartController extends AbstractAction
218 $this->_view->display('order-ensure', $data); 218 $this->_view->display('order-ensure', $data);
219 } 219 }
220 220
  221 + /**
  222 + * 下单流程 选择地址
  223 + */
  224 +
221 public function selectAddressAction() { 225 public function selectAddressAction() {
222 // 设置网站标题 226 // 设置网站标题
223 $this->setTitle('选择地址'); 227 $this->setTitle('选择地址');
@@ -235,6 +239,26 @@ class ShoppingCartController extends AbstractAction @@ -235,6 +239,26 @@ class ShoppingCartController extends AbstractAction
235 } 239 }
236 240
237 /** 241 /**
  242 + * 下单流程 选择优惠券
  243 + */
  244 +
  245 + public function selectCouponAction() {
  246 + // 设置网站标题
  247 + $this->setTitle('选择优惠券');
  248 + $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure'));
  249 +
  250 + $uid = $this->_uid;
  251 + $address = UserModel::getAddressData($uid);
  252 +
  253 + $this->_view->display('select-coupon', array(
  254 + 'selectCouponPage' => true,
  255 + 'pageFooter' => true,
  256 + 'address' => $address
  257 + ));
  258 +
  259 + }
  260 +
  261 + /**
238 * 读取chose-panel内容 262 * 读取chose-panel内容
239 */ 263 */
240 public function tplAction() 264 public function tplAction()