<%@ page contentType="text/html;charset=UTF-8" %>
<script>
$(document).ready(function() {
	$('#informationTable').bootstrapTable('hideLoading');
	//定义方法---在bootstrap数据循环中使用，必须定义在bootstrapTable之前
	window.operateEvents = {
		'click #TableView': function (e, value, row, index) {
			jp.openTab("${ctx}/sg/material?projectId="+row.projectId,'查看《'+row.projectName+'》物料情况', true);
		}
	};
	//bootstrapTable加载数据
	$('#informationTable').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: true,
                //排序方式
               sortOrder: "asc",
               //初始化加载第一页，默认第一页
               pageNumber:1,
               //每页的记录行数（*）
               pageSize: 10,
               //可供选择的每页的行数（*）
               pageList: [10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
               url: "${ctx}/sg/information/data",
               //默认值为 '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',
               onClickRow: function(row, $el){
               },
			onLoadSuccess: function () {  //加载成功时执行
				getTdValue();
			},
			onShowSearch: function () {
				$("#search-collapse").slideToggle();
			},
               columns: [
               	{
		        field: 'projectId',
		        title: '项目定义号',
				width:'120px',
		        sortName: 'project_id'
		    }
			,{
		        field: 'projectName',
		        title: '项目名称',
			    width:'120px',
		        sortName: 'project_name'
		    }
			,{
		        field: 'projectType',
		        title: '项目</br>类型',
			   	width:'60px',
		        sortName: 'project_type'
		    }
		   ,{
			   field: 'appendStatus',
			   title: '工作</br>状态',
			   width:'60px',
			   sortName: 'appendStatus'
		   }
		   ,{
			   field: 'approvalDate',
			   title: '审定</br>日期',
			   width:'60px',
			   sortName: 'approvalDate'
		   }
		   ,{
			   field: 'complete',
			   title: '是否</br>完成</br>甲供</br>材领</br>退料',
			   width:'60px',
		   }
		   ,{
			   field: 'finishDate',
			   title: '完成</br>甲供</br>物资</br>领退</br>料的</br>时间',
			   width:'60px',
		   }
		   ,{
			   field: 'noFinishDate',
			   title: '未完</br>成甲</br>供物</br>资领</br>退料</br>的时间',
			   width:'60px',
		   }
		   ,{
			   field: 'overdue',
			   title: '是否</br>超期',
			   width:'60px',
			   sortName: 'overdue'
		   }
		   ,{
			   field: 'trial',
			   title: '是否</br>决算</br>送审',
			   width:'60px',
			   sortName: 'trial'
		   }
		   ,{
			   field: 'firstFinish',
			   title: '第1次</br>是否</br>完成</br>甲供</br>物资</br>领退料',
			   width:'60px',
			   sortName: 'firstFinish'
		   }
		   ,{
			   field: 'firstFinishDate',
			   title: '第1次完成</br>甲供物资领</br>退料的日期',
			   width:'100px',
			   sortName: 'firstFinishDate'
		   }
		   ,{
			   field: 'secondFinish',
			   title: '第2次</br>是否</br>完成</br>甲供</br>物资</br>领退料',
			   width:'60px',
			   sortName: 'secondFinish'
		   }
		   ,{
			   field: 'secondFinishDate',
			   title: '第2次完成</br>甲供物资领</br>退料的日期',
			   width:'100px',
			   sortName: 'secondFinishDate'
		   }
		   ,{
			   field: 'suggestedAmount',
			   title: '建议</br>结算款',
			   width:'80px',
			   sortName: 'suggestedAmount'
		   }
		   ,{
			   field: 'firstUnits',
			   title: '一级</br>单位',
			   width:'60px',
			   sortName: 'first_units'
		   }
		   ,{
			   field: 'secondUnits',
			   title: '二级</br>单位',
			   width:'60px',
			   sortName: 'second_units'
		   }
		   ,{
			   field: 'underCentralized',
			   title: '归口部门',
			   width:'120px',
			   sortName: 'underCentralized'
		   }
			,{
		        field: 'projectGrade',
		        title: '电压</br>等级',
			   width:'60px',
		        sortName: 'project_grade'
		    }
			,{
		        field: 'projectYear',
		        title: '项目</br>预算</br>年度',
			   width:'60px',
		        sortName: 'project_year'
		    }
			,{
		        field: 'projectTotal',
		        title: '项目</br>总投资',
			   width:'70px',
		        sortName: 'project_total'
		    }
		   ,{
			   field: 'projectStart',
			   title: '实际开工</br>日期',
			   width:'100px',
			   sortName: 'project_start'
		   }
		   ,{
			   field: 'projectStop',
			   title: '实际竣工</br>日期',
			   width:'100px',
			   sortName: 'project_stop'
		   }
		   ,{
			   field: 'department',
			   title: '施工</br>单位',
			   width:'60px',
			   sortName: 'department'
		   }
		   ,{
			   field: 'projectFirm',
			   title: '结算审计</br>单位名称',
			   width:'100px',
			   sortName: 'project_firm'
		   }
		   ,{
			   field: 'subDate',
			   title: '提交送审</br>日期',
			   width:'100px',
			   sortName: 'subDate'
		   }
		   ,{
			   field: 'releaseDate',
			   title: '审计任务</br>下达日期',
					   width:'100px',
			   sortName: 'releaseDate'
		   }
		   ,{
			   field: 'endDate',
			   title: '审计</br>应结束日</br>时间',
			   width:'100px',
			   sortName: 'endDate'
		   }
		   ,{
			   field: 'resultDate',
			   title: '结果上传</br>时间',
			   width:'100px',
			   sortName: 'resultDate'
		   }
			,{
			   field: 'operate',
			   title: '操作',
			   width: '80px',
			   events: operateEvents,
			   formatter: operateFormatter
		   }
		     ],
			formatNoMatches:function(){
				return "没有对应数据";
			},

		});

	function operateFormatter(value, row, index) {
		return [
			'<input id="TableView" type="button" value="查看" class="btn btn-default">',
		].join('');
	}

	  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端
		  $('#informationTable').bootstrapTable("toggleView");
		}

	  //加载完成后，对第二次是否完成领退料判断变并变更行样式
	function getTdValue() {
		var tableId = document.getElementById("informationTable");
		if (tableId.rows.length>2){
		for(var i = 1;i < tableId.rows.length;i++) {
			if(tableId.rows[i].cells[12].innerHTML!="-"){
				tableId.rows[i].setAttribute("style","color: red;");
			}
		}
		}
		$("#hiddenSign").val("不是第一次加载")
	}


		//导入甲供材
	  	$("#btnInformation").click(function () {
			jp.open({
				type: 2,
				area: [500, 200],
				auto: true,
				title:"导入甲供材",
				content: "${ctx}/tag/importExcel" ,
				btn: ['确定', '关闭'],
				btn1: function(index, layero){
					var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
					iframeWin.contentWindow.importExcel('${ctx}/sg/information/import', function (data) {
						console.log(data);
						if(data.success){
						jp.success(data.msg);
						refresh();
						}else{
						jp.error(data.msg);
						}
						jp.close(index);
					});//调用保存事件
					return false;
				},
				btn2: function(index){
					jp.close(index);
				}
			})
		})

	//导入送审
	$("#btnInTrial").click(function () {
		jp.open({
			type: 2,
			area: [500, 200],
			auto: true,
			title:"导入数据",
			content: "${ctx}/tag/importExcel" ,
			btn: ['下载模板','确定', '关闭'],
			btn1: function(index, layero){
				jp.downloadFile('${ctx}/sg/information/import/templates');
			},
			btn2: function(index, layero){
				var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
				iframeWin.contentWindow.importExcel('${ctx}/sg/information/importInTrial', function (data) {
					if(data.success){
						jp.success(data.msg);
						refresh();
					}else{
						jp.error(data.msg);
					}
					jp.close(index);
				});//调用保存事件
				return false;
			},
			btn3: function(index){
				jp.close(index);
			}
		})
	})

	//导入综合信息
	$("#btnCom").click(function () {
		jp.open({
			type: 2,
			area: [500, 200],
			auto: true,
			title:"导入数据",
			content: "${ctx}/tag/importExcel" ,
			btn: ['确定', '关闭'],
			btn1: function(index, layero){
				var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
				iframeWin.contentWindow.importExcel('${ctx}/sg/information/importCom', function (data) {
					if(data.success){
						jp.success(data.msg);
						refresh();
					}else{
						jp.error(data.msg);
					}
					jp.close(index);
				});//调用保存事件
				return false;
			},
			btn2: function(index){
				jp.close(index);
			}
		})
	})

	//批量查询
    $("#btnSearch").click(function () {
        jp.open({
            type: 2,
            area: [500, 200],
            auto: true,
            title:"导入数据",
            content: "${ctx}/tag/importExcel" ,
            btn: ['下载模板','确定', '关闭'],
            btn1: function(index, layero){
                jp.downloadFile('${ctx}/sg/information/import/template');
            },
            btn2: function(index, layero){
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                iframeWin.contentWindow.importExcel('${ctx}/sg/information/btnSearch', function (data) {
                	top.layer.msg('成功', {icon:1})
					$('#informationTable').bootstrapTable('load',data);
					jp.close(index);
					getTdValue();
                });//调用保存事件
                return false;
            },
            btn3: function(index){
                jp.close(index);
            }
        })
    })

	//导入原因类型
	$("#btnInReason").click(function () {
		jp.open({
			type: 2,
			area: [500, 200],
			auto: true,
			title:"导入原因类型",
			content: "${ctx}/tag/importExcel" ,
			btn: ['确定', '关闭'],
			btn1: function(index, layero){
				var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
				iframeWin.contentWindow.importExcel('${ctx}/sg/information/btnInReason', function (data) {
					if(data.success){
						jp.alert(data.msg);
						refresh();
					}else{
						jp.alert(data.msg);
					}
					jp.close(index);
				});//调用保存事件
				return false;
			},
			btn2: function(index){
				jp.close(index);
			}
		})
	})

