352 lines
14 KiB
Plaintext
352 lines
14 KiB
Plaintext
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||
<!DOCTYPE html>
|
||
<!--引入bootstrap表格编辑单元格插件 -->
|
||
<link rel="stylesheet" href="<%=request.getContextPath()%>/plugins/bootstrap-editable/css/bootstrap-editable.css"/>
|
||
<script type="text/javascript" src="<%=request.getContextPath()%>/plugins/bootstrap-editable/js/bootstrap-editable.js" charset="utf-8"></script>
|
||
<script type="text/javascript" src="<%=request.getContextPath()%>/plugins/bootstrap-editable/js/bootstrap-table-editable.js" charset="utf-8"></script>
|
||
|
||
<script type="text/javascript">
|
||
var doSearchUser = function() {
|
||
$("#table_company").bootstrapTable('refresh');
|
||
};
|
||
//编辑可维护的厂区
|
||
var editMaintainerCompanyFun = function(companyId,maintainercompanyid) {
|
||
stopBubbleDefaultEvent();
|
||
$.post(ext.contextPath + '/maintenance/maintainer/editCompany.do', {companyId:companyId,maintainercompanyid:maintainercompanyid,maintainerId:"${maintainerId}"} , function(data) {
|
||
$("#subCompanyDiv").html(data);
|
||
openModal('subCompanyModal');
|
||
});
|
||
};
|
||
function dosave(dialog,grid) {
|
||
//获取勾选的数据
|
||
//var checkedItems = $("#table_company").bootstrapTable('getAllSelections');
|
||
var datas="";
|
||
$.each(selectionCompanyIds, function(index, item){
|
||
if(datas!=""){
|
||
datas+=",";
|
||
}
|
||
datas+=item;
|
||
});
|
||
$.post(ext.contextPath + '/maintenance/maintainer/saveMaintainerCompany.do', {companyIds:datas,maintainerId:"${maintainerId}"} , function(data) {
|
||
if(data >= 0){
|
||
closeModal('maintainerCompanyModal');
|
||
}else{
|
||
showAlert('d','保存失败');
|
||
}
|
||
});
|
||
};
|
||
|
||
|
||
function stateFormatter(value, row, index) {
|
||
var flag=false;
|
||
$.each(eval('${json}'), function(index, item){
|
||
if(row.id==item.id){
|
||
flag=true;
|
||
}
|
||
});
|
||
if (flag)
|
||
return {
|
||
checked : true//设置选中
|
||
};
|
||
return value;
|
||
}
|
||
var $table;
|
||
var switchStatus=false;
|
||
var selectionCompanyIds = []; //保存选中ids
|
||
function initialSelectionIds(){
|
||
var check_array =eval('${json}');
|
||
if(check_array!=null&& check_array.length>0){
|
||
selectionCompanyIds =new Array(check_array.length);
|
||
for(var i=0;i<check_array.length;i++){
|
||
selectionCompanyIds[i]=check_array[i].id;
|
||
}
|
||
}
|
||
}
|
||
function getCheckedIds(){
|
||
var ids="";
|
||
var check_array =eval('${json}');
|
||
$.each(check_array, function(index, item){
|
||
if(ids!=""){
|
||
ids+=",";
|
||
}
|
||
ids+=item.id;
|
||
});
|
||
return ids;
|
||
}
|
||
function queryParams(params) {
|
||
|
||
var temp={
|
||
rows: params.limit, // 每页要显示的数据条数
|
||
page: params.offset/params.limit+1, // 每页显示数据的开始页码
|
||
sort: params.sort, // 要排序的字段
|
||
order: params.order, // 排序规则
|
||
search_name: $('#search_name').val(),
|
||
maintainerId: '${maintainerId}'
|
||
};
|
||
var status =$('#switchBtn').bootstrapSwitch('state')
|
||
if(status){
|
||
temp.checkedIds=getCheckedIds();
|
||
}
|
||
return temp;
|
||
}
|
||
$(function() {
|
||
//jquery html()方法加载,导致box无法执行boxwidget(),手动初始化
|
||
$('#searchBox').boxWidget();
|
||
$('#switchBtn').bootstrapSwitch({
|
||
onText:'是',
|
||
offText:'否',
|
||
size:"small",
|
||
});
|
||
|
||
initialSelectionIds();
|
||
$table=$("#table_company").bootstrapTable({ // 对应table标签的id
|
||
url: ext.contextPath + '/user/getAllBizs.do', // 获取表格数据的url
|
||
//cache: false, // 设置为 false 禁用 AJAX 数据缓存, 默认为true
|
||
clickToSelect:false,
|
||
striped: true, //表格显示条纹,默认为false
|
||
pagination: true, // 在表格底部显示分页组件,默认false
|
||
pageList: [10, 20], // 设置页面可以显示的数据条数
|
||
pageSize: 20, // 页面数据条数
|
||
pageNumber: 1, // 首页页码
|
||
sidePagination: 'server', // 设置为服务器端分页
|
||
responseHandler:responseHandler, //在渲染页面数据之前执行的方法,此配置很重要!!!!!!!
|
||
queryParams: queryParams,
|
||
queryParamsType: "limit",
|
||
sortName: 'id', // 要排序的字段
|
||
sortOrder: 'desc', // 排序规则
|
||
/* showColumns: true,
|
||
showRefresh: true, */
|
||
columns: [
|
||
{
|
||
checkbox: true, // 显示一个勾选框
|
||
//formatter: stateFormatter
|
||
formatter: function (i,row) { // 每次加载 checkbox 时判断当前 row 的 id 是否已经存在全局 Set() 里
|
||
if($.inArray(row.id,Array.from(selectionCompanyIds))!=-1){ // 因为 Set是集合,需要先转换成数组
|
||
return {
|
||
checked : true // 存在则选中
|
||
}
|
||
}
|
||
}
|
||
}, {
|
||
field: 'name', // 返回json数据中的name
|
||
title: '名称', // 表格表头显示文字
|
||
align: 'center', // 左右居中
|
||
valign: 'middle', // 上下居中
|
||
width:'250px'
|
||
},{
|
||
field: 'maintainerCompany.startdate', // 返回json数据中的name
|
||
title: '开始日期', // 表格表头显示文字
|
||
align: 'center', // 左右居中
|
||
valign: 'middle', // 上下居中
|
||
width:'250px',
|
||
/* editable: {
|
||
type: 'date',
|
||
title: '开始日期',
|
||
placement: 'bottom',
|
||
datepicker: {
|
||
language: 'zh-CN',
|
||
}
|
||
} */
|
||
},{
|
||
field: 'maintainerCompany.enddate', // 返回json数据中的name
|
||
title: '结束日期', // 表格表头显示文字
|
||
align: 'center', // 左右居中
|
||
valign: 'middle', // 上下居中
|
||
width:'250px',
|
||
/* editable: {
|
||
type: 'date',
|
||
title:'结束日期',
|
||
placement: 'bottom',
|
||
datepicker: {
|
||
language: 'zh-CN',
|
||
}
|
||
} */
|
||
},{
|
||
field: 'maintainerCompany.maintainerleader', // 返回json数据中的name
|
||
title: '运维商负责人', // 表格表头显示文字
|
||
align: 'center', // 左右居中
|
||
valign: 'middle', // 上下居中
|
||
width:'250px'
|
||
},{
|
||
field: 'maintainerCompany.factorycontacter', // 返回json数据中的name
|
||
title: '厂区联系人', // 表格表头显示文字
|
||
align: 'center', // 左右居中
|
||
valign: 'middle', // 上下居中
|
||
width:'250px'
|
||
},{
|
||
title: "操作",
|
||
align: 'center',
|
||
valign: 'middle',
|
||
width: 120, // 定义列的宽度,单位为像素px
|
||
formatter: function (value, row, index) {
|
||
var buts= '';
|
||
buts+= '<button class="btn btn-default btn-sm" title="编辑" onclick="editMaintainerCompanyFun(\'' + row.id + '\',\'' + row.maintainerCompany.id + '\')"><i class="fa fa-edit"></i><span class="hidden-md hidden-lg"> 编辑</span></button>';
|
||
buts='<div class="btn-group" >'+buts+'</div>';
|
||
return buts;
|
||
}
|
||
}
|
||
|
||
],
|
||
onLoadSuccess: function(){ //加载成功时执行
|
||
adjustBootstrapTableView("table_company");
|
||
},
|
||
onLoadError: function(){ //加载失败时执行
|
||
console.info("加载数据失败");
|
||
}
|
||
|
||
})
|
||
|
||
//绑定选中事件、取消事件、全部选中、全部取消
|
||
$table.on('check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table', function (e, rows, $element) {
|
||
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
|
||
return row.id;
|
||
});
|
||
//获取被点击行的数据
|
||
var rowdata = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
|
||
return row;
|
||
});
|
||
func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference';
|
||
selectionCompanyIds = _[func](selectionCompanyIds, ids);
|
||
//根据勾选或取消勾选的状态弹出提示框
|
||
if('check' == e.type){
|
||
if(rowdata[0].maintainerCompany.startdate == "" || rowdata[0].maintainerCompany.enddate == ""){
|
||
swal({
|
||
text:"您还未编辑运维厂区的信息,不能勾选!",
|
||
dangerMode:true,
|
||
buttons: {
|
||
confirm: {
|
||
text:"确定",
|
||
value: true,
|
||
visible: true,
|
||
className: "btn btn-info btn-sm",
|
||
closeModal: true
|
||
}
|
||
}
|
||
}).then( function(willDelete){
|
||
if(willDelete){
|
||
selectionCompanyIds.splice($.inArray(rowdata[0].id,selectionCompanyIds),1);
|
||
//$("#table_company").bootstrapTable('refresh');
|
||
$($element.get(0)).removeAttr('checked');
|
||
$($element.get(0)).parent().removeClass('checked');
|
||
}
|
||
})
|
||
}
|
||
}else{
|
||
if(rowdata[0].maintainerCompany.startdate != "" && rowdata[0].maintainerCompany.enddate != ""){
|
||
swal({
|
||
text: "取消勾选并保存后,关联的维护厂区数据会被删除,您确定取消勾选?",
|
||
dangerMode: true,
|
||
buttons: {
|
||
cancel: {
|
||
text: "取消",
|
||
value: true,
|
||
visible: true,
|
||
className: "btn btn-default btn-sm",
|
||
closeModal: true,
|
||
},
|
||
confirm: {
|
||
text: "确定",
|
||
value: null,
|
||
visible: true,
|
||
className: "btn btn-info btn-sm",
|
||
closeModal: true
|
||
}
|
||
}
|
||
}).then( function(willDelete){
|
||
if (willDelete) {
|
||
selectionCompanyIds.push(rowdata[0].id);
|
||
// $("#table_company").bootstrapTable('refresh');
|
||
$($element.get(0)).parent().addClass('checked');
|
||
}
|
||
});
|
||
}
|
||
}
|
||
})
|
||
})
|
||
//选中事件操作数组
|
||
var union = function(array,ids){
|
||
$.each(ids, function (i, id) {
|
||
if($.inArray(id,array)==-1){
|
||
array[array.length] = id;
|
||
}
|
||
});
|
||
return array;
|
||
};
|
||
//取消选中事件操作数组
|
||
var difference = function(array,ids){
|
||
$.each(ids, function (i, id) {
|
||
var index = $.inArray(id,array);
|
||
if(index!=-1){
|
||
array.splice(index, 1);
|
||
}
|
||
});
|
||
return array;
|
||
};
|
||
var _ = {"union":union,"difference":difference};
|
||
|
||
//表格分页之前处理多选框数据
|
||
function responseHandler(res) {
|
||
$.each(res.rows, function (i, row) {
|
||
row.checkStatus = $.inArray(row.id, selectionCompanyIds) != -1; //判断当前行的数据id是否存在与选中的数组,存在则将多选框状态变为true
|
||
});
|
||
return res;
|
||
}
|
||
</script>
|
||
<div class="modal fade" id="maintainerCompanyModal">
|
||
<div class="modal-dialog modal-lg">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||
<span aria-hidden="true">×</span></button>
|
||
<h4 class="modal-title">可运维厂区配置</h4>
|
||
</div>
|
||
<div class="modal-body " style="width:100%">
|
||
<div id="alertDiv"></div>
|
||
|
||
<div class="box box-primary box-solid collapsed-box" id="searchBox" collapsed>
|
||
<div class="box-header">
|
||
<!-- tools box -->
|
||
<div class="pull-right box-tools">
|
||
<button type="button" class="btn btn-primary btn-sm pull-right" data-widget="collapse"
|
||
style="margin-right: 5px;">
|
||
<i class="fa fa-plus"></i></button>
|
||
</div>
|
||
<!-- /. tools -->
|
||
<i class="fa fa-search"></i>
|
||
</div>
|
||
<div class="box-body collapse" >
|
||
<form class="form-horizontal " >
|
||
<div class="form-group" style="margin-right: 20px;">
|
||
<label class="col-sm-2 control-label">厂名</label>
|
||
<div class="col-sm-4">
|
||
<input type="text" id="search_name" name="search_name" class="form-control input-sm" placeholder="厂名" style="width:170px;">
|
||
</div>
|
||
|
||
</div>
|
||
<div class="form-group" style="margin-right: 20px;">
|
||
<label class="col-sm-2 control-label">只看选中</label>
|
||
<div class="col-sm-4">
|
||
<div class="switch" data-on="primary" data-off="info">
|
||
<input id ="switchBtn" type="checkbox" />
|
||
</div>
|
||
</div>
|
||
<div class=" col-sm-6 button-group" style="padding: 0;">
|
||
<button type ="button" class="btn btn-default btn-sm pull-right" onclick="doSearchUser();"><i class="fa fa-search"> 搜索</i></button>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<div id="table_company" style="height:230px;overflow:auto;width:100%"></div>
|
||
</div>
|
||
</div>
|
||
<div class="modal-footer">
|
||
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
|
||
<button type="button" class="btn btn-primary" onclick="dosave()">保存</button>
|
||
</div>
|
||
</div>
|
||
<!-- /.modal-content -->
|
||
</div>
|
||
<!-- /.modal-dialog -->
|
||
</div> |