<%@ page contentType="text/html;charset=UTF-8" %>
<script>

	/*4.1、4.3数据回填方法*/
	function refreshCharts(uuid){
		jp.post("${ctx}/raiseCapitalDesign/disposeFormDataOnList",
			{
				"uuid":uuid
			},
			function (data) {
				if(data.success){
					for (var i = 0; i < data.data.length; i++) {
						$("#"+data.data[i].id).val(data.data[i].number)
					}
				}
			})
	}
	/*4.2数据回填方法*/
	function refreshCables(uuid){
		jp.post("${ctx}/raiseCapitalDesign/disposeFormCableDataList",
			{
				"uuid":uuid
			},
			function (data) {
				if(data.success){
					for (var i = 0; i < data.data.length; i++) {
						$("#"+data.data[i].id).val(data.data[i].number)
					}
				}
			})
	}
$(document).ready(function() {
	window.operateEvents = {
		'change input': function (e, value, row, index) {
			var ss = $('#' + row.id).val();
			jp.confirm('确认要修改？', function () {
				jp.get("${ctx}/picking/activiti/raiseUpdate?id=" + row.id + "&mdTotalAmount=" + ss, function (data) {
					jp.success(data.msg);
					refresh();
				})
			}, function () {
				$('#informationTable').bootstrapTable('refresh');
			})
		}
	};
	var item = "";
	//bootstrapTable加载数据
	$('#informationTable').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: false,
		//排序方式
		sortOrder: "asc",
		//初始化加载第一页，默认第一页
		pageNumber: 1,
		//每页的记录行数（*）
		pageSize: 10,
		//可供选择的每页的行数（*）
		pageList: [10, 25, 50, 100],
		//这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
		url: "${ctx}/picking/showlist/raiseData",
		//默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
		////查询参数,每次调用是会带上这个参数，可自定义
		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) {
		},
		onShowSearch: function () {
			$("#search-collapse").slideToggle();
		},
		formatNoMatches: function () {
			return "你的自定义文字说明";
		},
		columns: [
			{
				checkbox: true
			},
			{
				field: 'materialCode',
				title: '物料编码',
			}, {
				field: 'materialDescription',
				title: '物料名称',
			}, {
				field: 'extensionDescription',
				title: '扩展描述',
			}, {
				field: 'mdUnits',
				title: '单位',
			}, {
				field: 'mdTotalAmount',
				title: '总量',
				events: operateEvents,
				formatter: getTime
			}, {
				field: 'mdSingleWeight',
				title: '单重/kg',
			}, {
				field: 'mdTotalWeight',
				title: '总重/吨',
			}, {
				field: 'mdTheParty',
				title: '甲乙供',
			}, {
				field: 'mdText',
				title: '备注',
			}
		]
	});

	$('#informationTable2').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: false,
		//排序方式
		sortOrder: "asc",
		//初始化加载第一页，默认第一页
		pageNumber:1,
		//每页的记录行数（*）
		pageSize: 10,
		//可供选择的每页的行数（*）
		pageList: [10, 25, 50, 100],
		//这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
		url: "${ctx}/picking/showlist/mkData",
		//默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
		////查询参数,每次调用是会带上这个参数，可自定义
		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){
		},
		onShowSearch: function () {
			$("#search-collapse").slideToggle();
		},
		formatNoMatches:function(){
			return "你的自定义文字说明";
		},
		columns: [
			{
				field: 'mdBigClass',
				title: '模块大类',
			},
			{
				field: 'mdTheClass',
				title: '模块中类',
			},
			{
				field: 'mdName',
				title: '模块名称',
			},
			{
				field: 'materialCode',
				title: '物料编码',
			},{
				field: 'materialDescription',
				title: '物料名称',
			},{
				field: 'extensionDescription',
				title: '扩展描述',
			},{
				field: 'mdUnits',
				title: '单位',
			},{
				field: 'mdTotalAmount',
				title: '总量',
			},{
				field: 'mdSingleWeight',
				title: '单重/kg',
			},{
				field: 'mdTotalWeight',
				title: '总重/吨',
			},{
				field: 'mdTheParty',
				title: '甲乙供',
			},{
				field: 'mdText',
				title: '备注',
			}
		]
	});

	function getTime(value, row, index) {
		return [
			"<input  id="+row.id+" type='number' name='changeAmount' class='form-control required deal'  value="+row.mdTotalAmount+">",
		].join('');
	}

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

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

	function getTime(value, row, index) {
		return [
			"<input  id="+row.id+" type='number' name='changeAmount' class='form-control required deal'  value="+row.mdTotalAmount+">",
		].join('');
	}

	// 绑定查询按扭
	$("#search").click("click", function() {
		  $('#informationTable').bootstrapTable('refresh');
		});
    $("#click1").click("click", function() {
        // alert("1");
        $("#click2").attr("style","");
        $("#click3").attr("style","");
        $("#click1").attr("style","border-bottom: 0px;border-left: 1px solid rgb(221,221,221);border-right: 1px solid rgb(221,221,221);border-top: 1px solid rgb(221,221,221)");
    });
    $("#click2").click("click",function () {
        $("#click1").attr("style","");
		$("#click3").attr("style","");
        $("#click2").attr("style","border-bottom: 0px;border-left: 1px solid rgb(221,221,221);border-right: 1px solid rgb(221,221,221);border-top: 1px solid rgb(221,221,221)");
    });
	$("#click2").click("click",function () {
		$("#click1").attr("style","");
		$("#click2").attr("style","");
		$("#click3").attr("style","border-bottom: 0px;border-left: 1px solid rgb(221,221,221);border-right: 1px solid rgb(221,221,221);border-top: 1px solid rgb(221,221,221)");
	});
	// 绑定查询重置按扭
	 $("#reset").click("click", function() {
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		  $('#informationTable').bootstrapTable('refresh');
		});

		$("#dq").click("click", function () {
			$("#div1").attr("style", "display:block;");
			$("#div2").attr("style", "display:none;");
			$("#div3").attr("style", "display:none;");
		});
		$("#qd").click("click", function () {
			let projectName = $("#projectName").val();
			var item = "";
			$('input[name="need"]').each(function(){
				var val = $(this).val();
				if (val!=null&&val!=""&&val>0) {
					item += $(this).attr("id")+":"+val+";"
				}
			})
			//将item提交，遍历后保存数据
			if(projectName == null || projectName == ""){
				jp.error("项目名称不能为空！");
			} else if (item == null || item == "") {
				jp.error("请填写模块表");
			} else {
				$("#div1").attr("style", "display:none;");
				$("#div2").attr("style", "display:block;");
				$("#div3").attr("style", "display:none;");
				jp.post("${ctx}/picking/showlist/saveData",
					{
						"item": item,
						"projectName": projectName
					},
					function (data) {
						$('#informationTable').bootstrapTable('refresh', {
							query:
								{
									projectName: projectName
								}
						});
					})
			}
		});
	$("#mkqd").click("click", function () {
		$("#div1").attr("style", "display:none;");
		$("#div2").attr("style", "display:none;");
		$("#div3").attr("style", "display:block;");
		var item = "";
		$('input[name="need"]').each(function(){
			var val = $(this).val();
			if (val!=null&&val!=""&&val>0) {
				item += $(this).attr("id")+":"+val+";"
				console.log(item+"\t");
			}
		})
		$('#informationTable2').bootstrapTable('refresh', {
			query:
				{
					item: item
				}
		});
	});
	$("#agree").click(function () {
		var item = "";
		$('input[name="need"]').each(function(){
			var val = $(this).val();
			if (val!=null&&val!=""&&val>0) {
				item += $(this).attr("id")+":"+val+";"
				console.log(item+"\t");
			}
		})
		let projectNo = $("#projectNo").val();
		let uuid = $("#pickUuid").val();
		let approver = $("#approver").val();
		let erpCode = $("#erpCode").val();
		let reviewer = $("#reviewer").val();
		let projectName = $("#projectName").val();
		let preparedBy = $("#preparedBy").val();
		let manager = $("#manager").val();
		let reqUnit = $("#reqUnit").val();
		let preTime = $("#preTime").val();
		if(projectName == null || projectName == ""){
			jp.error("项目名称不能为空！");
		} else if (item == null || item == "") {
			jp.error("请填写模块表");
		} else {
			jp.post("${ctx}/raiseCapitalDesign/exportCache",
			{
			    "item":item,
				"projectNo": projectNo,
				"approver": approver,
				"erpCode": erpCode,
				"reviewer": reviewer,
				"projectName": projectName,
				"preparedBy": preparedBy,
				"manager": manager,
				"reqUnit": reqUnit,
				"preTime": preTime,
				"uuid": uuid
			},
			function (data) {
				if(data.success){
					jp.downloadFile('${ctx}/raiseCapitalDesign/export?projectName='+projectName + "&uuid="+uuid,'raiseCapital');//给个name是为了能够在某些条件下下载两个文件
					jp.success("下载成功")
					refreshWindows();
				}
			})
		}
	});




	function refreshWindows(){
		location.reload();
	}

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

	$(".list-tabs li").click(function(){
		$(".list-tabs li").each(function(){
			$(this).removeAttr("class","active");
			var id='#'+$(this).find("span").html();
			$(id).attr("class","hide");
		})
		$(this).attr("class","active");
		var id='#'+$(this).find("span").html();
		$(id).removeAttr("class","hide");

	})
})

