<%@ page language="java" pageEncoding="UTF-8"%><%@taglib
uri="http://www.springframework.org/tags" prefix="spring"%><%@ taglib
uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib
uri="/xxll-tags" prefix="x"%>
<%@ taglib uri="/sw-tags" prefix="sw"%>
$(document).ready(function() {
$(".datagrid-btable tbody tr").css({"height":"30px;"});
$("#organTypeDatagrid").datagrid({
nowrap: true,striped: true,fitColumns: true,fit:true,border:false,idField:'id',
toolbar:'#organTypetoolbar',
url:'${base}/business/organtype/listAll',
columns:[[
{field:'ck',checkbox:true,width:100},
{field:'organTypeName',title:'名称',width:100}
]]
});
});
//checkTable and checkType==================================================================
$(function(){
var all = window.document.body.clientHeight;
var s = $("#layoutTable").layout("panel","center");
var h = all-205-310;
var m = all-200;
$("#divTree").attr("style","height:"+h+"px;overflow:auto");
$("#divItem").attr("style","height:"+m+"px;overflow:auto");
$("#divForm").attr("style","height:"+m+"px;overflow:auto");
$("#checktable_type_add").click(function(){
var t=$.window({
href:'${base}/business/checktype/add',
title:'新增检查类型',height:280,
buttons:[
{text:'
handler:function(){
$.formSubmit(t);
var treeObj = $.fn.zTree.getZTreeObj("tableTree");
treeObj.reAsyncChildNodes(null, "refresh");
}
}
]
});
});
$("#checktable_add").click(function(){
var treeObj = $.fn.zTree.getZTreeObj("tableTree");
var nodes = treeObj.getSelectedNodes();
if(nodes.length==0||nodes[0].isParent==false){
Notifier.info("
return;
}
var ADD_URL="${base}/business/checktable/add?sid="+nodes[0].id;
var t=$.window({
href:ADD_URL,
title:'新增检查表',height:280,
buttons:[
{text:'
handler:function(){
$.formSubmit(t);
var treeObj = $.fn.zTree.getZTreeObj("tableTree");
treeObj.reAsyncChildNodes(nodes[0], "refresh");
}
}
]
});
});
$("#checktable_edit").click(function(){
var treeObj = $.fn.zTree.getZTreeObj("tableTree");
var nodes = treeObj.getSelectedNodes();
if(nodes.length==0){
Notifier.info("
return;
}
var set_={title:'',href:''};
if(nodes[0].isParent){
set_.title="修改检查类型";
set_.href="${base}/business/checktype/edit/"+nodes[0].id;
}else{
set_.title="修改检查表";
set_.href="${base}/business/checktable/edit/"+nodes[0].id;
}
var t=$.window({
href:set_.href,
title:set_.title,height:280,
buttons:[
{text:'
handler:function(){
$.formSubmit(t);
treeObj.reAsyncChildNodes(nodes[0].getParentNode(), "refresh");
}
}
]
});
});
$("#checktable_delete").click(function(){
var treeObj = $.fn.zTree.getZTreeObj("tableTree");
var nodes = treeObj.getSelectedNodes();
if(nodes.length==0){
Notifier.info("
return;
}
var DELETE_URL='';
if(nodes[0].isParent){
DELETE_URL="${base}/business/checktype/delete/"+nodes[0].id;
}else{
DELETE_URL="${base}/business/checktable/delete/"+nodes[0].id;
}
bootbox.confirm("
if(result) {
$.post(DELETE_URL,function(data){
Notifier.msg(data,function(){
treeObj.reAsyncChildNodes(nodes[0].getParentNode(), "refresh");
});
});
}
});
});
//CheckItem and CheckItemtype=============================================
$("#checkitem_type_add").click(function(){
var t=$.window({
href:'${base}/business/checkitemtype/add',
title:'新增检查项类型',height:250,
buttons:[
{text:'
handler:function(){
$.formSubmit(t);
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
treeObj.reAsyncChildNodes(null, "refresh");
}
}
]
});
});
$("#checkitem_add").click(function(){
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
var nodes = treeObj.getSelectedNodes();
if(nodes.length==0||nodes[0].isParent==false){
Notifier.info("
return;
}
var ADD_URL="${base}/business/checkitem/add?sid="+nodes[0].id;
var t=$.window({
href:ADD_URL,
title:'新增检查项',height:600,
buttons:[
{text:'
handler:function(){
$.formSubmit(t);
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
treeObj.reAsyncChildNodes(nodes[0], "refresh");
}
}
]
});
});
$("#checkitem_edit").click(function(){
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
var nodes = treeObj.getSelectedNodes();
if(nodes.length==0){
Notifier.info("
return;
}
var set_={title:'',href:'',height:250};
if(nodes[0].isParent){
set_.title="修改检查项类型";
set_.href="${base}/business/checkitemtype/edit/"+nodes[0].id;
}else{
set_.title="修改检查项";
set_.href="${base}/business/checkitem/edit/"+nodes[0].id;
set_.height=600;
}
var t=$.window({
href:set_.href,
title:set_.title,
height:set_.height,
buttons:[
{text:'
handler:function(){
$.formSubmit(t);
treeObj.reAsyncChildNodes(nodes[0].getParentNode(), "refresh");
}
}
]
});
});
$("#checkitem_delete").click(function(){
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
var nodes = treeObj.getSelectedNodes();
if(nodes.length==0){
Notifier.info("
return;
}
var DELETE_URL='';
if(nodes[0].isParent){
DELETE_URL="${base}/business/checkitemtype/delete/"+nodes[0].id;
}else{
DELETE_URL="${base}/business/checkitem/delete/"+nodes[0].id;
}
bootbox.confirm("
if(result) {
$.post(DELETE_URL,function(data){
Notifier.msg(data,function(){
treeObj.reAsyncChildNodes(nodes[0].getParentNode(), "refresh");
});
});
}
});
});
//tableItem add and delete==================================================================
var numIndex=0;
var groupTileClick=function(){
$('.groupTitle').removeClass("selectedGroup");
if($(this).hasClass("selectedGroup")){
$(this).removeClass("selectedGroup");
}else{
$(this).addClass("selectedGroup");
}
};
$("body").on("click",".groupTitle",groupTileClick);
$("#selected_addgroup").click(function(){
var id=$("#checkTableId").val();
if(id==""){
Notifier.info("请先选择左边的检查表");
return false;
}
var colne_content=$("#cloneGroup").clone(true).addClass("groupTitle");
numIndex++;
$(colne_content).find(".numSpan").text(numIndex);
$(colne_content).find(".groupName").attr("name","itemGroups["+(numIndex-1)+"].groupName");
$(colne_content).removeAttr("id").fadeIn('slow').appendTo($("#tableItemForm"));
});
$("body").on("click",".groupDetailDelete",function(){
if(numIndex==1){
return false;
}
$(this).parents(".groupTitle").remove();
numIndex--;
//重新计算index
$(".groupTitle").each(function(i){
$(this).find(".numSpan").text(i+1);
$(this).find(".v_val").attr("name","itemGroups["+i+"].checkItemId");
$(this).find(".groupName").attr("name","itemGroups["+i+"].groupName");
var v=$(this).find(".v_val").val();
$("#span"+v).attr("name","itemGroups["+i+"].detailNo");
});
});
$("body").on("click",".groupDetailUp",function(){
var p=$(this).parents(".groupTitle");
var b=$(p).prev(".groupTitle").first();
$(p).insertBefore(b);
//重新计算index
$(".groupTitle").each(function(i){
$(this).find(".numSpan").text(i+1);
$(this).find(".v_val").attr("name","itemGroups["+i+"].checkItemId");
$(this).find(".groupName").attr("name","itemGroups["+i+"].groupName");
var v=$(this).find(".v_val").val();
$("#span"+v).attr("name","itemGroups["+i+"].detailNo");
});
});
$("body").on("click",".groupDetailDown",function(){
var p=$(this).parents(".groupTitle");
var b=$(p).next(".groupTitle").first();
$(p).insertAfter(b);
//重新计算index
$(".groupTitle").each(function(i){
$(this).find(".numSpan").text(i+1);
$(this).find(".v_val").attr("name","itemGroups["+i+"].checkItemId");
$(this).find(".groupName").attr("name","itemGroups["+i+"].groupName");
var v=$(this).find(".v_val").val();
$("#span"+v).attr("name","itemGroups["+i+"].detailNo");
});
});
$("body").on("click",".itemDetailDown",function(){
var p=$(this).parents(".itemDetail");
var b=$(p).next().next().first();
var s=$(b).attr("id");//next id
var t=$(p).attr("id");//self id
var span1=$("#span"+s);//next span
var span2=$("#span"+t);//self span
$(p).insertAfter(b);
$(span1).insertBefore(p);//switch
$(span2).insertBefore(b);
//id switch,but value not switch
$(span1).attr("id","span"+t);
$(span2).attr("id","span"+s);
});
$("body").on("click",".itemDetailUp",function(){
var p=$(this).parents(".itemDetail");
var b=$(p).prev().prev().first();//prev
var s=$(b).attr("id");
var t=$(p).attr("id");
//alert(s+"===="+t)
var span1=$("#span"+s);//prev
var span2=$("#span"+t);//self
$(p).insertBefore(b);
$(span1).insertBefore(p);//switch
$(span2).insertBefore(b);
//id switch
$(span1).attr("id","span"+t);
$(span2).attr("id","span"+s);
});
$("body").on("click",".itemDetailRemove",function(){
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
var node=treeObj.getNodeByParam("id",$(this).parent().parent().attr("id"));
if(null!=node){
treeObj.checkNode(node, false,true);
}
var p=$(this).parents(".itemDetail");
var b=$(p).prev().first();//prev
var m=$(p).nextAll(".myspan");
$(m).each(function(index,item){
var k=$(item).val();
$(item).val(k-1);
})
$(this).parent().parent().fadeOut(50, function() { $(this).remove(); $(b).remove();});
});
$("body").on("mouseenter mouseleave",".itemDetail",function(event){
if(event.type=='mouseenter'){
$(this).addClass("selectedItem");
$(this).find(".itemDetailBtns").fadeIn(200);
$(this).find(".myspan").attr("z-index",9999);
}else{
$(this).removeClass("selectedItem");
$(this).find(".itemDetailBtns").fadeOut(200);
}
});
$("body").on("mouseenter click",".groupName",function(){
$(this).tooltip({
content:'
onShow: function(){
$(this).tooltip('tip').css({
backgroundColor: '#fcf8e3',
borderColor: '#8a6d3b'
});
}
});
});
//organType==================================================================
$("#organtype_add").click(function(){
var t=$.window({
href:'${base}/business/organtype/add',
title:'新增机构类型',width:450,height:180,
buttons:[
{text:'
handler:function(){$.formSubmit(t,'organTypeDatagrid');}
}
]
});
});
$("#organtype_edit").click(function(){
var nodes = $("#organTypeDatagrid").datagrid('getSelections');
if(nodes.length!=1){
Notifier.info("
return ;
}
var id=nodes[0].id;
var EDIT_URL="${base}/business/organtype/edit/"+id;
var t=$.window({
href:EDIT_URL,
title:'修改机构类型',width:450,height:180,
buttons:[
{text:'
handler:function(){$.formSubmit(t,'organTypeDatagrid');}
}
]
});
});
$("#organtype_delete").click(function(){
var nodes = $("#organTypeDatagrid").datagrid('getSelections');
if(nodes.length!=1){
Notifier.info("
return ;
}
var id=nodes[0].id;
var DELETE_URL="${base}/business/organtype/delete/"+id;
bootbox.confirm("
if(result) {
$.post(DELETE_URL,function(data){
Notifier.msg(data,function(){
$("#organTypeDatagrid").datagrid('reload');
});
});
}
});
});
//CheckTable and CheckType Tree
var tableSetting = {
async: {
enable: true,
url:"${base}/business/tableitem/listTable",
autoParam:["id=sid"]
},
callback:{
onClick:function(event, treeId, node){
if(!node.isParent){
$("#checkTableId").val(node.id);
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
treeObj.reAsyncChildNodes(null, "refresh");
$(".groupTitle").remove();
numIndex=0;
//select organType
$("#organTypeDatagrid").datagrid("uncheckAll");
if(node.attr.length>0){
$(node.attr).each(function(i,obj){
$("#organTypeDatagrid").datagrid("selectRecord",obj.id);
});
}
//show tableItem
$.ajax({
url:'${base}/business/tableitem/listTableItem.json',
type:'post',dataType:'html',
data:{"id":node.id},
success:function(obj){
if(obj.length>0){
$(obj).fadeIn('slow').appendTo($("#tableItemForm"));
numIndex=$(obj).find(".groupTitle").prevObject.length;
}
}
});
}else{
$("#checkTableId").val("");
}
}
}
};
$.fn.zTree.init($("#tableTree"), tableSetting);
//CheckItem and CheckItemType Tree
var itemSetting = {
async: {
enable: true,
url:"${base}/business/tableitem/listItem",
autoParam:["id=sid"]
},
check:{
enable:true,autoCheckTrigger:true
},
callback: {
onExpand:function(event, treeId, node){
var treeObj = $.fn.zTree.getZTreeObj("itemTree");
$(".itemDetail").each(function(){
var id_=$(this).attr("id");
$(node.children).each(function(i,o){
if(id_==o.id){
treeObj.checkNode(o,true,true);
}
});
});
},
beforeCheck:function(event, treeId, node){
var id=$("#checkTableId").val();
if(id==""){
Notifier.info("请先选择左边的检查表");
return false;
}
var selGoup=$(".selectedGroup");
if(selGoup.length==0){
Notifier.info("请选择要加入的分组");
return false;
}
},
onCheck: function(event, treeId, node){
if(node.checked){
var selGoup=$(".selectedGroup");
var idexits=$("#"+node.id).length>0;
if(!node.isParent&&!idexits){
var n=$(selGoup).find(".numSpan").text();
var idx=parseInt(n)-1;
//循环遍历当前group,有多少个li
var k=0;
var p=$(selGoup).find(".groupGrid ul").find("li");
$(p).each(function(index,item){
k++;
})
//循环遍历当前group,有多少个li end
var spanDetail=$("#cloneSpan").clone(true).attr("id","span"+node.id).val(k+1);
var itemDetail=$("#colneItemDetail").clone(true).addClass("itemDetail").attr("id",node.id);
//itemDetail.find(".v_checkbox").val(node.id);
itemDetail.find(".v_val").val(node.id).attr("name","itemGroups["+idx+"].checkItemId");
itemDetail.find(".v_label").text(node.name);
var v=node.id;
$(spanDetail).attr("name","itemGroups["+idx+"].detailNo");
//itemDetail.find(".v_groupName").attr("name","itemGroups["+idx+"].groupName");
$(spanDetail).insertBefore($(itemDetail));
$(spanDetail).fadeIn().appendTo($(selGoup).find(".groupGrid ul"));
$(itemDetail).fadeIn().appendTo($(selGoup).find(".groupGrid ul"));
}
}else{
$("#"+node.id).remove();
}
}
}
};
$.fn.zTree.init($("#itemTree"), itemSetting);
$("#tableItemSave").click(function(){
$("#tableItemForm").ajaxSubmit({
url:'${base}/business/tableitem/saveTableItem',
type:'post',
dataType:'json',
beforeSubmit:function(formData, jqForm, options){
//check CheckTable
if($("#checkTableId").val()==""){
Notifier.info("请选择检查表");
return false;
}
//check organType
var sel=$("#organTypeDatagrid").datagrid("getSelections");
if(sel.length==0){
Notifier.info("请选择机构类型");
return false;
}else{
$(sel).each(function(i,obj){
formData.push({"name":"organTypeIds","value":obj.id});
});
}
//check tableItem
},
beforeSend:function(){
$.messager.progress({
title:'请稍后...',
text:"数据正在保存中...",
interval:120
});
},
complete:function(){
$.messager.progress('close');
},
success:function(content){
$.messager.progress('close');
Notifier.msg(content);
},
error:function(content){
Notifier.msg(content);
}
});
});
});
.sel {
text-align: center!important; position: absolute;width:100px;height:200px;left:50%;top:50%;
margin-left:-50px;margin-top:-100px;}
.main .panel-tool button{
font-size: 12px!important;
margin: 0 3px;
}
.selectedGroup{
border:1px solid #428bca;
}
.groupTitle{
margin-bottom: 3px;
}
.groupGrid ul{
padding: 0 5px;
list-style: none;
}
.myspan{
line-height: 10px;
width:25px;
height:25px;
padding-top:3px;
float:left;
border:0;
}
.groupGrid ul li{
position:relative;
line-height: 30px;
color: #000;
border-bottom: 1px dotted #999;
list-style: outside disc none;
list-style-type: none;
vertical-align: middle;
}
.groupGrid ul li input{
position:absolute;
top:5px;
padding-top: 13px;
width: 16px;
height: 16px;
}
.groupGrid ul li label{
line-height: 30px;
padding-top:3px;
margin-left: 19px;
}
.selectedItem{
background: #dfdfdf;
}
转载于:https://my.oschina.net/u/2471041/blog/532619