Authored by biao

update for change apply

@@ -71,7 +71,29 @@ const refundApply = (req, res, next) => { @@ -71,7 +71,29 @@ const refundApply = (req, res, next) => {
71 }; 71 };
72 72
73 const exchange = (req, res, next) => { 73 const exchange = (req, res, next) => {
74 - next(); 74 + const code = req.params.orderCode;
  75 + const uid = req.user.uid || '8050560';
  76 +
  77 + returns.getChangeGoodsList(code, uid).then(result => {
  78 + res.display('index', {
  79 + page: 'returns-change',
  80 + isMe: true,
  81 + content: Object.assign({
  82 + nav: mcHandler.getMeCrumb('我的退/换货'),
  83 + navigation: mcHandler.getSideMenu('我的退/换货'),
  84 + banner: 'http://placehold.it/{width}x{height}'
  85 + }, result)
  86 + });
  87 + }).catch(next);
  88 +};
  89 +
  90 +const getProductInfo = (req, res, next) => {
  91 + const productId = req.query.productId;
  92 + const productSkn = req.query.productSkn;
  93 +
  94 + returns.getProductInfo(productId, productSkn).then(result => {
  95 + res.json(result);
  96 + }).catch(next);
75 }; 97 };
76 98
77 module.exports = { 99 module.exports = {
@@ -79,5 +101,6 @@ module.exports = { @@ -79,5 +101,6 @@ module.exports = {
79 detail, 101 detail,
80 refund, 102 refund,
81 refundApply, 103 refundApply,
82 - exchange 104 + exchange,
  105 + getProductInfo
83 }; 106 };
@@ -34,9 +34,27 @@ const refundSubmitAsync = (orderCode, uid, goods, payment) => { @@ -34,9 +34,27 @@ const refundSubmitAsync = (orderCode, uid, goods, payment) => {
34 }); 34 });
35 }; 35 };
36 36
  37 +const getChangeGoodsListAsync = (orderCode, uid) => {
  38 + return api.get('', {
  39 + method: 'app.change.goodsList',
  40 + order_code: orderCode,
  41 + uid: uid
  42 + });
  43 +};
  44 +
  45 +const getProductInfoAsync = (productId, productSkn) => {
  46 + return api.get('', {
  47 + method: 'app.product.data',
  48 + product_id: productId,
  49 + product_skn: productSkn
  50 + });
  51 +};
  52 +
37 module.exports = { 53 module.exports = {
38 getOrderInfoAsync, 54 getOrderInfoAsync,
39 getRefundGoodsAsync, 55 getRefundGoodsAsync,
40 - refundSubmitAsync 56 + refundSubmitAsync,
  57 + getChangeGoodsListAsync,
  58 + getProductInfoAsync
41 }; 59 };
42 60
@@ -16,6 +16,20 @@ const helpers = global.yoho.helpers; @@ -16,6 +16,20 @@ const helpers = global.yoho.helpers;
16 16
17 const pageSize = 10; 17 const pageSize = 10;
18 18
  19 +const _reduceArrByProductSku = data => {
  20 + const d = [];
  21 +
  22 + d.push(data[0]);
  23 +
  24 + data.reduce((p, c) => { //eslint-disable-line
  25 + if (p && c && p.productSku !== c.productSku) {
  26 + d.push[c];
  27 + }
  28 + });
  29 +
  30 + return d;
  31 +};
  32 +
