<template>
	<view v-if="!loading">
		<view v-if="recommendCard&&userInfo.id!=recommendCard.userId">
			<view style="height: 136rpx;"></view>
			<view class="sc-box ddflex">
				<image class="sc-header" :src="recommendCard.avatar?recommendCard.avatar:'../../static/images/userimg.png'">
				</image>
				<view class="sc-name">
					<view>{{recommendCard.realName}}</view>
					<view class="sc-tag">{{recommendCard.jobName}}</view>
				</view>
				<view class="sc-line"></view>
				<view class="sc-contact" @click="jumpSingleChatRoom()">
					<image src="/static/images/wxChat.png"></image>
					<view>聊一聊</view>
				</view>
				<block v-if="userInfo.manageSaleNo">
					<view class="sc-btn flex" @click="toIndex">进入我的微页</view>
				</block>
				<block v-else>
					<view class="sc-btn flex" style="border-radius: 80rpx  0  0 80rpx;" @click="toIndex">进入微页</view>
					<view class="sc-btn flex" style="margin-left: 10rpx;border-radius: 0 80rpx 80rpx 0;background-color: #FF7229;" v-if="!userInfo.manageSaleNo" @click="bindSale()">绑定</view>
				</block>
			</view>
		</view>
		
		<update-userinfo :update-info="isUpdateInfo" :update-mobile="isUpdateMobile" :is-update="true" v-if="isShowUpdate" @closeUpdate="closeUpdate" @updateMobile="updateMobileInfo" @updateInfo="updateInfo"></update-userinfo>
	</view>
</template>

<script>
	const app = getApp();
	const req = require("../../utils/request.js");
	const QQMapWX = require("../../utils/qqmap.js");

	export default {
		data() {
			return {
				userInfo:{},
				recommendCard: {},
				loading:true,
				
				isShowUpdate: false, //是否显示更新信息弹窗
				isUpdateInfo: false, //更新用户信息
				isUpdateMobile: false, //绑定手机号
			};
		},

		components: {},
		props: {
			userId:String
		},
		watch: {},

		mounted() {
			this.userInfo = req.getStorage('userInfo')
			QQMapWX.initMap();
			req.getLocation(res => {
				const to = {
					latitude: res.latitude,
					longitude: res.longitude
				};
				this.getRecommendCard(to)
			});
		},

		methods: {
			// 获取推荐销售
			getRecommendCard(loction) {
				let params = loction
				if(this.userId){
					params.userId = this.userId
					req.getRequest('/api/user/userInfoById', params, res => {
						if(res.visitingCardDTO){
							this.recommendCard = res.visitingCardDTO
							this.loading = false
						}else{
							params.shareSaleNo = req.getStorage("shareId")?req.getStorage("shareId"):null
							delete params.userId
							req.getRequest('/api/visiting/card/recommendCardInfo', params, res => {
								this.recommendCard = res
								this.loading = false
							})
						}
					})
				}else{
					params.shareSaleNo = req.getStorage("shareId")?req.getStorage("shareId"):null
					req.getRequest('/api/visiting/card/recommendCardInfo', params, res => {
						this.recommendCard = res
						this.loading = false
					})
				}
			},


			jumpSingleChatRoom() {
				if (this.recommendCard) {
					req.jumpSingleChatRoom(this.recommendCard.userId, this.recommendCard.avatar, this.recommendCard
						.realName);
					req.saveBehaviorNew(this.recommendCard.id,1,14)
				}

			},
			// jumpConversation() {
			// 	req.jumpConversation();
			// },
			toIndex() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			bindSale(){
				let userInfo = req.getStorage('userInfo');
				console.log('updateInfo userInfo.avatar',userInfo.avatar)
				if (!userInfo.avatar || !userInfo.nickName || userInfo.avatar.indexOf('thirdwx.qlogo') > -1 || userInfo.nickName.indexOf('用户') > -1) {
					this.isShowUpdate = true
					this.isUpdateInfo = true
					return false
				}
				if(userInfo.avatar&&!userInfo.mobile){
					this.isShowUpdate = true
					this.isUpdateMobile = true
					return false
				}
				uni.showModal({
					title:'提示',
					content:'是否绑定该顾问？',
					success: (con) => {
						if(con.confirm){
							req.postRequest('/api/visiting/card/bindManageSaleNo',{manageSaleNo:this.recommendCard.jobNumber},res=>{
								req.msg('已绑定专属顾问')
								let userInfo = req.getStorage('userInfo')
								userInfo.manageSaleNo = this.recommendCard.jobNumber
								req.setStorage('userInfo',userInfo)
								this.userInfo = req.getStorage('userInfo')
							})
						}
					}
				})
			},
			showUpdate(){
				this.isShowUpdate = true;
				this.isUpdateInfo = true;
			},
			closeUpdate(){
				this.isShowUpdate = false
				this.isUpdateInfo = false;
			},
			updateInfo(e){
				setTimeout(()=>{
					this.bindSale()
				},500)
			},
			updateMobileInfo(e){
				setTimeout(()=>{
					this.bindSale()
				},500)
			},
		}
	};
</script>
<style>
	@import "./index.css";
</style>