1 标签部分使用带搜索的下拉框
<div class="layui-inline"><label class="layui-form-label">单位</label><div class="layui-input-inline"><select name="org" lay-search id="org_dwbh" lay-filter="org_dwbh"></select></div>
</div>
2 编写数据加载方法
function DWInfoInit(isShow) {let bElement = $('#org_dwbh').parent().find('input'); new Promise((resolve, reject) => {let bContent = $(bElement).val();$.ajax({type: 'post',async: false,url: `***`,data: { Content: bContent, Num: 10 },success: function (res) {if (res.Code == 0) {resolve(res);} else {reject('单位信息获取异常');}},error: function (err) {reject('网络异常');}});}).then(res => {return new Promise((resolve, reject) => {let bValue = $(bElement).val();let bCount = res.Data.length;let bData = res.Data;let bContent = `<option value="">-请选择-</option>`;for (let i = 0; i < bCount; i++) {let bInfo = bData[i];bContent += `<option value="${bInfo.DWBH}">${bInfo.MC}(编号:${bInfo.DWBH})</option>`;}$('#org_dwbh').html(bContent);bForm.render();resolve(bValue);});}).then(res => {return new Promise((resolve, reject) => {if (checkMobile()) {$('#org_dwbh').parent().find('input').on('input', function () {DWInfoInit(true);});} else {$('#org_dwbh').parent().find('input').on('compositionend', function () {DWInfoInit(true);});}resolve(res);});}).then(res => {return new Promise((resolve, reject) => {$('#org_dwbh').parent().find('input').val(res);$('#org_dwbh').parent().find('input').focus();if (isShow) {$('#org_dwbh').next().addClass("layui-form-selected");}});}).catch(err => {bLayer.msg(err);});}