业务是这样的,当选择责任人时,同步选择后面的责任部门。因为 JeeSite 选择用户信息时,默认是包含部门信息的。
如 HTML 代码:
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required">*</span> ${text('责任人')}:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:treeselect id="dutyUserCode" title="${text('用户选择')}"
path="dutyUserCode.userCode" labelPath="dutyUserCode.userName"
url="${ctx}/sys/office/treeData?isLoadUser=true"
class="required" allowClear="true" callbackFuncName="dutyUserCodeCallback" />
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required">*</span> ${text('责任部门')}:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:treeselect id="dutyDepartmentCode" title="${text('机构选择')}"
path="dutyDepartmentCode.officeCode" labelPath="dutyDepartmentCode.officeName"
url="${ctx}/sys/office/treeData" class="required" allowClear="true"/>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required">*</span> ${text('责任人')}:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:treeselect id="dutyUserCode" title="${text('用户选择')}"
path="dutyUserCode.userCode" labelPath="dutyUserCode.userName"
url="${ctx}/sys/office/treeData?isLoadUser=true"
class="required" allowClear="true" callbackFuncName="dutyUserCodeCallback" />
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label col-sm-4" title="">
<span class="required">*</span> ${text('责任部门')}:<i class="fa icon-question hide"></i></label>
<div class="col-sm-8">
<#form:treeselect id="dutyDepartmentCode" title="${text('机构选择')}"
path="dutyDepartmentCode.officeCode" labelPath="dutyDepartmentCode.officeName"
url="${ctx}/sys/office/treeData" class="required" allowClear="true"/>
</div>
</div>
</div>
<div class="col-xs-6"> <div class="form-group"> <label class="control-label col-sm-4" title=""> <span class="required">*</span> ${text('责任人')}:<i class="fa icon-question hide"></i></label> <div class="col-sm-8"> <#form:treeselect id="dutyUserCode" title="${text('用户选择')}" path="dutyUserCode.userCode" labelPath="dutyUserCode.userName" url="${ctx}/sys/office/treeData?isLoadUser=true" class="required" allowClear="true" callbackFuncName="dutyUserCodeCallback" /> </div> </div> </div> <div class="col-xs-6"> <div class="form-group"> <label class="control-label col-sm-4" title=""> <span class="required">*</span> ${text('责任部门')}:<i class="fa icon-question hide"></i></label> <div class="col-sm-8"> <#form:treeselect id="dutyDepartmentCode" title="${text('机构选择')}" path="dutyDepartmentCode.officeCode" labelPath="dutyDepartmentCode.officeName" url="${ctx}/sys/office/treeData" class="required" allowClear="true"/> </div> </div> </div>
通过设置 人员选择的回调, callbackFuncName=”dutyUserCodeCallback”:
/**
* 选择回调方法
* @param id 标签的id
* @param act 动作事件:ok、clear、cancel
* @param index layer的索引号
* @param layero layer内容的jQuery对象
* @param nodes 当前选择的树节点数组
*/
function dutyUserCodeCallback(id, act, index, layero, nodes){
if (act ==='ok') {
let parent = nodes[0].getParentNode();
$("#dutyDepartmentCodeName").val(parent.name);
$("#dutyDepartmentCodeCode").val(parent.id);
}
if (act === 'clear') {
$("#dutyDepartmentCodeName").val('');
$("#dutyDepartmentCodeCode").val('');
}
}
/**
* 选择回调方法
* @param id 标签的id
* @param act 动作事件:ok、clear、cancel
* @param index layer的索引号
* @param layero layer内容的jQuery对象
* @param nodes 当前选择的树节点数组
*/
function dutyUserCodeCallback(id, act, index, layero, nodes){
if (act ==='ok') {
let parent = nodes[0].getParentNode();
$("#dutyDepartmentCodeName").val(parent.name);
$("#dutyDepartmentCodeCode").val(parent.id);
}
if (act === 'clear') {
$("#dutyDepartmentCodeName").val('');
$("#dutyDepartmentCodeCode").val('');
}
}
/** * 选择回调方法 * @param id 标签的id * @param act 动作事件:ok、clear、cancel * @param index layer的索引号 * @param layero layer内容的jQuery对象 * @param nodes 当前选择的树节点数组 */ function dutyUserCodeCallback(id, act, index, layero, nodes){ if (act ==='ok') { let parent = nodes[0].getParentNode(); $("#dutyDepartmentCodeName").val(parent.name); $("#dutyDepartmentCodeCode").val(parent.id); } if (act === 'clear') { $("#dutyDepartmentCodeName").val(''); $("#dutyDepartmentCodeCode").val(''); } }
通过 nodes[0].getParentNode() 获取父结点信息,以拿到部门信息。