shr.defineClass("shr.custom.CheckInApplicationList", shr.framework.List, {
	initalizeDOM: function () {
		shr.custom.CheckInApplicationList.superClass.initalizeDOM.call(this);

		// $("#entrys_checkInRoom").shrPromptBox("options",{
		// 	verifyBeforeOpenCallback:function(){

		// 		return false;
		// 	}
		// });

	},

	/**
	 * 新增
	 */
	// addNewAction: function (event) {
	// 	this.reloadPage({
	// 		uipk: "com.kingdee.eas.custom.dormitorysystem.application.app.CheckInApplication_self.form",
	// 		method: 'addNew'
	// 	});
	// },
	/**
	 * 批量新增
	 */
	addNewBatchAction: function () {
		this.reloadPage({
			uipk: "com.kingdee.eas.hr.ats.app.AtsLeaveBillAllBatchForm",
			method: 'addNew'
		});
	},

	assembleSaveData: function (action, realBillId) {
		var _self = this;
		var billId = realBillId;
		var data = _self.prepareParam(action + 'Action');
		data.method = action;
		data.operateState = "LIST";
		data.billId = billId.join(",");
		return data;
	},
	/**
	 * 提交生效 
	 */
	submitEffectAction: function (event) {
		var _self = this,
			workArea = _self.getWorkarea(),
			$form = $('form', workArea);
		var billId = $("#grid").jqGrid("getSelectedRows");
		if (billId == undefined || billId.length == 0 || (billId && billId.length == 1 && billId[0] == "")) {
			shr.showWarning({ "message": "请先选中单据!" });
			return false;
		}
		shr.showConfirm("是否提交生效？", function () {
			_self.prepareSubmitEffect(event, 'submitEffect');
		});
	},
	/**
	 * 提交生效 
	 */
	prepareSubmitEffect: function (event, action) {
		//		var _self = this;
		//		var billData = _self.selectedRowData;
		//		var realBillId = [];
		//		for(var i=0;i<billData.length;i++){
		//		    var billState = billData[i]['billState'];
		//		   if("未提交" == billState.alias && $.inArray(billData[i].id, realBillId) == -1){
		//		      realBillId.push(billData[i].id);
		//		   }
		//		}
		var _self = this;
		var billId = $("#grid").jqGrid("getSelectedRows");
		var realBillId = [];
		for (var i = 0; i < billId.length; i++) {
			var billState = "";
			if ($("tr[id='" + billId[i] + "']").length > 1) {//多人单据
				billState = $($("tr[id='" + billId[i] + "']")[0]).find("td[aria-describedby='grid_billState']").text();
			} else {
				billState = $("tr[id='" + billId[i] + "'] td[aria-describedby='grid_billState']").text();
			}
			if ("未提交" == billState && $.inArray(billId[i], realBillId) == -1) {
				realBillId.push(billId[i]);
			}
		}
		if (realBillId.length == 0) {
			shr.showError({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_20 });
			return;
		}
		var data = _self.assembleSaveData(action, realBillId);

		var target;
		if (event && event.currentTarget) {
			target = event.currentTarget;
		}
		//openLoader(1, jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_47);

		//审核操作
		//  _self.doRemoteWithBatchExtendAction({
		// 	method: "sendInterviewNotice",
		// 	type: '600' //列表页签类型-未审核

		// });
		_self.defaultBatchActionHandle("submitEffect");

		// _self.remoteCall({
		// 	type: "post",
		// 	method: "submitEffect",
		// 	param: data,
		// 	success: function (res) {
		// 		closeLoader();
		// 		var failMsg = "";
		// 		if (res.error != "" && res.error != null && res.error != undefined) {
		// 			shr.showError({ message: res.error });
		// 		} else {
		// 			if (res.submitNum - res.submitSuccessNum > 0) {
		// 				failMsg = "，" + jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_36 + (res.submitNum - res.submitSuccessNum)
		// 			}
		// 			shr.showInfo({ message: shr.formatMsg(jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_37, [res.submitNum, res.submitSuccessNum]) + failMsg, hiddenAfter: 5 });
		// 			$("#grid").jqGrid().jqGrid("reloadGrid");
		// 		}
		// 	},
		// 	error: function (e) {
		// 		closeLoader();
		// 	}
		// });
	},/**
	* 描述:删除操作
	* @action 
	*/
	// deleteAction: function () {
	// 	var _self = this;
	// 	var billId = $(this.gridId).jqGrid("getSelectedRows");;
	// 	if (billId == undefined || billId.length <= 0 || (billId && billId.length == 1 && billId[0] == "")) {
	// 		shr.showWarning({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_28 });
	// 		return false;
	// 	}
	// 	//var selectedIds = _self.getSelectedIds();
	// 	var selectedIds = shr.atsBillUtil.getSelectedIds();
	// 	if (shr.atsBillUtil.isInWorkFlow(selectedIds)) {
	// 		shr.showConfirm(jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_34, function () {
	// 			top.Messenger().hideAll();
	// 			shr.atsBillUtil.abortWorkFlow(selectedIds);//废弃未提交且已绑定流程的单据
	// 			_self.doRemoteAction({
	// 				method: 'delete',
	// 				billId: selectedIds
	// 			});
	// 		});
	// 	} else {
	// 		if (selectedIds) {
	// 			this.deleteRecord(selectedIds);
	// 		}
	// 	}
	// },

	/**
	 *提交之前的校验逻辑
	 */
	beforeSubmit: function () {
		var _self = this;
		var realIds = _self.getSelectedRealIds();
		//校验房间是否入住(批量)
		var result = _self.callServiceReturnResponse('validateRoomAvailableByBillIdsService', {
			billIds: realIds
		});
		if (result.code == 500) {
			shr.showWarning({
				message: result.errorMsg.join("<br/>"),
				hideAfter: 5
			});
			return false;
		}
		return true;
	},
	/**
	 * 提交
	 */
	submitAction: function (event) {
		var _self = this;
		_self.beforeSubmit();
		if (!_self.beforeSubmit()) {
			return;
		}
		var realIds = _self.getSelectedRealIds();
		var uipk = _self.getUrlParams('uipk');
		if (!realIds) {
			shr.showError({ message: $.shrI18n.framework.tips.noCanSubmitRecord, hiddenAfter: 5 });
			return;
		}
		//调用OSF获取所选未提交单据的下一步参与人信息
		var response = _self.getBillsNextPersonInfo(realIds, uipk);
		shr.showConfirm($.shrI18n.common.tips.submitConfirm, function () {
			_self.doSubmit(event, 'submit', response, realIds);
		});

		/*this.defaultActionHandle({
			methodName: 'submit',
			requireConfirm: true,
			message: '您确认要提交吗？'
		});*/
	},
	/**
	 * 撤销
	 * @param {*} event 
	 * @returns 
	 */
	abortBillAction: function (event) {
		var realBillId = [];
		var that = this;
		//var billId = this.selectedRowId;
		var billId = $(this.gridId).jqGrid("getSelectedRows");
		if (billId == undefined || billId.length == 0 || (billId && billId.length == 1 && billId[0] == "")) {
			shr.showWarning({ "message": jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_28 });
			return;
		}
		that.defaultBatchActionHandle("abortBizBill");

		// var billLength = billId.length;
		// for (var i = 0; i < billLength; i++) {
		// 	//去除重复处理
		// 	if ($.inArray(billId[i], realBillId) == -1) {
		// 		realBillId.push(billId[i]);
		// 	}
		// }
		// var _self = this;
		// shr.showConfirm(jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_22, function () {
		// 	top.Messenger().hideAll();
		// 	_self.remoteCall({
		// 		type: "post",
		// 		method: "abortBill",
		// 		param: { billId: realBillId.toString() },
		// 		success: function (res) {
		// 			shr.showInfo({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_3 });
		// 			_self.reloadGrid();
		// 		}
		// 	});
		//});
	},
	/**
	 * 反审批
	 * @returns 
	 */
	againstApproveAction: function () {
		var that = this;
		var billId = $(this.gridId).jqGrid("getSelectedRows");;
		if (billId == undefined || billId.length == 0 || (billId && billId.length == 1 && billId[0] == "")) {
			shr.showError({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_33 });
			return;
			// }else if(billId.length > 1){
			// 	shr.showError({message: "只能选中一条记录进行反审批！"});
			// 	return ;
		} else {
			var billIds = that.getSelectedIds();
			that.defaultBatchActionHandle("againstApprove");

			// var url = shr.getContextPath() + "/dynamic.do?method=checkAgainstInfo" + "&uipk=" + shr.getUrlRequestParam('uipk');
			// shr.ajax({
			// 	type: "post",
			// 	async: false,
			// 	data: { billIds: billIds },
			// 	url: url,
			// 	success: function (res) {
			// 		info = res;

			// 	}
			// });
			// if (info != null) {
			// 	var error = jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_0 + "<br/>";
			// 	var type = 1;

			// 	if (info.auditInfo) {
			// 		error = error + jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_21 + "[" + info.auditInfo + " ]<br/>";
			// 		type = 2;
			// 	}

			// 	if (info.cancelInfoList) {
			// 		error = error + jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_46 + "[" + info.cancelInfoList + " ]<br/>";
			// 		type = 2;
			// 	}

			// 	if (type == 2) {
			// 		shr.showError({ message: error });
			// 		return;
			// 	}
			// }
		}

		//校验请假明细有没有生成汇总记录
		var hasSummary = false;
		var hasSalary = false;
		var msg = "";
		var salaryMsg = "";
		var url = shr.getContextPath() + "/dynamic.do?method=checkDetailSummary" + "&uipk=" + shr.getUrlRequestParam('uipk');
		shr.ajax({
			type: "post",
			async: false,
			data: { billIds: billIds },
			url: url,
			success: function (res) {
				hasSummary = res.hasSummary == "true" ? true : false;
				hasSalary = res.hasSalary == "true" ? true : false;
				msg = res.msg;
				salaryMsg = res.salaryMsg;
			}
		});

		if (hasSalary) {
			shr.showError({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_11 + salaryMsg });
			return;
		}

		//
		var confirmStr = jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_23;
		if (hasSummary) {
			confirmStr = msg;
		}

		//新增反审批原因	    
		var serviceId = shr.getUrlRequestParam("serviceId");
		$("#orgFillDiv").attr("src", shr.getContextPath() + '/dynamic.do?checkLicense=true&uipk=com.kingdee.eas.hr.ats.app.AtsBill.reason' + '&serviceId=' + encodeURIComponent(serviceId));
		$('#orgFillDiv').dialog({
			title: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_52,
			width: 900,
			height: 400,
			modal: true,
			resizable: false,
			position: {
				my: 'center',
				at: 'top+20%',
				of: window
			},
			open: function (event, ui) {
			},
			buttons: [{
				text: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_50,
				click: function () {
					var reason = $("#orgFillDiv #reason").val();
					if (reason) {
						$(this).dialog("close");
						shr.showConfirm(jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_23, function () {
							top.Messenger().hideAll();

							var data = {
								method: 'againstApprove',
								billIds: billIds,
								reason: reason.substring(0, 400)
							};
							data = $.extend(that.prepareParam(), data);

							shr.remoteCall({
								type: "post",
								method: "againstApprove",
								param: data,
								url: shr.getContextPath() + "/dynamic.do?uipk=com.kingdee.eas.hr.ats.app.AtsLeaveBillAllList",
								success: function (res) {
									if (res.flag == "1") {
										shr.showInfo({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_9 });
										that.queryGrid();
									} else {
										shr.showError({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_10 });
									}
								}
							});

						});
					} else {
						shr.showError({ message: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_53 });
						return;
					}
				}
			}, {
				text: jsBizMultLan.atsManager_atsLeaveBillAllList_i18n_51,
				click: function () {
					$(this).dialog("close");
				}
			}],
			close: function () { }
		});
		var addWorkString = '<div style=" margin: 35px; ">'
			+ '<div id="allCalculateDatePicker" style=" margin-top: 19px;">'
			+ '<textarea id="reason" type="text" class="block-father valid" name="remark" cols="3" rows="3" placeholder="" dataextenal="" istotemplate="true" ctrlrole="textarea" validate="{maxlength:255}"></textarea>'
			+ ''
			+ '</div>'
			+ '</div>';
		$("#orgFillDiv").html("").append(addWorkString);
	},
	/**
	 * 扩展批处理方法
	 */
	doRemoteWithBatchExtendAction: function (option) {
		var $grid = $(this.gridId),
			totalRecords = $grid.jqGrid('getGridParam', 'records');
		option.rows = totalRecords;
		option.realMethod = option.method;
		delete option.method;
		var params = that.getCommonParamsForBatchAction(option);
		params.theMaxRecords = this.theMaxRecords;
		params.submitRecordsStep = this.submitRecordsStep;
		params.dealWithOriginalPostData = this.dealWithOriginalPostData;
		params.virtualQueryMode = this.virtualQueryMode;
		params.isCancelCrossPageSelected = option.isCancelCrossPageSelected;
		params.isShowCustomerMessage = option.isShowCustomerMessage;
		if (option.isCancelCrossPageSelected == undefined) {
			params.isCancelCrossPageSelected = true;
		}
		if (option.gridFrame != undefined && option.gridFrame != "") {
			this.gridFrame = option.gridFrame;
		}
		var messageFun;
		if ($.isFunction(top.Messenger)) {
			messageFun = top.Messenger();
		} else {
			messageFun = Messenger();
		}
		messageFun.hideAll();
		// if (this.isCrossPageSelectAll() == this._crossPage.YES || option.selectAll ) {
		//     var message = '';
		//     /*if (totalRecords > this.theMaxRecords) {
		//         message = this.theMaxRecordsMessage;
		//         params.rows = this.theMaxRecords;
		//         message = shr.formatMsg(message, [this.theMaxRecords, this.theMaxRecords]);
		//     } else*/
		//     if (totalRecords > this.maxRecords) {
		//         message = this.maxRecordsMessage;
		//         message = shr.formatMsg(message, [this.maxRecords]);
		//     }

		//     if (message) {
		//         /*if (this.isOverTheMaxRecordsRefuseDeal && totalRecords > this.theMaxRecords) {
		//             shr.showWarning({message: this.theMaxRecordsMessage});
		//         } else {*/
		//             shr.showConfirm(message, function () {
		//                 that._doRemoteWithCrossPageSelectAllAction(params);
		//                 that.cancelCrossPageSelected(params.isCancelCrossPageSelected);
		//             });
		//         /*}*/
		//     } else {
		//         that._doRemoteWithCrossPageSelectAllAction(params);
		//         that.cancelCrossPageSelected(params.isCancelCrossPageSelected); // 批处理操作完后是否自动取消页面的跨页全选操作)
		//     }
		// } else {
		that.doRemoteWithBatchAction(params);
		//that.cancelCrossPageSelected(params.isCancelCrossPageSelected);
		//}
	},
	doRemoteWithBatchAction: function (param) {
		var _self = this;
		var data = param;
		var func = data.func;
		var success = param.success;
		delete data.func;
		data = $.extend(_self.prepareParam(), data);
		data = $.extend({ permItemId: shr.getCurrentPagePermItemId() }, data);
		//增加异步处理不弹框
		var showDialog = param.showDialog;
		if (showDialog == undefined || showDialog == 'undefined' || showDialog == null) {
			showDialog = true;
		}
		var async = param.async;
		if (async == undefined || async == 'undefined' || async == null) {
			async = false;
		}
		var showBlock = param.showBlock;
		if (showBlock == undefined || showBlock == 'undefined' || showBlock == null) {
			showBlock = true;
		}
		shr.doWithBatchAction({
			url: _self.dynamicPage_url,
			type: 'post',
			data: data,
			async: async,
			showBlock: showBlock,
			success: function (response) {
				if (response) {
					if (func && typeof func === "function") {
						func(response);
					}

					if (success && typeof success === "function") {
						return success(response);
					}
					var batchTipsData = _self.batchTipsDataHandler(response, data);
					if (showDialog) {
						$(_self).shrMessageTips({
							isSuccess: batchTipsData.isSuccess,
							successCount: batchTipsData.successCount,
							failureCount: batchTipsData.failureCount,
							confirmCallback: function () {
								$(_self).shrDetailTips({
									tableData: batchTipsData.tmp,
									successCount: batchTipsData.successCount,
									failureCount: batchTipsData.failureCount,
									colNamesData: batchTipsData.tableModel,
									isSortable: _self.batchHandlerWhetherSortable(),
									modalWidth: param.modalWidth || ''
								}).shrDetailTips("open");
							},

							closeCallback: function () {
								_self.reloadGrid();
							}
						}).shrMessageTips("open");
					}
				} else {
					$(_self).shrMessageTips("_setDetailDisable");
				}
			},
			error: function (response) {
				if (param.billId && param.billId.split(',').length > 1) {
					_self.reloadGrid();
				}
			}
		});
	},
});