Authored by 郭成尧

Merge branch 'feature/address' into 'release/6.3'

Feature/address



See merge request !1134
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 2
3 // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md'; 3 // doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md';
4 4
  5 +const _ = require('lodash');
  6 +
5 class AddressModel extends global.yoho.BaseModel { 7 class AddressModel extends global.yoho.BaseModel {
6 constructor(ctx) { 8 constructor(ctx) {
7 super(ctx); 9 super(ctx);
@@ -22,6 +24,11 @@ class AddressModel extends global.yoho.BaseModel { @@ -22,6 +24,11 @@ class AddressModel extends global.yoho.BaseModel {
22 cache: false 24 cache: false
23 } 25 }
24 }).then(result => { 26 }).then(result => {
  27 + // 在接口返回处统一编码
  28 + _.set(result, 'data', _.map(_.get(result, 'data', []), item => {
  29 + return Object.assign(item, {address_id: encodeURIComponent(item.address_id)});
  30 + }));
  31 +
25 return result; 32 return result;
26 }, () => { 33 }, () => {
27 return {code: 500, data: [], message: '地址获取失败'}; 34 return {code: 500, data: [], message: '地址获取失败'};
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <span class="tel">{{mobile}}</span> 6 <span class="tel">{{mobile}}</span>
7 <p class="address-info">{{area}} {{address}}</p> 7 <p class="address-info">{{area}} {{address}}</p>
8 <div class="action iconfont"> 8 <div class="action iconfont">
9 - <span class="edit" data-href="/home/addressAct?id={{address_id}}&refer=buynow&product_sku={{product_sku}}&buy_number={{buy_number}}">&#xe61e;</span> 9 + <span class="edit" data-href="/home/addressAct?id={{address_id}}&refer=buynow&product_sku={{../product_sku}}&buy_number={{../buy_number}}">&#xe61e;</span>
10 <span class="del" data-id="{{address_id}}">&#xe621;</span> 10 <span class="del" data-id="{{address_id}}">&#xe621;</span>
11 </div> 11 </div>
12 </div> 12 </div>
@@ -62,7 +62,7 @@ exports.addressJson = (req, res, next) => { @@ -62,7 +62,7 @@ exports.addressJson = (req, res, next) => {
62 */ 62 */
63 exports.addressAct = (req, res, next) => { 63 exports.addressAct = (req, res, next) => {
64 req.ctx(addressModel).address({ 64 req.ctx(addressModel).address({
65 - id: req.query.id ? decodeURIComponent(req.query.id) : null, 65 + id: req.query.id ? req.query.id : null,
66 uid: req.user.uid 66 uid: req.user.uid
67 }).then(result => { 67 }).then(result => {
68 let responseData = { 68 let responseData = {
@@ -54,7 +54,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -54,7 +54,7 @@ module.exports = class extends global.yoho.BaseModel {
54 return this.get({ 54 return this.get({
55 data: { 55 data: {
56 method: params.id ? 'app.address.update' : 'app.address.add', 56 method: params.id ? 'app.address.update' : 'app.address.add',
57 - id: params.id, 57 + id: decodeURIComponent(params.id),
58 address: params.address, 58 address: params.address,
59 area_code: params.area_code, 59 area_code: params.area_code,
60 consignee: params.consignee, 60 consignee: params.consignee,
@@ -76,7 +76,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -76,7 +76,7 @@ module.exports = class extends global.yoho.BaseModel {
76 data: { 76 data: {
77 method: 'app.address.setdefault', 77 method: 'app.address.setdefault',
78 uid: params.uid, 78 uid: params.uid,
79 - id: params.id 79 + id: decodeURIComponent(params.id)
80 } 80 }
81 }); 81 });
82 } 82 }
@@ -90,7 +90,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -90,7 +90,7 @@ module.exports = class extends global.yoho.BaseModel {
90 return this.get({ 90 return this.get({
91 data: { 91 data: {
92 method: 'app.address.del', 92 method: 'app.address.del',
93 - id: params.id, 93 + id: decodeURIComponent(params.id),
94 uid: params.uid 94 uid: params.uid
95 } 95 }
96 }); 96 });
@@ -106,47 +106,33 @@ module.exports = class extends global.yoho.BaseModel { @@ -106,47 +106,33 @@ module.exports = class extends global.yoho.BaseModel {
106 ]; 106 ];
107 107
108 if (params.id) { // 如果有 ID 是编辑地址页面 108 if (params.id) { // 如果有 ID 是编辑地址页面
  109 + params.id = decodeURIComponent(params.id);
109 apiList.push(this._getThrAddressData(params)); 110 apiList.push(this._getThrAddressData(params));
110 } 111 }
111 112
112 return api.all(apiList).then(result => { 113 return api.all(apiList).then(result => {
113 - let selfAddress = result[0]; 114 + let selfAddress = _.get(result, '[0].data', []);
  115 + let editAddress = {};
114 116
115 - if (selfAddress.data) {  
116 -  
117 - _.forEach(selfAddress.data, (value) => { 117 + _.forEach(selfAddress, (value) => {
118 if (value.area.length > 11) { 118 if (value.area.length > 11) {
119 value.showArea = value.area.substr(0, 5) + '...' + value.area.substr(-5); 119 value.showArea = value.area.substr(0, 5) + '...' + value.area.substr(-5);
120 } else { 120 } else {
121 value.showArea = value.area; 121 value.showArea = value.area;
122 } 122 }
123 - });  
124 -  
125 - /* 如果有 ID 是地址编辑页面 */  
126 - if (params.id) {  
127 - let returnResult = {  
128 - address: camelCase(_.find(selfAddress.data, o => {  
129 - return decodeURIComponent(o.address_id) === params.id;  
130 - })),  
131 - addressList: camelCase(result[1] ? result[1].data : []),  
132 - navTitle: '编辑地址'  
133 - };  
134 -  
135 - let area = _.get(returnResult, 'address.area', '');  
136 123
137 - if (area.length > 11) {  
138 - returnResult.address.area = area.substr(0, 5) + '...' + area.substr(-5); 124 + if (params.id && value.address_id === params.id) {
  125 + editAddress = value;
139 } 126 }
140 127
141 - return returnResult;  
142 - } else { 128 + value.address_id = encodeURIComponent(value.address_id);
  129 + });
  130 +
143 return { 131 return {
144 - address: camelCase(selfAddress.data),  
145 - addressList: camelCase(result[1] ? result[1].data : []),  
146 - navTitle: '添加地址' 132 + address: camelCase(params.id ? editAddress : selfAddress),
  133 + addressList: camelCase(_.get(result, '[1].data', [])),
  134 + navTitle: params.id ? '编辑地址' : '添加地址'
147 }; 135 };
148 - }  
149 - }  
150 }); 136 });
151 } 137 }
152 138
@@ -219,7 +205,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -219,7 +205,7 @@ module.exports = class extends global.yoho.BaseModel {
219 method: 'app.SpaceOrders.updateDeliveryAddress', 205 method: 'app.SpaceOrders.updateDeliveryAddress',
220 uid: uid, 206 uid: uid,
221 order_code: orderCode, 207 order_code: orderCode,
222 - address_id: addressId 208 + address_id: decodeURIComponent(addressId)
223 } 209 }
224 }).then((result) => { 210 }).then((result) => {
225 return result; 211 return result;