shr.defineClass("shr.custom.RoomChangeApplicationEdit", shr.custom.HRBillBaseEdit, {
	initalizeDOM: function () {
		shr.custom.RoomChangeApplicationEdit.superClass.initalizeDOM.call(this);
		var that = this;
		if (this.getOperateState().toUpperCase() != 'VIEW') {
			that.entrysOldOccupantsF7Action();
			that.occupantsFilter();
			that.adjustRoomFilter();
		}
	},
	adjustRoomFilter() {
		var self = this;
		$("#entrys_adjustRoom").shrPromptBox("option", {
			verifyBeforeOpenCallback: function () {
				var checkInDate = $("#entrys_checkInDate").shrDateTimePicker("getValue");
				var person = $("#entrys_person").shrPromptBox("getValue");
				if (!person.id || person.id == '') {
					shr.showWarning({
						message: "请先选择入住人员！",
						hideAfter: 5
					});
					return false;
				}
				//必须先选择入住日期
				if (!checkInDate || checkInDate == '') {
					shr.showWarning({
						message: "请先选择入住日期！",
						hideAfter: 5
					});
					return false;
				}
				var checkInDate = $("#entrys_checkInDate").shrDateTimePicker("getValue");
				var checkoutDate = $("#entrys_checkoutDate").shrDateTimePicker("getValue");
				var personId = $("#entrys_person_el").val();
				var result = self.callServiceReturnResponse('getOptionalRoomIdsService', {
					checkInDate: checkInDate,
					checkoutDate: checkoutDate,
					personId: personId
				});
				if (result.code == 500) {
					shr.showWarning({
						message: result.errorMsg,
						hideAfter: 5
					});
					return false;
				}
				//设置过滤条件
				$("#entrys_adjustRoom").shrPromptBox("setFilter", "id in (" + result + ")");
				return true;
			}
		});
			$("#entrys_checkInDate").shrDateTimePicker("option", {
				onChange: function (event) {
					//当换宿改变时清空入住房间
					$("#entrys_adjustRoom").shrPromptBox("setValue", null);
				}
			});
	},
	actSubmit: function (event, action) {
		var _self = this;
		var data = _self.assembleSaveData(action);
		data.nextPers = shr.toJSON(_self.nextPers);
		var target;
		if (event && event.currentTarget) {
			target = event.currentTarget;
		}
		shr.doAction({
			target: target,
			url: _self.dynamicPage_url,
			type: 'post',
			data: data,
			success: function (response) {
				if (_self.isFromWF()) {
					// 来自任务中心
					var parent = window.parent,
						submitSuccess = parent.submitSuccess;

					if ($.isFunction(submitSuccess)) {
						// 回调父页面方法
						var assignmentID = shr.getAssignmentId();
						submitSuccess.call(parent, assignmentID);
					} else {
						// 查看状态
						_self.viewAction();
					}
				} else {
					// 普通提交，返回上一页面
					_self.back();
					// _self.goNextPage(target,response);
				}
				//来自portal流程中心，关闭窗口
				if (location.href.indexOf("isShrBill=true") > 0) window.close();
			}
		});
	},
	/**
	*
	*/
	occupantsFilter() {
		const currentDate = new Date();
		const year = currentDate.getFullYear();
		const month = String(currentDate.getMonth() + 1).padStart(2, '0');
		const day = String(currentDate.getDate()).padStart(2, '0');

		const formattedDate = `${year}-${month}-${day}`;
		console.log(formattedDate);

		var filter = "CheckOutDate > '" + formattedDate + "'"
		$("#entrys_oldOccupants").shrPromptBox("setFilter", filter);
	},
	/**
	 * 原入住人员信息
	 *  */
	entrysOldOccupantsF7Action() {
		var that = this;
		//没有填写入住人员信息前禁用
		if ($("#entrys_oldOccupants").shrPromptBox('getValue').id == "") {
			that.isDisableOrenable("disable")
		}
		$('#entrys_oldOccupants').shrPromptBox('option', {
			onchange: function (e, value) {
				var data = value.current || [];
				// 人员
				var person = new Object();
				person.id = data["personPosition.person.id"];
				person.name = data["personPosition.person.name"];
				$('#entrys_person').shrPromptBox('setValue', person);
				// 组织
				var adminObj = new Object();
				adminObj.id = data["personPosition.personDep.id"];
				adminObj.name = data["personPosition.personDep.name"];
				$('#entrys_adminOrg').shrPromptBox('setValue', adminObj);
				// 职位
				var position = new Object();
				position.id = data["personPosition.primaryPosition.id"];
				position.name = data["personPosition.primaryPosition.name"];
				$('#entrys_position').shrPromptBox('setValue', position);
				// 房间
				var dormitory = new Object();
				dormitory.id = data["Dormitory.id"];
				dormitory.name = data["Dormitory.name"];
				$('#entrys_currentRoom').shrPromptBox('setValue', dormitory);
				that.isDisableOrenable("enable")

			}
		});
	},
	isDisableOrenable(type) {
		$('#entrys_currentRoom').shrPromptBox("disable");
		//$('#entrys_currentRoom').shrPromptBox(type);
		$('#entrys_checkInDate').shrDateTimePicker(type);
		$('#entrys_adjustRoom').shrPromptBox(type);
		$('#entrys_checkoutDate').shrDateTimePicker("disable");
	}

});
