You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
519 lines
19 KiB
Plaintext
519 lines
19 KiB
Plaintext
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title></title>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
|
|
<script src="../../Scripts/jquery-1.11.0.min.js" type="text/javascript"></script>
|
|
<script type="text/javascript" src="../../Scripts/QueryString.js"></script>
|
|
<script type="text/javascript" src="../../Scripts/config.js"></script>
|
|
<script type="text/javascript" src="../../Comm/Gener.js"></script>
|
|
<script src="../../Scripts/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
|
<link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
|
|
<link href="../../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" type="text/css" />
|
|
|
|
<script src="../../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.js" type="text/javascript"></script>
|
|
<link href="../../Scripts/bootstrap/bootstrap-table/src/bootstrap-table.css" rel="stylesheet" type="text/css" />
|
|
<script src="../../Scripts/bootstrap/bootstrap-table/src/locale/bootstrap-table-zh-CN.js" type="text/javascript"></script>
|
|
|
|
<script src="../../Scripts/bootstrap/bootstrap-treeview/src/js/bootstrap-treeview.js" type="text/javascript"></script>
|
|
<link href="../../Scripts/bootstrap/bootstrap-treeview/src/css/bootstrap-treeview.css" rel="stylesheet" type="text/css" />
|
|
<style type="text/css">
|
|
.row-margin-top {
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.search-margin {
|
|
margin-top: 15px;
|
|
}
|
|
</style>
|
|
<script type="text/javascript">
|
|
var mapExt = null;
|
|
var saveType = GetQueryString("SaveType");
|
|
if (saveType == null || saveType == undefined || saveType == "" || saveType == "0")
|
|
saveType = 0;
|
|
else
|
|
saveType = 1;
|
|
|
|
var para = GetQueryString("Para");
|
|
if (para == null || para == undefined || para == "")
|
|
para = null;
|
|
var paraVal = GetQueryString("ParaVal");
|
|
var para1 = GetQueryString("Para1");
|
|
if (para1 == null || para1 == undefined || para1 == "")
|
|
para1 = null;
|
|
var paraVal1 = GetQueryString("ParaVal1");
|
|
|
|
|
|
//存储在一个字段的集合
|
|
var selectRows = ",";
|
|
|
|
var rootNo;
|
|
$(function () {
|
|
|
|
//global
|
|
var global = window;
|
|
global.selectedNodes = [];
|
|
global.selectedRows = [];
|
|
|
|
var pkval = GetQueryString("PKVal");
|
|
|
|
var tip = "请输入关键字"; //mapExt.GetPara("SearchTip");
|
|
$("#TB_Key").attr("placeholder", tip); //设置查询提示.
|
|
|
|
//跟节点编号.
|
|
rootNo = "0";
|
|
if (rootNo == "@WebUser.FK_Dept") {
|
|
var webUser = new WebUser();
|
|
rootNo = webUser.FK_Dept;
|
|
}
|
|
|
|
if (rootNo == "")
|
|
rootNo = "0";
|
|
|
|
//多对多实体.
|
|
var dot2DotEnsName = new Entities(GetQueryString("Dot2DotEnsName"));
|
|
|
|
var dot2DotEnName = new Entities(GetQueryString("Dot2DotEnName"));
|
|
|
|
if (para == null)
|
|
dot2DotEnsName.Retrieve(GetQueryString("AttrOfOneInMM"), pkval);
|
|
else if (para1 == null)
|
|
dot2DotEnsName.Retrieve(GetQueryString("AttrOfOneInMM"), pkval, para, paraVal);
|
|
else
|
|
dot2DotEnsName.Retrieve(GetQueryString("AttrOfOneInMM"), pkval, para, paraVal, para1, paraVal1);
|
|
|
|
if (saveType == 1) {
|
|
if (dot2DotEnsName.length != 0) {
|
|
selectRows = dot2DotEnsName[0][GetQueryString("AttrOfMInMM")];
|
|
var strs = selectRows.split(",");
|
|
for (var i = 0; i < strs.length; i++) {
|
|
if (strs[i] == "")
|
|
continue;
|
|
global.selectedNodes.push({
|
|
"No": strs[i]
|
|
});
|
|
}
|
|
}
|
|
} else {
|
|
$.each(dot2DotEnsName, function (i, o) {
|
|
|
|
var enDot = new Entity(dot2DotEnName, o);
|
|
|
|
var no = enDot[GetQueryString("AttrOfMInMM")];
|
|
var name = enDot[GetQueryString("AttrOfMInMM") + "Text"];
|
|
global.selectedNodes.push({
|
|
"No": no,
|
|
"Name": name
|
|
});
|
|
});
|
|
}
|
|
|
|
|
|
// search
|
|
$("#TB_Key").on("keyup", function () {
|
|
|
|
var keyWord = $(this).val();
|
|
if (keyWord == "") {
|
|
$('#viewGrid_Panel').hide();
|
|
$('#tree_Panel').show();
|
|
return;
|
|
}
|
|
loadViewGrid(keyWord);
|
|
|
|
});
|
|
|
|
|
|
$('#viewGrid_Panel').hide();
|
|
$('#tree_Panel').show();
|
|
|
|
loadTree(rootNo, global);
|
|
|
|
});
|
|
|
|
//树形结构转换
|
|
var treeJson = [];
|
|
function createJsonToTree(jsonArray, parentNo) {
|
|
for (var i = 0; i < jsonArray.length; i++) {
|
|
var data = jsonArray[i];
|
|
if (data.ParentNo == parentNo) {
|
|
var checked = false;
|
|
var selectedNodes = window.selectedNodes;
|
|
var sel = $.grep(selectedNodes, function (obj) {
|
|
return data.No == obj.No;
|
|
});
|
|
|
|
if (sel.length > 0) {
|
|
checked = true;
|
|
}
|
|
treeJson.push({
|
|
"id": data.No,
|
|
"text": data.Name,
|
|
"nodes": creatTreeChildern(jsonArray, data.No),
|
|
"state": { checked: checked, disabled: false }
|
|
});
|
|
}
|
|
}
|
|
function _(treeArray) {
|
|
$.each(treeArray, function (i, o) {
|
|
if ($.isArray(o.nodes)) {
|
|
if (o.nodes.length == 0) {
|
|
o.nodes = undefined;
|
|
} else {
|
|
_(o.nodes);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
_(treeJson);
|
|
return treeJson;
|
|
}
|
|
|
|
function creatTreeChildern(jsonArray, parentNo) {
|
|
var childList = []
|
|
for (var i = 0; i < jsonArray.length; i++) {
|
|
var data = jsonArray[i];
|
|
if (data.ParentNo == parentNo) {
|
|
var checked = false;
|
|
var selectedNodes = window.selectedNodes;
|
|
var sel = $.grep(selectedNodes, function (obj) {
|
|
return data.No == obj.No;
|
|
});
|
|
|
|
if (sel.length > 0) {
|
|
checked = true;
|
|
}
|
|
childList.push({
|
|
"id": data.No,
|
|
"text": data.Name,
|
|
"nodes": creatTreeChildern(jsonArray, data.No),
|
|
"state": { checked: checked, disabled: false }
|
|
});
|
|
}
|
|
}
|
|
|
|
return childList;
|
|
}
|
|
|
|
|
|
function loadTree(rootNo, global) {
|
|
|
|
var ens = new Entities(GetQueryString("EnsOfM")); //BP.Port.Depts
|
|
ens.RetrieveAll();
|
|
var jsonTree = createJsonToTree(ens, rootNo);
|
|
$('#tree').treeview({
|
|
data: jsonTree, // 数据源
|
|
showCheckbox: true, //是否显示复选框
|
|
highlightSelected: false, //是否高亮选中
|
|
//nodeIcon: 'glyphicon glyphicon-user', //节点上的图标
|
|
nodeIcon: 'glyphicon',
|
|
emptyIcon: '', //没有子节点的节点图标
|
|
multiSelect: false, //多选
|
|
onNodeChecked: function (event, node) {
|
|
var selectNodes = getChildNodeIdArr(node, true); //获取所有子节点
|
|
if (selectNodes.length > 0) { //子节点不为空,则选中所有子节点
|
|
$('#tree').treeview('checkNode', [selectNodes, { silent: true }]);
|
|
saveCheckNodes(selectNodes, 1);
|
|
}
|
|
|
|
var en = new Entity(GetQueryString("Dot2DotEnName"));
|
|
en[GetQueryString("AttrOfOneInMM")] = GetPKVal();
|
|
if (saveType == 1) {
|
|
if (selectRows.indexOf("," + node.id + ",") != -1)
|
|
return;
|
|
selectRows += node.id + ",";
|
|
en[GetQueryString("AttrOfMInMM")] = selectRows;
|
|
} else {
|
|
en[GetQueryString("AttrOfMInMM")] = node.id;
|
|
}
|
|
|
|
if (para != null)
|
|
en[para] = paraVal;
|
|
if (para1 != null)
|
|
en[para1] = paraVal1;
|
|
|
|
en.Save();
|
|
|
|
|
|
|
|
},
|
|
onNodeUnchecked: function (event, node) {
|
|
|
|
var selectNodes = getChildNodeIdArr(node, false); //获取所有子节点
|
|
if (selectNodes.length > 0) { //子节点不为空,则取消选中所有子节点
|
|
$('#tree').treeview('uncheckNode', [selectNodes, { silent: true }]);
|
|
deleteCheckNodes(selectNodes, 1);
|
|
}
|
|
|
|
var en = new Entity(GetQueryString("Dot2DotEnName"));
|
|
en[GetQueryString("AttrOfOneInMM")] = GetPKVal();
|
|
if (saveType == 1) {
|
|
selectRows = selectRows.replace("," + node.id + ",", ",");
|
|
en[GetQueryString("AttrOfMInMM")] = selectRows;
|
|
if (para != null)
|
|
en[para] = paraVal;
|
|
if (para1 != null)
|
|
en[para1] = paraVal1;
|
|
|
|
en.Save();
|
|
} else {
|
|
en[GetQueryString("AttrOfMInMM")] = node.id;
|
|
en.Delete(GetQueryString("AttrOfOneInMM"), GetPKVal(), GetQueryString("AttrOfMInMM"), node.id);
|
|
}
|
|
|
|
},
|
|
onNodeSelected: function (event, node) {
|
|
|
|
var tree = $('#tree');
|
|
if (node.state.expanded) {
|
|
//处于展开状态则折叠
|
|
tree.treeview('collapseNode', node.nodeId);
|
|
} else {
|
|
//展开
|
|
tree.treeview('expandNode', node.nodeId);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
//查询列表
|
|
function loadViewGrid(gridUrl) {
|
|
|
|
var global = window;
|
|
var columns = mapExt.Tag;
|
|
var searchTableColumns = [{
|
|
field: "_checkbox",
|
|
checkbox: true,
|
|
formatter: function (value, row, index) {
|
|
if (row.checked) {
|
|
return {
|
|
"checked": true,
|
|
"disabled": row.disabled
|
|
}
|
|
}
|
|
}
|
|
}];
|
|
|
|
//显示列的中文名称.
|
|
if (typeof columns == "string") {
|
|
$.each(columns.split(","), function (i, o) {
|
|
var exp = o.split("=");
|
|
var field;
|
|
var title;
|
|
if (exp.length == 1) {
|
|
field = title = exp[0];
|
|
} else if (exp.length == 2) {
|
|
field = exp[0];
|
|
title = exp[1];
|
|
}
|
|
if (!isLegalName(field)) {
|
|
return true;
|
|
}
|
|
searchTableColumns.push({
|
|
field: field,
|
|
title: title
|
|
});
|
|
});
|
|
} else {
|
|
// by default
|
|
searchTableColumns.push({
|
|
field: 'No',
|
|
title: '编号'
|
|
});
|
|
searchTableColumns.push({
|
|
field: 'Name',
|
|
title: '名称'
|
|
});
|
|
}
|
|
// grid
|
|
$('#viewGrid').bootstrapTable({
|
|
cache: false,
|
|
minimumCountColumns: 2,
|
|
clickToSelect: true,
|
|
sortable: false,
|
|
maintainSelected: true,
|
|
singleSelect: !mapExt.ShowCheckBox,
|
|
uniqueId: "No",
|
|
columns: searchTableColumns
|
|
});
|
|
|
|
var json = DBAccess.RunDBSrc(gridUrl, mapExt.DBType, mapExt.FK_DBSrc); //执行url返回json.
|
|
if ($.isArray(json)) {
|
|
$('#tree_Panel').hide();
|
|
$('#viewGrid_Panel').show();
|
|
var selectedRows = window.selectedNodes;
|
|
if ($.isArray(selectedRows)) {
|
|
$.each(json, function (i, o) {
|
|
var sel = $.grep(selectedRows, function (obj) {
|
|
return o.No == obj.No;
|
|
});
|
|
if (sel.length > 0) {
|
|
o.checked = true;
|
|
//多选时才需要禁用已选
|
|
if (mapExt.ShowCheckBox == true) {
|
|
o.disabled = true;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
$('#viewGrid').bootstrapTable("load", json);
|
|
}
|
|
}
|
|
|
|
function isLegalName(name) {
|
|
|
|
if (name == false) {
|
|
return false;
|
|
}
|
|
return name.match(/^[a-zA-Z\$_][a-zA-Z\d\$_]*$/);
|
|
}
|
|
|
|
|
|
|
|
|
|
function getChildNodeIdArr(node, checked) {
|
|
var ts = [];
|
|
if (node.nodes) {
|
|
for (x in node.nodes) {
|
|
ts.push(node.nodes[x].nodeId);
|
|
if (node.nodes[x].nodes) {
|
|
var getNodeDieDai = getChildNodeIdArr(node.nodes[x]);
|
|
for (j in getNodeDieDai) {
|
|
ts.push(getNodeDieDai[j]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return ts;
|
|
}
|
|
|
|
function setParentNodeCheck(node) {
|
|
var parentNode = $("#tree").treeview("getNode", node.parentId);
|
|
if (parentNode.nodes) {
|
|
var checkedCount = 0;
|
|
for (x in parentNode.nodes) {
|
|
if (parentNode.nodes[x].state.checked) {
|
|
checkedCount++;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
if (checkedCount === parentNode.nodes.length) {
|
|
var en = new Entity(GetQueryString("Dot2DotEnName"));
|
|
en[GetQueryString("AttrOfOneInMM")] = GetPKVal();
|
|
en[GetQueryString("AttrOfMInMM")] = parentNode.nodeId;
|
|
en.Save();
|
|
$("#tree").treeview("checkNode", parentNode.nodeId);
|
|
setParentNodeCheck(parentNode);
|
|
}
|
|
}
|
|
}
|
|
|
|
var en = null;
|
|
function saveCheckNodes(selectNodes, flag) {
|
|
if (saveType == 0) {
|
|
for (var i = 0; i < selectNodes.length; i++) {
|
|
en = new Entity(GetQueryString("Dot2DotEnName"));
|
|
en[GetQueryString("AttrOfOneInMM")] = GetPKVal();
|
|
if (flag == 0)
|
|
en[GetQueryString("AttrOfMInMM")] = selectNodes[i].id;
|
|
else
|
|
en[GetQueryString("AttrOfMInMM")] = $('#tree').treeview('getNode', selectNodes[i]).id;
|
|
en.Save();
|
|
}
|
|
return;
|
|
}
|
|
for (var i = 0; i < selectNodes.length; i++) {
|
|
|
|
|
|
if (flag == 0) {
|
|
if (selectRows.indexOf("," + selectNodes[i].id + ",") != -1)
|
|
continue;
|
|
selectRows += selectNodes[i].id + ",";
|
|
}
|
|
else {
|
|
if (selectRows.indexOf("," + $('#tree').treeview('getNode', selectNodes[i]).id+ ",") != -1)
|
|
continue;
|
|
selectRows += $('#tree').treeview('getNode', selectNodes[i]).id+",";
|
|
}
|
|
|
|
}
|
|
en = new Entity(GetQueryString("Dot2DotEnName"));
|
|
en[GetQueryString("AttrOfOneInMM")] = GetPKVal();
|
|
en[GetQueryString("AttrOfMInMM")] = selectRows;
|
|
if (para != null)
|
|
en[para] = paraVal;
|
|
if (para1 != null)
|
|
en[para1] = paraVal1;
|
|
|
|
en.Save();
|
|
|
|
}
|
|
function deleteCheckNodes(selectNodes, flag) {
|
|
if (saveType == 0) {
|
|
for (var i = 0; i < selectNodes.length; i++) {
|
|
var en = new Entity(GetQueryString("Dot2DotEnName"));
|
|
en[GetQueryString("AttrOfOneInMM")] = GetPKVal();
|
|
if (flag == 0)
|
|
en[GetQueryString("AttrOfMInMM")] = selectNodes[i].id;
|
|
else
|
|
en[GetQueryString("AttrOfMInMM")] = $('#tree').treeview('getNode', selectNodes[i]).id;
|
|
|
|
en.Delete(GetQueryString("AttrOfOneInMM"), GetPKVal(), GetQueryString("AttrOfMInMM"), en[GetQueryString("AttrOfMInMM")]);
|
|
}
|
|
return;
|
|
}
|
|
for (var i = 0; i < selectNodes.length; i++) {
|
|
|
|
if (flag == 0)
|
|
selectRows = selectRows.replace(","+selectNodes[i].id+",",",");
|
|
else
|
|
selectRows = selectRows.replace(","+$('#tree').treeview('getNode', selectNodes[i]).id+",",",");
|
|
}
|
|
en = new Entity(GetQueryString("Dot2DotEnName"));
|
|
en[GetQueryString("AttrOfOneInMM")] = GetPKVal();
|
|
en[GetQueryString("AttrOfMInMM")] = selectRows;
|
|
if (para != null)
|
|
en[para] = paraVal;
|
|
if (para1 != null)
|
|
en[para1] = paraVal1;
|
|
|
|
en.Save();
|
|
}
|
|
function CheckAll() {
|
|
$('#tree').treeview('checkAll', { silent: true });
|
|
var selectNodes = $('#tree').treeview('getChecked');
|
|
if (selectNodes) { //子节点不为空,则选中所有子节点
|
|
saveCheckNodes(selectNodes, 0);
|
|
}
|
|
|
|
}
|
|
function UnCheckAll() {
|
|
$('#tree').treeview('uncheckAll', { silent: true });
|
|
var selectNodes = $('#tree').treeview('getUnselected');
|
|
|
|
if (selectNodes) { //子节点不为空,则取消选中所有子节点
|
|
deleteCheckNodes(selectNodes, 0);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function Close() {
|
|
alert("尚未实现.");
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div class="row row-margin-top" style="width:96%;margin-left:10px">
|
|
<div id="tree" style="overflow-y:auto; overflow-x:auto; width:auto; height:480px;"></div>
|
|
</div>
|
|
|
|
<input type="button" value="全选" id="Cancel" onclick="CheckAll()" />
|
|
<input type="button" value="全不选" id="Button1" onclick="UnCheckAll()" />
|
|
|
|
</body>
|
|
</html>
|