<template>
	<view class="page" :style="{'height':h+'px','padding-top':mt+'px'}">
		<c-nav-bar title="选择门店" backUrl="/pages/login/index" @goBack="goBack" :showHome="false"></c-nav-bar>
		<view class="card" v-for="(item,index) in list" :key="index" @tap="toHome(item)">
			<view>
				<text>{{item.merchantName}}</text>
				<text>{{item.typeName}}</text>
			</view>
			<view>进店</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//userInfo: null,
				merchantId: '',
				types: [],
				list: []
			}
		},
		created() {
			if(uni.getStorageSync('userInfo')) this.getType();
			else{
				// #ifdef APP-PLUS
					uni.reLaunch({
						url: '/pages/login/appIndex'
					})
				// #endif
				// #ifdef MP-WEIXIN
					uni.reLaunch({
						url: '/pages/login/index'
					})
				// #endif
			}
		},
		onLoad(option) {
			//if (option.userInfo) this.userInfo = JSON.parse(decodeURIComponent(option.userInfo));
			if(uni.getStorageSync('userInfo')) this.getList();
			else{
				// #ifdef APP-PLUS
					uni.reLaunch({
						url: '/pages/login/appIndex'
					})
				// #endif
				// #ifdef MP-WEIXIN
					uni.reLaunch({
						url: '/pages/login/index'
					})
				// #endif
			}
		},
		methods: {
			goBack(e) {
				uni.clearStorageSync();
			},
			getType() {
				this.$api.post('/api/dict/getListByTypes', ['BusinessType']).then(res => {
					if (res.data.code === 0) {
						this.types = res.data.data
					} else this.$showToast(res.data.msg);
				})
			},
			getList() {
				this.$api.post('/merchant/register/getMerchantStoreList').then(res => {
					if (res.data.code === 0) {
						this.list = res.data.data;
						this.list.forEach(l => {
							let t = this.types.find(t => t.dictValue == l.merchantType);
							l.typeName = t ? t.dictLabel : ''
						})
					} else this.$showToast(res.data.msg);
				})
			},
			toHome(item) { //1711268640588517378   1721450548101648385
				uni.setStorageSync('merchantType', item.merchantType);
				if (item.merchantType == 2) { //民宿
					uni.setStorageSync('homestayId', item.merchantId);
					uni.setStorageSync('merchantId', '');
					uni.setStorageSync('merchantName', item.merchantName);
					uni.reLaunch({
						url: '/pages/home/index'
					})
				} else { //渔家乐和餐饮
					uni.setStorageSync('homestayId', '');
					uni.setStorageSync('merchantId', item.merchantId);
					uni.setStorageSync('merchantName', item.merchantName);
					uni.reLaunch({
						url: '/pagesHouse/home/index'
					})
				}

			}
		}
	}
</script>

<style scoped lang="less">
	.page {
		background: #F3F4F4;
		padding-bottom: 20rpx;
		box-sizing: border-box;
		overflow-y: auto;

		.card {
			width: calc(100% - 60rpx);
			height: 180rpx;
			background: #FFFFFF;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			margin: 20rpx 30rpx 0;
			padding: 0 30rpx 0 60rpx;
			box-sizing: border-box;
			background: url(https://fsy.shengsi.gov.cn/file/20240109/1ee084be17f74dde94617dcb7f7c8af3.png) no-repeat;
			background-size: 100% 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;

			&>view {
				&:first-child {
					display: flex;
					flex-direction: column;

					text {
						font-size: 32rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 800;
						color: #1E3A62;

						&:last-child {
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							color: #1E3A62;
							margin-top: 10rpx;
						}
					}
				}

				&:last-child {
					width: 140rpx;
					height: 56rpx;
					border-radius: 36rpx 36rpx 36rpx 36rpx;
					border: 1rpx solid #70849F;
					background: transparent;
					line-height: 56rpx;
					text-align: center;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 800;
					color: #1E3A62;
				}
			}
		}
	}
</style>