<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>
				<view class="sc-btn flex" @click="toIndex">进入我的微页</view>
			</view>
		</view>
	</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
			};
		},

		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'
				})
			}
		}
	};
</script>
<style>
	@import "./index.css";
</style>