Showing
9 changed files
with
174 additions
and
17 deletions
@@ -10,6 +10,12 @@ const mRoot = '../models'; | @@ -10,6 +10,12 @@ const mRoot = '../models'; | ||
10 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 10 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
11 | const addressModel = require(`${mRoot}/address`); // 地址管理 MODEL | 11 | const addressModel = require(`${mRoot}/address`); // 地址管理 MODEL |
12 | 12 | ||
13 | +/** | ||
14 | + * 地址管理页面 | ||
15 | + * @param req | ||
16 | + * @param res | ||
17 | + * @param next | ||
18 | + */ | ||
13 | exports.address = (req, res, next) => { | 19 | exports.address = (req, res, next) => { |
14 | let responseData = { | 20 | let responseData = { |
15 | module: 'home', | 21 | module: 'home', |
@@ -21,13 +27,19 @@ exports.address = (req, res, next) => { | @@ -21,13 +27,19 @@ exports.address = (req, res, next) => { | ||
21 | }; | 27 | }; |
22 | 28 | ||
23 | addressModel.address({ | 29 | addressModel.address({ |
24 | - uid: req.user.uid | 30 | + uid: req.user.uid || 8039759 |
25 | }).then(result => { | 31 | }).then(result => { |
26 | - res.render('address/index', Object.assign(responseData, {address: result})); | ||
27 | - }); | 32 | + res.render('address/index', Object.assign(responseData, result)); |
33 | + }).catch(next); | ||
28 | 34 | ||
29 | }; | 35 | }; |
30 | 36 | ||
37 | +/** | ||
38 | + * 地址编辑页面 | ||
39 | + * @param req | ||
40 | + * @param res | ||
41 | + * @param next | ||
42 | + */ | ||
31 | exports.addressAct = (req, res, next) => { | 43 | exports.addressAct = (req, res, next) => { |
32 | let responseData = { | 44 | let responseData = { |
33 | module: 'home', | 45 | module: 'home', |
@@ -38,5 +50,24 @@ exports.addressAct = (req, res, next) => { | @@ -38,5 +50,24 @@ exports.addressAct = (req, res, next) => { | ||
38 | title: '编辑地址' | 50 | title: '编辑地址' |
39 | }; | 51 | }; |
40 | 52 | ||
41 | - res.render('address/address-act', responseData); | 53 | + addressModel.address({ |
54 | + id: req.params.id, | ||
55 | + uid: req.user.uid || 8039759 | ||
56 | + }).then(result => { | ||
57 | + res.render('address/address-act', Object.assign(responseData, result)); | ||
58 | + }).catch(next); | ||
59 | +}; | ||
60 | + | ||
61 | +/** | ||
62 | + * 异步获取三级地址数据 | ||
63 | + * @param req | ||
64 | + * @param res | ||
65 | + * @param next | ||
66 | + */ | ||
67 | +exports.locationList = (req, res, next) => { | ||
68 | + addressModel.locationList({ | ||
69 | + uid: req.user.uid || 8039759 | ||
70 | + }).then(result => { | ||
71 | + res.render('address/address-act', Object.assign(result)); | ||
72 | + }).catch(next); | ||
42 | }; | 73 | }; |
@@ -23,32 +23,74 @@ const _getAddressData = (params) => { | @@ -23,32 +23,74 @@ const _getAddressData = (params) => { | ||
23 | }; | 23 | }; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | + * 获取三级地址列表数据 | ||
27 | + * @param params | ||
28 | + * @returns {*} | ||
29 | + * @private | ||
30 | + */ | ||
31 | +const _getThrAddressData = (params) => { | ||
32 | + return api.get('', { | ||
33 | + method: 'app.address.getlist', | ||
34 | + uid: params.uid | ||
35 | + }, {code: 200, cache: true}); | ||
36 | +}; | ||
37 | + | ||
38 | +/** | ||
26 | * 地址管理页面 | 39 | * 地址管理页面 |
27 | * @param params | 40 | * @param params |
28 | - * @param id | ||
29 | */ | 41 | */ |
30 | const address = (params) => { | 42 | const address = (params) => { |
31 | - return _getAddressData(params).then(result => { | ||
32 | - if (result.data) { | 43 | + let apiList = [ |
44 | + _getAddressData(params) | ||
45 | + ]; | ||
46 | + | ||
47 | + if (params.id) { // 如果有 ID 是编辑地址页面 | ||
48 | + apiList.push(_getThrAddressData(params)); | ||
49 | + } | ||
50 | + | ||
51 | + return api.all(apiList).then(result => { | ||
52 | + let selfAddress = result[0]; | ||
53 | + | ||
54 | + if (selfAddress.data) { | ||
33 | 55 | ||
34 | - _.forEach(result.data, (value, key) => { | ||
35 | - result.data[key].address_id = crypto.encryption(null, result.data[key].address_id); | 56 | + /* 加密地址 ID */ |
57 | + _.forEach(selfAddress.data, (value, key) => { | ||
58 | + selfAddress.data[key].address_id = crypto.encryption(null, selfAddress.data[key].address_id); | ||
36 | }); | 59 | }); |
60 | + | ||
61 | + /* 如果有 ID 是地址编辑页面 */ | ||
37 | if (params.id) { | 62 | if (params.id) { |
38 | return { | 63 | return { |
39 | - address: camelCase(_.find(result.data, o => { | 64 | + address: camelCase(_.find(selfAddress.data, o => { |
40 | return o.address_id === params.id; | 65 | return o.address_id === params.id; |
41 | - })) | 66 | + })), |
67 | + addressList: camelCase(result[1] ? result[1].data : []), | ||
68 | + addressActionPage: true | ||
42 | }; | 69 | }; |
43 | } else { | 70 | } else { |
44 | return { | 71 | return { |
45 | - address: camelCase(result.data) | 72 | + address: camelCase(selfAddress.data) |
46 | }; | 73 | }; |
47 | } | 74 | } |
48 | } | 75 | } |
49 | }); | 76 | }); |
50 | }; | 77 | }; |
51 | 78 | ||
79 | +/** | ||
80 | + * 三级地址数据 | ||
81 | + * @param params | ||
82 | + */ | ||
83 | +const locationList = (params) => { | ||
84 | + return _getThrAddressData(params).then(result => { | ||
85 | + if (result.data) { | ||
86 | + return { | ||
87 | + addressList: camelCase(result.data) | ||
88 | + } | ||
89 | + } | ||
90 | + }); | ||
91 | +}; | ||
92 | + | ||
52 | module.exports = { | 93 | module.exports = { |
53 | - address | 94 | + address, |
95 | + locationList | ||
54 | }; | 96 | }; |
@@ -16,5 +16,6 @@ const addressController = require(`${cRoot}/address`); | @@ -16,5 +16,6 @@ const addressController = require(`${cRoot}/address`); | ||
16 | router.get('/QRcode/:id', personalController.QRcode); | 16 | router.get('/QRcode/:id', personalController.QRcode); |
17 | router.get('/address', addressController.address); // 地址管理界面 | 17 | router.get('/address', addressController.address); // 地址管理界面 |
18 | router.get('/addressAct/:id', addressController.addressAct); // 地址管理界面 | 18 | router.get('/addressAct/:id', addressController.addressAct); // 地址管理界面 |
19 | +router.get('/locationList', addressController.locationList); // 异步获取三级地址数据 | ||
19 | 20 | ||
20 | module.exports = router; | 21 | module.exports = router; |
1 | +{{> address/address-list}} |
1 | +<ul class="address-list"> | ||
2 | + {{# addressList}} | ||
3 | + <li class="address"> | ||
4 | + <span class="caption">{{caption}}</span> | ||
5 | + <span class="iconfont"></span> | ||
6 | + <ul> | ||
7 | + {{# sub}} | ||
8 | + <li class="address"> | ||
9 | + <span class="caption">{{caption}}</span> | ||
10 | + <span class="iconfont"></span> | ||
11 | + <ul class="address-list"> | ||
12 | + {{# sub}} | ||
13 | + <li class="address-last" data-id="{{code}}"> | ||
14 | + <span class="caption">{{caption}}</span> | ||
15 | + </li> | ||
16 | + {{/ sub}} | ||
17 | + </ul> | ||
18 | + </li> | ||
19 | + {{/ sub}} | ||
20 | + </ul> | ||
21 | + </li> | ||
22 | + {{/ addressList}} | ||
23 | +</ul> |
@@ -4,10 +4,10 @@ | @@ -4,10 +4,10 @@ | ||
4 | * @date: 2015/11/30 | 4 | * @date: 2015/11/30 |
5 | */ | 5 | */ |
6 | var $ = require('yoho-jquery'), | 6 | var $ = require('yoho-jquery'), |
7 | - Hammer = require('yoho.hammer'), | ||
8 | - tip = require('../plugin/tip'), | ||
9 | - security = require('../plugin/security'), | ||
10 | - loading = require('../plugin/loading'); | 7 | + Hammer = require('yoho-hammer'), |
8 | + tip = require('../../plugin/tip'), | ||
9 | + security = require('../../plugin/security'), | ||
10 | + loading = require('../../plugin/loading'); | ||
11 | 11 | ||
12 | var $addressForm = $('.edit-address'), | 12 | var $addressForm = $('.edit-address'), |
13 | $submit = $('.submit'), | 13 | $submit = $('.submit'), |
public/js/home/address/address-modify.js
0 → 100644
1 | +/** | ||
2 | + * 订单 地址修改 | ||
3 | + * @author: liangxiaosong | ||
4 | + * @date: 2016/5/11 | ||
5 | + */ | ||
6 | + | ||
7 | +var $ = require('yoho-jquery'), | ||
8 | + tip = require('../../plugin/tip'); | ||
9 | + | ||
10 | +var $confimMod = $('.confim-modify-mask'), | ||
11 | + $modifyAdd = $('.modifyAdd'), | ||
12 | + orderCode = $modifyAdd.data('orderCode'), | ||
13 | + selectId; | ||
14 | + | ||
15 | +require('../../common'); | ||
16 | + | ||
17 | +$('.address-item').on('touchend', function() { | ||
18 | + selectId = $(this).data('addressId'); | ||
19 | + | ||
20 | + if ($modifyAdd.data('rel') === true) { | ||
21 | + $confimMod.find('.content').text('关联订单的收货地址将会一起修改且不可修改第二次,请确认是否修改?'); | ||
22 | + $confimMod.fadeIn(); | ||
23 | + } else { | ||
24 | + $confimMod.find('.content').text('收货地址仅且只能修改一次,请确认是否修改?'); | ||
25 | + $confimMod.fadeIn(); | ||
26 | + } | ||
27 | +}); | ||
28 | + | ||
29 | +$confimMod.on('touchend', '.cancel', function(e) { | ||
30 | + selectId = null; | ||
31 | + $confimMod.fadeOut(); | ||
32 | + return false; | ||
33 | +}).on('touchend', '.confim', function() { | ||
34 | + $.ajax({ | ||
35 | + method: 'GET', | ||
36 | + url: '/home/chooseAddress', | ||
37 | + data: { | ||
38 | + addressId: selectId, | ||
39 | + orderCode: orderCode | ||
40 | + } | ||
41 | + }).then(function(res) { | ||
42 | + if ($.type(res) !== 'object') { | ||
43 | + res = {}; | ||
44 | + } | ||
45 | + if (res.code !== 200) { | ||
46 | + $confimMod.fadeOut(); | ||
47 | + tip.show(res.message || '网络出了点问题~'); | ||
48 | + } else { | ||
49 | + window.location.href = '/home/orderdetail?order_code=' + orderCode; | ||
50 | + } | ||
51 | + }).fail(function() { | ||
52 | + tip.show('网络出了点问题~'); | ||
53 | + }).always(function() { | ||
54 | + selectId = null; | ||
55 | + }); | ||
56 | + return false; | ||
57 | +}); |
-
Please register or login to post a comment