//导出物料清单
	$("#export").click(function(){
		var projectId = encodeURI(encodeURI($("#projectId").val()));
		var projectName = encodeURI(encodeURI($("#projectName").val()));
		var projectType = encodeURI(encodeURI($("#projectType").val()));
		var projectYear = encodeURI(encodeURI($("#projectYear").val()));
		var firstUnits = encodeURI(encodeURI($("#firstUnits").val()));
		var secondUnits = encodeURI(encodeURI($("#secondUnits").val()));
		var firstFinish = encodeURI(encodeURI($("#firstFinish").val()));
		var extendedStatus = encodeURI(encodeURI($("#extendedStatus").val()));
		var extendedTime = encodeURI(encodeURI($("#extendedTime").val()));
		var hiddenSign = encodeURI(encodeURI($("#hiddenSign").val()));
/*		console.log(projectId );
		console.log(projectName);
		console.log(projectType);
		console.log(projectYear);
		console.log(firstUnits);
		console.log(secondUnits);
		console.log(firstFinish);
		console.log(extendedStatus);
		console.log(extendedTime);
		console.log(hiddenSign);*/
		jp.downloadFile('${ctx}/sg/information/exportMaterial?projectId='+projectId+'&projectName='+projectName+'&projectType='+projectType+'&projectYear='+projectYear+'&firstUnits='+firstUnits+'&secondUnits='+secondUnits+'&firstFinish='+firstFinish+'&extendedStatus='+extendedStatus+'&extendedTime='+extendedTime+'&hiddenSign='+hiddenSign);
	});

