<%@ page contentType="text/html;charset=UTF-8" %>
<script>
	$(document).ready(function() {
		window.operateEvents = {
			'change input': function (e, value, row, index) {
				var ss = $('#'+row.id).val();
				jp.confirm('确认要修改？', function () {
					jp.get("${ctx}/settActivi/updateUsed?id="+row.id+"&usedQuantity="+ss, function (data) {
						jp.success(data.msg);
						$('#settTable').bootstrapTable('refresh');
					})
				},function () {
					$('#settTable').bootstrapTable('refresh');
				})
			}
		};
		var procInsId = $('#procInsId').val();
		$('#settTable').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}/settActivi/useQuantityData?procInsId="+procInsId,
			//默认值为 '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: 'materialEncoding',
					title: '物料编码',
				}, {
					field: 'materialName',
					title: '物料名称',
				}, {
					field: 'company',
					title: '单位',
				},{
					field: 'unitPrice',
					title: '出库单价（元）',
				}, {
				field: 'totalPrice',
				title: '出库总价（元）',
				},
				{
					field: 'outgoingQuantity',
					title: '出库数量'
				},{
					field: 'usedQuantity',
					title: '现场使用数量',
					events: operateEvents,
					formatter: getTime
				}, {
					field: 'reviewQuantity',
					title: '审计现场复核数量',
				}, {
					field: 'settMark',
					title: '施工单位备注',
				}
			]
		});


		jp.ajaxForm("#inputForm",function(data){
			if(data.success){
				jp.alert(data.msg);
				jp.go("${ctx}"+ data.body.targetUrl);
			}else{
				jp.alert(data.msg);
				$("#inputForm").find("button:submit").button("reset");
			}
		});

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

		$("#agree").click(function () {
			jp.prompt("同意, 审批意见", function (message) {
				jp.post("${ctx}/act/task/useQuantityTask",
					{
						"taskId":"${settActivi.act.taskId}",
						"taskName":"${settActivi.act.taskName}",
						"taskDefKey":"${settActivi.act.taskDefKey}",
						"procInsId": "${settActivi.act.procInsId}",
						"procDefId":"${settActivi.act.procDefId}",
						"flag":"yes",
						"comment":window.encodeURI(message)
					},
					function (data) {
						if(data.success){
							jp.success(data.msg);
							jp.go("${ctx}/act/task/todo")
						}
					})
			})
		})


		$("#printf").click(function () {
			var procInsId = $("#procInsId").val();
			// jp.downloadFile('${ctx}/settActivi/exportSett?procInsId='+procInsId);
			 jp.downloadFile('${ctx}/settActivi/exportExcel?procInsId='+procInsId);
		});

		$("#importLedger").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();
					var reserveProjectName = "${settActivi.reserveProjectName}";
					var procInsId = "${settActivi.procInsId}";
					iframeWin.contentWindow.importExcel('${ctx}/settActivi/importLedger?reserveProjectName='+reserveProjectName+'&procInsId='+procInsId, function (data) {
						if(data.success){
							jp.alert(data.msg);
							refresh();
						}else{
							jp.alert(data.msg);
						}
						jp.close(index);
					});//调用保存事件
					refresh();
					return false;
				},
				btn2: function(index){
					jp.close(index);
				}
			})
		})

		$('#acceptDate').datetimepicker({
			format: "YYYY-MM-DD HH:mm:ss"
		});

		$('#examineDate').datetimepicker({
			format: "YYYY-MM-DD HH:mm:ss"
		});
		//富文本初始化
		$('#reason').summernote({
			height: 300,
			lang: 'zh-CN',
			callbacks: {
				onChange: function(contents, $editable) {
					$("input[name='reason']").val($('#reason').summernote('code'));//取富文本的值
				}
			}
		});
	})

	function refresh(){
		$('#settTable').bootstrapTable('refresh');
	}
</script>
