<template>
	<view>
		<view :class="'mine' + (skinNotColor ? ' not-color' : '')+(config.greyTheme==1?' grayTheme':'')">
			<view :style="'height:' + systems.barHeight + 'rpx;'"></view>
			<view
				:style="'top:' + systems.ktxStatusHeight + 'rpx;z-index:3;position: absolute;'+'line-height: '+ systems.navigationHeight+'rpx;text-align: center;left: 0;font-size: 34rpx;right: 0;color: #FFFFFF;'">
				我的
			</view>
			<image src="../../static/pages/images/userBg.png" class="wdbg" @click="jumpUrl('mine/userinfo/userinfo')">
			</image>
			<view class="minec">
				<view class="minec-img" @click="jumpUrl('mine/userinfo/userinfo')">
					<image :src="userInfos.avatar ? userInfos.avatar : '/static/pages/images/userimg.png'"
						mode="aspectFit" class="user"></image>
				</view>
				<view class="mines" @click="jumpUrl('mine/userinfo/userinfo')" v-if="isLogin">
					<view class="ddflex">
						{{ userInfos.nickName }}
						<view class="ddflex" style="font-size: 24rpx;font-weight: 400;" @click.stop="isShowBind=true" v-if="userInfos.userType!=1">
							<image style="width: 23rpx;height: 22rpx;margin-right: 10rpx;" src="/static/images/bind.png" class="auth-img"></image>
							绑定工号
						</view>
						<view class="ddflex" style="font-size: 24rpx;font-weight: 400;" v-if="userInfos.userType==1&&userInfos.saleNo">
							<image style="width: 23rpx;height: 22rpx;margin-right: 10rpx;" src="/static/images/bind.png" class="auth-img"></image>
							{{ userInfos.saleNo }}
						</view>
					</view>
					<text class="edu" v-if="userInfos.mobile">{{ userInfos.mobile }}</text>
				</view>
				<view class="flex" v-else><text class="login-btn" @click="jumpUrl('')">点击登录</text></view>
				<view class="rule dflex" @click="isSign == 0 || sign == 1 ? jumpUrl('') : signFun()" v-if="isShowSign">
					<image src="/static/pages/images/qdico.png"></image>
					{{ !isLogin ? '签到' : isSign == 0 || sign == 1 ? '已签到' : '签到' }}
				</view>
				<!-- </navigator> -->
			</view>
			<view class="datas dflex">
				<!-- @click="jumpUrl('mine/coupons/coupons')" -->
				<navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/collect/collect')">
					<text>{{ myCount.matchNo ? myCount.matchNo : '0' }}</text>
					我的收藏
				</navigator>
				<navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/follow/index')">
					<text>{{ myCount.followNo ? myCount.followNo : '0' }}</text>
					我的关注
				</navigator>
				<navigator url="" hover-class="none" class="li"
					@click="jumpUrl('match/activity/activity')">
					<text>{{ myCount.enlistMatchNo ? myCount.enlistMatchNo : '0' }}</text>
					参与活动
				</navigator>
				<!-- <navigator url="/mine/footprint/footprint" hover-class="none" class="li"><text>{{footprint?footprint:'0'}}</text>足迹</navigator> -->
			</view>
			<view style="height: 80rpx;"></view>
		</view>

		<view :class="(config.greyTheme==1?' grayTheme':'')">
			<view class="con" style="margin-top: -80rpx;" v-if="userInfos.userType!=1">
						<view class="order">
							<navigator url="" hover-class="none" class="tits dflex" @click="jumpUrl('match/activity/activity')">
								<view class="flex">我的活动</view>
								全部活动
								<image src="../../static/pages/images/more.png" class="rico"></image>
							</navigator>
							<view class="ddflex" style="justify-content: space-between;padding: 40rpx 0rpx;">
								<view class="order-item ddflex fflex" @click="jumpUrl('match/activity/activity?current=2')">
									<image src="/static/images/hd_dcy.png"></image>
									<view>待参与</view>
								</view>
								<vieW class="order-line"></vieW>
								<view class="order-item ddflex fflex" @click="jumpUrl('match/activity/activity?current=3')">
									<image src="/static/images/hd_ywc.png"></image>
									<view>已完成</view>
								</view>
							</view>
						</view>
					</view>
					<view class="con" style="margin-top: -80rpx;" v-else>
						<view class="order">
							<view class="ddflex" style="justify-content: space-between;padding: 40rpx 0rpx;">
								<!-- <view class="order-item ddflex fflex" @click="jumpUrl('match/activityManage/activityManage')">
									<image src="/static/images/hdgl.png"></image>
									<view>活动管理</view>
								</view>
								<vieW class="order-line"></vieW> -->
								<view class="order-item ddflex fflex" @click="jumpUrl('library/poster/index')">
									<image src="/static/images/hbtg.png"></image>
									<view>海报推广</view>
								</view>
								<vieW class="order-line"></vieW>
								<view class="order-item ddflex fflex" @click="jumpUrl('library/page/page')">
									<image src="/static/images/yxdy.png"></image>
									<view>营销单页</view>
								</view>
							</view>
						</view>
					</view>
			
					<view class="con" v-if="!userInfos.userType&&recommendCard">
						<view class="order">
							<navigator url="" hover-class="none" class="tits dflex" @click="jumpUrl('mine/order/order')">
								<view class="flex">我的顾问</view>
							</navigator>
							<view class="service-person">
								<view class="dflex" @click="jumpUrl('/card/index/index')">
									<image class="service-person-header" :src="recommendCard.avatar?recommendCard.avatar:'../../static/pages/images/userimg.png'"></image>
									<view class="fflex">
										<view class="dflex">
											<view class="fflex">
												<view class="service-person-name ddflex">
													<view>Hi~我是{{recommendCard.realName}}</view>
													<image src="/static/images/rico2.png" class="rico"></image>
												</view>
												<view class="service-person-number">(工号:{{recommendCard.jobNumber}}) 您的1V1专属保险顾问</view>
											</view>
											<view class="service-person-btn" @click="jumpSingleChatRoom()">在线咨询</view>
										</view>
										<view class="service-person-options ddflex">
											<view class="service-person-option ddflex">
												<image src="/static/pages/images/dz_hui.png"></image>
												<view>{{recommendCard.favorableComment}}%</view>
											</view>
											<view class="service-person-option ddflex">
												<image src="/static/pages/images/cy_hui.png"></image>
												<view>入司{{recommendCard.inDate?monthDayDiff(recommendCard.inDate):'1年'}}</view>
											</view>
											<view class="service-person-option ddflex">
												<image src="/static/pages/images/fw_hui.png"></image>
												<view>为{{recommendCard.cntCust?recommendCard.cntCust:0}}人服务</view>
											</view>
										</view>
									</view>
								</view>
								<view class="service-person-phone ddflex">
									<view class="ddflex flex" style="justify-content: center;" @click.stop="callPhone(recommendCard.phone)">
										<image src="/static/pages/images/phone1.png"></image>
										<view>联系电话</view>
									</view>
									<view class="order-line" v-if="recommendCard.phone&&(recommendCard.wechat||recommendCard.wechatCode||recommendCard.wechatCompanyCode)"></view>
									<view class="ddflex flex" v-if="recommendCard.wechat||recommendCard.wechatCode||recommendCard.wechatCompanyCode" style="justify-content: center;" @click.stop="(recommendCard.wechat||recommendCard.wechatCode||recommendCard.wechatCompanyCode)?showCodePop():''">
										<image style="width: 35rpx;height: 28rpx;" src="/static/pages/images/qw.png"></image>
										<view>加微信</view>
									</view>
								</view>
							</view>
						</view>
					</view>
			<!-- url="/promote/invite/invite" -->
					<view class="box mlist" v-if="userInfos.userType!=1">
						<button class="li ddflex"  open-type="share">
							<image src="/static/images/yqhy.png" class="mico"></image>
							<view class="fflex">推荐好友</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</button>
					</view>
					<view class="box mlist" v-else>
						<navigator class="li ddflex" @click="toCard()" hover-class="none">
							<image src="/static/images/wdmp.png" class="mico"></image>
							<view class="fflex">我的名片</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</navigator>
						<!-- <navigator class="li ddflex" @click="jumpUrl('mine/clientManage/clientManage')" hover-class="none">
							<image src="/static/images/wdmp.png" class="mico"></image>
							<view class="fflex">我的客户</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</navigator> -->
					</view>
			
					<view class="box mlist">
						<view class="li ddflex" v-if="!config.INTELLIGENT_CUSTOMER_SERVICE">
							<view class="fflex">
								<contact-button class-name="ddflex" img-url="/static/images/lxkf.png"
									img-style='width: 49rpx;height: 49rpx;margin: 0 25rpx 0 0;' button-text="联系客服"
									styles="line-height:initial;"></contact-button>
							</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</view>
						<navigator class="li ddflex" @click="toKf()" hover-class="none" v-else>
							<image src="/static/images/lxkf.png" class="mico" mode="aspectFit"></image>
							<view class="fflex">智能客服</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</navigator>
						<navigator class="li ddflex" url="/mine/help/help" hover-class="none">
							<image src="/static/images/bzzx.png" class="mico" mode="aspectFit"></image>
							<view class="fflex">帮助中心</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</navigator>
						<navigator class="li ddflex" url="/mine/feedback/feedback" hover-class="none">
							<image src="/static/images/jyfk.png" class="mico"></image>
							<view class="fflex">建议与反馈</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</navigator>
						<navigator class="li ddflex" url="/pages/about/about" hover-class="none">
							<image src="/static/images/gywm.png" class="mico"></image>
							<view class="fflex">关于中国人寿</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</navigator>
						<navigator class="li ddflex" url="/mine/set/set" hover-class="none">
							<image src="/static/images/setting.png" class="mico"></image>
							<view class="fflex">设置中心</view>
							<image src="../../static/pages/images/more.png" class="rico"></image>
						</navigator>
					</view>
		</view>
		<!-- <footer-copyright></footer-copyright> -->
		<view style="height: 80rpx;"></view>
		<!-- <view class="placeholder-view" :style="'height:' + (bottomBlankHeignt + 115) + 'rpx'"></view> -->
		<foot channel="user"></foot>
		
		<to-userinfo v-if="isShowUpdate"></to-userinfo>


		<msgNumber bottom="230rpx"></msgNumber>
		
		<view class="ceng2" v-if="isShowCodePop" @click="isShowCodePop = false"  @touchmove.stop.prevent="moveHandle"></view>
		<view class="code-pop" v-if="isShowCodePop">
			<view v-if="recommendCard.wechatCode||recommendCard.wechatCompanyCode" class="ddflex" style="justify-content: center;">
				<view class="code-content" v-if="recommendCard.wechatCode">
					<image :src="recommendCard.wechatCode?recommendCard.wechatCode:'/static/images/wxCode.jpg'" :style="recommendCard.wechatCompanyCode?'width: 200rpx;height: 200rpx;':''"
						show-menu-by-longpress="true"></image>
					<view style="text-align: center;font-size: 24rpx;color: #999;margin-bottom: 50rpx;">长按识别微信二维码</view>
				</view>
				<view class="code-content" v-if="recommendCard.wechatCompanyCode" :style="recommendCard.wechatCode?'margin-left:30rpx':''">
					<image :src="recommendCard.wechatCompanyCode?recommendCard.wechatCompanyCode:'/static/images/wxCode.jpg'" :style="recommendCard.wechatCode?'width: 200rpx;height: 200rpx;':''"
						show-menu-by-longpress="true"></image>
					<view style="text-align: center;font-size: 24rpx;color: #999;margin-bottom: 50rpx;">长按识别企微二维码</view>
				</view>
			</view>
			<view class="code-text" v-else>
				<view>微信号</view>
				<view>{{recommendCard.wechat}}</view>
			</view>
			<view class="code-btn" @click="copy(recommendCard.wechat)" v-if="recommendCard.wechat">
				复制微信号
			</view>
		</view>

		<bindJobnum v-if="isShowBind" @closeBind="closeBind()"></bindJobnum>
	</view>
