Authored by 郭成尧

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

Feature/address



See merge request !1134
... ... @@ -2,6 +2,8 @@
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/个人中心/地址管理.md';
const _ = require('lodash');
class AddressModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
... ... @@ -22,6 +24,11 @@ class AddressModel extends global.yoho.BaseModel {
cache: false
}
}).then(result => {
// 在接口返回处统一编码
_.set(result, 'data', _.map(_.get(result, 'data', []), item => {
return Object.assign(item, {address_id: encodeURIComponent(item.address_id)});
}));
return result;
}, () => {
return {code: 500, data: [], message: '地址获取失败'};
... ...
... ... @@ -6,7 +6,7 @@
<span class="tel">{{mobile}}</span>
<p class="address-info">{{area}} {{address}}</p>
<div class="action iconfont">
<span class="edit" data-href="/home/addressAct?id={{address_id}}&refer=buynow&product_sku={{product_sku}}&buy_number={{buy_number}}">&#xe61e;</span>
<span class="edit" data-href="/home/addressAct?id={{address_id}}&refer=buynow&product_sku={{../product_sku}}&buy_number={{../buy_number}}">&#xe61e;</span>
<span class="del" data-id="{{address_id}}">&#xe621;</span>
</div>
</div>
... ...
... ... @@ -62,7 +62,7 @@ exports.addressJson = (req, res, next) => {
*/
exports.addressAct = (req, res, next) => {
req.ctx(addressModel).address({
id: req.query.id ? decodeURIComponent(req.query.id) : null,
id: req.query.id ? req.query.id : null,
uid: req.user.uid
}).then(result => {
let responseData = {
... ...
... ... @@ -54,7 +54,7 @@ module.exports = class extends global.yoho.BaseModel {
return this.get({
data: {
method: params.id ? 'app.address.update' : 'app.address.add',
id: params.id,
id: decodeURIComponent(params.id),
address: params.address,
area_code: params.area_code,
consignee: params.consignee,
... ... @@ -76,7 +76,7 @@ module.exports = class extends global.yoho.BaseModel {
data: {
method: 'app.address.setdefault',
uid: params.uid,
id: params.id
id: decodeURIComponent(params.id)
}
});
}
... ... @@ -90,7 +90,7 @@ module.exports = class extends global.yoho.BaseModel {
return this.get({
data: {
method: 'app.address.del',
id: params.id,
id: decodeURIComponent(params.id),
uid: params.uid
}
});
... ... @@ -106,47 +106,33 @@ module.exports = class extends global.yoho.BaseModel {
];
if (params.id) { // 如果有 ID 是编辑地址页面
params.id = decodeURIComponent(params.id);
apiList.push(this._getThrAddressData(params));
}
return api.all(apiList).then(result => {
let selfAddress = result[0];
let selfAddress = _.get(result, '[0].data', []);
let editAddress = {};
if (selfAddress.data) {
_.forEach(selfAddress.data, (value) => {
_.forEach(selfAddress, (value) => {
if (value.area.length > 11) {
value.showArea = value.area.substr(0, 5) + '...' + value.area.substr(-5);
} else {
value.showArea = value.area;
}
});
/* 如果有 ID 是地址编辑页面 */
if (params.id) {
let returnResult = {
address: camelCase(_.find(selfAddress.data, o => {
return decodeURIComponent(o.address_id) === params.id;
})),
addressList: camelCase(result[1] ? result[1].data : []),
navTitle: '编辑地址'
};
let area = _.get(returnResult, 'address.area', '');
if (area.length > 11) {
returnResult.address.area = area.substr(0, 5) + '...' + area.substr(-5);
if (params.id && value.address_id === params.id) {
editAddress = value;
}
return returnResult;
} else {
value.address_id = encodeURIComponent(value.address_id);
});
return {
address: camelCase(selfAddress.data),
addressList: camelCase(result[1] ? result[1].data : []),
navTitle: '添加地址'
address: camelCase(params.id ? editAddress : selfAddress),
addressList: camelCase(_.get(result, '[1].data', [])),
navTitle: params.id ? '编辑地址' : '添加地址'
};
}
}
});
}
... ... @@ -219,7 +205,7 @@ module.exports = class extends global.yoho.BaseModel {
method: 'app.SpaceOrders.updateDeliveryAddress',
uid: uid,
order_code: orderCode,
address_id: addressId
address_id: decodeURIComponent(addressId)
}
}).then((result) => {
return result;
... ...