Authored by 郭成尧

'partial'

... ... @@ -10,6 +10,12 @@ const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const addressModel = require(`${mRoot}/address`); // 地址管理 MODEL
/**
* 地址管理页面
* @param req
* @param res
* @param next
*/
exports.address = (req, res, next) => {
let responseData = {
module: 'home',
... ... @@ -21,13 +27,19 @@ exports.address = (req, res, next) => {
};
addressModel.address({
uid: req.user.uid
uid: req.user.uid || 8039759
}).then(result => {
res.render('address/index', Object.assign(responseData, {address: result}));
});
res.render('address/index', Object.assign(responseData, result));
}).catch(next);
};
/**
* 地址编辑页面
* @param req
* @param res
* @param next
*/
exports.addressAct = (req, res, next) => {
let responseData = {
module: 'home',
... ... @@ -38,5 +50,24 @@ exports.addressAct = (req, res, next) => {
title: '编辑地址'
};
res.render('address/address-act', responseData);
addressModel.address({
id: req.params.id,
uid: req.user.uid || 8039759
}).then(result => {
res.render('address/address-act', Object.assign(responseData, result));
}).catch(next);
};
/**
* 异步获取三级地址数据
* @param req
* @param res
* @param next
*/
exports.locationList = (req, res, next) => {
addressModel.locationList({
uid: req.user.uid || 8039759
}).then(result => {
res.render('address/address-act', Object.assign(result));
}).catch(next);
};
... ...
... ... @@ -23,32 +23,74 @@ const _getAddressData = (params) => {
};
/**
* 获取三级地址列表数据
* @param params
* @returns {*}
* @private
*/
const _getThrAddressData = (params) => {
return api.get('', {
method: 'app.address.getlist',
uid: params.uid
}, {code: 200, cache: true});
};
/**
* 地址管理页面
* @param params
* @param id
*/
const address = (params) => {
return _getAddressData(params).then(result => {
if (result.data) {
let apiList = [
_getAddressData(params)
];
if (params.id) { // 如果有 ID 是编辑地址页面
apiList.push(_getThrAddressData(params));
}
return api.all(apiList).then(result => {
let selfAddress = result[0];
if (selfAddress.data) {
_.forEach(result.data, (value, key) => {
result.data[key].address_id = crypto.encryption(null, result.data[key].address_id);
/* 加密地址 ID */
_.forEach(selfAddress.data, (value, key) => {
selfAddress.data[key].address_id = crypto.encryption(null, selfAddress.data[key].address_id);
});
/* 如果有 ID 是地址编辑页面 */
if (params.id) {
return {
address: camelCase(_.find(result.data, o => {
address: camelCase(_.find(selfAddress.data, o => {
return o.address_id === params.id;
}))
})),
addressList: camelCase(result[1] ? result[1].data : []),
addressActionPage: true
};
} else {
return {
address: camelCase(result.data)
address: camelCase(selfAddress.data)
};
}
}
});
};
/**
* 三级地址数据
* @param params
*/
const locationList = (params) => {
return _getThrAddressData(params).then(result => {
if (result.data) {
return {
addressList: camelCase(result.data)
}
}
});
};
module.exports = {
address
address,
locationList
};
... ...
... ... @@ -16,5 +16,6 @@ const addressController = require(`${cRoot}/address`);
router.get('/QRcode/:id', personalController.QRcode);
router.get('/address', addressController.address); // 地址管理界面
router.get('/addressAct/:id', addressController.addressAct); // 地址管理界面
router.get('/locationList', addressController.locationList); // 异步获取三级地址数据
module.exports = router;
... ...
... ... @@ -31,4 +31,5 @@
</div>
</div>
</div>
{{> address/address-list}}
</div>
... ...
{{> address/address-list}}
... ...
<ul class="address-list">
{{# addressList}}
<li class="address">
<span class="caption">{{caption}}</span>
<span class="iconfont">&#xe604;</span>
<ul>
{{# sub}}
<li class="address">
<span class="caption">{{caption}}</span>
<span class="iconfont">&#xe604;</span>
<ul class="address-list">
{{# sub}}
<li class="address-last" data-id="{{code}}">
<span class="caption">{{caption}}</span>
</li>
{{/ sub}}
</ul>
</li>
{{/ sub}}
</ul>
</li>
{{/ addressList}}
</ul>
... ...
... ... @@ -87,3 +87,4 @@ $action.on('touchstart', 'a,span', function() {
});
require('./address/address-act');
require('./address/address-modify');
... ...
... ... @@ -4,10 +4,10 @@
* @date: 2015/11/30
*/
var $ = require('yoho-jquery'),
Hammer = require('yoho.hammer'),
tip = require('../plugin/tip'),
security = require('../plugin/security'),
loading = require('../plugin/loading');
Hammer = require('yoho-hammer'),
tip = require('../../plugin/tip'),
security = require('../../plugin/security'),
loading = require('../../plugin/loading');
var $addressForm = $('.edit-address'),
$submit = $('.submit'),
... ...
/**
* 订单 地址修改
* @author: liangxiaosong
* @date: 2016/5/11
*/
var $ = require('yoho-jquery'),
tip = require('../../plugin/tip');
var $confimMod = $('.confim-modify-mask'),
$modifyAdd = $('.modifyAdd'),
orderCode = $modifyAdd.data('orderCode'),
selectId;
require('../../common');
$('.address-item').on('touchend', function() {
selectId = $(this).data('addressId');
if ($modifyAdd.data('rel') === true) {
$confimMod.find('.content').text('关联订单的收货地址将会一起修改且不可修改第二次,请确认是否修改?');
$confimMod.fadeIn();
} else {
$confimMod.find('.content').text('收货地址仅且只能修改一次,请确认是否修改?');
$confimMod.fadeIn();
}
});
$confimMod.on('touchend', '.cancel', function(e) {
selectId = null;
$confimMod.fadeOut();
return false;
}).on('touchend', '.confim', function() {
$.ajax({
method: 'GET',
url: '/home/chooseAddress',
data: {
addressId: selectId,
orderCode: orderCode
}
}).then(function(res) {
if ($.type(res) !== 'object') {
res = {};
}
if (res.code !== 200) {
$confimMod.fadeOut();
tip.show(res.message || '网络出了点问题~');
} else {
window.location.href = '/home/orderdetail?order_code=' + orderCode;
}
}).fail(function() {
tip.show('网络出了点问题~');
}).always(function() {
selectId = null;
});
return false;
});
... ...