HTML代码:
<label class="layui-form-label">物流公司</label>
<div class="layui-input-inline">
<select class="select" name="company" id="company" lay-filter="company">
<option value="">--请选择物流公司--</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">物流网点</label>
<div class="layui-input-inline">
<select id="companyUrl" name="companyUrl" class="select" lay-filter="companyUrl">
<option value="">--请选择物流公司网点--</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">送货人员</label>
<div class="layui-input-inline">
<select id="personnel" name="personnel" class="select" lay-filter="personnel">
<option value="">--请选择送货人员--</option>
</select>
</div>
</div>
script部分代码:
layui.use(['jquery', 'form'], function () {
var form = layui.form
, $ = layui.jquery;
test();
function test() {
/*$('#company').html("");*/
$.ajax({
url: "/aaa/aaa",
type: "post",
dataType: "json",
contentType: "application/json",
async: false,//同步
success: function (result) {
$.each(result.data, function (i, item) {
$('#company').append('<option value=' + item.id + '>' + item.name + '</option>');
})
}
})
form.render();
}
form.on('select(company)', function (data) {
var id = data.value;
$('#companyUrl').empty();
$('#companyUrl').append('<option value="">--请选择物流公司网点--</option>');
$.ajax({
url: '/aaa/aaa?id=' + id,//带参数将这个传到后台条件查询方法里面
type: "post",
dataType: "json",
contentType: "application/json",
async: false,//同步
success: function (result) {
if (result.code === "00") {
$.each(result.data, function (i, item) {
$('#companyUrl').append('<option value=' + item.id + '>' + item.address + '</option>');
})
} else {
$('#companyUrl').empty();
$('#companyUrl').append('<option value="">--暂无网点--</option>');
}
}
})
form.render();
});
form.on('select(companyUrl)', function (data) {
var id = data.value;
$('#personnel').empty();
$('#personnel').append('<option value="">--请选择送货人员--</option>');
$.ajax({
url: '/aaa/aaa?id=' + id,//带参数将这个传到后台条件查询方法里面
type: "post",
dataType: "json",
contentType: "application/json",
async: false,//同步
success: function (result) {
if (result.code === "00") {
$.each(result.data, function (i, item) {
$('#personnel').append('<option value=' + item.id + '>' + item.name + "-" + item.phone + '</option>');
})
} else {
$('#personnel').empty();
$('#personnel').append('<option value="">--暂无送货人员--</option>');
}
}
})
form.render();
})
});