fastadmin下拉框联动,地址表加另一个关联表
新增页面:add.html
控制器:Ajax.php
/**
* 读取分类数据,联动列表
*/
public function engineer()
{
$province = $this->request->get('province', '');
$city = $this->request->get('city', '');
$area = $this->request->get('area');
$where = [];
if ($province !== '' && $city !== '' && $area !== '') {
$where['province_id'] = $province;
$where['city_id'] = $city;
$where['area_id'] = $area;
}
if ($area) {
$where['area_id'] = $area;
}
$engineerlist = Db::name('engineers')->where($where)->field('id as value,name,beizhu,mobile')->select();
foreach ($engineerlist as $key => $value) {
$engineerlist[$key]['name'] = $value['name'] . '(' . $value['beizhu'] . $value['mobile'].')';
unset($engineerlist[$key]['beizhu']);
unset($engineerlist[$key]['mobile']);
}
$this->success('', '', $engineerlist);
}
/**
* 读取省市区数据,联动列表
*/
public function area()
{
$params = $this->request->get("row/a");
if (!empty($params)) {
$province = isset($params['province']) ? $params['province'] : '';
$city = isset($params['city']) ? $params['city'] : '';
} else {
$province = $this->request->get('province', '');
$city = $this->request->get('city', '');
}
$where = ['pid' => 0, 'level' => 1];
$provincelist = null;
if ($province !== '') {
$where['pid'] = $province;
$where['level'] = 2;
if ($city !== '') {
$where['pid'] = $city;
$where['level'] = 3;
}
}
$provincelist = Db::name('area')->where($where)->field('id as value,name')->select();
$this->success('', '', $provincelist);
}