//查询赋值
function query(form) {
var _vals = $('input[name=select_province]').val();
var _vals1 = $('input[name=select_city]').val();
var _vals2 = $('input[name=select_area]').val();
provinceChange(form, _vals, _vals1, _vals2);
}
function loadProvince(pid = 0) {
$.ajax({
url: '/categorycity/citypid',
type: 'post',
async: false,//使用同步的方式,true为异步方式
data: {'pid': pid},//这里使用json对象
success: function (data) {
// console.log(data);
var areaData = data.data;
provinceChange(form, areaData, data_.city, data_.county);
},
fail: function () {
}
});
}
/**
* 初始化省
*/
function provinceChange(form, provinceValue, cityValue, countyValue) {
$.ajax({
url: '/categorycity/citypid',
type: 'post',
async: false,//使用同步的方式,true为异步方式
data: {'pid': 0},//这里使用json对象
success: function (data) {
// console.log(data);
var provinces = data.data;
var province = $('select[name=province]');
province.empty();
province.append('');
for (var i = 0; i < provinces.length; i++) {
if (provinces[i].id == provinceValue) {
province.append('');
} else {
province.append('');
}
}
form.render('select');
cityChange(form, provinceValue, cityValue, countyValue);
},
fail: function () {
}
});
}
/**
* 初始化市
*/
function cityChange(form, provinceValue, cityValue, countyValue) {
//改变市
var province = $('select[name=city]');
province.empty();
province.append('');
if (provinceValue) {
$.ajax({
url: '/categorycity/citypid',
type: 'post',
async: false,//使用同步的方式,true为异步方式
data: {'pid': provinceValue},//这里使用json对象
success: function (data) {
// console.log(data);
var provinces = data.data;
for (var i = 0; i < provinces.length; i++) {
if (provinces[i].id == cityValue) {
province.append('');
} else {
province.append('');
}
}
form.render('select');
countyChange(form, cityValue, countyValue);
},
fail: function () {
}
});
}
}
/**
* 初始化县/区
*/
function countyChange(form, cityValue, countyValue) {
//改变县/区
var province = $('select[name=area]');
province.empty();
province.append('');
if (cityValue) {
$.ajax({
url: '/categorycity/citypid',
type: 'post',
async: false,//使用同步的方式,true为异步方式
data: {'pid': cityValue},//这里使用json对象
success: function (data) {
// console.log(data);
var provinces = data.data;
for (var i = 0; i < provinces.length; i++) {
if (provinces[i].id == countyValue) {
province.append('');
} else {
province.append('');
}
}
form.render('select');
},
fail: function () {
}
});
}
}
layui.use(['form'], function () {
var $ = layui.$
, layer = layui.layer
, form = layui.form;
//查询赋值
query(form);
/*监听省select*/
form.on('select(provinceone)', function (data) {
cityChange(form, data.value, "", "")
});
/*监听市select*/
form.on('select(cityone)', function (data) {
countyChange(form, data.value, "")
});
});