<!-- 地址列表 -->
<template>
	<view class="address-wrap">
		<u-checkbox-group :wrap="true" v-for="(item,index) in houseList" :key="index">
			<view class="card_list" @click="checked(item)">
				<view class="card_list_left">
					<u-icon name="home"></u-icon>
					<text class="padding-left-10">{{item.address}}</text>
				</view>
				<view class="card_list_right">
					<u-checkbox style="float: right;" v-model="item.checked" :name="item.id"></u-checkbox>
				</view>
			</view>
		</u-checkbox-group>

		<view
			style="position: fixed;bottom: 70rpx;display: flex;justify-content: center;align-items: center;width: 100%;">
			<u-button size="medium" :customStyle="cancelStyle" @click="auth">创建新房间</u-button>
			<u-button size="medium" :customStyle="confirmStyle" type="primary" @click="confirm">确定绑定</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				houseList: [],
				cancelStyle: {
					width: '260rpx',
					border: '1rpx solid #d0d0d0',
					borderRadius: 0,
					marginRight: '20rpx'
				},
				confirmStyle: {
					width: '260rpx',
					borderRadius: 0,
					marginLeft: '20rpx'
				}
			};
		},
		computed: {},
		onLoad() {
			this.initData()
		},
		methods: {
			initData() {
				this.houseList = uni.getStorageSync("houseList") || []
				this.houseList.forEach(item => {
					item.checked = false
				})
			},
			checked(item) {
				item.checked = !item.checked
				this.$forceUpdate()
			},
			confirm() {
				let memberId = getApp().globalData.member.id
				let checkedList = this.houseList.filter(item => item.checked)
				if (this.$isEmpty(checkedList)) {
					this.$u.toast('至少选择一个房间')
					return
				}
				let ids = checkedList.map(item => item.id)
				this.$http.bindRoom(memberId, ids).then(res => {
					if (res.data.success) {
						uni.removeStorageSync("houseList")
						this.$dialog.showModal('绑定成功', false).then(() => {
							uni.reLaunch({
								url: "../index/index"
							})
						})
					}
				})
			},
			auth() {
				uni.redirectTo({
					url: "../auth/auth"
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.card_list {
		background-color: #FFFFFF;
		padding: 30rpx 0rpx 30rpx 30rpx;
		display: flex;
		justify-content: space-between;
		margin: 10rpx 0;

		&_left {}
	}

	// 底部按钮
	.foot_box-wrap {
		height: 140rpx;
		width: 100%;
	}

	.foot_box {
		padding: 10rpx 20rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		// border-top: 1rpx solid rgba(#ccc, 0.2);
		// background-color: #fff;

		.sync-wxaddress {
			flex: 1;
			line-height: 80rpx;
			background: #ff9900;
		}

		.add-btn {
			line-height: 80rpx;
			flex: 1;
			background: $base;
			color: rgba(255, 255, 255, 1);
		}
	}
</style>
