<template>
	<view class="page">
		<u-sticky>
			<u-tabs active-color="#EF9944" :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</u-sticky>
		<card1 v-if="current==0"></card1>
		<card2 @login="showLogin" v-else></card2>
		
		<login ref="login" @signIn="signIn"></login>
	</view>
</template>
<script>
	import card1 from "./comps/card1.vue"
	import card2 from "./comps/card2.vue"
	import login from "@/components/login.vue"
	export default {
		components:{
			card1,card2,login
		},
		data() {
			return {
				list: [{
					name: '参与活动'
				}, {
					name: '代理推广'
				}],
				current: 0
			}
		},
		onLoad(options) {
			this.current=options.current || 0
		},
		mounted() {
			
		},
		methods:{
			showLogin(){
				this.$refs.login.show()
			},
			showPhoneModal(){
				this.$refs.login.showPhoneModal()
			},
			signIn(resp){
				this.judgeAgenterType()
				if (!this.vuex_phone) {
					this.showPhoneModal()
				}
			},
			change(e){
				this.current=e
				if (this.current==1 && this.$isEmpty(this.vuex_userId)) {
					this.showLogin()
					return
				}
				if (this.current==1 && this.$isEmpty(this.vuex_phone)) {
					this.showPhoneModal()
				}
			},
			judgeAgenterType(){
				let params={
					userId:this.vuex_userId,
					enabled:1
				}
				this.$api.agenter.list(params).then(res=>{
					if (!this.$isEmpty(res.data.records)) {
						let item=res.data.records[0]
						let type=this.$isEmpty(item.agenterTypeId)?1:2
						this.$u.vuex('vuex_agenter_type',type)
					}
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		background-color: #f6f6f6;
		min-height: 100vh;
	}
</style>

