新增级联下载
This commit is contained in:
parent
d3d48fb343
commit
63c2c3745d
@ -663,6 +663,105 @@ function LayuiUtil(layui, viewer) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 级联下拉
|
||||||
|
* @param opt
|
||||||
|
*/
|
||||||
|
this.selectLinkage = function(opt) {
|
||||||
|
var self = this;
|
||||||
|
// 级联url
|
||||||
|
var url = opt.url;
|
||||||
|
// option key
|
||||||
|
var valueKey = opt.valueKey;
|
||||||
|
// option text key
|
||||||
|
var nameKey = opt.nameKey;
|
||||||
|
var optionDataKeyArray = opt.optionDataKeyArray && (opt.optionDataKeyArray instanceof Array) ? opt.optionDataKeyArray : [];
|
||||||
|
// 级联数量
|
||||||
|
var linkageSize = opt.linkageSize ? opt.linkageSize : 1;
|
||||||
|
// 选择ID
|
||||||
|
var selectId = opt.selectId;
|
||||||
|
var baseRootId = opt.baseRootId;
|
||||||
|
var onSelect = opt.onSelect && typeof(opt.onSelect) === 'function' ? opt.onSelect : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
* @param parentId 上级ID
|
||||||
|
* @param selectIndex 选择下标
|
||||||
|
*/
|
||||||
|
function initSelect(parentId, selectIndex) {
|
||||||
|
if(parentId === '') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var refreshSelectId = (selectId + parseInt(selectIndex));
|
||||||
|
top.restAjax.get(top.restAjax.path(url, [parentId]), {}, null, function(code, data) {
|
||||||
|
$('#'+ refreshSelectId).append('<option value="">请选择</option>');
|
||||||
|
$.each(data, function (index, item) {
|
||||||
|
// option携带的值
|
||||||
|
var optionDatas = '';
|
||||||
|
for(var i = 0, optionDataKey; optionDataKey = optionDataKeyArray[i++];) {
|
||||||
|
var optionDataValue = item[optionDataKey];
|
||||||
|
if(!optionDataValue) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
optionDatas += ' data-data'+ i +'="'+ item[optionDataKey] +'"';
|
||||||
|
}
|
||||||
|
$('#'+ refreshSelectId).append('<option value="'+ item[valueKey] +'"'+ optionDatas +'>'+ item[nameKey] +'</option>');
|
||||||
|
});
|
||||||
|
// 渲染表单下拉框
|
||||||
|
form.render('select');
|
||||||
|
}, function(code, data) {
|
||||||
|
top.dialog.msg(data.msg);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 初始化级联事件
|
||||||
|
* @param selectId 选择ID
|
||||||
|
* @param size 级联长度
|
||||||
|
*/
|
||||||
|
function addLinkageEvent() {
|
||||||
|
for(var i = 0; i < linkageSize; i++) {
|
||||||
|
form.on('select('+ (selectId + i) +'Select)', function(data) {
|
||||||
|
var index = parseInt(data.elem.id.replace(selectId, ''));
|
||||||
|
var nextIndex = index + 1;
|
||||||
|
// 级联清空
|
||||||
|
for(var j = nextIndex; j < linkageSize; j++) {
|
||||||
|
$('#'+ (selectId + j)).empty();
|
||||||
|
}
|
||||||
|
form.render('select');
|
||||||
|
// 最后一个不触发初始化事件
|
||||||
|
if(index < (linkageSize - 1)) {
|
||||||
|
initSelect(data.value, nextIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(onSelect) {
|
||||||
|
var option = self.selectedOption('#'+ data.elem.id, data.value);
|
||||||
|
onSelect(data, option, index);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initSelect(baseRootId, 0);
|
||||||
|
addLinkageEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地区级联下拉
|
||||||
|
* @param opt
|
||||||
|
*/
|
||||||
|
this.selectLinkageArea = function(opt) {
|
||||||
|
this.selectLinkage({
|
||||||
|
url: 'api/area/listbyparentid/{parentId}',
|
||||||
|
valueKey: 'areaId',
|
||||||
|
nameKey: 'areaName',
|
||||||
|
linkageSize: opt.linkageSize ? opt.linkageSize : 5,
|
||||||
|
baseRootId: opt.baseRootId,
|
||||||
|
selectId: opt.selectId,
|
||||||
|
optionDataKeyArray: opt.optionDataKeyArray,
|
||||||
|
onSelect: opt.onSelect && typeof(opt.onSelect) === 'function' ? opt.onSelect : null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 禁用表单全部字段
|
* 禁用表单全部字段
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user