<template>
	<view class="page-container">
		<view class="room-type-item" v-for="item in roomTypeList">
			<view class="room-type-item-left">
				<u-image :src="item.roomPicPath" width="200rpx" height="200rpx" radius="10"></u-image>
			</view>
			<view class="room-type-item-middle">
				<view class="room-type-item-middle-text">
					<text>{{item.roomTypeName}}</text>
				</view>
				<view class="room-type-item-middle-bottom">
					<!-- <text>{{item.breakfirst}} </text> -->
					<text>{{item.roomArea}}㎡ </text>
				</view>

			</view>
			<view class="room-type-item-right">
				<view class="room-type-item-right-text">
					<text>￥{{item.unitPrice}}</text>
				</view>
				<u-button text="选房" @click="gotoSelectRoom(item)"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		IMG_BASE_URL
	} from "../../config.js"
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				roomTypeList: {},
				roomTypeMap: {},
			};
		},
		computed: {
			...mapState('m_business', ['currentHotelId', 'reservationInfo']),
			...mapState('m_user', ['userInfo'])
		},
		methods: {
			...mapMutations('m_business', ['updateRoomType', 'updateReservationInfo']),
			async gotoSelectRoom(item) {
				let res = await uni.$http.post('/hotelOrder', {
					name: this.userInfo.name,
					phone: this.userInfo.phone,
					hotelId: this.currentHotelId,
					roomType: item.roomType,
					startTime: this.reservationInfo.startTime,
					endTime: this.reservationInfo.endTime
				})
				this.reservationInfo.orderInfo = res.data.data
				this.reservationInfo.price = item.unitPrice
				this.reservationInfo.roomType = item.roomType
				this.reservationInfo.roomTypeName = item.roomTypeName
				this.updateReservationInfo(this.reservationInfo)

				uni.navigateTo({
					url: '/subpkg_checkin/submitOrder/submitOrder'
				});
			},
			async getRoomTypeList() {
				let res = await uni.$http.post('/roomType', {
					hotelId: this.currentHotelId,
					pageNo: 1,
					pageSize: 10
				})
				this.roomTypeList = res.data.data.records
				this.roomTypeList.forEach((item) => {
					item.roomPicPath = IMG_BASE_URL + '/' + item.roomPicPath
				})
			}
		},
		onLoad() {
			this.getRoomTypeList()
		}
	}
</script>

<style lang="scss">
	.page-container {
		background-color: #F5F5F5;

		.room-type-item {
			border-radius: 30rpx;
			background-color: #FFFFFF;
			margin: 20rpx 20rpx;
			padding: 40rpx 20rpx;
			display: flex;
			background: #FFFFFF;
			box-shadow: 0rpx 10rpx 6rpx 1rpx rgba(75, 75, 75, 0.1);
			border-radius: 10rpx;

			.room-type-item-middle {
				margin-left: 30rpx;
				display: flex;
				flex-direction: column;
				width: 200rpx;

				.room-type-item-middle-text {
					font-size: 40rpx;
					font-weight: bold;
					color: #333333;
				}

				.room-type-item-middle-bottom {
					margin-top: 40rpx;
					font-size: 25rpx;

					text {
						margin-right: 20rpx;
						color: #666666
					}
				}
			}

			.room-type-item-right {
				width: 25%;
				margin-left: 20rpx;

				.room-type-item-right-text {
					margin-top: 30rpx;
					margin-bottom: 20rpx;
				}

				text {
					font-size: 40rpx;
					font-weight: bold;
					color: #FF5C58
				}

				button {
					background-color: #F69B49;
					height: 60rpx;
					width: 100%;

					text {
						color: white
					}
				}

			}
		}
	}
</style>