<!DOCTYPE html>
<html>
<head>
<title>指示配置管理</title>
<%@ page contentType="text/html;charset=UTF-8"%>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<%@ include file="/WEB-INF/jsp/include/public.jsp"%>
<%@ include file="/WEB-INF/jsp/include/bootstrap.jsp"%>
<link href="${path}/css/EasyuiGrid.css" rel="stylesheet" type="text/css" />
<link href="${path}/css/layui.css" rel="stylesheet" type="text/css" />
<script src="${path}/layui.js"></script>
</head>
<style>
html,body{width:100%;height:100%;position:fixed;top:0;left:0;}
.dnzl{font-weight:bold;margin:0 0 0 20px;}
#btn .btn{padding:2px 6px;/* display:none; */}
#btn .btn-success{background:#70d392}
#ff table
{
border-collapse:collapse;
}
#ff table #left2 td
{
border:2px solid black;
text-align:center;
padding:10px 0 10 0;
}
::-webkit-scrollbar {display:none }
</style>
<body>
<div style="width:100%;height:100%;background:#eeeeee;">
<div style="width:100%;height:100%;float:right;background:#fff;" class="TgDiv">
<div class="row" style="margin:5px 0">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<span class="dnzl">健康度评估模型管理</span>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<div id="btn" class="pull-right">
<button class="layui-btn layui-btn-danger layui-btn-sm" id="add">新增</button>
<button class="layui-btn layui-btn-danger layui-btn-sm" id="edit">编辑</button>
<button class="layui-btn layui-btn-danger layui-btn-sm" id="remove">删除</button>
</div>
</div>
</div>
<div id="testtg" style="width:100%;" class="tg">
<div id="tg"></div>
</div>
</div>
</div>
</body>
<script>
var _modelTypes=[],_Id;
var dataleft;
var dataright;
var dataleftbj;
var datarightbj;
var iframeId=window.frameElement && window.frameElement.id || '';
$(function(){
checkRight();
$(".tg").css("height",$(".TgDiv").height()-$(".row").outerHeight(true)+"px");
getData();
//新增
$("#add").click(function(){
easyui.ajax({
url:path+"/schemeMapping/beforeInsertSchemeAndRatioAndMeun",
func:function(data){
dataleft = data.modelIndexList;
dataright = data.terminalAccountList;
var nodes =$("<form id='ff' class='form-inline' style='padding:25px;overflow:hidden;align:center;' onselectstart='javascript:return false;'>"
+"<div style='overflow:hidden;'>"
+"<div style='width:700px;height:20px;text-align:center;padding: 10px 0 20px 50px;'>"
+"<label><span style='margin-right:10px'>方案名称</span><input type='text' id='schemename' name='mingceng' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;'></label>"
+"</div>"
+"<div id='toggelleft' style='height:65px;width:400px;text-align:center;float:left;padding: 10px 0 0 0;'>"
+"<label><div style='margin-right:10px'>指标项</div><textarea rows='3' cols='30' id='textarealeft' disabled='disabled' style='border-radius:5px;border:1px solid #95B8E7;resize:none;'></textarea></label>"
+"</div>"
+"<div id='toggelright' style='height:65px;text-align:center;padding: 10px 0 0 0;'>"
+"<label><div style='margin-right:10px'>用途项</div><textarea rows='3' cols='30'id='textarearight' disabled='disabled' style='border-radius:5px;border:1px solid #95B8E7;resize:none;'></textarea></label>"
+"</div>"
+"<div id='lefted' style='height:300px;overflow-y:scroll;float:left;padding-left:60px;'> "
+"<table border='1' style='border:1px solid #95B8E7;'>"
+"<thead>"
+"<tr>"
+"<th style='text-align:center;padding:10px;'>指标项</th>"
+"<th style='text-align:center;padding:10px;'>占比</th>"
+"</tr>"
+"</thead>"
+"<tbody id='left2'>"
+"</tbody>"
+"</table>"
+"</div>"
+"<div id='right' style='height:300px;overflow-y:scroll;float:right;margin-right:20px;'> "
+"<table border='1' style='width:420px;height:250px;border:1px solid #95B8E7;'>"
+"<thead>"
+"<tr>"
+"<th style='text-align:center;padding:10px;'>设备名称</th>"
+"<th style='text-align:center;padding:10px;'>方案用途</th>"
+"</tr>"
+"</thead>"
+"<tbody id='right2'>"
+"</tbody>"
+"</table>"
+"</div>"
+"</div>"
+"</from>"
+"<div style='text-align:center;margin-bottom:5px;padding-top:30px;'>"
+"<button class='layui-btn layui-btn-sm layui-btn-primary' id='submit' style='border-radius:5px;border:1px solid #95B8E7;'>保存</button>"
+"<button class='layui-btn layui-btn-sm layui-btn-primary' id='clear' style='margin-left:5px;border-radius:5px;border:1px solid #95B8E7;'>取消</button>"
+"</div>"
)
window.parent.popup({
type:"add",
id:iframeId,
node:nodes,
title:"新增维保信息",
onOpen:function(){
//左边滚动条
$("#ff #lefted",parent.document).niceScroll({
cursorcolor: "#ddd",
autohidemode:false,
zindex:200,
cursorwidth: 3,
cursorborderradius: 3,
cursorborder:"1px solid #ddd"
});
//右边滚动条
$("#ff #right",parent.document).niceScroll({
cursorcolor: "#ddd",
autohidemode:false,
zindex:200,
cursorwidth: 3,
cursorborderradius: 3,
cursorborder:"1px solid #ddd"
});
}
});
/* Math.formatFloat = function(f, digit) {
var m = Math.pow(10, digit);
return parseInt(f * m, 10) / m;
} */
$.each(dataleft,function(i,v){
var nodeleft =$("<tr><td style='padding:10px;'><div><input id='"+("check"+[i])+"' style='height:13px; vertical-align:text-top; margin-top:0;margin-right:5px;' type='checkbox' class='textcheck'><span style='display:inline-block;'>"+dataleft[i].NAME+"</span></td><td style='padding:10px;'><input class='testcheck2' name='newnum' text2='' text='' type='text' id='"+("name"+[i])+"' disabled='disabled' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;'/></div></td></tr>")
$("#left2",parent.document).append(nodeleft);
//input值改变显示在textarea
$("#name"+i,parent.document).on('change',function(){
//已添加的text、text2属性,用于存储标记,并给text、text2赋值
$(this).attr("text2",$("#name"+i,parent.document).val());
var num = 0;
$(this).attr("text",dataleft[i].NAME+":"+$("#name"+i,parent.document).val()+";");
var val_="";
//遍历出每一个text、text2值,赋给val_、num
for(var n=0;n<dataleft.length;n++){
val_+=$("#left2 .testcheck2:eq("+n+")",parent.document).attr("text");
num +=Number($("#left2 .testcheck2:eq("+n+")",parent.document).attr("text2"));
}
num = parseFloat(num).toFixed(2);
//添加到显示框
$("#textarealeft",parent.document).val(val_);
if(num>1){
var numbe = (num-1).toFixed(2);
alert("占比总和应为1,已超"+numbe+",请重新填写");
$(this).val("");
$(this).attr("text","");
$(this).attr("text2","");
$("#textarealeft",parent.document).val("");
//遍历出每一个text
var newval_="";
for(var n=0;n<dataleft.length;n++){
newval_+=$("#left2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
//添加到显示框
$("#textarealeft",parent.document).val(newval_);
return;
}
});
});
//点击下拉显示
/* $("#toggelleft",parent.document).click(function(){
//执行完动画,回调执行滚动条
$("#lefted",parent.document).slideToggle("slow",function(){
$("#ff #lefted",parent.document).niceScroll().resize();
});
});
$("#toggelright",parent.document).click(function(){
$("#right",parent.document).slideToggle("slow",function(){
$("#ff #right",parent.document).niceScroll().resize();
});
}); */
$.each(dataright,function(i,v){
var noderight =$("<tr><td style='padding:10px;'><div><input id='"+("checkbox"+[i])+"' style='height:13px; vertical-align:text-top; margin-top:0;margin-right:5px' type='checkbox' class='textcheck'><span style='display:inline-block;'>"+dataright[i].equipmentName+"</span></div></td><td style='padding:10px;width:200px'><select id='"+("select"+[i])+"' text='' class='testcheck2' disabled='disabled' name='newnum' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;'><option value=''>请选择</option><option value='1'>计算设备剩余寿命</option><option value='2'>计算设备健康度</option></select><span><button class='layui-btn layui-btn-sm layui-btn-primary' id='"+("unbundling"+[i])+"' style='padding:2px 5px 2px 5px;margin-left:5px;display:none;line-height:10px;border-radius:5px;border:1px solid #95B8E7;'>解绑</button></span></td></tr>")
$("#right2",parent.document).append(noderight);
var isCorrelation;
if(dataright[i].isCorrelation==true){
$("#unbundling"+i,parent.document).css("display","inline");
$("#checkbox"+i,parent.document).attr("disabled", "disabled");
}else{
$("#unbundling"+i,parent.document).css("display","none");
$("#checkbox"+i,parent.document).removeAttr("disabled");
}
//获得所有绑定按钮,点击触发解除绑定
$("#unbundling"+i,parent.document).click(function(e){
e.preventDefault();// 防止触发默认事件
var correlationSchemeName = dataright[i].correlationSchemeName;//获得与其他方案绑定的方案名称
if(confirm("此设备已和方案"+correlationSchemeName+"绑定,确定要解绑吗?")){
}else{
return;
}
facilityId = dataright[i].facilityId;
schemeId = dataright[i].schemeId;
easyui.ajax({
url:path+"/schemeMapping/removeBind",
data:{'facilityId':facilityId,'schemeId':schemeId},
func:function(data){
var error;
if(!data||data.error){
easyui.msg("请求失败");
return;
}
easyui.msg(data.msg);
$("#unbundling"+i,parent.document).css("display","none");
$("#checkbox"+i,parent.document).removeAttr("disabled");
}
})
});
$("#select"+i,parent.document).on('change',function()//下拉选择改变,同步显示在textarea
{
//为select添加text属性,用于存储和标记
$(this).attr("text",dataright[i].equipmentName+":"+$("#select"+i,parent.document).find("option[value='"+$(this).val()+"']").text()+";")
var val_="";
//遍历出没一个text值,并赋给显示框
for(var n=0;n<dataright.length;n++){
val_+=$("#right2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
$("#textarearight",parent.document).val(val_);
});
});
$.each($(".textcheck",window.parent.document),function(i,v){
(function(){
var index = i,val = v;
$(val).on("click",function(e){
if($(this).hasClass('check')){
$(this).removeClass('check');
$(this).parents("td").next().find(".testcheck2").attr("text","");//将选中的text赋为空值
$(this).parents("td").next().find(".testcheck2").attr("text2","");//将选中的text2赋为空值
$(".testcheck2",parent.document).eq(index).attr('disabled', 'disabled');
$(".testcheck2",parent.document).eq(index).val("");//取消选择 清空
var val_="";
for(var n=0;n<$("#left2 .testcheck2",parent.document).length;n++){
val_+=$("#left2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
$("#textarealeft",parent.document).val(val_);
var val2_="";
for(var n=0;n<$("#right2 .testcheck2",parent.document).length;n++){
val2_+=$("#right2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
$("#textarearight",parent.document).val(val2_);
}else{
$(this).addClass('check');
$(".testcheck2",parent.document).eq(index).removeAttr('disabled');
}
})
})()
});
}
});
});
//编辑
$("#edit").click(function(){
if(!$("#tg").datagrid("getSelected")){
easyui.msg("请选择要编辑的信息");
return;
}else{
var tgSelect=$("#tg").datagrid("getSelected");
var schemeId = tgSelect.id;//选中的方案id
var schemeName = tgSelect.schemeName
easyui.ajax({
url:path+"/schemeMapping/beforeUpdateSchemeAndRatioAndMeun",
data:{'schemeId':schemeId},
func:function(data){
dataleftbj = data.modelIndexList;
datarightbj = data.terminalAccountList;
var nodes2 =$("<form id='ff' class='form-inline' style='padding:25px;overflow:hidden;align:center;' onselectstart='javascript:return false;'>"
+"<div style='overflow:hidden;'>"
+"<div style='width:850px;height:20px;text-align:center;padding: 10px 0 20px 0;'>"
+"<label><span style='margin-right:10px'>方案名称</span><input type='text' id='schemename' name='mingceng' style='width:150px;height:28px;text-align:center;line-height:28px;border-radius:5px;border:1px solid #95B8E7;' value="+schemeName+"></label>"
+"</div>"
+"<div id='toggelleft' style='height:65px;width:400px;text-align:center;float:left;padding: 10px 0 0 0;'>"
+"<label><div style='margin-right:10px'>指标项</div><textarea rows='3' cols='30' id='textarealeft' disabled='disabled' style='border-radius:5px;border:1px solid #95B8E7;resize:none;'></textarea></label>"
+"</div>"
+"<div id='toggelright' style='height:65px;text-align:center;padding: 10px 0 0 0;'>"
+"<label><div style='margin-right:10px'>用途项</div><textarea rows='3' cols='30'id='textarearight' disabled='disabled' style='border-radius:5px;border:1px solid #95B8E7;resize:none;'></textarea></label>"
+"</div>"
+"<div id='lefted' style='height:300px;overflow-y:scroll;float:left;padding-left:60px;'> "
+"<table border='1' style='border:1px solid #95B8E7;'>"
+"<thead>"
+"<tr>"
+"<th style='text-align:center;padding:10px;'>指标项</th>"
+"<th style='text-align:center;padding:10px;'>占比</th>"
+"</tr>"
+"</thead>"
+"<tbody id='left2'>"
+"</tbody>"
+"</table>"
+"</div>"
+"<div id='right' style='height:300px;overflow-y:scroll;float:right;margin-right:20px;'> "
+"<table border='1' style='width:420px;height:250px;border:1px solid #95B8E7;'>"
+"<thead>"
+"<tr>"
+"<th style='text-align:center;padding:10px;'>设备名称</th>"
+"<th style='text-align:center;padding:10px;'>方案用途</th>"
+"</tr>"
+"</thead>"
+"<tbody id='right2'>"
+"</tbody>"
+"</table>"
+"</div>"
+"</div>"
+"</from>"
+"<div style='text-align:center;margin-bottom:5px;padding-top:30px;'>"
+"<button class='layui-btn layui-btn-sm layui-btn-primary' id='submit' style='border-radius:5px;border:1px solid #95B8E7;'>保存</button>"
+"<button class='layui-btn layui-btn-sm layui-btn-primary' id='clear' style='margin-left:5px;border-radius:5px;border:1px solid #95B8E7;'>取消</button>"
+"</div>"
)
window.parent.popup({
type:"edit",
id:iframeId,
node:nodes2,
title:"编辑维保信息",
onOpen:function(){
//左边滚动条
$("#ff #lefted",parent.document).niceScroll({
cursorcolor: "#ddd",
autohidemode:false,
zindex:200,
cursorwidth: 3,
cursorborderradius: 3,
cursorborder:"1px solid #ddd"
});
//右边滚动条
$("#ff #right",parent.document).niceScroll({
cursorcolor: "#ddd",
autohidemode:false,
zindex:200,
cursorwidth: 3,
cursorborderradius: 3,
cursorborder:"1px solid #ddd"
});
}
});
$.each(dataleftbj,function(i,v){
if(dataleftbj[i].isSelect==true){//复选框选中
var nodeleft =$("<tr><td style='padding:10px;'><div><input type='checkbox' id='"+("check"+[i])+"' style='height:13px; vertical-align:text-top; margin-top:0;margin-right:5px;' class='textcheck' checked><span style='display:inline-block;'>"+dataleftbj[i].NAME+"</span></div></td><td style='padding:10px;'><input class='testcheck2' text='' text2='' disabled='disabled' id='"+("name"+[i])+"' name='equipment_name' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;' value="+dataleftbj[i].ratio+"></div></td></tr>")
}else{
var nodeleft =$("<tr><td style='padding:10px;'><div><input type='checkbox' id='"+("check"+[i])+"' style='height:13px; vertical-align:text-top; margin-top:0;margin-right:5px;' class='textcheck'><span style='display:inline-block;'>"+dataleftbj[i].NAME+"</span></div></td><td style='padding:10px;'><input class='testcheck2' text='' text2='' disabled='disabled' id='"+("name"+[i])+"' name='equipment_name' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;' value="+dataleftbj[i].ratio+"></div></td></tr>")
}
$("#left2",parent.document).append(nodeleft);
var newtextarealeft = $("#textarealeft",parent.document).val();//左边大框的值
//输入框有值,可输入
if($("#name"+i,parent.document).val()!=""){
$("#check"+i,parent.document).addClass('check');
$("#name"+i,parent.document).removeAttr("disabled");
$("#name"+i,parent.document).attr("text2",$("#name"+i,parent.document).val());
$("#name"+i,parent.document).attr("text",dataleftbj[i].NAME+":"+$("#name"+i,parent.document).val()+";");
newtextarealeft += dataleftbj[i].NAME+":"+dataleftbj[i].ratio+";";//左边大框显示已有值
$("#textarealeft",parent.document).val(newtextarealeft)
}else{
$("#name"+i,parent.document).attr('disabled', 'disabled');
}
//input值改变显示在textarea,并且如果总输入值大于一提示
$("#name"+i,parent.document).on('change',function(){
//已添加的text、text2属性,用于存储标记,并给text、text2赋值
$(this).attr("text2",$("#name"+i,parent.document).val());
var num = 0;
$(this).attr("text",dataleftbj[i].NAME+":"+$("#name"+i,parent.document).val()+";");
var val_="";
//遍历出每一个text、text2值,赋给val_、num
for(var n=0;n<dataleftbj.length;n++){
val_+=$("#left2 .testcheck2:eq("+n+")",parent.document).attr("text");
num +=Number($("#left2 .testcheck2:eq("+n+")",parent.document).attr("text2"));
}
//添加到显示框
$("#textarealeft",parent.document).val(val_);
if(num>1){
var numbe = (num-1).toFixed(2);
alert("占比总和应为1,已超"+numbe+",请重新填写");
$(this).val("");
$(this).attr("text","");
$(this).attr("text2","");
$("#textarealeft",parent.document).val("");
//遍历出每一个text
var newval_="";
for(var n=0;n<dataleftbj.length;n++){
newval_+=$("#left2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
//添加到显示框
$("#textarealeft",parent.document).val(newval_);
return;
}
});
})
$.each(datarightbj,function(i,v){
if(datarightbj[i].isSelect==true){//下拉框选中
if(datarightbj[i].schemeType==1){
var noderight =$("<tr><td style='padding:10px;'><div><input id='"+("checkbox"+[i])+"' type='checkbox' class='textcheck' style='height:13px; vertical-align:text-top; margin-top:0;margin-right:5px;' checked><span style='display:inline-block;'>"+datarightbj[i].equipmentName+"</span></div></td><td style='padding:10px;width:200px;'><select class='testcheck2' id='"+("select"+[i])+"' text='' disabled='disabled' name='d' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;'><option value=''>请选择</option><option value='1' selected>计算设备剩余寿命</option><option value='2'>计算设备健康度</option></select><span><button class='layui-btn layui-btn-sm layui-btn-primary' id='"+("unbundling"+[i])+"' style='padding:2px 5px 2px 5px;margin-left:5px;display:none;line-height:10px;border-radius:5px;border:1px solid #95B8E7;'>解绑</button></span></td></tr>")
}else if(datarightbj[i].schemeType==2){
var noderight =$("<tr><td style='padding:10px;'><div><input id='"+("checkbox"+[i])+"' type='checkbox' class='textcheck' style='height:13px; vertical-align:text-top; margin-top:0;margin-right:5px;' checked><span style='display:inline-block;'>"+datarightbj[i].equipmentName+"</span></div></td><td style='padding:10px;width:200px;'><select class='testcheck2' id='"+("select"+[i])+"' text='' disabled='disabled' name='d' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;'><option value=''>请选择</option><option value='1'>计算设备剩余寿命</option><option value='2' selected>计算设备健康度</option></select><span><button class='layui-btn layui-btn-sm layui-btn-primary' id='"+("unbundling"+[i])+"' style='padding:2px 5px 2px 5px;margin-left:5px;display:none;line-height:10px;border-radius:5px;border:1px solid #95B8E7;'>解绑</button></span></td></tr>")
}
}else{
var noderight =$("<tr><td style='padding:10px;'><div><input id='"+("checkbox"+[i])+"' type='checkbox' class='textcheck' style='height:13px; vertical-align:text-top; margin-top:0;margin-right:5px;'><span style='display:inline-block;'>"+datarightbj[i].equipmentName+"</span></div></td><td style='padding:10px;width:200px;'><select class='testcheck2' id='"+("select"+[i])+"' name='d' text='' disabled='disabled' style='width:150px;height:28px;line-height:28px;border-radius:5px;border:1px solid #95B8E7;'><option value=''>请选择</option><option value='1'>计算设备剩余寿命</option><option value='2'>计算设备健康度</option></select><span><button class='layui-btn layui-btn-sm layui-btn-primary' id='"+("unbundling"+[i])+"' style='padding:2px 5px 2px 5px;margin-left:5px;display:none;line-height:10px;border-radius:5px;border:1px solid #95B8E7;'>解绑</button></span></td></tr>")
}
$("#right2",parent.document).append(noderight);
//checkbox选中,下拉框可选择,并将内容显示在框内
if($("#checkbox"+i,parent.document).is(":checked")==true){
$("#checkbox"+i,parent.document).addClass('check');
$("#select"+i,parent.document).removeAttr("disabled");
$("#select"+i,parent.document).attr("text",datarightbj[i].equipmentName+":"+$("#select"+i,parent.document).find("option[value='"+datarightbj[i].schemeType+"']").text()+";");
var newtextarearight = $("#textarearight",parent.document).val();//如果复选框选中,将选到的值显示到大框上
newtextarearight += datarightbj[i].equipmentName+":"+$("#select"+i,parent.document).find("option[value='"+datarightbj[i].schemeType+"']").text()+";";
$("#textarearight",parent.document).val(newtextarearight);
}else{
$("#select"+i,parent.document).attr('disabled', 'disabled');
}
//有关联显示解绑按钮
if(datarightbj[i].isCorrelation==true){
$("#unbundling"+i,parent.document).css("display","inline");
$("#checkbox"+i,parent.document).attr("disabled", "disabled");
}else{
$("#unbundling"+i,parent.document).css("display","none");
$("#checkbox"+i,parent.document).removeAttr("disabled");
}
//获得所有绑定按钮,点击触发解除绑定
$("#unbundling"+i,parent.document).click(function(e){
e.preventDefault();// 防止触发默认事件
var correlationSchemeName = datarightbj[i].correlationSchemeName;
if(confirm("此设备已和方案"+correlationSchemeName+"绑定,确定要解绑吗?")){
}else{
return;
}
facilityId = datarightbj[i].facilityId;
schemeId = datarightbj[i].schemeId;
easyui.ajax({
url:path+"/schemeMapping/removeBind",
data:{'facilityId':facilityId,'schemeId':schemeId},
func:function(data){
var error;
if(!data||data.error){
easyui.msg("请求失败");
return;
}
easyui.msg(data.msg);
$("#unbundling"+i,parent.document).css("display","none");
$("#checkbox"+i,parent.document).removeAttr("disabled");
}
})
})
//选择改变在textarea上显示
$("#select"+i,parent.document).on('change',function()
{
$(this).attr("text",datarightbj[i].equipmentName+":"+$("#select"+i,parent.document).find("option[value='"+$(this).val()+"']").text()+";")
var val_="";
for(var n=0;n<datarightbj.length;n++){
val_+=$("#right2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
$("#textarearight",parent.document).val(val_);
});
})
//点击下拉显示或隐藏,回调执行滚动条
/* $("#toggelleft",parent.document).click(function(){
$("#lefted",parent.document).slideToggle("slow",function(){
$("#ff #lefted",parent.document).niceScroll().resize();
});
});
$("#toggelright",parent.document).click(function(){
$("#right",parent.document).slideToggle("slow",function(){
$("#ff #right",parent.document).niceScroll().resize();
});
}); */
//点击才可以输入、选择
$.each($(".textcheck",window.parent.document),function(i,v){
(function(){
var index = i,val = v;
$(val).on("click",function(e){
if($(this).hasClass('check')){
$(this).removeClass('check');
$(this).parents("td").next().find(".testcheck2").attr("text","");//复选框取消选择时,清空选中的text
$(this).parents("td").next().find(".testcheck2").attr("text2","");//复选框取消选择时,清空选中的text2
$(".testcheck2",parent.document).eq(index).attr('disabled', 'disabled');
$(".testcheck2",parent.document).eq(index).val("");
var val_="";
//遍历出取消选择了几个,则清空几个text,并重新赋值给显示框
for(var n=0;n<$("#left2 .testcheck2",parent.document).length;n++){
val_+=$("#left2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
$("#textarealeft",parent.document).val(val_);
var val2_="";
for(var n=0;n<$("#right2 .testcheck2",parent.document).length;n++){
val2_+=$("#right2 .testcheck2:eq("+n+")",parent.document).attr("text");
}
$("#textarearight",parent.document).val(val2_);
}else{
$(this).addClass('check');
$(".testcheck2",parent.document).eq(index).removeAttr('disabled');
}
})
})()
});
}
});
}
});
//删除
$("#remove").click(function(){
if(!$("#tg").datagrid("getSelected")){
easyui.msg("请选择要删除的信息");
return;
}else{
if($("#tg").datagrid("getSelected").length == undefined){
var checkLength=1;
}else{
var checkLength=$("#tg").datagrid("getSelected").length;
}
window.parent.confirm(checkLength,function(r){
if(r){//确认删除
var page = $(".pagination-num").val();
var rows = $(".pagination-page-list").val();
var tgSelect=$("#tg").datagrid("getSelected");
var schemeId = tgSelect.id;//选中的方案id
easyui.ajax({
url:path+"/schemeMapping/deleteSchemeAndRatioAndMeunBySchemeId",
data:{'schemeId':schemeId,'page':page,'rows':rows},
func:function(data){
easyui.msg(data.msg);
if(data.success){
$("#tg").datagrid("loadData",data.grid);
}
}
})
}
});
}
})
})
//动态合并行方法,扩展Easyui
/* 使用方法:$('#grid).datagrid("autoMergeCells", ['field1', 'field2','field3',……]);
后面的数组 即 你想要合并的显示的 列 如果你只有一个列需要合并 那么数组中指定一个列的field即可 */
$.extend($.fn.datagrid.methods, {
autoMergeCells: function (jq, fields) {
return jq.each(function () {
var target = $(this);
if (!fields) {
fields = target.datagrid("getColumnFields");
}
var rows = target.datagrid("getRows");
var i = 0,
j = 0,
temp = {};
for (i; i < rows.length; i++) {
var row = rows[i];
j = 0;
for (j; j < fields.length; j++) {
var field = fields[j];
var tf = temp[field];
if (!tf) {
tf = temp[field] = {};
tf[row[field]] = [i];
} else {
var tfv = tf[row[field]];
if (tfv) {
tfv.push(i);
} else {
tfv = tf[row[field]] = [i];
}
}
}
}
$.each(temp, function (field, colunm) {
$.each(colunm, function () {
var group = this;
if (group.length > 1) {
var before,after,megerIndex = group[0];
for (var i = 0; i < group.length; i++) {
before = group[i];
after = group[i + 1];
if (after && (after - before) == 1) {
continue;
}
var rowspan = before - megerIndex + 1;
if (rowspan > 1) {
target.datagrid('mergeCells', {
index: megerIndex,
field: field,
rowspan: rowspan
});
}
if (after && (after - before) != 1) {
megerIndex = after;
}
}
}
});
});
});
}
});
function getData(){
var ele={
"page":1,
"rows":10
}
easyui.ajax({
url:path+"/schemeMapping/getSchemes",
data:ele,
func:function(data){
$(".num").text(data.total);
easyui.grid({
id:"#tg",
data:data,
rownumbers:true,
pagination:true,
pageSize:10,
columns:[[
{field:"id",title:"复选框",align:"center",checkbox:true,width:70},
{field:"schemeName",title:"方案名称",align:"center",width:70},
{field:"indexName",title:"指标",align:"center",width:70},
{field:"ratio",title:"占比",align:"center",width:70},
{field:"equipmentName",title:"设备名称",align:"center",width:70},
{field:"schemeType",title:"方案用途",align:"center",width:70,
formatter:function(value,rowData,index){
if(value == 1){
return "计算设备剩余寿命";
}else if(value == 2){
return "计算设备健康度";
}else{
return "";
}
}
}
]],
success:function(data){
$("#tg").datagrid("autoMergeCells",["id","schemeName"]);//合并行
newScroll(".datagrid-view2 .datagrid-body","#dddddd",false,6);//加载成功设置滚动条
//左边序号根据方案个数排列
var count = 0;
var str = true;
var page = $(".pagination-num").val();
var rows = $(".pagination-page-list").val();
var number = (page-1)*rows+1;
while(str ==true){
var tab = $("#datagrid-row-r1-2-"+count+" td");
if(tab.length !=0){
var a = $("#datagrid-row-r1-1-"+count+" td .datagrid-cell-rownumber")[0];
a.innerHTML = ""+number;
if(tab[0].rowSpan >1){
$("#datagrid-row-r1-1-"+count+" td")[0].rowSpan = tab[0].rowSpan;
count +=tab[0].rowSpan -1;
}
}else{
str=false;
}
number++;
count++;
}
}
});
easyui.page({
id:"#tg",
url:path+"/schemeMapping/getSchemes",
data:ele
})
}
});
}
function Easyuisave(obj){
var total = 0;
//新增保存按钮
var modelScheme = {"scheme_name":$("input#schemename",parent.document).val(), "remark": ""} ;//方案名称
var modelIndexRatioList = new Array();
var newData = dataleft;//指标项
for(var i in newData){
var ratio = {};
ratio["index_id"] = newData[i].ID;
ratio["ratio"] = $("input#name"+i,parent.document).val()
modelIndexRatioList.push(ratio);
total += Number($("input#name"+i,parent.document).val())
};
total = parseFloat(total).toFixed(2);
var modelIndexMeunList = new Array();
var newData2 = dataright;//指标项
for(var i in newData2){
var meun = {};
meun["facility_id"] = newData2[i].facilityId;
meun["scheme_type"] = $("#select"+i+" option:selected",parent.document).val()
modelIndexMeunList.push(meun);
};
var params = {};
params.modelScheme = JSON.stringify(modelScheme);
params.modelIndexRatioList = JSON.stringify(modelIndexRatioList);
params.modelIndexMeunList = JSON.stringify(modelIndexMeunList);
params.page = $(".pagination-num").val();
params.rows = $(".pagination-page-list").val();
var arr = {'modelScheme':modelScheme,'modelIndexRatioList':modelIndexRatioList,'modelIndexMeunList':modelIndexMeunList};
if(obj.type=="add"){
if($("input#schemename",parent.document).val()==""){
alert("方案名称不能为空");
return;
}
if(total<1){
var numbe = (1-total).toFixed(2);
alert("占比总和应为1,还差"+numbe+",您可以再添加指标项或重新填写");
return;
}else if(total>1){
var numbe =(total-1).toFixed(2);
alert("占比总和应为1,已超"+numbe+",请重新填写");
return;
}else{
}
easyui.ajax({
url:path+"/schemeMapping/insertSchemeAndRatioAndMeun",
data:params,
func:function(data){
if(data.success){
$("#tg").datagrid("loadData",data.grid);
$(".num").text(data.total);
window.parent.popupClose();
}
easyui.msg(data.msg);
},
error:function(error){
easyui.msg("新增失败");
window.parent.popupClose();
}
})
}else if(obj.type=="edit"){
//编辑按钮触发
var totalbj = 0;
var tgSelect=$("#tg").datagrid("getSelected");
var schemeId = tgSelect.id;//选中的方案id
var modelScheme = {"scheme_name":$("input#schemename",parent.document).val(), "remark": "","id":schemeId} ;//方案名称
var modelIndexRatioList = new Array();
var newDatabj = dataleftbj;//指标项
for(var i in newDatabj){
var ratio = {};
ratio["index_id"] = newDatabj[i].ID;
ratio["ratio"] = $("input#name"+i,parent.document).val()
modelIndexRatioList.push(ratio);
totalbj += Number($("input#name"+i,parent.document).val())
};
totalbj = parseFloat(totalbj).toFixed(2);
var modelIndexMeunList = new Array();
var newDatabj2 = datarightbj;//指标项
for(var i in newDatabj2){
var meun = {};
meun["facility_id"] = newDatabj2[i].facilityId;
meun["scheme_type"] = $("#select"+i+" option:selected",parent.document).val()
modelIndexMeunList.push(meun);
};
var paramsbj = {};
paramsbj.modelScheme = JSON.stringify(modelScheme);
paramsbj.modelIndexRatioList = JSON.stringify(modelIndexRatioList);
paramsbj.modelIndexMeunList = JSON.stringify(modelIndexMeunList);
paramsbj.page = $(".pagination-num").val();
paramsbj.rows = $(".pagination-page-list").val();
var arrbj = {'modelScheme':modelScheme,'modelIndexRatioList':modelIndexRatioList,'modelIndexMeunList':modelIndexMeunList};
if($("input#schemename",parent.document).val()==""){
alert("方案名称不能为空,请填写!");
return;
}
if(totalbj<1){
var numbed = (1-totalbj).toFixed(2);
alert("占比总和应为1,还差"+numbed+",您可以再添加指标项或重新填写");
return;
}else if(totalbj>1){
var numbed =(totalbj-1).toFixed(2);
alert("占比总和应为1,已超"+numbed+",请重新填写")
return;
}else{
}
easyui.ajax({
url:path+"/schemeMapping/updateSchemeAndRatioAndMeunBySchemeId",
data:paramsbj,
func:function(data){
if(data.success){
$("#tg").datagrid("loadData",data.grid);
window.parent.popupClose();
}
easyui.msg(data.msg);
},
error:function(error){
easyui.msg("编辑失败!");
window.parent.popupClose();
}
});
}
}
function operation(type){
if(type=="add"){//新增
}else if(type=="edit"){//编辑
}
}
function select(record){
for(var i=0;i<_modelTypes.length;i++){
if(_modelTypes[i].id == record.name){
$("#model_tname",parent.document).val(_modelTypes[i].text).attr("model_id",_modelTypes[i].id);
}
}
}
//button显示隐藏控制
function checkRight(){
easyui.ajax({
url:path+"/right/checkRightByMenuId",
data:{"menuId":iframeId},
func:function(ableRight){
$.each(ableRight,function(i,v){
$.each($("#btn button"),function(i2,v2){
if(v["rightLinkWebComponentId"]==$(v2).attr("id")){
$(v2).show();
}
});
});
}
});
}
</script>
</html>
合并相同行方法
//动态合并行方法,扩展Easyui
/* 使用方法:$('#grid).datagrid("autoMergeCells", ['field1', 'field2','field3',……]);
后面的数组 即 你想要合并的显示的 列 如果你只有一个列需要合并 那么数组中指定一个列的field即可 */
$.extend($.fn.datagrid.methods, {
autoMergeCells: function (jq, fields) {
return jq.each(function () {
var target = $(this);
if (!fields) {
fields = target.datagrid("getColumnFields");
}
var rows = target.datagrid("getRows");
var i = 0,
j = 0,
temp = {};
for (i; i < rows.length; i++) {
var row = rows[i];
j = 0;
for (j; j < fields.length; j++) {
var field = fields[j];
var tf = temp[field];
if (!tf) {
tf = temp[field] = {};
tf[row[field]] = [i];
} else {
var tfv = tf[row[field]];
if (tfv) {
tfv.push(i);
} else {
tfv = tf[row[field]] = [i];
}
}
}
}
$.each(temp, function (field, colunm) {
$.each(colunm, function () {
var group = this;
if (group.length > 1) {
var before,after,megerIndex = group[0];
for (var i = 0; i < group.length; i++) {
before = group[i];
after = group[i + 1];
if (after && (after - before) == 1) {
continue;
}
var rowspan = before - megerIndex + 1;
if (rowspan > 1) {
target.datagrid('mergeCells', {
index: megerIndex,
field: field,
rowspan: rowspan
});
}
if (after && (after - before) != 1) {
megerIndex = after;
}
}
}
});
});
});
}
合并行法二:
function uniteTable(tableId,colLength) {//表格ID,表格列数
var tb=document.getElementsByClassName(tableId)[0];
tb.style.display='';
var i = 0;
var j = 0;
var rowCount = tb.rows.length; // 行数
var colCount = tb.rows[0].cells.length; // 列数
var obj1 = null;
var obj2 = null;
//为每个单元格命名
for (i = 0; i < rowCount; i++) {
for (j = 0; j < colCount; j++) {
tb.rows[i].cells[j].id = "tb__" + i.toString() + "_" + j.toString();
}
}
//合并行
for (i = 0; i < colCount; i++) {
if (colLength.indexOf(i) == -1) continue;
obj1 = document.getElementById("tb__0_" + i.toString())
for (j = 1; j < rowCount; j++) {
obj2 = document.getElementById("tb__" + j.toString() + "_" + i.toString());
if (obj1.innerText == obj2.innerText && ((obj2.innerText != "" || obj1.innerText != "")&&(obj1.innerText != "-"|| obj2.innerText != "-"))) {
obj1.rowSpan++;
obj2.parentNode.removeChild(obj2);
} else {
obj1 = document.getElementById("tb__" + j.toString() + "_" + i.toString());
}
}
}
//合并列
/* for (i = 0; i < rowCount; i++) {
colCount = tb.rows[i].cells.length;
obj1 = document.getElementById(tb.rows[i].cells[0].id);
for (j = 1; j < colCount; j++) {
if (j >= colLength) break;
if (obj1.colSpan >= colLength) break;
obj2 = document.getElementById(tb.rows[i].cells[j].id);
if (obj1.innerText == obj2.innerText && ((obj2.innerText != "" || obj1.innerText != "")&&(obj1.innerText != "-"|| obj2.innerText != "-"))) {
obj1.colSpan++;
obj2.parentNode.removeChild(obj2);
j = j - 1;
}
else {
obj1 = obj2;
j = j + obj1.rowSpan;
}
}
}*/
}
使用:
uniteTable("datagrid-btable",[2,5,8,11]);
法三:根据上下行的名称和值是否相同才合并
var mark = 1;//根据上下行的名称和值是否相同才合并
if (data.rows[i]['MP_NAME_ONE'] == data.rows[i-1]['MP_NAME_ONE']&&data.rows[i]['TOTAL_ONE'] == data.rows[i-1]['TOTAL_ONE']) {
mark += 1;
$("#tb").datagrid('mergeCells',{
index: i+1-mark, //第几行开始合并
field: 'TOTAL_ONE', //合并的列
rowspan:mark //合并的格数
})
}else{
mark=1;
}