123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- layui.define(['jquery', 'layer', 'uParas', 'form', 'admin', 'zTree', 'formSelects', 'iconPicker'], function (exports) {
- var $ = layui.$, uParas = layui.uParas, iconPicker = layui.iconPicker, form = layui.form;
- admin = layui.admin, formSelectsFormSelectsV4 = layui.formSelects;
- var _g = {
- init: function (insTb) {
- var setting = {
- check: {
- enable: false,
- chkboxType: {"Y": "", "N": ""}
- },
- view: {
- dblClickExpand: false
- },
- data: {
- simpleData: {
- enable: true,
- idKey: "gId",
- pIdKey: "groupParent",
- rootPId: null
- },
- key: {
- name: "groupName"
- }
- },
- callback: {
- onClick: onClick
- }
- };
- /**
- * ztree 文本下拉
- */
- admin.req(uParas.baseUrl + '/admin/common/getGroupLists', {}, function (res) {
- if (res.code == 1) {
- $.fn.zTree.init($('#groupTree'), setting, res.data);
- $.fn.zTree.getZTreeObj("groupTree").expandAll(true);
- layer.closeAll('loading');
- hideMenu();
- }
- }, 'get');
- function onClick(event, treeId, treeNode, clickFlag) {
- var zTree = $.fn.zTree.getZTreeObj("groupTree"),
- nodes = zTree.getSelectedNodes(),
- v = "", idlist = "";
- for (var i = 0, l = nodes.length; i < l; i++) {
- v += nodes[i].groupName + ",";
- idlist += nodes[i].gId + ",";
- }
- if (v.length > 0) {
- v = v.substring(0, v.length - 1);
- idlist = idlist.substring(0, idlist.length - 1);
- }
- var cityObj = $("#groupName");
- if (cityObj.val() == v) {
- cityObj.attr("value", "点击选择");
- $("#groupId").attr("value", "");
- } else {
- cityObj.attr("value", v);
- $("#groupId").attr("value", idlist);
- }
- hideMenu();
- var groupId = idlist;
- if (groupId != "-1") {
- var Obj = new Object();
- Obj.gId = groupId;
- if (insTb != null && insTb != undefined) {
- insTb.reload({where: Obj}, 'data');
- }
- }
- }
- function hideMenu() {
- $("#menuContent").fadeOut("fast");
- $("body").unbind("mousedown", onBodyDown);
- }
- $("#groupName").click(function () {
- $("#menuContent").slideDown("fast");
- $("body").bind("mousedown", onBodyDown);
- });
- function onBodyDown(event) {
- if (!(event.target.id === "groupName" || event.target.id === "menuContent" || $(event.target).parents("#menuContent").length > 0)) {
- hideMenu();
- }
- }
- },
- initgroupTreeAndUsers: function (groupUrl, groupTree, groupName, groupId, menuContent,divName, formFilter, valStr) {
- var setting = {
- check: {
- enable: false,
- chkboxType: {"Y": "", "N": ""}
- },
- view: {
- dblClickExpand: false
- },
- data: {
- simpleData: {
- enable: true,
- idKey: "gId",
- pIdKey: "groupParent",
- rootPId: null
- },
- key: {
- name: "groupName"
- }
- },
- callback: {
- onClick: onClick
- }
- };
- /**
- * ztree 文本下拉
- */
- $.getJSON(uParas.baseUrl + groupUrl, {}, function (res) {
- if (res.code == 1) {
- $.fn.zTree.init($('#' + groupTree), setting, res.data);
- $.fn.zTree.getZTreeObj(groupTree).expandAll(true);
- //初始化已选中的值
- if (valStr != undefined && valStr != ''){
- initChecked();
- }
- layer.closeAll('loading');
- hideMenu();
- }
- });
- function onClick(event, treeId, treeNode, clickFlag) {
- var zTree = $.fn.zTree.getZTreeObj(groupTree),
- nodes = zTree.getSelectedNodes(),
- v = "", idlist = "";
- for (var i = 0, l = nodes.length; i < l; i++) {
- v += nodes[i].groupName + ",";
- idlist += nodes[i].gId + ",";
- }
- if (v.length > 0) {
- v = v.substring(0, v.length - 1);
- idlist = idlist.substring(0, idlist.length - 1);
- }
- var cityObj = $("#" + groupName);
- if (cityObj.val() == v) {
- cityObj.attr("value", "");
- $("#" + groupId).attr("value", "");
- } else {
- cityObj.attr("value", v);
- $("#" + groupId).attr("value", idlist);
- }
- hideMenu();
- var groupId_ = idlist;
- if (groupId_ != "-1") {
- var Obj = new Object();
- Obj.gId = groupId_;
- //初始化人员
- initUsers(groupId_);
- }
- }
- function initChecked() {
- debugger
- var groupName_ = $("#" + groupName).val();
- var groupId_ = $("#" + groupId).val();
- var zTree = $.fn.zTree.getZTreeObj(groupTree);
- var checkeds = zTree.getNodes();
- //遍历所有节点
- $(checkeds).each(function (i) {
- //判断得到 中国 这个节点
- if (zTree.getNodes()[i].groupName == groupName_ || zTree.getNodes()[i].gId == groupId_) {
- // 1. 勾选这个节点
- zTree.checkNode(zTree.getNodes()[i], true, true);
- // 2.设置文本域
- //设置执行区域显示的文本
- $("#" + groupName).val(zTree.getNodes()[i].groupName);
- //设置执行区域实际获得的值
- $("#" + groupId).val(zTree.getNodes()[i].gId);
- }
- });
- //初始化已选中的人员
- initUsers(groupId_);
- }
- function initUsers(groupId_) {
- admin.req(uParas.baseUrl + '/admin/common/getUsersByGroupId?gId=' + groupId_, {}, function (res) {
- if (res.code == 1) {
- // $("#" + divName + "").attr("lay-verify", 'required');
- var html = '<option value="">==请选择==</option>';
- $.each(res.data, function (i, v) {
- if (valStr == v["aId"]) {
- html += '<option value="' + v["aId"] + '" selected>' + v["accountRealName"] + '</option>';
- } else {
- html += '<option value="' + v["aId"] + '">' + v["accountRealName"] + '</option>';
- }
- });
- $("#" + divName + "").html(html);
- form.render('select', formFilter);
- }
- }, 'get');
- }
- function hideMenu() {
- $("#" + menuContent).fadeOut("fast");
- $("body").unbind("mousedown", onBodyDown);
- }
- $("#" + groupName).click(function () {
- $("#" + menuContent).slideDown("fast");
- $("body").bind("mousedown", onBodyDown);
- });
- function onBodyDown(event) {
- if (!(event.target.id === groupName || event.target.id === menuContent || $(event.target).parents("#" + menuContent).length > 0)) {
- hideMenu();
- }
- }
- },
- /**初始化部门过滤*/
- initGroupColation: function (insTb, groupUrl, groupTree, groupName, groupId, menuContent) {
- /**
- * ztree 文本下拉
- */
- admin.req(uParas.baseUrl + groupUrl, {}, function (res) {
- if (res.code == 1) {
- $.fn.zTree.init($('#' + groupTree), setting, res.data);
- $.fn.zTree.getZTreeObj(groupTree).expandAll(true);
- //初始化已选中的值
- initChecked();
- layer.closeAll('loading');
- hideMenu();
- }
- }, 'get');
- var setting = {
- check: {
- enable: false,
- chkboxType: {"Y": "", "N": ""}
- },
- view: {
- dblClickExpand: false
- },
- data: {
- simpleData: {
- enable: true,
- idKey: "gId",
- pIdKey: "groupParent",
- rootPId: null
- },
- key: {
- name: "groupName"
- }
- },
- callback: {
- onClick: onClick
- }
- };
- function onClick(event, treeId, treeNode, clickFlag) {
- var zTree = $.fn.zTree.getZTreeObj(groupTree),
- nodes = zTree.getSelectedNodes(),
- v = "", idlist = "";
- for (var i = 0, l = nodes.length; i < l; i++) {
- v += nodes[i].groupName + ",";
- idlist += nodes[i].gId + ",";
- }
- if (v.length > 0) {
- v = v.substring(0, v.length - 1);
- idlist = idlist.substring(0, idlist.length - 1);
- }
- var cityObj = $("#" + groupName);
- if (cityObj.val() == v) {
- cityObj.attr("value", "");
- $("#" + groupId).attr("value", "");
- } else {
- cityObj.attr("value", v);
- $("#" + groupId).attr("value", idlist);
- }
- hideMenu();
- var groupId_ = idlist;
- if (groupId_ != "-1") {
- var Obj = new Object();
- Obj.gId = groupId_;
- }
- if (insTb != null && insTb != undefined && insTb != '') {
- insTb.reload({where: Obj}, 'data');
- }
- }
- function initChecked() {
- var groupName_ = $("#" + groupName).val();
- var groupId_ = $("#" + groupId).val();
- var zTree = $.fn.zTree.getZTreeObj(groupTree);
- var checkeds = zTree.getNodes();
- //遍历所有节点
- $(checkeds).each(function (i) {
- //判断得到 中国 这个节点
- if (zTree.getNodes()[i].groupName == groupName_ || zTree.getNodes()[i].groupId == groupId_) {
- // 1. 勾选这个节点
- zTree.checkNode(zTree.getNodes()[i], true, true);
- // 2.设置文本域
- //设置执行区域显示的文本
- $("#" + groupName).val(zTree.getNodes()[i].groupName);
- //设置执行区域实际获得的值
- $("#" + groupId).val(zTree.getNodes()[i].gId);
- }
- });
- }
- function hideMenu() {
- $("#" + menuContent).fadeOut("fast");
- $("body").unbind("mousedown", onBodyDown);
- }
- $("#" + groupName).click(function () {
- $("#" + menuContent).slideDown("fast");
- $("body").bind("mousedown", onBodyDown);
- });
- function onBodyDown(event) {
- if (!(event.target.id === groupName || event.target.id === menuContent || $(event.target).parents("#" + menuContent).length > 0)) {
- hideMenu();
- }
- }
- }
- }
- exports("_groupTree", _g);
- });
|