building-sign/public/static/manager/js/common/address.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-01-09 08:41:41 +00:00
let province = $('#input-province').val();
let city = $('#input-city').val();
let county = $('#input-county').val();
let _width = 200;
let _height = 34;
province = province ? province : '110000';
city = city ? city : '110100';
county = county ? county : '110101';
if ($('#target').length > 0) {
if ($('#target').data('width') != undefined) {
_width = $('#target').data('width');
}
if ($('#target').data('height') != undefined) {
_height = $('#target').data('height');
}
}
var picker =iPicker.create("#target", {
width: _width,
height: _height,
data: {
// 此处以通过 jquery 库获取本地数据源为例
source: Promise.resolve($.getJSON("/static/js/iPicker/area.json"))
},
onSelect: (code, name, all) => {
// 返回参数均为数组形式
// console.log( code );
// console.log( name );
// console.log( all );
let len = code.length;
if (len === 3) {
$('#input-province').val(code[0]);
$('#input-city').val(code[1]);
$('#input-county').val(code[2]);
$('#input-province-text').val(name[0]);
$('#input-city-text').val(name[1]);
$('#input-county-text').val(name[2]);
}
},
selected: [province, city, county],
})