<%@ page contentType="text/html;charset=UTF-8" %>
<script>
$(document).ready(function() {
	$('#projectTable').bootstrapTable({
		  //请求方法
               method: 'post',
               //类型json
               dataType: "json",
               contentType: "application/x-www-form-urlencoded",
               // //显示检索按钮
	           // showSearch: true,
               //显示刷新按钮
               showRefresh: true,
               // //显示切换手机试图按钮
               // showToggle: true,
               // //显示 内容列下拉框
    	       // showColumns: true,
    	       // //显示到处按钮
    	       // showExport: true,
    	       // //显示切换分页按钮
    	       // showPaginationSwitch: true,
    	       //最低显示2行
    	       minimumCountColumns: 2,
               //是否显示行间隔色
               striped: true,
               //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
               cache: false,
               //是否显示分页（*）
               pagination: false,
                //排序方式
               sortOrder: "asc",
               //初始化加载第一页，默认第一页
                pageNumber:1,
                // useCurrentPage:true,
               //每页的记录行数（*）
               // pageSize: 3000,
               //可供选择的每页的行数（*）
               // pageList: [5,10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
               url: "${ctx}/sg/managementCenter/projectPlanArrage/dataPower2",
               //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
               //queryParamsType:'',
               ////查询参数,每次调用是会带上这个参数，可自定义
               queryParams : function(params) {
               	var searchParam = $("#searchForm").serializeJSON();
               	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
               	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
               	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                   return searchParam;
               },
               //分页方式：client客户端分页，server服务端分页（*）
               sidePagination: "server",
               contextMenuTrigger:"right",//pc端 按右键弹出菜单
               contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
               contextMenu: '#context-menu',
               onContextMenuItem: function(row, $el){
                   if($el.data("item") == "edit"){
                   		edit(row.id);
                   }else if($el.data("item") == "view"){
                       view(row.id);
                   } else if($el.data("item") == "delete"){
                        jp.confirm('确认要删除该表单记录吗？', function(){
                       	jp.loading();
                       	jp.get("${ctx}/sg/managementcenter/project/delete?id="+row.id, function(data){
                   	  		if(data.success){
                   	  			$('#projectTable').bootstrapTable('refresh');
                   	  			jp.success(data.msg);
                   	  		}else{
                   	  			jp.error(data.msg);
                   	  		}
                   	  	})

                   	});

                   }
               },
                onLoadSuccess:function(data) {
                    var split = data.rows;
                    var tb = document.getElementById('projectTable');    // table 的 id
                    var rows = tb.rows;                           // 获取表格所有行
                    for (var i =0;i<split.length;i++){
                        if (split[i].htmlStatus=="1"){
                            // this.data.rows[i].setAttribute("style","color: red;");
                            rows[i+1].style.color = "red"
                        }
                    }
                },
                onClickRow: function(row, $el){
               },

            onShowSearch: function () {
			$("#search-collapse").slideToggle();
		},
               columns: [
                   {
		        field: 'projectNumber',
		        title: '项目定义号'

            }
                   ,{
                       field: 'projectName',
                       title: '项目名称'

                   }
                   ,{
                       field: 'projectMonthDate',
                       title: '停电月份'

                   }
                   ,{
                       field: 'projectPowerRange',
                       title: '停电范围',
                       width:300

                   }
                   ,{
                       field: 'projectPowerOut',
                       title: '是否带电',
                       width:120,
                       formatter: getTime
                   },{
                       field: 'constructionUnit',
                       title: '施工单位项目经理'

                   }
                   ,{
                       field: 'associatedBag',
                       title: '关联包'
                   }
                   ,{
                       field: 'powerPackage',
                       title: '停电包'
                   }
		     ]
		});
    function getTime(value, row, index) {
        if(row.projectPowerOut == "带电") {
            return [
                "<select class='form-control' id=" + row.id + "><option value='停电'>停电</option><option value='带电'  selected>带电</option><select>",
            ].join('');
        }else {
            return [
                "<select class='form-control' id=" + row.id + "><option value='停电'  selected>停电</option><option value='带电' >带电</option><select>",
            ].join('');
        }
    }
    // onclick='submit("+row.id+")'
	  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端

		 
		  $('#projectTable').bootstrapTable("toggleView");
		}
	  
	  $('#projectTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
            $('#remove').prop('disabled', ! $('#projectTable').bootstrapTable('getSelections').length);
            $('#view,#edit').prop('disabled', $('#projectTable').bootstrapTable('getSelections').length!=1);
        });
		    
	  $("#search").click("click", function() {// 绑定查询按扭
		  $('#projectTable').bootstrapTable('refresh');
		});
	 
	 $("#reset").click("click", function() {// 绑定查询按扭
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		  $("#searchForm  .select-item").html("");
		  $('#projectTable').bootstrapTable('refresh');
		});
		
		$('#beginBeginDate').datetimepicker({
			 format: "YYYY-MM-DD HH:mm:ss"
		});
		$('#endBeginDate').datetimepicker({
			 format: "YYYY-MM-DD HH:mm:ss"
		});
		$('#endDate').datetimepicker({
			 format: "YYYY-MM-DD HH:mm:ss"
		});
		
	});
		
  function getIdSelections() {
        return $.map($("#projectTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }
    function getDate() {
        return $.map($("#projectTable").bootstrapTable('getData'), function (row) {
            return row
        });
    }
    // function f() {
    //
    // }
    //刷新列表
  function refresh(){
  	$('#projectTable').bootstrapTable('refresh');
  }
  
   function add(){
	  jp.openSaveDialog('新增项目计划安排', "${ctx}/sg/managementCenter/constructionProject/form",'800px', '500px');
  }
  // function submit(data) {
  //     alert("1");
  //     alert(data);
  // }

  
   function edit(id){//没有权限时，不显示确定按钮
       if(id == undefined){
	      id = getIdSelections();
	}
	jp.openSaveDialog('编辑项目管理表单', "${ctx}/sg/managementcenter/project/form?id=" + id, '800px', '500px');
  }
  
 function view(id){//没有权限时，不显示确定按钮
      if(id == undefined){
             id = getIdSelections();
      }
        jp.openViewDialog('查看项目管理表单', "${ctx}/sg/managementcenter/project/form?id=" + id, '800px', '500px');
 }

function save() {
    var date = getDate();
    var idPower = "";
    var id = "";
    for (var i = 0; i < date.length; i++){
        id = date[i].id;
        idPower += date[i].id + "," + $("#"+id).val() + ";";
    }
    idPower = idPower.substring(0,idPower.length-1);
    $("#idPower").val(idPower);
    jp.loading();
    jp.post("${ctx}/sg/managementCenter/projectPlanArrage/inspectionNetWork",$('#inputForm').serialize(),function(data){
        if(data.success){
            refresh();
            // $('#projectTable').bootstrapTable('refresh');
            jp.success(data.msg);
        }else{
            jp.error(data.msg);
        }
    })
}

function saveSure(){
    var date = getDate();
    var idPower = "";
    var id = "";
    for (var i = 0; i < date.length; i++){
        id = date[i].id;
        idPower += date[i].id + "," + $("#"+id).val() + ";";
    }
    idPower = idPower.substring(0,idPower.length-1);
    return idPower;
    // $("#idPower").val(idPower);
    // jp.loading();
    // jp.post("${ctx}/sg/managementCenter/projectPlanArrage/sureInspection",$('#inputForm').serialize(),function(data){
    //     if(data.success){
    //         jp.confirm('带电项目在停电开关集合，是否通过？', function () {
    //             var dialogIndex = parent.layer.getFrameIndex(window.name); // 获取窗口索引
    //             // parent.layer.close(dialogIndex);
    //             addDatePlan();
    //             jp.success("项目计划流程发起");
    //             jp.go("${ctx}/act/task/todo");
    //         })
    //     }else{
    //         var dialogIndex = parent.layer.getFrameIndex(window.name); // 获取窗口索引
    //         parent.layer.close(dialogIndex);
    //         addDatePlan();
    //     }
    // })
}


// function addDatePlan() {
//     jp.post("${ctx}/sg/managementCenter/projectPlanArrage/save",function(data){
//         if(data.success){
//             jp.success("项目计划流程发起");
//             jp.go("${ctx}/act/task/todo")
//         }else {
//             jp.error("流程发起失败,请重新发起!");
//         }
//     })
// }
</script>