<template>
	<view>

		<navbar :title="$t('pageTitle.selectIdentity')" :leftClick="!$route.query.back"
			@leftClick="$utils.navigateBack" />

		<view class="container">
			
			<view class="title">{{ $t('components.selectIdentity') }}</view>
			<view class="button-group">
				<!--供应商-->
				<view :class="{'identity-button' : true, act : !!$store.state.buy}" @click="selectIdentity(0)">
					<view class="identity-text"> {{ $t('other.iAmBuyer') }}</view>
					<view class="identity-icon">
						<img src="../../static/image/index/5.png" style="width: 100%; height: 100%;">
					</view>
				</view>
				<!--采购-->
				<view :class="{'identity-button' : true, act : !!$store.state.shopData}" @click="selectIdentity(1)">
					<view class="identity-text"> {{ $t('other.iAmSupplier') }}</view>
					<view class="identity-icon">
						<img src="../../static/image/index/6.png" style="width: 100%; height: 100%;">
					</view>
				</view>
			</view>
			
			
			<view style="margin-top: 100rpx;
				text-decoration: underline;color: blue;
				display: flex;
				gap: 100rpx;">
				<view style=""
				@click="refus">
					刷新身份信息
				</view>
				
				
				<view style=""
				@click="$store.commit('logout')">
					退出登录
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		mapGetters
	} from 'vuex'

	export default {
		computed: {
			...mapGetters(['userShop', "userInfo"]),
		},
		onShow() {
			this.$store.commit('getUserInfo')
		},
		methods: {
			selectIdentity(identity) {
				// if (userInfo)
				if (identity == 0 && this.$store.state.buy) {
					this.$store.commit('setShop', false)
					uni.reLaunch({
						url: '/pages/index/index'
					})
				} else if (identity == 1 && this.$store.state.shopData) {
					this.$store.commit('setShop', true)
					uni.reLaunch({
						url: '/pages/index/index'
					})
				} else {
					uni.navigateTo({
						url: `/pages_order/auth/registerShop?identity=${identity}`
					})
				}
			},
			refus(){
				this.$store.commit('getUserInfo')
				uni.showLoading()
				setTimeout(() => {
					uni.showToast({
						title: '刷新成功',
						icon: 'none'
					})
					uni.hideLoading()
				}, 500)
			},
		}
	}
</script>

<style scoped lang="scss">
	* {
		box-sizing: border-box;
	}

	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		//height: 100vh;
		background-color: #f5f5f5;

		.title {
			font-size: 40rpx;
			color: #333;
			margin: 80rpx 0;
		}

		.button-group {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			width: 100vw;
			//padding: 0 20px;

			.identity-button {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 80%;
				margin-bottom: 40rpx;
				padding: 40rpx 50rpx;
				background-color: #2d2f5997;
				border-radius: 20rpx;
				color: white;

				.identity-text {
					font-size: 40rpx;
				}

				.identity-icon {
					width: 130rpx;
					height: 130rpx;
				}
			}
			.act{
				background-color: #2d2f59;
			}
		}
	}
</style>