//刷新列表
function refresh() {
    let projectName = $("#projectName").val();
    $('#informationTable').bootstrapTable('refresh',{
        query:
            {
                projectName: projectName
            }
    });
}
//刷新列表
function dataTableRefresh() {
    let projectName = $("#projectName").val();
    $('#dataTable').bootstrapTable('refresh',{
        query:
            {
                projectName: projectName
            }
    });
}

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

function deleteAll(){
	jp.confirm('确认要删除该领料信息？', function(){
		jp.loading();
		jp.get("${ctx}/picking/activiti/deleteRaiseAll?ids=" + getIdSelections(), function(data){
			refresh();
			jp.success(data.msg);
		})
	})
}

function aerialConductor(){
	var item = "";
	$('input[name="need"]').each(function(){
		var val = $(this).val();
		if (val!=null&&val!=""&&val>0) {
			item += $(this).attr("id")+":"+val+";"
		}
	})
	var pickUuid = $("#pickUuid").val();
	jp.openSaveDialog('架空导线计算表', "${ctx}/raiseCapitalDesign/aerialConductorForm?uuid="+pickUuid+"&item="+item, '800px', '500px');

}
function cableSection(){
	var pickUuid = $("#pickUuid").val();
	console.log(pickUuid);
	jp.openSaveDialog('新增领料信息', "${ctx}/raiseCapitalDesign/cableSectionForm?uuid="+pickUuid, '80%', '80%');
}
function inventory(){
	var pickUuid = $("#pickUuid").val();
	console.log(pickUuid);
	jp.openSaveDialog('新增领料信息', "${ctx}/raiseCapitalDesign/inventoryForm?uuid="+pickUuid, '80%', '80%');
}

function add(){
	var projectName = $("#projectName").val();
	jp.openSaveDialog('新增领料信息', "${ctx}/picking/activiti/netRaise?projectName=" + projectName, '800px', '500px');
}
// $(document).ready(function (){
//     $("li").each(function(index){
//         $(this).click(function(){
//             alert(index)
//             $("li").removeClass("style");//删除当前元素的样式
//             $("li").eq(index).attr("style","border-bottom: 0px;border-left: 1px solid rgb(221,221,221);border-right: 1px solid rgb(221,221,221);border-top: 1px solid rgb(221,221,221)");//添加当前元素的样式
//         });
//     });
// });

</script>
