<template>
	<view class="content main-bg">
		<soldier ref="soldier" v-if="type === '2' || type === '3'"></soldier>
		<!-- <soldier v-if="type === '3'"></soldier> -->
		<merchant ref="merchant" v-if="type === '5'"></merchant>
		<merchantExamine ref="merchantExamine" v-if="type === '4'"></merchantExamine>
	</view>
</template>
<script>
	import soldier from '@/pages/soldier/home/index'
	import merchant from '@/pages/merchant/home/index'
	import merchantExamine from '@/pages/manage/merchant/merchantExamine'
	export default {
		components:{
			soldier,
			merchant,
			merchantExamine
		},
		data() {
			return {
				type: '2'
			}
		},
		onLoad() {
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			let role = uni.getStorageSync('role');
			if(role){
				this.type = role;
			}
			if(this.type === '1'){
				this.type = '5'
				this.handleShow();
			}else if(this.type === '4'){
				this.handleManage();
			}
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShow() {
			let role = uni.getStorageSync('role');
			if(role){
				this.type = role;
			}
			if(this.type === '1'){
				this.type = '5'
				this.handleShow();
			}else if(this.type === '4'){
				this.handleManage();
			}else{
				console.log('onShow handleSoldier ')
				this.handleSoldier();
			}
		},
		methods: {
			handleShow(){
				let userInfo = uni.getStorageSync('userInfo');
				if(userInfo.nickName === "null"){
					uni.redirectTo({
						url: '/pages/merchant/home/modify'
					})
				}else{
					let that = this;
					this.$nextTick(function(){
						that.$refs.merchant.show();
					})
				}
			},
			handleManage(){
				this.type = '4';
				let that = this;
				this.$nextTick(function(){
					that.$refs.merchantExamine.show("qwe")
				})
			},
			handleSoldier(){
				console.log('this.type', this.type)
				console.log('this.$refs.soldier', this.$refs.soldier)
				let that = this;
				this.$nextTick(function(){
					that.$refs.soldier.showSoldier()
				})
			}
		}
	}
</script>

<style>
	.content {
		width: 100%;
		height: auto;
	}
</style>
