#region 下拉樹菜單
/// <summary>
/// 獲取工作人員樹菜單
/// </summary>
/// <param name="addid"></param>
/// <param name="unitid"></param>
/// <returns></returns>
public string GetUserMenu(int addid)
{
AID_UNIT_DAL unitdal = AID_UNIT_DAL._();
decimal unitid = this.CurrentUnitId;
List<AID_UNIT> unitList = unitdal.GetList().Where(c => c.UNITID == unitid).ToList();
List<Menu> menulist = new List<Menu>();
if (unitList.Count > 0)
{
Menu menu = new Menu();
foreach (var page in unitList)
{
menu.id = page.UNITID.ToString();
menu.text = page.UNITNAME;
var count = unitList.Where(c => c.PARENTUNIT == page.UNITID).Count();
if (count > 0)
{
menu.state = "closed";
BindMenu(menu, unitid);
}
BindStaffMenu(menu, unitid);
menulist.Add(menu);
}
}
string js = JsonMapper.ToJson(menulist);
return js;
}
/// <summary>
/// 綁定用戶信息
/// </summary>
/// <param name="staffMenu"></param>
/// <param name="unitid"></param>
private void BindStaffMenu(Menu staffMenu, decimal unitid)
{
INFO_STAFF_DAL staffdal = INFO_STAFF_DAL._();
List<INFO_STAFF> staffList = staffdal.GetList().Where(c => c.WORKUNIT == unitid).ToList();
foreach (var staff in staffList)
{
Menu childMenu = new Menu();
childMenu.id = staff.STAFFID.ToString();
childMenu.text = staff.STAFFNAME;
//遞歸綁定
// BindStaffMenu(childMenu,unitid);
//給父菜單添加子菜單
staffMenu.children.Add(childMenu);
}
}
/// <summary>
/// 綁定子單位
/// </summary>
/// <param name="parentMenu"></param>
private void BindMenu(Menu parentMenu, decimal unitid)
{
AID_UNIT_DAL unitdal = AID_UNIT_DAL._();
List<AID_UNIT> secondary = unitdal.GetList().Where(p => p.PARENTUNIT == unitid).ToList();
foreach (var second in secondary)
{
Menu childMenu = new Menu();
childMenu.id = second.UNITID.ToString();
childMenu.text = second.UNITNAME;
var count = secondary.Where(c => c.PARENTUNIT == second.UNITID).Count();
if (count > 0)
childMenu.state = "closed";
//遞歸綁定
BindMenu(childMenu, unitid);
//給父菜單添加子菜單
parentMenu.children.Add(childMenu);
}
}
//定義菜單類
private class Menu
{
private string _id;
private string _text;
private string _state;
private List<Menu> _children = new List<Menu>();
public string id { get { return _id; } set { _id = value; } }
public string text { get { return _text; } set { _text = value; } }
public string state { get { return _state; } set { _state = value; } }
public List<Menu> children { get { return _children; } set { _children = value; } }
}
#endregion
/// <summary>
/// 初始化單位下列樹菜單
/// </summary>
/// <param name="addid">addid>0時,下拉樹菜單含“頂級菜單”,addid<0時,下拉樹菜單不含“頂級菜單”</param>
/// <returns></returns>
public ActionResult getReletiveUser(int addid)
{
string js = GetUserMenu(addid);
return Content(js, "application/json");
}
<script type="text/javascript">
$("#USID").tree({
url: "/SystemMng/getReletiveUser?addid=" + 0,
required: true,
panelHeight: 120,
checkbox: true,
onBeforeSelect: function (node) {
if (node.state == "open") {
$("#hidUnit").val(node.id);
} else {
alert("請選擇子單位!")
}
}
});
</script>
<ul class="easyui-tree" type="text" name="USID" id="USID" style="width:100%; height:34px; margin-left:15px;" data-options="">