<template>
</template>

<script>
	import { choseType } from '@/api/index.js';
	import {
		login,
		getUserInfo
	} from '@/api/login.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	export default {
		data() {
			return {
				type: '',
				typeName: ''
			}
		},
		onLoad(opt) {
			let obj = this
			obj.type = opt.type
			if (obj.type == 1) {
				obj.typeName = '病人'
			} else if (obj.type == 2) {
				obj.typeName = '医生'
			} else if (obj.type == 3) {
				obj.typeName = '机构'
			}
			// 保存用户
			obj.setChooseType(obj.type)
			if (obj.hasLogin) {
				// 判断用户类型是否和入口类型一致
				getUserInfo({}).then(e => {
					obj.setUserInfo(e.data);
					if(obj.userInfo.ext_info == null) {
						choseType({
							type: obj.type*1
						})
							.then(function(re) {
								if (re.msg == '修改成功') {
									if (obj.type == 1) {
										uni.navigateTo({
											url: `/pages/public/PatRegister`
										});
									}
									if (obj.type == 2) {
										uni.navigateTo({
											url: `/pages/public/DocRegister`
										});
									}
									if (obj.type == 3) {
										uni.navigateTo({
											url: `/pages/public/MecRegister`
										});
									}
								}
							})
							.catch(eer => {
								
							});
					}else {
						if (obj.userInfo.type != obj.type) {
							uni.showModal({
								title: '提示',
								content: '您当前的用户类型和入口类型不一致，请选择相应的入口进入！',
								success: function(res) {
						
									setTimeout(function() {
										//安卓手机
										document.addEventListener(
											"WeixinJSBridgeReady",
											function() {
												WeixinJSBridge.call("closeWindow");
											},
											false
										);
										//ios手机
										WeixinJSBridge.call("closeWindow");
									}, 100);
						
								}
							})
						} else {
						
							if (obj.userInfo.type == 2) {
								uni.setTabBarItem({
									index: 0,
									text: '首页',
									iconPath: 'static/tabBar/tab-home.png',
									selectedIconPath: 'static/tabBar/tab-home-current.png'
								});
								uni.setTabBarItem({
									index: 1,
									text: '我的病人',
									iconPath: 'static/tabBar/tab-cate.png',
									selectedIconPath: 'static/tabBar/tab-cate-current.png',
									visible: true
								});
								uni.setTabBarItem({
									index: 2,
									text: '科普学习',
									iconPath: 'static/tabBar/tab-study.png',
									selectedIconPath: 'static/tabBar/tab-study-current.png',
									visible: false
								});
								uni.setTabBarItem({
									index: 3,
									text: '接单',
									iconPath: 'static/tabBar/jd.png',
									selectedIconPath: 'static/tabBar/jd-act.png',
									visible: true
								})
								uni.setTabBarItem({
									index: 4,
									text: '我的',
									iconPath: 'static/tabBar/tab-my.png',
									selectedIconPath: 'static/tabBar/tab-my-current.png'
								});
							}
							if (obj.userInfo.type == 3) {
								uni.setTabBarItem({
									index: 0,
									text: '首页',
									iconPath: 'static/tabBar/tab-home.png',
									selectedIconPath: 'static/tabBar/tab-home-current.png'
								});
								uni.setTabBarItem({
									index: 1,
									text: '咨询记录',
									iconPath: 'static/tabBar/tab-cate.png',
									selectedIconPath: 'static/tabBar/tab-cate-current.png',
									visible: true
								});
								uni.setTabBarItem({
									index: 2,
									text: '科普学习',
									iconPath: 'static/tabBar/tab-study.png',
									selectedIconPath: 'static/tabBar/tab-study-current.png',
									visible: false
								});
								uni.setTabBarItem({
									index: 3,
									text: '发布订单',
									iconPath: 'static/tabBar/jd.png',
									selectedIconPath: 'static/tabBar/jd-act.png',
									pagePath: '/pages/dd/dd',
									visible: true
								})
						
								uni.setTabBarItem({
									index: 4,
									text: '我的',
									iconPath: 'static/tabBar/tab-my.png',
									selectedIconPath: 'static/tabBar/tab-my-current.png'
								});
							}
							if (obj.userInfo.type == 1) {
								uni.setTabBarItem({
									index: 0,
									text: '首页',
									iconPath: 'static/tabBar/tab-home.png',
									selectedIconPath: 'static/tabBar/tab-home-current.png'
								});
								uni.setTabBarItem({
									index: 1,
									text: '咨询记录',
									iconPath: 'static/tabBar/tab-cate.png',
									selectedIconPath: 'static/tabBar/tab-cate-current.png',
									visible: true
								});
								uni.setTabBarItem({
									index: 2,
									text: '科普学习',
									iconPath: 'static/tabBar/tab-study.png',
									selectedIconPath: 'static/tabBar/tab-study-current.png',
									visible: true
								});
								uni.setTabBarItem({
									index: 3,
									text: '接单',
									iconPath: 'static/tabBar/jd.png',
									selectedIconPath: 'static/tabBar/jd-act.png',
									visible: false
								})
								uni.setTabBarItem({
									index: 4,
									text: '我的',
									iconPath: 'static/tabBar/tab-my.png',
									selectedIconPath: 'static/tabBar/tab-my-current.png.png'
								});
							}
							uni.switchTab({
								url: '/pages/index/home'
							})
						}
					}
					
				})
				
				
			} else {
				let bool = uni.getStorageSync('weichatBrowser')
				if(bool) {
					uni.navigateTo({
						url: '/pages/public/wxLogin'
					})
				}else {
					uni.navigateTo({
						url:'/pages/public/login'
					})
				}
				
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			...mapMutations(['setChooseType','setUserInfo'])
		}
	}
</script>

<style>
</style>
