shr.defineClass("shr.custom.RoomChangeApplicationList", shr.framework.List, {
	initalizeDOM: function () {
		shr.custom.RoomChangeApplicationList.superClass.initalizeDOM.call(this);
		var that = this;
	},
	/**
 * 撤销
 * @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");
	}
	/**
	 * 描述:删除操作
	 * @action 
	 */
	, deleteAction: function () {
		var _self = this;
		var billId = $("#grid").jqGrid("getSelectedRows");
		if (billId == undefined || billId.length <= 0 || (billId && billId.length == 1 && billId[0] == "")) {
			shr.showWarning({ message: "请先选中行！" });
			return false;
		}
		var selectedIds = this.getSelectedIds();
		if (shr.atsBillUtil.isInWorkFlow(selectedIds)) {
			shr.showConfirm(jsBizMultLan.atsManager_atsOverTimeBillAllList_i18n_10, function () {
				top.Messenger().hideAll();
				shr.atsBillUtil.abortWorkFlow(selectedIds);//撤回未提交且已绑定流程的单据
				_self.doRemoteAction({
					method: 'delete',
					billId: selectedIds
				});
			});
		} else {
			if (selectedIds) {
				this.deleteRecord(selectedIds);
			}
		}

	}
	/**
	 * 获得选中的id,且满足选中的数据仅是未提交的数据。
	 */
	, getSelectedIds: function () {
		var $grid = $(shr.getCurrentViewPage().gridId);
		var selectedIds = $grid.jqGrid("getSelectedRows");
		if (selectedIds.length > 0) {
			var billIds = [];
			for (var i = 0, length = selectedIds.length; i < length; i++) {
				var billState = $grid.jqGrid("getCell", selectedIds[i], "billState") || 0;
				if (billState == 0) {
					billIds.push($grid.jqGrid("getCell", selectedIds[i], "id"));
				}
			}
			if (billIds.length < selectedIds.length) {
				shr.showWarning({
					message: "只能删除未提交状态的数据，请选中表格中未提交的数据!"
				});
			} else {
				return billIds.toString();
			}
		}
	}
	/**
	 * 个人列表-查看功能
	 */
	, viewAction: function (billId) {
		var _self = this;
		var isMultiEntry = $("#grid").jqGrid("getRowData", billId).isMultiEntry;
		// 批量提交
		if (isMultiEntry == "1") {
			_self.reloadPage({
				uipk: "com.kingdee.eas.custom.dormitorysystem.application.app.RoomChangeApplicationBatch.form",
				billId: billId,
				method: 'view'
			});
			// 普通提交
		} else {
			_self.reloadPage({
				uipk: "com.kingdee.eas.custom.dormitorysystem.application.app.RoomChangeApplication.form",
				billId: billId,
				method: 'view'
			});
		}

	}
	/**
	* 多人换宿单
	*/
	, addNewBatchAction: function () {
		this.reloadPage({
			uipk: "com.kingdee.eas.custom.dormitorysystem.application.app.RoomChangeApplicationBatch.form",
			method: 'addNew'
		});
	}
	/**
	 * 提交生效 
	 */
	, 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(event, action) {
		var _self = this;

		_self.defaultBatchActionHandle("submitEffect");
	}
	/**
	 * 反审批单据
	 */
	, againstApproveAction: function () {
		var _self = this;
		_self.beforeAgainstApproveAction();
	}
	/**
	 * 反审批前动作
	 */
	, beforeAgainstApproveAction: function () {
		var billId = $("#grid").jqGrid("getSelectedRows");
		if (billId == undefined || billId.length == 0 || (billId && billId.length == 1 && billId[0] == "")) {
			shr.showWarning({ message: "请选择选中行！" });
			return;
		}
		// var realBillId = [];
		// var billLength = billId.length;
		// for (var i = 0; i < billLength; i++) {
		// 	//去除重复处理
		// 	if ($.inArray(billId[i], realBillId) == -1) {
		// 		realBillId.push(billId[i]);
		// 	}
		// }
		//支持批量反审批
		// if(realBillId.length>1){
		// 	shr.showWarning({message: "请选中一行！"});
		// 	return ;
		// }
		var _self = this;
		shr.showConfirm("您确认对此单据进行反审批吗？", function () {
			// top.Messenger().hideAll();
			// var data = {
			// 	method: 'againstApprove'
			// };

			// data = $.extend(_self.prepareParam(), data);
			// data.billId = realBillId.join(",")

			// _self.remoteCall({
			// 	method: "againstApprove",
			// 	param: data,
			// 	success: function (res) {
			// 		if (res && res.msg !== '') {
			// 			shr.showInfo({ message: res.msg });
			// 		}
			// 		_self.reloadGrid();
			// 	}, error: function (response) {
			// 		shr.showError({
			// 			message: response
			// 		});
			// 	}
			// });
			_self.defaultBatchActionHandle("againstApprove");
		});
	}
	/**
	 * 默认的action处理方法
	 */
	, defaultBatchActionHandle: function (option) {
		// var selectedIds = this.getSelectedIds();
		// if (!selectedIds) {
		// 	return;
		// }
		var $grid = $(shr.getCurrentViewPage().gridId);
		var selectedIds = $grid.jqGrid("getSelectedRows").toString();
		if (typeof option == 'string') {
			option = { methodName: option };
		}

		if (option.requireConfirm && option.message) {
			// 需要提示信息
			var _self = this;
			shr.showConfirm(option.message, function () {
				top.Messenger().hideAll();
				_self.doRemoteWithBatchAction({
					method: option.methodName,
					billId: selectedIds
				});
			});
		} else {
			this.doRemoteWithBatchAction({
				method: option.methodName,
				billId: selectedIds
			});

		}
	},
	/**
	 * 执行远程服务端方法，适用于有批量操作的远程调用
	 */
	doRemoteWithBatchAction: function (param) {
		var _self = this;
		var data = param;
		data = $.extend(_self.prepareParam(), data);
		data = $.extend({ permItemId: shr.getCurrentPagePermItemId() }, data);
		shr.doWithBatchAction({
			url: _self.dynamicPage_url,
			type: 'post',
			data: data,
			success: function (response) {
				if (response) {
					var batchTipsData = _self.batchTipsDataHandler(response, data);

					$(_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 () {
							// 这里需要存一下是否全部成功的标识
							sessionStorage.setItem('deleteSuccess', batchTipsData.failureCount ? 0 : 1);
							_self.reloadGrid();
						}
					}).shrMessageTips("open");
				} else {
					$(_self).shrMessageTips("_setDetailDisable");
				}
			},
			error: function (response) {
				if (param.billId && param.billId.split(',').length > 1) {
					_self.reloadGrid();
				}
			}
		});
	}
});
