<template>
	<view class="container">
		<view class="top">{{topTitle}}</view>
		<view class="sub">{{subTitle}}</view>
		<view class="account-content">
			<view class="item" v-for="(item, index) in accountList" :style="{'opacity':item.staffState!==200?'0.6':''}" :key="index" @click="goAccount(item)">
				<image class="left" :src="item.avatar" mode=""></image>
				<view class="middle">
					<view class="middle-item">{{item.staffName}}</view>
					<view class="middle-next-item">{{item.accountName}}</view>
				</view>
				<image class="right" src="../../static/arrow-right.png" mode=""></image>
			</view>
		</view>
		<view class="bottom" v-if="!isSettingEnter">
			<image v-if="!selectTips" class="select-img" src="../../static/select-n.png" mode="" @click="selectTips=!selectTips"></image>
			<image v-else class="select-img" src="../../static/select-h.png" mode="" @click="selectTips=false"></image>
			<view class="tips">
				查看并同意<text @click="$router.push('Agreement')">《隐私政策》</text>和<text @click="$router.push('Agreement')">《服务协议》</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				topTitle: '选择账号',
				subTitle: '系统检测到该手机号已在多家公司注册',
				accountList: [],
				selectTips: false,
				isSettingEnter: false
			};
		},
		onLoad(options) {
			this.isSettingEnter = options.isSettingEnter || false
			if (this.isSettingEnter) {
				this.topTitle = '切换账号'
				this.subTitle = '点击下方账号信息即可完成切换'
			}
			this.getAllAccount()
		},
		created() {
			
		},
		methods: {
			goAccount(item) {
				if (!this.selectTips && !this.isSettingEnter) {
					this.toast('请先查看并同意《隐私政策》和《服务协议》')
					return
				}
				if (item.staffState!==200) {
					this.toast('该帐号已被禁用')
					return
				}
				this.$net.post('/account/change', {'accountCode': item.accountCode}).then(res => {
					if (res.code === 200) {
						if (this.isSettingEnter) {
							this.$router.replaceTo('Mine')
							this.$store.commit('refreshSelectAccount', true)
						} else {
							this.$router.pop()
						}
					} else {
						this.toast(res.message)
					}
				})
			},
			getAllAccount() {
				this.$net.get('/account/query').then(res => {
					if (res.code === 200) {
						this.accountList = this.accountList.concat(res.data.QueryAccountOutput)
					} else {
						this.toast(res.message)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.container {
	height: 100%;
	padding: 64rpx;
	.top {
		font-size: 40rpx;
		color: #333333;
	}
	.sub {
		font-size: 24rpx;
		color: #666666;
		margin-top: 16rpx;
	}
	.account-content {
		height: 550rpx;
		overflow-y: auto;
		margin-top: 128rpx;
		.first-item{
			margin-top: 0;
		}
		.item {
			margin-top: 40rpx;
			border-radius: 16rpx;
			border: 2rpx solid #F0F0F0;
			display: flex;
			padding: 24rpx;
			align-items: center;
			.left {
				display: block;
				height: 96rpx;
				width: 96rpx;
				border-radius: 96rpx;
			}
			.middle {
				height: 86rpx;
				margin-left: 24rpx;
				font-size: 26rpx;
				color: #333333;
				.middle-item {
					height: 36rpx;
					line-height: 38rpx;
					width: 402rpx;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}
				.middle-next-item {
					margin-top: 14rpx;
				}
			}
			.right {
				display: block;
				margin-left: 40rpx;
				height: 20rpx;
				width: 12rpx;
			}
		}
	}
	.bottom {
		position: fixed;
		bottom: 118rpx;
		left: 0;
		right: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		.select-img {
			height: 28rpx;
			width: 28rpx;
		}
		.tips {
			margin-left: 16rpx;
			font-size: 22rpx;
			color: #999999;
			text {
				color: #338AFF;
			}
		}
	}
}
</style>
