123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- //查询赋值
- 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('<option value="'+""+'">'+"请选择省"+'</option>');
- for (var i = 0; i < provinces.length; i++) {
- if(provinces[i].id == provinceValue){
- province.append('<option selected value="'+provinces[i].id+'">'+provinces[i].city_name+'</option>');
- }else{
- province.append('<option value="'+provinces[i].id+'">'+provinces[i].city_name+'</option>');
- }
- }
- 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('<option value="'+""+'">'+"请选择市"+'</option>');
- 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('<option selected value="'+provinces[i].id+'">'+provinces[i].city_name+'</option>');
- }else{
- province.append('<option value="'+provinces[i].id+'">'+provinces[i].city_name+'</option>');
- }
- }
- form.render('select');
- countyChange(form,cityValue,countyValue);
- },
- fail:function(){
- }
- });
- }
- }
- /**
- * 初始化县/区
- */
- function countyChange(form,cityValue,countyValue){
- //改变县/区
- var province = $('select[name=area]');
- province.empty();
- province.append('<option value="'+""+'">'+"请选择县/区"+'</option>');
- 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('<option selected value="'+provinces[i].id+'">'+provinces[i].city_name+'</option>');
- }else{
- province.append('<option value="'+provinces[i].id+'">'+provinces[i].city_name+'</option>');
- }
- }
- 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,"")
- });
- });
|