</template>

<script>
	// pages/user/user.js
	const app = getApp();
	const req = require('../../utils/request.js');
	const util = require('../../utils/util.js');
	const route = require('../../utils/route');
	import foot from '../../components/nav-bar/index';
	import footerCopyright from '../../components/footer-copyright/footer-copyright';
	import bindJobnum from '../../components/bind-jobnum/index.vue';
	import msgNumber from '../../components/msg-number/index.vue';

	export default {
		data() {
			return {
				systems: {},
				skinNotColor: req.public.skinNotColor,
				picUrlss: req.public.picUrls,
				bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
				// merchantId: '',
				iconSrc: req.public.iconSrc,
				//头部页面背景链接
				isHideVip: true,
				//隐藏会员
				isVip: true,
				//是否是会员
				IS_secondary_members: 0,
				distr: '',
				userinfovip: '',
				userMoney: '',
				istetphone: '',
				logo: '',
				name: '',
				is_open_wallet: '',
				Open_Points_Mall: '',
				statistics: '',
				vipList: '',
				rongkang: req.header.appId,
				isSign: '',
				sign: 0,
				isLogin: false,
				noLogin: false,
				is_open_shop: '',
				isShowSign: false, //是否显示签到按钮
				config: {},
				userInfo: {},
				userInfos: {},
				isShowUpdate: false, //是否显示更新信息弹窗
				recommendCard:'',
				isShowCodePop:false,
				isShowBind:false,
				myCount:{
					enlistMatchNo:0,
					followNo:0,
					matchNo:0
				}
			};
		},

		components: {
			foot,
			footerCopyright,
			bindJobnum,
			msgNumber
		},
		props: {},

		onLoad(options) {
			uni.hideTabBar();

			uni.setNavigationBarColor({
				frontColor: this.skinNotColor ? '#000' : '#ffffff',
				backgroundColor: this.skinNotColor ? '#fff' : req.public.titleTopBgColor
			});

			if (JSON.parse(req.getStorage('configRes')).IS_secondary_members) {
				let IS_secondary_members = JSON.parse(req.getStorage('configRes')).IS_secondary_members;
				console.log(IS_secondary_members);
				this.setData({
					IS_secondary_members: IS_secondary_members
				});
			}
			this.userInfo = req.getStorage('userInfo');
			// #ifdef MP-WEIXIN
			let userInfo = req.getStorage('userInfo');
			if (req.isAuth()) {
				setTimeout(res => {
					this.isShowUpdate = true;
				}, 500);
			}
			// #endif
			req.saveBehaviorNew('',16,4)
		},

		onShow: function() {
			let userInfo = req.getStorage('userInfo');
			this.isLogin = req.isLogins(false);
			if (this.isLogin) {
				this.getMy();
				this.getAbout();
				this.getMyCount()
				this.noLogin = true;
				
				console.log("userInfo",userInfo)
				if(this.isShowUpdate == true){
					this.isShowUpdate = false;
				}
				
			} else {
				this.noLogin = false;
			}
		},
		onShareAppMessage(res) {
			if (res.from == 'button') {
				let userInfo = req.getStorage('userInfo');
				return {
					title: userInfo.nickName+'邀请您加入'+this.config.CONFIG_PROJECT_TITLE,
					path: '/pages/index/index',
					imageUrl: this.config.CONFIG_PROJECT_LOGO, // 分享图
				};
			}
		},
		methods: {

			jumpUrl(url) {
				if (req.isLogins(true)) {
					app.globalData.navigateTo(url);
				}
			},

			jumpMerchantManage() {
				let token = req.getStorage('AUTH_TOKEN');
				this.jumpUrl('merchant/index?appId=' + req.header.appId + '&token=' + token);
			},

			gouserInfo() {
				app.globalData.navigateTo('mine/userinfo/userinfo');
			},
			getMy() {
				let that = this;
				req.getRequest('/api/user/info', {}, data => {
					// data.merchantId = req.getStorage('userInfo').merchantId
					data.nickName = req.excludeSpecial(data.nickName);
					this.userInfos = data;
					// that.setData(data); // this.isbindmobile();
					console.log('userinfo==' + JSON.stringify(data));
					this.getRecommendCard()
					// console.log(this);
				});
			},

			getAbout() {
				var _this = this;

				req.getRequest('/api/other/config', {}, function(res) {
					_this.phone = res.CONFIG_SERVICE_HOT_MOBILE;
					_this.config = res;
					_this.setData({
						istetphone: res.user_bind_mobile,
						logo: res.CONFIG_PROJECT_LOGO,
						name: res.CONFIG_PROJECT_TITLE
					});

					// console.log(res);
					if (res && res.is_open_wallet) {
						_this.setData({
							is_open_wallet: JSON.parse(res.is_open_wallet)
						});
					}

					if (res.is_open_shop) {
						_this.is_open_shop = res.is_open_shop;
					}
				});
			},

			callPhone() {
				if (req.isLogins(true)) {
					uni.makePhoneCall({
						phoneNumber: this.phone
					});
				}
			},

			goUrl() {
				app.globalData.openPage('mine/vip/vip');
			},
			showInfo(index) {
				if (!this.vipList[index].isShowInfo) {
					this.vipList.map(it => {
						it.isShowInfo = false;
						return it;
					});
				}
				this.vipList[index].isShowInfo = !this.vipList[index].isShowInfo;
			},
			closeUpdate() {
				this.isShowUpdate = false;
			},
			updateInfo(e) {
				this.isUpdateInfo = e;
				this.getMy();
			},
			updateMobile(e) {
				this.isUpdateMobile = e;
				this.getMy();
			},
			closeBind(){
				this.isShowBind = false;
			},

			// 判断强制绑定手机号
			// isbindmobile() {
			//   if (req.getStorage('configRes')) {
			//     let configRes = JSON.parse(req.getStorage('configRes'))
			//     this.setData({ istetphone: configRes.user_bind_mobile, logo: configRes.CONFIG_PROJECT_LOGO, name: configRes.CONFIG_PROJECT_TITLE })
			//   } else {
			//     req.g('/api/config', (res) => {
			//       req.setStorage('configRes', JSON.stringify(res))
			//       this.setData({ istetphone: res.user_bind_mobile, logo: res.CONFIG_PROJECT_LOGO, name: res.CONFIG_PROJECT_TITLE })
			//     })
			//   }
			//   if(this.data.istetphone=='1'){
			//       // 获取用户手机号
			//     let userInfo= req.getStorage('userInfo')
			//     if(userInfo.mobile==null||userInfo.mobile==''){
			//       console.log("获取用户手机号===============================")
			//       app.openPage('pages/authorize/authorize?bindmobile=1')
			//     }
			//   }
			// },
			// 获取推荐销售
			getRecommendCard(){
				if(this.userInfos.userType==1){
					req.getRequest('/api/visiting/card/userInfo',{},res=>{
						this.recommendCard = res
					})
				}else{
					if(this.userInfos.manageSaleNo){
						req.getRequest('/api/visiting/card/recommendCardInfo',{},res=>{
							this.recommendCard = res
						})
					}else{
						this.recommendCard = ''
					}
				}
			},
			monthDayDiff(date){
				return util.monthDayDiff(date)
			},
			showCodePop(){
				this.isShowCodePop = true
				req.saveBehaviorNew(this.recommendCard.id,1,18)
			},
			// 拨打电话
			callPhone(val) {
				if(!val) return false
			    uni.makePhoneCall({
			        phoneNumber: val,
					success(res){
						req.saveBehaviorNew(this.recommendCard.id,1,17,this.recommendCard.phone)
					}
			    });
			},
			copy(val){
				this.isShowCodePop = false
				uni.setClipboardData({
					data: val,
					complete() {
						req.msg('复制成功')
					}
				})
			},
			jumpSingleChatRoom() {
				if (this.recommendCard) {
					req.jumpSingleChatRoom(this.recommendCard.userId, this.recommendCard.avatar, this.recommendCard
						.realName);
					req.saveBehaviorNew(this.recommendCard.id,1,14)
				}
			
			},
			getMyCount(){
				req.getRequest('/api/my/count',{},res=>{
					this.myCount = res
				})
			},
			toCard(){
				if(this.recommendCard){
					if(this.recommendCard.auditState==0){
						// 待审核
						this.jumpUrl('card/success/success?state=0')
						return false
					}else if(this.recommendCard.auditState==1){
						// 审核成功
						this.jumpUrl('card/success/success?state=1')
						return false
					}else if(this.recommendCard.auditState==2){
						// 审核失败
						this.jumpUrl('card/success/success?state=2&&msg='+this.recommendCard.auditFailReason)
						return false
					}
				}else{
					this.jumpUrl('card/create/create')
				}
			},
			// 智能客服
			toKf(){
				this.jumpUrl('pages/web/web?url='+encodeURIComponent(this.config.INTELLIGENT_CUSTOMER_SERVICE));
			}
		},
		created() {
			const systemInfo = uni.getSystemInfoSync();
			// px转换到rpx的比例
			let pxToRpxScale = 750 / systemInfo.windowWidth;
			let systems = {
				ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
				navigationHeight: 44 * pxToRpxScale // 导航栏的高度
			};
			systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
			this.systems = systems;
		}
	};
</script>
<style>
	@import './user.css';
</style>