<%@ 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,
               // //每页的记录行数（*）
               // pageSize: 5000,
               // //可供选择的每页的行数（*）
               // pageList: [5,10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
               url: "${ctx}/sg/managementCenter/projectPlanArrage/planNetDateTable",
               //默认值为 '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;
            for (var i = 0; i < split.length; i++) {
                var arrangeTime = split[i].projectMonthDate;
                var date = new Date(arrangeTime);
                var date1 = new Date(arrangeTime);
                date1.setMonth(date1.getMonth()+1);
                $('#' + split[i].id).datetimepicker({
                    format: "YYYY-MM-DD"
                    // minDate:date,
                    // maxDate:date1,
                }).on('dp.change', function (i) {
                    return function (ev) {
                        var newDateTime = ev.date ? ev.date.format('YYYY-MM-DD') : "";
                        var oldDateTime = ev.oldDate ? ev.oldDate.format('YYYY-MM-DD') : "";
                        if (newDateTime != oldDateTime) {
                            if ("" != oldDateTime) {
                                jp.confirm('确认要更新时间吗？', function () {
                                    jp.get("${ctx}/sg/managementCenter/projectPlanArrage/addtimeNet?id=" + split[i].id + "&projectDate=" + newDateTime, function (data) {
                                        if (data.success) {
                                            jp.success(data.msg);
                                        } else {
                                            jp.error(data.msg);
                                        }
                                    })
                                })
                            } else {
                                jp.get("${ctx}/sg/managementCenter/projectPlanArrage/addtimeNet?id=" + split[i].id + "&projectDate=" + newDateTime, function (data) {
                                    if (data.success) {
                                        // jp.success(data.msg);
                                    } else {
                                        jp.error(data.msg);
                                    }
                                })
                            }

                        }
                    }
                }(i));
            }
        },
               onClickRow: function(row, $el){
               },

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

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

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

                   }
                   ,{
                       field: 'projectMonthDate',
                       width:160,
                       title: '计划月份'
                   }
                   ,{
                       field: 'constructionUnit',
                       width:160,
                       title: '施工单位项目经理'
                   }
                   ,{
                       field: 'associatedBag',
                       width:160,
                       title: '关联包'
                   }
                   ,{
                       field: 'powerPackage',
                       width:160,
                       title: '停电包'
                   }
                   ,{
                       field: 'projectDate',
                       title: '安排计划时间',
                       width:160,
                       formatter: getTime
                   }
		     ]
		
		});

    function getTime(value, row, index) {
        return [
            "<div class='input-group form_datetime' style='width: 100%' id="+row.id+"> <input type='text' id="+row.id+"input"+"   name='deliverySchedule' class='form-control required'  value="+row.projectDate+"/> <span class='input-group-addon'> <span class='glyphicon glyphicon-calendar'></span> </span></div>" ,
        ].join('');

    }
	  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 refresh(){
  	$('#projectTable').bootstrapTable('refresh');
  }
    function save() {
        var date = getDate();
        var idPower = "";
        var id = ""
        var flag = false;
        for (var i = 0; i < date.length; i++){
            id = date[i].id;
            idPower = $("#"+id+"input").val();
            if (null == idPower||"" == idPower){
                flag = true;
            }
        }
        if (flag){
            jp.error("请选择具体时间!")
            return false;
        } else {
            return true;
        }
        return true;
    }
</script>