//导出项目清单
	$("#exportMaterial").click(function(){
		var projectId = encodeURI(encodeURI($("#projectId").val()));
		var projectName = encodeURI(encodeURI($("#projectName").val()));
		var projectType = encodeURI(encodeURI($("#projectType").val()));
		var projectYear = encodeURI(encodeURI($("#projectYear").val()));
		var firstUnits = encodeURI(encodeURI($("#firstUnits").val()));
		var secondUnits = encodeURI(encodeURI($("#secondUnits").val()));
		var firstFinish = encodeURI(encodeURI($("#firstFinish").val()));
		var extendedStatus = encodeURI(encodeURI($("#extendedStatus").val()));
		var extendedTime = encodeURI(encodeURI($("#extendedTime").val()));
		var hiddenSign = encodeURI(encodeURI($("#hiddenSign").val()));
/*		console.log(projectId );
		console.log(projectName);
		console.log(projectType);
		console.log(projectYear);
		console.log(firstUnits);
		console.log(secondUnits);
		console.log(firstFinish);
		console.log(extendedStatus);
		console.log(extendedTime);
		console.log(hiddenSign);*/
		jp.downloadFile('${ctx}/sg/information/export?projectId='+projectId+'&projectName='+projectName+'&projectType='+projectType+'&projectYear='+projectYear+'&firstUnits='+firstUnits+'&secondUnits='+secondUnits+'&firstFinish='+firstFinish+'&extendedStatus='+extendedStatus+'&extendedTime='+extendedTime+'&hiddenSign='+hiddenSign);

	});