19 const getUserReturn = (uid, page) => { 33 const getUserReturn = (uid, page) => {
20 34
21 return api.get('', { 35 return api.get('', {
@@ -133,8 +147,52 @@ const saveRefund = (orderCode, uid, goods, payment) => { @@ -133,8 +147,52 @@ const saveRefund = (orderCode, uid, goods, payment) => {
133 }); 147 });
134 }; 148 };
135 149
  150 +const getProductInfo = (productId, productSkn) => {
  151 + return returnsAPI.getProductInfoAsync(productId, productSkn).then(result => {
  152 + if (result.code === 200) {
  153 + camelCase(result);
  154 + result.data.goodsList.forEach(good => {
  155 + good.colorImage = helpers.image(good.colorImage, 20, 20);
  156 + });
  157 + }
  158 + return result;
  159 + });
  160 +};
  161 +
  162 +const getChangeGoodsList = (orderCode, uid) => {
  163 + return returnsAPI.getChangeGoodsListAsync(orderCode, uid).then(result => {
  164 + const basicData = {
  165 + title: '申请退货'
  166 + };
  167 + let data;
  168 +
  169 + console.log(result);
  170 +
  171 + if (result && result.data) {
  172 + data = camelCase(result.data);
  173 +
  174 +
  175 + data.goodsList = _reduceArrByProductSku(data.goodsList);
  176 + data.hidePrice = true;
  177 +
  178 + data.goodsList.forEach(good => {
  179 + good.showCheckbox = true;
  180 + good.hidePrice = true;
  181 + good.buyNumber = good.num;
  182 + });
  183 + }
  184 +
  185 +
  186 + return {
  187 + returnsChange: Object.assign(basicData, data)
  188 + };
  189 + });
  190 +};
  191 +
136 module.exports = { 192 module.exports = {
137 getUserReturn, 193 getUserReturn,
138 getRefundGoodsData, 194 getRefundGoodsData,
139 - saveRefund 195 + saveRefund,
  196 + getChangeGoodsList,
  197 + getProductInfo
140 }; 198 };
@@ -32,6 +32,7 @@ router.get('/return/refund/:orderCode', returns.refund); @@ -32,6 +32,7 @@ router.get('/return/refund/:orderCode', returns.refund);
32 router.get('/return/exchange/:orderCode', returns.exchange); 32 router.get('/return/exchange/:orderCode', returns.exchange);
33 router.get('/return/:returnId', returns.detail); 33 router.get('/return/:returnId', returns.detail);
34 router.post('/return/refund/apply', returns.refundApply); 34 router.post('/return/refund/apply', returns.refundApply);
  35 +router.get('/return/getProductInfo', returns.getProductInfo);
35 36
36 // 个人中心首页/收货地址 37 // 个人中心首页/收货地址
37 router.get('/address', address.index); 38 router.get('/address', address.index);
@@ -41,6 +41,11 @@ @@ -41,6 +41,11 @@
41 {{> returns-list}} 41 {{> returns-list}}
42 {{/if}} 42 {{/if}}
43 43
  44 + {{!-- 发起换货申请 --}}
  45 + {{#if returnsChange}}
  46 + {{> returns-change}}
  47 + {{/if}}
  48 +
44 {{!-- 我的收藏 --}} 49 {{!-- 我的收藏 --}}
45 {{#if collection}} 50 {{#if collection}}
46 {{> collection}} 51 {{> collection}}
  1 +<div class="good-info {{#if @last}}last{{/if}}">
  2 + <img src="{{image goodsImage 65 90}}">
  3 + <div class="detail">
  4 + <p class="with-bottom-space">{{productName}}</p>
  5 + <span class="with-space">颜色:{{colorName}}</span>
  6 + <span>尺码:
  7 + <span class="bold">{{sizeName}}</span>
  8 + </span>
  9 + <p class="bold buy-number">{{> icon/error-round}}{{buyNumber}}</p>
  10 + </div>
  11 +</div>
1 <div class="goods-container special-border {{#if hidePrice}}no-price{{/if}}"> 1 <div class="goods-container special-border {{#if hidePrice}}no-price{{/if}}">
2 {{#orderGoods}} 2 {{#orderGoods}}
3 - <div class="good-info {{#if @last}}last{{/if}}">  
4 - <img src="{{image goodsImage 65 90}}">  
5 - <div class="detail">  
6 - <p class="with-bottom-space">{{productName}}</p>  
7 - <span class="with-space">颜色:{{colorName}}</span>  
8 - <span>尺码:  
9 - <span class="bold">{{sizeName}}</span>  
10 - </span>  
11 - <p class="bold buy-number">{{> icon/error-round}}{{buyNumber}}</p>  
12 - </div>  
13 - </div> 3 + {{> order/good-info}}
14 {{#unless hidePrice}} 4 {{#unless hidePrice}}
15 <div class="sub-column right-border bold"> 5 <div class="sub-column right-border bold">
16 <p class="{{#if @last}}last{{/if}}">¥{{goodsPrice}}</p> 6 <p class="{{#if @last}}last{{/if}}">¥{{goodsPrice}}</p>
17 </div> 7 </div>
18 - {{/unless}}  
19 <div class="sub-column right-border special-column bold"> 8 <div class="sub-column right-border special-column bold">
20 <p class="bold">{{buyNumber}}</p> 9 <p class="bold">{{buyNumber}}</p>
21 </div> 10 </div>
22 <div class="sub-column special-column bold"> 11 <div class="sub-column special-column bold">
23 <p class="bold">¥{{goodsAmount}}</p> 12 <p class="bold">¥{{goodsAmount}}</p>
24 </div> 13 </div>
  14 + {{/unless}}
25 {{/orderGoods}} 15 {{/orderGoods}}
26 </div> 16 </div>
@@ -28,7 +28,9 @@ @@ -28,7 +28,9 @@
28 {{#if showEditOption}} 28 {{#if showEditOption}}
29 <p class="subtext">评价晒单</p> 29 <p class="subtext">评价晒单</p>
30 <p class="subtext">申请退货</p> 30 <p class="subtext">申请退货</p>
31 - <p class="subtext">申请换货</p> 31 + <a href="/return/exchange?code={{orderCode}}&id={{productId}}&skn={{productSkn}}">
  32 + <p class="subtext">申请换货</p>
  33 + </a>
32 <p class="subtext delete">删除订单</p> 34 <p class="subtext delete">删除订单</p>
33 {{/if}} 35 {{/if}}
34 {{#if showGetBtn}} 36 {{#if showGetBtn}}
  1 +<div class="return-wrap user-order change">
  2 + {{#returnsChange}}
  3 + {{> common/subtitle}}
  4 + <div class="order">
  5 + <div class="table returns">
  6 + <ul class="header">
  7 + <li class="info">商品信息</li>
  8 + <li class="change-reason">换货原因</li>
  9 + <li class="change-num">换货数量</li>
  10 + </ul>
  11 + {{#goodsList}}
  12 + <div class="table-body">
  13 + <div class="goods-container no-price" data-id="{{productId}}" data-skn="{{productSkn}}">
  14 + {{# showCheckbox}}
  15 + {{> icon/checkbox}}
  16 + <!--
  17 + <span class="iconfont checkbox {{#if checked}}checked{{/if}}">{{#if checked}}&#xe602;{{^}}&#xe601;{{/if}}</span>
  18 + -->
  19 + {{/ showCheckbox}}
  20 + {{> order/good-info}}
  21 + <div class="sub-column">
  22 + 退货原因
  23 + </div>
  24 + <div class="sub-column">
  25 + 数量
  26 + </div>
  27 + </div>
  28 + </div>
  29 + <div class="form">
  30 + <div class="group color">
  31 + <span class="title">
  32 + <span class="artirisk">*</span>
  33 + 换货Color: <span class="color-text" data-color={{colorId}}>{{colorName}}</span>
  34 + </span>
  35 + </div>
  36 + <div class="group size">
  37 + <span class="title">
  38 + <span class="artirisk">*</span>
  39 + 换货Size: <span class="size-text" data-size="{{sizeId}}">{{sizeName}}</span>
  40 + </span>
  41 + </div>
  42 + </div>
  43 + {{/goodsList}}
  44 + </div>
  45 + </div>
  46 + {{/returnsChange}}
  47 +</div>
@@ -19,7 +19,7 @@ module.exports = { @@ -19,7 +19,7 @@ module.exports = {
19 }, 19 },
20 cookieDomain: 'yohoblk.com', 20 cookieDomain: 'yohoblk.com',
21 domains: { 21 domains: {
22 - api: 'http://testapi.yoho.cn:28078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078 22 + api: 'http://devapi.yoho.cn:58078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
23 service: 'http://testservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077 23 service: 'http://testservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
24 search: 'http://192.168.102.216:8080/yohosearch/' 24 search: 'http://192.168.102.216:8080/yohosearch/'
25 }, 25 },
  1 +var colorTpl = require('../../tpl/me/color-list.hbs');
  2 +var sizeTpl = require('../../tpl/me/size-list.hbs');
  3 +
  4 +// var scope = {
  5 +// 1: {
  6 +// min: true,
  7 +// do: function() {
  8 +// console.log('min');
  9 +// }
  10 +// }
  11 +// }
  12 +
  13 +function renderList(data) {
  14 + var cTpl;
  15 + var sTpl;
  16 + var $c = $('.group.color');
  17 + var $s = $('.group.size');
  18 +
  19 + if (data) {
  20 + cTpl = colorTpl(data);
  21 + sTpl = sizeTpl(data);
  22 + $c.append(cTpl);
  23 + $s.append(sTpl);
  24 + }
  25 +}
  26 +
  27 +function bindColorEvent() {
  28 + $('.color-list img').on('click', function() {
  29 + var $this = $(this);
  30 + var $sizeList = $('.size-list');
  31 + var index = $this.data('index');
  32 + var colorId = $this.data('color');
  33 + var colorText = $this.attr('alt');
  34 + var $c = $('.group.color .color-text');
  35 +
  36 + $c.text(colorText);
  37 + $c.attr('data-color', colorId);
  38 +
  39 +
  40 + $sizeList.removeClass('hide');
  41 + $sizeList.addClass('hide');
  42 +
  43 + $sizeList.eq(index).removeClass('hide');
  44 + });
  45 +}
  46 +
  47 +function initSizeId() {
  48 + var s = $('.size-list:not("hide")').find('span').eq(0).data('size');
  49 +
  50 + $('.group.size .size-text').eq(0).attr('data-size', s);
  51 +}
  52 +
  53 +function bindSizeEvent() {
  54 + $('.size-list span').on('click', function() {
  55 + var $this = $(this);
  56 + var s = $this.text();
  57 + var id = $this.data('size');
  58 + var $s = $('.group.size .size-text');
  59 +
  60 + $s.text(s);
  61 + $s.attr('data-size', id);
  62 + });
  63 +}
  64 +
  65 +// function bindNumberEvent() {
  66 +// $('.number .minus').on('click', function() {
  67 +// var val = $('.number .value').text();
  68 +//
  69 +// if (scope[val].min) {
  70 +// scope[val].do();
  71 +// }
  72 +// });
  73 +// }
  74 +
  75 +function getProductInfo() {
  76 + var $el = $('.goods-container');
  77 + var id = $el.data('id');
  78 + var skn = $el.data('skn');
  79 +
  80 + if (id && skn) {
  81 + $.ajax({
  82 + url: '/me/return/getProductInfo',
  83 + data: {
  84 + productId: id,
  85 + productSkn: skn
  86 + }
  87 + }).done(function(result) {
  88 + console.log(result);
  89 + if (result.code === 200) {
  90 + renderList(result.data);
  91 + initSizeId();
  92 + bindColorEvent();
  93 + bindSizeEvent();
  94 + }
  95 + });
  96 + }
  97 +}
  98 +
  99 +getProductInfo();
1 .return-wrap { 1 .return-wrap {
2 .table { 2 .table {
3 width: 100%; 3 width: 100%;
  4 + max-width: 990px;
4 5
5 .header { 6 .header {
6 .info { 7 .info {
@@ -9,12 +10,26 @@ @@ -9,12 +10,26 @@
9 } 10 }
10 11
11 .st, 12 .st,
12 - .op { 13 + .op,
  14 + .change-reason,
  15 + .change-num {
13 width: 206px; 16 width: 206px;
14 } 17 }
15 } 18 }
16 19
  20 + &.returns {
  21 + .good-info {
  22 + border: none;
  23 +
  24 + .detail {
  25 + width: 380px !important;
  26 + }
  27 + }
  28 + }
  29 +
17 .goods-container { 30 .goods-container {
  31 + width: 990px;
  32 +
18 .for-return { 33 .for-return {
19 display: block; 34 display: block;
20 } 35 }
@@ -23,24 +38,36 @@ @@ -23,24 +38,36 @@
23 .no-price { 38 .no-price {
24 .good-info { 39 .good-info {
25 border-right: none; 40 border-right: none;
26 - }  
27 41
28 - .good-info {  
29 .detail { 42 .detail {
30 width: 408px; 43 width: 408px;
31 } 44 }
32 } 45 }
33 } 46 }
34 47
  48 + .sub-column {
  49 + width: 204px !important;
  50 + }
  51 +
  52 + .checkbox-column {
  53 + display: table-cell;
  54 + width: 100px;
  55 + }
  56 +
35 .common-column { 57 .common-column {
36 width: 208px; 58 width: 208px;
37 59
38 .refund-status { 60 .refund-status {
39 margin-bottom: 10px; 61 margin-bottom: 10px;
40 } 62 }
  63 +
41 .refund-type { 64 .refund-type {
42 position: static; 65 position: static;
43 } 66 }
  67 +
  68 + &.no-border {
  69 + width: 204px !important;
  70 + }
44 } 71 }
45 } 72 }
46 73
  1 +<div class="color-list">
  2 + {{#goodsList}}
  3 + <img src="{{colorImage}}" alt="{{colorName}}" data-index="{{@index}}" data-color={{colorId}}>
  4 + {{/goodsList}}
  5 +</div>
  6 +
  1 +<div>
  2 + {{#goodsList}}
  3 + <div class="{{#unless @first}}hide{{/unless}} size-list" data-index="{{@index}}">
  4 + {{#sizeList}}
  5 + <span data-size="{{sizeId}}">{{sizeName}}</span>
  6 + {{/sizeList}}
  7 + </div>
  8 + {{/goodsList}}
  9 +</div>