Authored by xuqi

address with areacode

@@ -122,7 +122,9 @@ function addressDialogFactory(opt, $the) { @@ -122,7 +122,9 @@ function addressDialogFactory(opt, $the) {
122 consignee, 122 consignee,
123 detail, 123 detail,
124 mobile, 124 mobile,
125 - phone; 125 + phone,
  126 + areaCode,
  127 + isDefault;
126 128
127 // 验证输入 129 // 验证输入
128 if (validateAddress(address.$el)) { 130 if (validateAddress(address.$el)) {
@@ -132,6 +134,8 @@ function addressDialogFactory(opt, $the) { @@ -132,6 +134,8 @@ function addressDialogFactory(opt, $the) {
132 detail = $el.find('.address-detail').val(); 134 detail = $el.find('.address-detail').val();
133 mobile = $el.find('.address-mobile').val(); 135 mobile = $el.find('.address-mobile').val();
134 phone = $el.find('.address-phone').val(); 136 phone = $el.find('.address-phone').val();
  137 + areaCode = $el.address.getAreaIds().split(',')[2];
  138 + isDefault = $el.default ? 'Y' : 'N';
135 139
136 if (opt && opt.id) { 140 if (opt && opt.id) {
137 141
@@ -146,22 +150,22 @@ function addressDialogFactory(opt, $the) { @@ -146,22 +150,22 @@ function addressDialogFactory(opt, $the) {
146 address: detail, 150 address: detail,
147 mobile: mobile, 151 mobile: mobile,
148 phone: phone, 152 phone: phone,
149 - 'area_code': '320107'// eslint-disable-line 153 + 'is_default': isDefault, // eslint-disable-line
  154 + 'area_code': areaCode // eslint-disable-line
150 } 155 }
151 }).then(function(data) { 156 }).then(function(data) {
152 if (data.code === 200) { 157 if (data.code === 200) {
153 $the.before(addressTpl({ 158 $the.before(addressTpl({
154 - address: [  
155 - {  
156 - consignee: consignee,  
157 - address: detail,  
158 - mobile: mobile,  
159 - phone: phone,  
160 - area_code: data.data.area_code, // eslint-disable-line  
161 - id: opt.id,  
162 - focus: $the.hasClass('focus')  
163 - }  
164 - ] 159 + address: [{
  160 + consignee: consignee,
  161 + address: detail,
  162 + mobile: mobile,
  163 + phone: phone,
  164 + area_code: data.data.area_code, // eslint-disable-line
  165 + id: opt.id,
  166 + focus: $the.hasClass('focus'),
  167 + area: $el.address.getAreaLabels().replace(/,/g, ' ')
  168 + }]
165 })); 169 }));
166 170
167 $the.remove(); 171 $the.remove();
@@ -180,7 +184,8 @@ function addressDialogFactory(opt, $the) { @@ -180,7 +184,8 @@ function addressDialogFactory(opt, $the) {
180 address: detail, 184 address: detail,
181 mobile: mobile, 185 mobile: mobile,
182 phone: phone, 186 phone: phone,
183 - 'area_code': '320107'// eslint-disable-line 187 + 'is_default': isDefault, // eslint-disable-line
  188 + 'area_code': areaCode// eslint-disable-line
184 } 189 }
185 }).then(function(data) { 190 }).then(function(data) {
186 var the; 191 var the;
@@ -215,20 +220,34 @@ function addressDialogFactory(opt, $the) { @@ -215,20 +220,34 @@ function addressDialogFactory(opt, $the) {
215 return address; 220 return address;
216 } 221 }
217 222
218 -// 初始化弹窗内容  
219 -function initAddressContent($el) { 223 +/**
  224 + * 初始化弹窗内容
  225 + * @param $el dialog的jquery对象
  226 + * @param areaCode 区码,初始化选择区域的组件
  227 + */
  228 +function initAddressContent($el, areaCode) {
220 229
221 - // 初始化地址组件  
222 - cascadingAddress({ 230 + // 初始化地址组件/将组件attr到$el方便操作
  231 + $el.address = cascadingAddress({
223 el: '#address', 232 el: '#address',
224 url: 'http://localhost:3000/areas/0', 233 url: 'http://localhost:3000/areas/0',
225 resource: 'areas' 234 resource: 'areas'
226 }); 235 });
227 236
  237 + if (areaCode) {
  238 + $el.address.setAddress({
  239 + province: '32',
  240 + city: '3201',
  241 + dist: areaCode
  242 + });
  243 + }
  244 +
  245 + // init default
  246 + $el.default = $el.find('.default-address-radio .iconfont').hasClass('checked');
228 $el.find('.default-address-radio').check({ 247 $el.find('.default-address-radio').check({
229 type: 'radio', 248 type: 'radio',
230 onChange: function(el, checked) { 249 onChange: function(el, checked) {
231 - console.log(checked); 250 + $el.default = checked;
232 } 251 }
233 }); 252 });
234 } 253 }
@@ -243,7 +262,7 @@ function newAddress() { @@ -243,7 +262,7 @@ function newAddress() {
243 262
244 // 显示全部地址 263 // 显示全部地址
245 $('.address-all').click(function() { 264 $('.address-all').click(function() {
246 - $(this).siblings('.address-list').removeClass('shrink').end().remove(); 265 + $(this).siblings('.address-list').removeClass('shrink').end().addClass('vhide');
247 }); 266 });
248 267
249 // 新增地址 268 // 新增地址
@@ -265,6 +284,7 @@ $('.address-list').on('click', '.address', function() { @@ -265,6 +284,7 @@ $('.address-list').on('click', '.address', function() {
265 284
266 // 修改地址 285 // 修改地址
267 var $this = $(this).closest('.address'); 286 var $this = $(this).closest('.address');
  287 + var areaCode = $this.data('areacode');
268 var address = addressDialogFactory({ 288 var address = addressDialogFactory({
269 updateAddress: true, 289 updateAddress: true,
270 id: $this.data('id'), 290 id: $this.data('id'),
@@ -272,11 +292,11 @@ $('.address-list').on('click', '.address', function() { @@ -272,11 +292,11 @@ $('.address-list').on('click', '.address', function() {
272 name: $this.data('name'), 292 name: $this.data('name'),
273 mobile: $this.data('mobile'), 293 mobile: $this.data('mobile'),
274 phone: $this.data('phone'), 294 phone: $this.data('phone'),
275 - areacode: $this.data('areacode'), 295 + areacode: areaCode,
276 detail: $this.data('address') 296 detail: $this.data('address')
277 }, $this); 297 }, $this);
278 298
279 - initAddressContent(address.$el); 299 + initAddressContent(address.$el, areaCode);
280 300
281 address.show(); 301 address.show();
282 302
@@ -348,7 +368,7 @@ $.ajax({ @@ -348,7 +368,7 @@ $.ajax({
348 list = data.data; 368 list = data.data;
349 if (list.length === 0) { 369 if (list.length === 0) {
350 370
351 - //new address 371 + // new address
352 newAddress(); 372 newAddress();
353 } else { 373 } else {
354 $('#address-list').append(addressTpl({ 374 $('#address-list').append(addressTpl({