<template>
  <view class="switch-roles">
    <nav-bar title="切换身份"></nav-bar>
    <view class="roles-content">
      <view class="content">
        <image src="/static/images/my/zhaopingzhe.svg" mode="scaleToFill" />
        <view class="roles-desc">你当前的身份是“{{userType==1?'求职者':'招聘者'}}”</view>
        <view class="roles-btn" @click="bindQe">切换为“{{userType==2?'求职者':'招聘者'}}”身份</view>
      </view>
    </view>
  </view>
</template>
<script>
import navBar from "@/components/nav-bar/index.vue";
export default {
  data() {
    return {
		userType:1
	}
  },
  components: {
    navBar,
  },
  onLoad(){
	this.getUserInfo()
  },
  methods: {
	/**
	 * 获取个人信息
	 */
	getUserInfo() {
		this.$Request.get("/app/user/selectUserById").then((res) => {
			if (res.code == 0) {
				
				if (res.data.userType == 1 || res.data.userType == null) {
					this.userType = 1;
					uni.setStorageSync("userType", 1);
				} else {
					this.userType = 2;
					uni.setStorageSync("userType", 2);
				}
			}
		});
	},
	// 切换身份
	bindQe() {
		let that = this;
		if (uni.getStorageSync("userId")) {
		let index=3-this.userType
	
			if (index == 1) {
				//企业换个人
				uni.showModal({
					title: "提示",
					content: "确认切换到求职者身份吗？",
					confirmColor: "#016BF6",
					complete(ret) {
						if (ret.confirm) {
							let data = {
							  userType: 1,
							};
							that.$Request.postT("/app/user/updateUserEntity", data).then((res) => {
							  if (res.code == 0) {
								  uni.$emit('changeRole',{userType:index})
								  uni.navigateBack()
							  }
							});
	
	
						}
					},
				});
	
			} else if (index == 2) {
				//个人换企业
				uni.showModal({
					title: "提示",
					content: "确认切换到招聘者身份吗？",
					confirmColor: "#016BF6",
					complete(ret) {
						if (ret.confirm) {
							 uni.$emit('changeRole',{userType:index})
							 uni.navigateBack()
						}
					},
				});
			}
		} else {
			this.noLogin();
		}
	},
	//未登录
	noLogin() {
		// uni.showModal({
		// 	title: '提示',
		// 	content: '您还未登录,请先登录',
		// 	confirmColor:'#016BF6',
		// 	success: function(res) {
		// 		if (res.confirm) {
		// 			console.log('用户点击确定');
		// 			// uni.reLaunch({
		// 			// 	url:'/pages/public/login'
		// 			// })
		// 			uni.navigateTo({
		// 				url: '/pages/public/login'
		// 			})
		// 		} else if (res.cancel) {
		// 			console.log('用户点击取消');
		// 		}
		// 	}
		// })
		uni.navigateTo({
			url: "/pages/public/login",
		});
	},
  },
};
</script>
<style lang="scss" scoped>
.switch-roles {
  background: linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%);
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  .roles-content {
    width: 100%;
    flex: 1;
    overflow: hidden;
    overflow-y: auto;
    padding-top: 10vh;
    box-sizing: border-box;
    .content {
      padding: 62rpx;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      image {
        width: 364rpx;
        height: 364rpx;
      }
      .roles-desc {
        color: rgba(255, 255, 255, 1);
        font-family: DM Sans;
        font-size: 32rpx;
        font-weight: 400;
        line-height: 48rpx;
        text-align: center;
        padding: 24rpx 0 36rpx 0;
        box-sizing: border-box;
      }
      .roles-btn {
        color: #016bf6;
        font-family: DM Sans;
        font-size: 32rpx;
        font-weight: 400;
        line-height: 48rpx;
        letter-spacing: 0%;
        background-color: #fff;
        text-align: center;
        padding: 16rpx 32rpx;
        box-sizing: border-box;
        border-radius: 100rpx;
      }
    }
  }
}
</style>
