<template>
	<view class="index flex-colum">
		<navseat :opacity='false' title=" " :titleshow='true' :namecolor='"#fff"' iconcolor='#fff'></navseat>
		<view class="index_text">
			点击切换商户账号
		</view>
		<view class="index_box">
			<view class="index_item flex-between" v-for="(item,index) in list" :key="index" @click="clickes(item)">
				<view class="index_itemone flex-start">
					<!-- <image class="index_itemoneimage" :src="item.avatar" mode=""></image> -->
					<view class="flex-colum-start">
						<view class="index_itemone_one">
							{{item.title}}
						</view>
						<!-- 	<view class="index_itemone_tow">
							{{item.class}}
						</view> -->
					</view>
				</view>
				<view class="index_itemonetext" v-if="item.is_online == 1">
					当前使用
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import navseat from '@/components/navseat.vue'
	export default {
		components: {
			navseat
		},
		data() {
			return {
				screenheight: '',
				list: [],
				storeid: uni.cache.get('user').store_id
			}
		},
		onLoad() {
			this.useraccountlist()
			uni.getSystemInfo({
				success: (e) => {
					let screenHeight = 0
					console.log(e)
					screenHeight = e.windowHeight
					this.screenheight = {
						'height': screenHeight + 'px'
					}
				}
			})
		},
		methods: {
			async useraccountlist() {
				let res = await this.api.kstorelist()
				if (res.code = 1) {
					this.list = res.data
				}
			},
			// 切换商户
			async postuserswitchstore() {

			},
			async clickes(e) {
				if (e.is_online == 1) {
					return false;
				}
				uni.showModal({
					title: '提示',
					content: '确定切换商家吗？',
					success: async (res) => {
						if (res.confirm) {
							let res = await this.api.userswitchstore({
								id: e.id
							})
							uni.cache.set('userId', res.data.userinfo.store_id);
							uni.cache.set('logintoken', res.data.userinfo.token);
							uni.cache.set('store_status', res.data.store_status);
							uni.cache.set('userinfo', res.data.userinfo);
							uni.cache.set('Type', res.data.type);
							uni.cache.set('set_pwd', res.data.set_pwd);
							if (res.data.set_pwd == 1) {
								uni.navigateTo({
									url: '/pages/login/repairpassword'
								})
							} else {
								uni.reLaunch({
									url: '/pages/index/index?restype=' + 1
								});
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})

			}
		}
	}
</script>

<style lang="scss">
	page {

		background: #EDEDED;
	}

	.index {
		height: 100%;

		.index_text {
			font-size: 52rpx;
			font-family: SourceHanSansCN-Regular, SourceHanSansCN;
			font-weight: 400;
			color: #333333;
			margin-top: 100rpx;
		}

		.index_box {
			padding: 0 48rpx 60rpx 48rpx;
			width: 100%;

			.index_item {
				align-items: flex-start;
				margin-top: 32rpx;
				width: 100%;
				padding: 32rpx 28rpx;
				background: #FFFFFF;
				border-radius: 20rpx;

				.index_itemone {
					.index_itemoneimage {
						width: 114rpx;
						height: 114rpx;
					}

					.flex-colum-start {
						// margin-left: 32rpx;

						.index_itemone_one {
							width: 400rpx;
							font-size: 30rpx;
							font-family: SourceHanSansCN-Bold, SourceHanSansCN;
							font-weight: 400;
							color: #333333;
						}

						.index_itemone_tow {
							margin-top: 10rpx;
							font-size: 32rpx;
							font-family: SourceHanSansCN-Regular, SourceHanSansCN;
							font-weight: 400;
							color: #999999;
						}
					}
				}

				.index_itemonetext {
					font-size: 28rpx;
					font-family: SourceHanSansCN-Regular, SourceHanSansCN;
					font-weight: 400;
					color: #2F87FD;
				}
			}
		}
	}
</style>