Authored by shuaiguo

feat(一件代发): 店铺编辑

... ... @@ -20,6 +20,9 @@ module.exports = function (app){
});
app.get("/supplier/store/update/:shopsId", "shop.Edit", "shopAdd_getShopDetailById", function (rs,req,res){
if(rs.data && rs.data.shopsAddressInfo) {
rs.data.shopsAddressInfo = JSON.stringify(rs.data.shopsAddressInfo);
}
this.$extend={
moduleName:"店铺管理",
pageName:"店铺编辑",
... ...
... ... @@ -26,8 +26,9 @@ module.exports={
// 店铺地址
{name:"province",type:"String"},
{name:"city",type:"String"},
{name:"country",type:"String"},
{name:"street",type:"String"}
{name:"county",type:"String"},
{name:"street",type:"String"},
{name:"detailAdd",type:"String"}
]
},
... ...
... ... @@ -3,6 +3,7 @@
<form id="storeForm" role="form" class="form-horizontal form-bordered" method="post" action="<%action%>">
<input type="hidden" id="shopsId" value="<%data.shopsId%>">
<input type="hidden" id="shopsAddressInfo" value="<%data.shopsAddressInfo%>">
<div class="contentpanel">
<div class="panel panel-default">
<div class="panel-heading">
... ... @@ -88,7 +89,7 @@
</select>
</div>
<div class="col-sm-2">
<select name="country" id="country"
<select name="county" id="county"
class="form-control">
<option value="-1">请选择区/县</option>
</select>
... ... @@ -101,7 +102,7 @@
</div>
<div class="col-sm-8" style="margin-top: 10px">
<div class="input-group">
<input style="width: 350px;" type="text" name="shopsAddressInfo" id="detailAdd"
<input style="width: 350px;" type="text" name="detailAdd" id="detailAdd"
class="form-control" placeholder="详细地址"
aria-describedby="basic-addon2">
</div>
... ...
... ... @@ -328,15 +328,30 @@ e.on("validate", function() {
* https://cdn.yoho.cn/platform/gs/region/regions.js
*/
const Region = {
initProvice() {
init(shopsAddressInfo) {
if(shopsAddressInfo) {
const province = regions.find(region => region.label == shopsAddressInfo.province);
this.selected.province = {
value: province.value,
label: province.label
}
this.initProvice(province, shopsAddressInfo);
$('#detailAdd').val(shopsAddressInfo.detailAdd);
}
},
initProvice(province,shopsAddressInfo) {
const $select = $('#province');
for(let i=0; i< regions.length; i++) {
const province = regions[i];
$select.append("<option value='"+province.value+"'>"+province.label+"</option>")
}
if(province) {
$select.val(province.value);
const selectedCity = province.children.find(city => city.label == shopsAddressInfo.city);
this.initCity(province.children, selectedCity, shopsAddressInfo);
}
},
initCity(cities = []) {
initCity(cities = [], selectedCity, shopsAddressInfo) {
const $select = $('#city');
$select.empty();
const tempCities = cities.slice();
... ... @@ -345,9 +360,21 @@ const Region = {
const city = tempCities[i];
$select.append("<option value='"+city.value+"'>"+city.label+"</option>")
}
if(selectedCity) {
this.selected.city = {
value: selectedCity.value,
label: selectedCity.label
}
$select.val(selectedCity.value);
let selectedContry = null;
if(selectedCity.children && selectedCity.children.length) {
selectedContry = selectedCity.children.find(county => county.label == shopsAddressInfo.county);
}
this.initCountry(selectedCity.children, selectedContry, shopsAddressInfo)
}
},
initCountry(coutries = []) {
const $select = $('#country');
initCountry(coutries = [], selectedContry, shopsAddressInfo) {
const $select = $('#county');
if(!coutries.length) {
$select.hide();
$('#street').hide();
... ... @@ -359,11 +386,23 @@ const Region = {
const tempCounties = coutries.slice();
tempCounties.unshift({value: '-1', label: '请选择区/县'})
for(let i=0; i< tempCounties.length; i++) {
const country = tempCounties[i];
$select.append("<option value='"+country.value+"'>"+country.label+"</option>")
const county = tempCounties[i];
$select.append("<option value='"+county.value+"'>"+county.label+"</option>")
}
if(selectedContry) {
this.selected.county = {
value: selectedContry.value,
label: selectedContry.label
}
$select.val(selectedContry.value);
let selectedStreet = null;
if(selectedContry.children && selectedContry.children.length) {
selectedStreet = selectedContry.children.find(street => street.label == shopsAddressInfo.street);
}
this.initStreet(selectedContry.children, selectedStreet)
}
},
initStreet(streets = []) {
initStreet(streets = [],selectedStreet) {
const $select = $('#street');
if(!streets.length) {
$select.hide();
... ... @@ -377,14 +416,30 @@ const Region = {
const street = tempCounties[i];
$select.append("<option value='"+street.value+"'>"+street.label+"</option>")
}
if(selectedStreet){
this.selected.street = {
value: selectedStreet.value,
label: selectedStreet.label
}
$select.val(selectedStreet.value)
}
},
empty($el, option) {
$el.empty();
$el.append("<option value='"+option.value+"'>"+option.label+"</option>")
},
selected:{province: {}, city: {}, country: {}, street: {}, detailAdd: ''}
selected:{province: {}, city: {}, county: {}, street: {}, detailAdd: ''}
}
$(function(){
var shopsAddressInfo = $('#shopsAddressInfo').val();
if(shopsAddressInfo) {
shopsAddressInfo = JSON.parse(shopsAddressInfo);
}
Region.init(shopsAddressInfo);
})
$('#detailAdd').on('input', function() {
Region.selected.detailAdd = $(this).val();
})
... ... @@ -398,7 +453,7 @@ $('#province').on('change',function() {
}
Region.empty($('#city'), {value: '-1', label: '请选择市'});
Region.empty($('#country'), {value: '-1', label: '请选择区/县'});
Region.empty($('#county'), {value: '-1', label: '请选择区/县'});
Region.empty($('#street'), {value: '-1', label: '请选择街道'});
const region = regions.find(region => region.value == Region.selected.province.value) || {};
... ... @@ -412,7 +467,7 @@ $('#city').on('change',function() {
label: $selected.text()
}
Region.empty($('#country'),{value: '-1', label: '请选择区/县'});
Region.empty($('#county'),{value: '-1', label: '请选择区/县'});
Region.empty($('#street'), {value: '-1', label: '请选择街道'});
const region = regions.find(region => region.value == Region.selected.province.value) || {};
... ... @@ -420,10 +475,10 @@ $('#city').on('change',function() {
Region.initCountry(city.children || []);
})
$('#country').on('change',function() {
$('#county').on('change',function() {
const $selected = $(this).children('option:selected')
Region.selected.country = {
Region.selected.county = {
value: +$selected.val(),
label: $selected.text()
}
... ... @@ -432,8 +487,8 @@ $('#country').on('change',function() {
const region = regions.find(region => region.value == Region.selected.province.value) || {};
const city = region.children.find(city => city.value === Region.selected.city.value) || {};
const country = city.children.find(country => country.value === Region.selected.country.value) || {};
Region.initStreet(country.children || []);
const county = city.children.find(county => county.value === Region.selected.county.value) || {};
Region.initStreet(county.children || []);
})
$('#street').on('change',function() {
... ... @@ -497,14 +552,14 @@ function submitForm(callback) {
// 一件代发地址存储汉字
option.data.province = Region.selected.province.label;
option.data.city = Region.selected.city.label;
option.data.country = Region.selected.country.label;
option.data.county = Region.selected.county.label;
option.data.street = Region.selected.street.label;
// if(+option.data.shopNature == 6) {
// option.data.shopsAddressInfo = {
// province: Region.selected.province.label,
// city: Region.selected.city.label,
// country: Region.selected.country.label,
// county: Region.selected.county.label,
// street: Region.selected.street.label,
// detailAdd: Region.selected.detailAdd
// }
... ...