<%@ page contentType="text/html;charset=UTF-8" %>
<script>
$(document).ready(function() {
	$('#testPicTable').bootstrapTable({
		  //请求方法
               method: 'post',
               //类型json
               dataType: "json",
               contentType: "application/x-www-form-urlencoded",
               //显示检索按钮
	           showSearch: false,
               //显示刷新按钮
               showRefresh: false,
               //显示切换手机试图按钮
               showToggle: false,
               //显示 内容列下拉框
    	       showColumns: false,
    	       //显示到处按钮
    	       showExport: false,
    	       //显示切换分页按钮
    	       showPaginationSwitch: false,
    	       //最低显示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/reserveProcess/uploadData",
               //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
               //queryParamsType:'',
               ////查询参数,每次调用是会带上这个参数，可自定义
               queryParams : function(params) {
			   	var searchParam = $("#inputForm").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){
               },
               onClickRow: function(row, $el){
               },
               	onShowSearch: function () {

				},
               columns: [
				   {
					   field: 'budgetStatement',
					   title: '预算书',
					   formatter:function(value, row , index){
						   var valueArray = value.split("|");
						   var labelArray = [];
						   for(var i =0 ; i<valueArray.length; i++){
							   if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(valueArray[i]))
							   {
								   labelArray[i] = "<a href=\""+valueArray[i]+"\" url=\""+valueArray[i]+"\" target=\"_blank\">"+decodeURIComponent(valueArray[i].substring(valueArray[i].lastIndexOf("/")+1))+"</a>"
							   }else{
								   labelArray[i] = '<img   onclick="jp.showPic(\''+valueArray[i]+'\')"'+' height="50px" src="'+valueArray[i]+'">';
							   }
						   }
						   return labelArray.join(" ");
					   }

				   }, {
					   field: 'projectProposal',
					   title: '项目建议书',
					   formatter:function(value, row , index){
						   var valueArray = value.split("|");
						   var labelArray = [];
						   for(var i =0 ; i<valueArray.length; i++){
							   if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(valueArray[i]))
							   {
								   labelArray[i] = "<a href=\""+valueArray[i]+"\" url=\""+valueArray[i]+"\" target=\"_blank\">"+decodeURIComponent(valueArray[i].substring(valueArray[i].lastIndexOf("/")+1))+"</a>"
							   }else{
								   labelArray[i] = '<img   onclick="jp.showPic(\''+valueArray[i]+'\')"'+' height="50px" src="'+valueArray[i]+'">';
							   }
						   }
						   return labelArray.join(" ");
					   }

				   }, {
					   field: 'drawings',
					   title: '图纸',
					   formatter:function(value, row , index){
						   var valueArray = value.split("|");
						   var labelArray = [];
						   for(var i =0 ; i<valueArray.length; i++){
							   if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(valueArray[i]))
							   {
								   labelArray[i] = "<a href=\""+valueArray[i]+"\" url=\""+valueArray[i]+"\" target=\"_blank\">"+decodeURIComponent(valueArray[i].substring(valueArray[i].lastIndexOf("/")+1))+"</a>"
							   }else{
								   labelArray[i] = '<img   onclick="jp.showPic(\''+valueArray[i]+'\')"'+' height="50px" src="'+valueArray[i]+'">';
							   }
						   }
						   return labelArray.join(" ");
					   }

				   }, {
					   field: 'drawingSpecification',
					   title: '施工图设计说明书',
					   formatter:function(value, row , index){
						   var valueArray = value.split("|");
						   var labelArray = [];
						   for(var i =0 ; i<valueArray.length; i++){
							   if(!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(valueArray[i]))
							   {
								   labelArray[i] = "<a href=\""+valueArray[i]+"\" url=\""+valueArray[i]+"\" target=\"_blank\">"+decodeURIComponent(valueArray[i].substring(valueArray[i].lastIndexOf("/")+1))+"</a>"
							   }else{
								   labelArray[i] = '<img   onclick="jp.showPic(\''+valueArray[i]+'\')"'+' height="50px" src="'+valueArray[i]+'">';
							   }
						   }
						   return labelArray.join(" ");
					   }
				   }
			   ]
		});

	$('#dataTable').bootstrapTable({
		//请求方法
		method: 'post',
		//类型json
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		//显示检索按钮
		showSearch: false,
		//显示刷新按钮
		showRefresh: true,
		//显示切换手机试图按钮
		showToggle: false,
		//显示 内容列下拉框
		showColumns: false,
		//显示到处按钮
		showExport: false,
		//显示切换分页按钮
		showPaginationSwitch: false,
		//最低显示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/reserveProcess/materialData",
		//默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
		//queryParamsType:'',
		////查询参数,每次调用是会带上这个参数，可自定义
		queryParams : function(params) {
			var searchParam = $("#searchForm").serializeJSON();
			searchParam.projectName = $("#projectName").val();
			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){
		},
		onClickRow: function(row, $el){
		},
		onLoadSuccess: function () {  //加载成功时执行
		},
		onShowSearch: function () {
			$("#search-collapse").slideToggle();
		},
		columns: [
			{
				field: 'projectName',
				width:230,
				title: '项目名称'
			}
			,{
				field: 'materialCode',
				width:100,
				title: '物料编码'
			}
			,{
				field: 'materialName',
				width:200,
				title: '物料名称'
			}
			,{
				field: 'extendDescription',
				width:200,
				title: '扩展描述'
			}
			,{
				field: 'unit',
				width:60,
				title: '单位'
			}
			,{
				field: 'totalCount',
				width:60,
				title: '总量'
			}
			,{
				field: 'weightKg',
				width:80,
				title: '单重/kg'
			}
			,{
				field: 'weightTon',
				width:80,
				title: '总重/吨'
			}
			,{
				field: 'supplyType',
				width:80,
				title: '甲乙供'
			}
		]

	})



	if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端


		  $('#testPicTable').bootstrapTable("toggleView");
		}

	  $('#testPicTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
            $('#remove').prop('disabled', ! $('#testPicTable').bootstrapTable('getSelections').length);
            $('#view,#edit').prop('disabled', $('#testPicTable').bootstrapTable('getSelections').length!=1);
        });

	$("#export").click(function(){//导出甲供材清册
		var projectName = $("#projectName").val();
		jp.downloadFile('${ctx}/sg/reserveProcess/exportAct?projectName=' + projectName);
	});


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

	 $("#reset").click("click", function() {// 绑定查询按扭
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		  $("#searchForm  .select-item").html("");
		  $('#testPicTable').bootstrapTable('refresh');
	});




	});

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

  function deleteAll(){
		jp.confirm('确认要删除该图片管理记录吗？', function(){
			jp.loading();
			jp.get("${ctx}/managementcenter/upload/delete?ids=" + getIdSelections(), function(data){
         	  		if(data.success){
         	  			$('#testPicTable').bootstrapTable('refresh');
         	  			jp.success(data.msg);
         	  		}else{
         	  			jp.error(data.msg);
         	  		}
         	  	})

		})
  }

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

   function add(){
	  jp.openSaveDialog('新增图片管理', "${ctx}/managementcenter/upload/list",'800px', '500px');
  }



   function edit(id){//没有权限时，不显示确定按钮
       if(id == undefined){
	      id = getIdSelections();
	}
	jp.openSaveDialog('编辑图片管理', "${ctx}/managementcenter/upload/imagesForm?id=" + id, '800px', '500px');
  }

 function view(id){//没有权限时，不显示确定按钮
      if(id == undefined){
             id = getIdSelections();
      }
        jp.openViewDialog('查看图片管理', "${ctx}/managementcenter/upload/imagesForm?id=" + id, '800px', '500px');
 }



</script>