Authored by jinhu.tung

fix address component url request

@@ -90,10 +90,33 @@ const setDefaultAddress = (req, res) => { @@ -90,10 +90,33 @@ const setDefaultAddress = (req, res) => {
90 }); 90 });
91 }; 91 };
92 92
  93 +/**
  94 + * 获取地址信息
  95 + * @function getAddressData
  96 + * @return { Object }
  97 + */
  98 +const getAddressData = (req, res) => {
  99 + addressModel.getAddressData(req.params.areaId).then(result => {
  100 + if (result.code === 200) {
  101 + result.data = result.data.map((item) => {
  102 + return {
  103 + is_support: item.is_support_express,
  104 + text: item.caption,
  105 + value: item.id
  106 + };
  107 + });
  108 + res.json(result);
  109 + } else {
  110 + res.json(result);
  111 + }
  112 + });
  113 +};
  114 +
93 module.exports = { 115 module.exports = {
94 index, 116 index,
95 addAddressData, 117 addAddressData,
96 updateAddressData, 118 updateAddressData,
97 delAddressData, 119 delAddressData,
98 - setDefaultAddress 120 + setDefaultAddress,
  121 + getAddressData
99 }; 122 };
@@ -119,10 +119,28 @@ const setDefaultAddress = (id, uid) => { @@ -119,10 +119,28 @@ const setDefaultAddress = (id, uid) => {
119 }); 119 });
120 }; 120 };
121 121
  122 +/**
  123 + * 获取地址信息
  124 + * @function getAddressData
  125 + * @return { Array } [返回带有areaId的地址数组]
  126 + * @param id
  127 + * @param caption
  128 + * @param is_support_express
  129 + */
  130 +const getAddressData = (areaId) => {
  131 + return api.get('', {
  132 + method: 'app.address.provinces',
  133 + id: areaId || 0
  134 + }).then(result => {
  135 + return result;
  136 + });
  137 +};
  138 +
122 module.exports = { 139 module.exports = {
123 getAddressDataAsync: getAddressDataAsync, 140 getAddressDataAsync: getAddressDataAsync,
124 addAddressData: addAddressData, 141 addAddressData: addAddressData,
125 updateAddressData: updateAddressData, 142 updateAddressData: updateAddressData,
126 delAddressData: delAddressData, 143 delAddressData: delAddressData,
127 - setDefaultAddress: setDefaultAddress 144 + setDefaultAddress: setDefaultAddress,
  145 + getAddressData
128 }; 146 };
@@ -24,5 +24,6 @@ router.post('/address/add', address.addAddressData); @@ -24,5 +24,6 @@ router.post('/address/add', address.addAddressData);
24 router.post('/address/update', address.updateAddressData); 24 router.post('/address/update', address.updateAddressData);
25 router.post('/address/del', address.delAddressData); 25 router.post('/address/del', address.delAddressData);
26 router.post('/address/default', address.setDefaultAddress); 26 router.post('/address/default', address.setDefaultAddress);
  27 +router.get('/address/areas/:areaId', address.getAddressData);
27 28
28 module.exports = router; 29 module.exports = router;
1 var $ = require('yoho-jquery'), 1 var $ = require('yoho-jquery'),
2 lazyLoad = require('yoho-jquery-lazyload'), 2 lazyLoad = require('yoho-jquery-lazyload'),
  3 + common = require('../common'),
3 dialog = require('../plugins/dialog'); 4 dialog = require('../plugins/dialog');
4 5
5 var _dialog = dialog.Dialog, 6 var _dialog = dialog.Dialog,
@@ -95,11 +96,8 @@ $(function() { @@ -95,11 +96,8 @@ $(function() {
95 // 运行此demo 96 // 运行此demo
96 // 1. 安装 npm i -g json-server 97 // 1. 安装 npm i -g json-server
97 // 2. json-server --watch mock/address.json 98 // 2. json-server --watch mock/address.json
98 - window.add = cascadingAddress({  
99 - el: '#address',  
100 - url: 'http://localhost:3000/areas/0',  
101 - resource: 'areas'  
102 - }); 99 + common.setCookie('uid', '8050484');
  100 + window.add = cascadingAddress({el: '#address'});
103 }); 101 });
104 102
105 $('.weixin').click(function() { 103 $('.weixin').click(function() {
@@ -17,7 +17,7 @@ var $ = require('yoho-jquery'); @@ -17,7 +17,7 @@ var $ = require('yoho-jquery');
17 17
18 // 默认配置 18 // 默认配置
19 var settings = { 19 var settings = {
20 - url: '', 20 + url: '/me/address/areas/0',
21 containerClass: 'cascading-address', 21 containerClass: 'cascading-address',
22 levels: 3, 22 levels: 3,
23 resources: 'areas', 23 resources: 'areas',