|
@@ -328,15 +328,30 @@ e.on("validate", function() { |
|
@@ -328,15 +328,30 @@ e.on("validate", function() { |
328
|
* https://cdn.yoho.cn/platform/gs/region/regions.js
|
328
|
* https://cdn.yoho.cn/platform/gs/region/regions.js
|
329
|
*/
|
329
|
*/
|
330
|
const Region = {
|
330
|
const Region = {
|
331
|
- initProvice() {
|
331
|
+ init(shopsAddressInfo) {
|
|
|
332
|
+ if(shopsAddressInfo) {
|
|
|
333
|
+ const province = regions.find(region => region.label == shopsAddressInfo.province);
|
|
|
334
|
+ this.selected.province = {
|
|
|
335
|
+ value: province.value,
|
|
|
336
|
+ label: province.label
|
|
|
337
|
+ }
|
|
|
338
|
+ this.initProvice(province, shopsAddressInfo);
|
|
|
339
|
+ $('#detailAdd').val(shopsAddressInfo.detailAdd);
|
|
|
340
|
+ }
|
|
|
341
|
+ },
|
|
|
342
|
+ initProvice(province,shopsAddressInfo) {
|
332
|
const $select = $('#province');
|
343
|
const $select = $('#province');
|
333
|
-
|
|
|
334
|
for(let i=0; i< regions.length; i++) {
|
344
|
for(let i=0; i< regions.length; i++) {
|
335
|
const province = regions[i];
|
345
|
const province = regions[i];
|
336
|
$select.append("<option value='"+province.value+"'>"+province.label+"</option>")
|
346
|
$select.append("<option value='"+province.value+"'>"+province.label+"</option>")
|
337
|
}
|
347
|
}
|
|
|
348
|
+ if(province) {
|
|
|
349
|
+ $select.val(province.value);
|
|
|
350
|
+ const selectedCity = province.children.find(city => city.label == shopsAddressInfo.city);
|
|
|
351
|
+ this.initCity(province.children, selectedCity, shopsAddressInfo);
|
|
|
352
|
+ }
|
338
|
},
|
353
|
},
|
339
|
- initCity(cities = []) {
|
354
|
+ initCity(cities = [], selectedCity, shopsAddressInfo) {
|
340
|
const $select = $('#city');
|
355
|
const $select = $('#city');
|
341
|
$select.empty();
|
356
|
$select.empty();
|
342
|
const tempCities = cities.slice();
|
357
|
const tempCities = cities.slice();
|
|
@@ -345,9 +360,21 @@ const Region = { |
|
@@ -345,9 +360,21 @@ const Region = { |
345
|
const city = tempCities[i];
|
360
|
const city = tempCities[i];
|
346
|
$select.append("<option value='"+city.value+"'>"+city.label+"</option>")
|
361
|
$select.append("<option value='"+city.value+"'>"+city.label+"</option>")
|
347
|
}
|
362
|
}
|
|
|
363
|
+ if(selectedCity) {
|
|
|
364
|
+ this.selected.city = {
|
|
|
365
|
+ value: selectedCity.value,
|
|
|
366
|
+ label: selectedCity.label
|
|
|
367
|
+ }
|
|
|
368
|
+ $select.val(selectedCity.value);
|
|
|
369
|
+ let selectedContry = null;
|
|
|
370
|
+ if(selectedCity.children && selectedCity.children.length) {
|
|
|
371
|
+ selectedContry = selectedCity.children.find(county => county.label == shopsAddressInfo.county);
|
|
|
372
|
+ }
|
|
|
373
|
+ this.initCountry(selectedCity.children, selectedContry, shopsAddressInfo)
|
|
|
374
|
+ }
|
348
|
},
|
375
|
},
|
349
|
- initCountry(coutries = []) {
|
|
|
350
|
- const $select = $('#country');
|
376
|
+ initCountry(coutries = [], selectedContry, shopsAddressInfo) {
|
|
|
377
|
+ const $select = $('#county');
|
351
|
if(!coutries.length) {
|
378
|
if(!coutries.length) {
|
352
|
$select.hide();
|
379
|
$select.hide();
|
353
|
$('#street').hide();
|
380
|
$('#street').hide();
|
|
@@ -359,11 +386,23 @@ const Region = { |
|
@@ -359,11 +386,23 @@ const Region = { |
359
|
const tempCounties = coutries.slice();
|
386
|
const tempCounties = coutries.slice();
|
360
|
tempCounties.unshift({value: '-1', label: '请选择区/县'})
|
387
|
tempCounties.unshift({value: '-1', label: '请选择区/县'})
|
361
|
for(let i=0; i< tempCounties.length; i++) {
|
388
|
for(let i=0; i< tempCounties.length; i++) {
|
362
|
- const country = tempCounties[i];
|
|
|
363
|
- $select.append("<option value='"+country.value+"'>"+country.label+"</option>")
|
389
|
+ const county = tempCounties[i];
|
|
|
390
|
+ $select.append("<option value='"+county.value+"'>"+county.label+"</option>")
|
|
|
391
|
+ }
|
|
|
392
|
+ if(selectedContry) {
|
|
|
393
|
+ this.selected.county = {
|
|
|
394
|
+ value: selectedContry.value,
|
|
|
395
|
+ label: selectedContry.label
|
|
|
396
|
+ }
|
|
|
397
|
+ $select.val(selectedContry.value);
|
|
|
398
|
+ let selectedStreet = null;
|
|
|
399
|
+ if(selectedContry.children && selectedContry.children.length) {
|
|
|
400
|
+ selectedStreet = selectedContry.children.find(street => street.label == shopsAddressInfo.street);
|
|
|
401
|
+ }
|
|
|
402
|
+ this.initStreet(selectedContry.children, selectedStreet)
|
364
|
}
|
403
|
}
|
365
|
},
|
404
|
},
|
366
|
- initStreet(streets = []) {
|
405
|
+ initStreet(streets = [],selectedStreet) {
|
367
|
const $select = $('#street');
|
406
|
const $select = $('#street');
|
368
|
if(!streets.length) {
|
407
|
if(!streets.length) {
|
369
|
$select.hide();
|
408
|
$select.hide();
|
|
@@ -377,14 +416,30 @@ const Region = { |
|
@@ -377,14 +416,30 @@ const Region = { |
377
|
const street = tempCounties[i];
|
416
|
const street = tempCounties[i];
|
378
|
$select.append("<option value='"+street.value+"'>"+street.label+"</option>")
|
417
|
$select.append("<option value='"+street.value+"'>"+street.label+"</option>")
|
379
|
}
|
418
|
}
|
|
|
419
|
+ if(selectedStreet){
|
|
|
420
|
+ this.selected.street = {
|
|
|
421
|
+ value: selectedStreet.value,
|
|
|
422
|
+ label: selectedStreet.label
|
|
|
423
|
+ }
|
|
|
424
|
+ $select.val(selectedStreet.value)
|
|
|
425
|
+ }
|
380
|
},
|
426
|
},
|
381
|
empty($el, option) {
|
427
|
empty($el, option) {
|
382
|
$el.empty();
|
428
|
$el.empty();
|
383
|
$el.append("<option value='"+option.value+"'>"+option.label+"</option>")
|
429
|
$el.append("<option value='"+option.value+"'>"+option.label+"</option>")
|
384
|
},
|
430
|
},
|
385
|
- selected:{province: {}, city: {}, country: {}, street: {}, detailAdd: ''}
|
431
|
+ selected:{province: {}, city: {}, county: {}, street: {}, detailAdd: ''}
|
386
|
}
|
432
|
}
|
387
|
|
433
|
|
|
|
434
|
+$(function(){
|
|
|
435
|
+ var shopsAddressInfo = $('#shopsAddressInfo').val();
|
|
|
436
|
+ if(shopsAddressInfo) {
|
|
|
437
|
+ shopsAddressInfo = JSON.parse(shopsAddressInfo);
|
|
|
438
|
+ }
|
|
|
439
|
+ Region.init(shopsAddressInfo);
|
|
|
440
|
+})
|
|
|
441
|
+
|
|
|
442
|
+
|
388
|
$('#detailAdd').on('input', function() {
|
443
|
$('#detailAdd').on('input', function() {
|
389
|
Region.selected.detailAdd = $(this).val();
|
444
|
Region.selected.detailAdd = $(this).val();
|
390
|
})
|
445
|
})
|
|
@@ -398,7 +453,7 @@ $('#province').on('change',function() { |
|
@@ -398,7 +453,7 @@ $('#province').on('change',function() { |
398
|
}
|
453
|
}
|
399
|
|
454
|
|
400
|
Region.empty($('#city'), {value: '-1', label: '请选择市'});
|
455
|
Region.empty($('#city'), {value: '-1', label: '请选择市'});
|
401
|
- Region.empty($('#country'), {value: '-1', label: '请选择区/县'});
|
456
|
+ Region.empty($('#county'), {value: '-1', label: '请选择区/县'});
|
402
|
Region.empty($('#street'), {value: '-1', label: '请选择街道'});
|
457
|
Region.empty($('#street'), {value: '-1', label: '请选择街道'});
|
403
|
|
458
|
|
404
|
const region = regions.find(region => region.value == Region.selected.province.value) || {};
|
459
|
const region = regions.find(region => region.value == Region.selected.province.value) || {};
|
|
@@ -412,7 +467,7 @@ $('#city').on('change',function() { |
|
@@ -412,7 +467,7 @@ $('#city').on('change',function() { |
412
|
label: $selected.text()
|
467
|
label: $selected.text()
|
413
|
}
|
468
|
}
|
414
|
|
469
|
|
415
|
- Region.empty($('#country'),{value: '-1', label: '请选择区/县'});
|
470
|
+ Region.empty($('#county'),{value: '-1', label: '请选择区/县'});
|
416
|
Region.empty($('#street'), {value: '-1', label: '请选择街道'});
|
471
|
Region.empty($('#street'), {value: '-1', label: '请选择街道'});
|
417
|
|
472
|
|
418
|
const region = regions.find(region => region.value == Region.selected.province.value) || {};
|
473
|
const region = regions.find(region => region.value == Region.selected.province.value) || {};
|
|
@@ -420,10 +475,10 @@ $('#city').on('change',function() { |
|
@@ -420,10 +475,10 @@ $('#city').on('change',function() { |
420
|
Region.initCountry(city.children || []);
|
475
|
Region.initCountry(city.children || []);
|
421
|
})
|
476
|
})
|
422
|
|
477
|
|
423
|
-$('#country').on('change',function() {
|
478
|
+$('#county').on('change',function() {
|
424
|
const $selected = $(this).children('option:selected')
|
479
|
const $selected = $(this).children('option:selected')
|
425
|
|
480
|
|
426
|
- Region.selected.country = {
|
481
|
+ Region.selected.county = {
|
427
|
value: +$selected.val(),
|
482
|
value: +$selected.val(),
|
428
|
label: $selected.text()
|
483
|
label: $selected.text()
|
429
|
}
|
484
|
}
|
|
@@ -432,8 +487,8 @@ $('#country').on('change',function() { |
|
@@ -432,8 +487,8 @@ $('#country').on('change',function() { |
432
|
|
487
|
|
433
|
const region = regions.find(region => region.value == Region.selected.province.value) || {};
|
488
|
const region = regions.find(region => region.value == Region.selected.province.value) || {};
|
434
|
const city = region.children.find(city => city.value === Region.selected.city.value) || {};
|
489
|
const city = region.children.find(city => city.value === Region.selected.city.value) || {};
|
435
|
- const country = city.children.find(country => country.value === Region.selected.country.value) || {};
|
|
|
436
|
- Region.initStreet(country.children || []);
|
490
|
+ const county = city.children.find(county => county.value === Region.selected.county.value) || {};
|
|
|
491
|
+ Region.initStreet(county.children || []);
|
437
|
})
|
492
|
})
|
438
|
|
493
|
|
439
|
$('#street').on('change',function() {
|
494
|
$('#street').on('change',function() {
|
|
@@ -497,14 +552,14 @@ function submitForm(callback) { |
|
@@ -497,14 +552,14 @@ function submitForm(callback) { |
497
|
// 一件代发地址存储汉字
|
552
|
// 一件代发地址存储汉字
|
498
|
option.data.province = Region.selected.province.label;
|
553
|
option.data.province = Region.selected.province.label;
|
499
|
option.data.city = Region.selected.city.label;
|
554
|
option.data.city = Region.selected.city.label;
|
500
|
- option.data.country = Region.selected.country.label;
|
555
|
+ option.data.county = Region.selected.county.label;
|
501
|
option.data.street = Region.selected.street.label;
|
556
|
option.data.street = Region.selected.street.label;
|
502
|
|
557
|
|
503
|
// if(+option.data.shopNature == 6) {
|
558
|
// if(+option.data.shopNature == 6) {
|
504
|
// option.data.shopsAddressInfo = {
|
559
|
// option.data.shopsAddressInfo = {
|
505
|
// province: Region.selected.province.label,
|
560
|
// province: Region.selected.province.label,
|
506
|
// city: Region.selected.city.label,
|
561
|
// city: Region.selected.city.label,
|
507
|
- // country: Region.selected.country.label,
|
562
|
+ // county: Region.selected.county.label,
|
508
|
// street: Region.selected.street.label,
|
563
|
// street: Region.selected.street.label,
|
509
|
// detailAdd: Region.selected.detailAdd
|
564
|
// detailAdd: Region.selected.detailAdd
|
510
|
// }
|
565
|
// }
|