//导出说明word
	$("#exportInformation").click(function(){
		var projectId = encodeURI(encodeURI($("#projectId").val()));
		var projectName = encodeURI(encodeURI($("#projectName").val()));
		var projectType = encodeURI(encodeURI($("#projectType").val()));
		var projectYear = encodeURI(encodeURI($("#projectYear").val()));
		var firstUnits = encodeURI(encodeURI($("#firstUnits").val()));
		var secondUnits = encodeURI(encodeURI($("#secondUnits").val()));
		var firstFinish = encodeURI(encodeURI($("#firstFinish").val()));
		var extendedStatus = encodeURI(encodeURI($("#extendedStatus").val()));
		var extendedTime = encodeURI(encodeURI($("#extendedTime").val()));
		var hiddenSign = encodeURI(encodeURI($("#hiddenSign").val()));
/*		console.log(projectId );
		console.log(projectName);
		console.log(projectType);
		console.log(projectYear);
		console.log(firstUnits);
		console.log(secondUnits);
		console.log(firstFinish);
		console.log(extendedStatus);
		console.log(extendedTime);
		console.log(hiddenSign);*/
		jp.downloadFile('${ctx}/sg/information/exportInformation?projectId='+projectId+'&projectName='+projectName+'&projectType='+projectType+'&projectYear='+projectYear+'&firstUnits='+firstUnits+'&secondUnits='+secondUnits+'&firstFinish='+firstFinish+'&extendedStatus='+extendedStatus+'&extendedTime='+extendedTime+'&hiddenSign='+hiddenSign);
	});

	$("#editOverTime").click(function () {
		jp.openViewDialog('配置超期时间','${ctx}/sg/information/editOverTime','1000px','800px');
	});

	// 绑定查询按扭
	$("#search").click("click", function() {
		  sessionStorage.removeItem("path");
		  $('#informationTable').bootstrapTable('refresh');
		});

	// 绑定查询重置按扭
	 $("#reset").click("click", function() {
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		  $('#informationTable').bootstrapTable('refresh');
		});
	});


  function getIdSelections() {
        return $.map($("#informationTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }



    //刷新列表
  function refresh() {
      $('#informationTable').bootstrapTable('refresh');
  }





	function addRow(list, idx, tpl, row){
		$(list).append(Mustache.render(tpl, {
			idx: idx, delBtn: true, row: row
		}));
	}

</script>
