Browse Source

省市区三级联动

master
ZLW-PC\Administrator 7 years ago
parent
commit
7bf40274e0
  1. 4
      app/Http/Model/Region.php
  2. 4
      public/js/jquery.validate.min.js
  3. 127
      resources/views/weixin/address/userAddressAdd.blade.php
  4. 6
      routes/web.php

4
app/Http/Model/Region.php

@ -26,12 +26,12 @@ class Region extends BaseModel
public static function getList($parent_id=86)
{
return self::where('parent_id', $parent_id)->get()->toArray();
return self::where('parent_id', $parent_id)->get();
}
public static function getOne($id)
{
$res = self::where('id', $id)->first()->toArray();
$res = self::where('id', $id)->first();
if (!empty($res))
{
return $res;

4
public/js/jquery.validate.min.js
File diff suppressed because it is too large
View File

127
resources/views/weixin/address/userAddressAdd.blade.php

@ -34,6 +34,7 @@
border: 1px solid #ddd;
border-radius: 0;box-sizing:border-box;
}
.adr-form-group select{padding:5px;margin-right:10px;}
.bottoma{display:block;font-size:18px;padding:10px;color:white;background-color: #f23030;text-align:center;}
</style>
@ -47,8 +48,130 @@
<input type="text" name="mobile" class="" id="mobile" placeholder="输入手机号码">
</div>
<div class="adr-form-group">
<label for="doc-ipt-email-1">地区</label>
<input type="text" class="" id="doc-ipt-email-1" placeholder="输入电子邮件">
地区: <select id='sheng'></select><select id='shi'></select><select id='qu'></select>
<script>
// JavaScript Document
$(document).ready(function(e) {
//加载省的数据
LoadSheng();
//加载市的数据
LoadShi();
//加载区的数据
LoadQu();
//给省的下拉加点击事件
$("#sheng").change(function(){
//重新加载市
LoadShi();
//重新加载区
LoadQu();
});
//给市的下拉加点击事件
$("#shi").change(function(){
//重新加载区
LoadQu();
});
});
//加载省份的方法
function LoadSheng(parent_id,select_id)
{
//省的父级代号
parent_id = parent_id || '86';
select_id = select_id || 0;
$.ajax({
async:false,
url:'<?php echo env('APP_API_URL')."/region_list"; ?>',
data:{id:parent_id},
type:"GET",
dataType:"json",
success: function(res){
var hang = res.data;
var str = "";
for(var i=0;i<hang.length;i++)
{
if(select_id != 0 && select_id == hang[i].id)
{
str = str+"<option selected='selected' value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
else
{
str = str+"<option value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
}
$("#sheng").html(str);
}
});
}
//加载市的方法
function LoadShi(parent_id,select_id)
{
//找市的父级代号
parent_id = parent_id || $("#sheng").val();
select_id = select_id || 0;
$.ajax({
async:false,
url:'<?php echo env('APP_API_URL')."/region_list"; ?>',
data:{id:parent_id},
type:"GET",
dataType:"json",
success: function(res){
var hang = res.data;
var str = "";
for(var i=0;i<hang.length;i++)
{
if(select_id != 0 && select_id == hang[i].id)
{
str = str+"<option selected='selected' value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
else
{
str = str+"<option value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
}
$("#shi").html(str);
}
});
}
//加载区的方法
function LoadQu(parent_id,select_id)
{
//找区的父级代号
parent_id = parent_id || $("#shi").val();
select_id = select_id || 0;
$.ajax({
url:'<?php echo env('APP_API_URL')."/region_list"; ?>',
data:{id:parent_id},
type:"GET",
dataType:"json",
success: function(res){
var hang = res.data;
var str = "";
for(var i=0;i<hang.length;i++)
{
if(select_id != 0 && select_id == hang[i].id)
{
str = str+"<option selected='selected' value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
else
{
str = str+"<option value='"+hang[i].id+"'>"+hang[i].name+"</option>";
}
}
$("#qu").html(str);
}
});
}
</script>
</div>
<div class="adr-form-group">
<label for="doc-ta-1">详细地址</label>

6
routes/web.php

@ -105,6 +105,9 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
//商品
Route::get('/goods_list', 'GoodsController@goodsList'); //商品列表
Route::get('/goodstype_list', 'GoodsTypeController@goodsTypeList'); //商品分类列表
//地区,省市区
Route::get('/region_list', 'RegionController@regionList');
Route::get('/region_detail', 'RegionController@regionDetail');
});
//API接口路由,需token验证
@ -170,9 +173,6 @@ Route::group(['prefix' => 'dataapi', 'namespace' => 'Api', 'middleware' => ['web
Route::post('/user_address_add', 'UserAddressController@userAddressAdd');
Route::post('/user_address_update', 'UserAddressController@userAddressUpdate');
Route::post('/user_address_delete', 'UserAddressController@userAddressDelete');
//地区,省市区
Route::get('/region_list', 'RegionController@regionList');
Route::get('/region_detail', 'RegionController@regionDetail');
});

Loading…
Cancel
Save