<template>
	<view class="userPage" :style="[mainStyle]">
		<view class="mine" :style="'padding-top:'+systems.barHeight+'rpx;'">
			<image :src="picUrlss + 'wdbg1.png'" class="wdbg"></image>
			<view class="minec">
				<view class="avatar-box">
					<image :src="userInfos.avatar?userInfos.avatar:'../../static/pages/images/userimg.png'"
						mode="aspectFit" class="user" @click="jumpUrlInfo()"></image>
					<view class="avatar-up" v-if="!userInfos.avatar || userInfos.avatar.indexOf('thirdwx.qlogo') > -1">
						更新头像</view>
				</view>
				<view class="mines" @click="jumpUrlInfo()" v-if="isLogin">
					<view class="ddflex" style="justify-content: space-between;">
						<view class="ddflex">
							{{ userInfos.nickName ? userInfos.nickName : '-' }}
							<image :src="picUrlss+'info_bj.png'" class="info-bj"
								v-if="!userInfos.avatar || userInfos.avatar.indexOf('thirdwx.qlogo') > -1 || userInfos.nickName.indexOf('用户') > -1"
								@click.stop="showUpdate()"></image>
							<image :src="config.ordinary_member_icon" class="common-vip"
								v-if="config.ordinary_member_icon && !userinfovip.levelGrade"></image>
						</view>
					</view>
					<text class="edu" v-if="userInfos.mobile">{{ userInfos.mobile ? userInfos.mobile: '手机号' }}</text>
				</view>
				<view class="flex" v-else><text class="login-btn" @click="jumpUrl('')">点击登录</text></view>
				<!-- #ifdef MP-WEIXIN -->
				<view class="card" @click.stop="jumpConversation()" style="position: relative;margin-right: 10rpx;">
					<image style="width: 48rpx;height: 48rpx;" src="../../static/images/chat.png"></image>
					<view v-if="unReadSpotNum>0" class="newsDot"></view>
					消息
				</view>
				<!-- #endif -->


				<view class="card" @click="jumpCardUrl()"
					v-if="(distr.distributionIsOpen==1&&userInfos.isDistriUser == 2) || userInfos.isStaff">
					<image src="../../static/images/mp_ico.png" style="width: 45rpx;height: 48rpx;" mode="aspectFit">
					</image>
					名片
				</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> -->
			</view>
			<view class="datas dflex">
				<navigator url="" hover-class="none" class="li" v-if="is_open_wallet.isOpenWallet == 1"
					@click="checkUpdate('wallet/index/index')">
					<text>{{ userMoney ? userMoney : '0.00' }}</text>
					余额
				</navigator>
				<!-- <navigator
					url=""
					hover-class="none"
					class="li"
					:style="is_open_wallet.isOpenWallet != 1 && Open_Points_Mall != 1 ? 'width:50%' : ''"
					@click="jumpUrl('mine/coupons/coupons')"
				>
					<text>{{ userInfos.coupon ? userInfos.coupon : '0' }}</text>
					优惠券
				</navigator> -->
				<!-- <navigator url="" hover-class="none" class="li" @click="jumpUrl('integralshop/index/index')">
					<text>{{ userInfos.integral ? userInfos.integral : '0' }}</text>
					积分
				</navigator> -->
				<navigator url="" hover-class="none" class="li"
					:style="is_open_wallet.isOpenWallet != 1 && Open_Points_Mall != 1 ? 'width:50%' : ''"
					@click="jumpUrl('mine/collect/collect')">
					<text>{{ userInfos.collect ? userInfos.collect : '0' }}</text>
					收藏
				</navigator>
				<navigator @click="jumpUrl('mine/footprint/footprint')" url="" hover-class="none" class="li">
					<text>{{ userInfos.footprint ? userInfos.footprint : '0' }}</text>
					足迹
				</navigator>
			</view>
			<block v-if="isLogin">
				<view class="upgrade ddflex"
					v-if="config.ordinary_member_icon && userinfovip.levelGrade < vipList.length">
					<view :class="'li' + (!userinfovip.levelGrade ? ' active' : '')">
						<view>普通会员</view>
					</view>
					<view class="li" :class="{ active: userinfovip.level == item.id, cur: item.isShowInfo }"
						v-for="(item, index) in vipList" :key="index" @click="showInfo(index)">
						<view class="vip-info" v-if="item.isShowInfo && item.upgradeTerm.terms.length > 0">
							<text
								v-if="item.upgradeTerm.terms[0].bind == 'order_money'">累计消费金额达到{{ item.upgradeTerm.terms[0].value }}元即可升级</text>
							<text
								v-if="item.upgradeTerm.terms[0].bind == 'order_num'">累计购买订单达到{{ item.upgradeTerm.terms[0].value }}笔即可升级</text>
							<text
								v-if="item.upgradeTerm.terms[0].bind == 'share_new'">分享拉新人数累计达到{{ item.upgradeTerm.terms[0].value }}人即可升级</text>
						</view>
						<view class="vip-tit">{{ item.title }}</view>
					</view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" hover-class="none" class="vip"
					v-if="!userInfos.mobile">
					<image :src="picUrlss + 'blue/vip_bg.png'" class="vipbg"></image>
					<view class="vipc dflex">
						<view class="dflex flex">
							<image src="/static/pages/images/hg_ico1.png" class="vipimg"></image>
							<text class="huiyuan">会员立享专属权益</text>
						</view>
						<view class="ling">立即开通</view>
					</view>
				</button>
				<!-- #endif -->
				<!-- #ifndef MP-WEIXIN -->
				<view @click="goToVip()" hover-class="none" class="vip" v-if="!userInfos.mobile">
					<image :src="picUrlss + 'blue/vip_bg.png'" class="vipbg"></image>
					<view class="vipc dflex">
						<view class="dflex flex">
							<image src="/static/pages/images/hg_ico1.png" class="vipimg"></image>
							<text class="huiyuan">会员立享专属权益</text>
						</view>
						<view class="ling">立即开通</view>
					</view>
				</view>
				<!-- #endif -->
				<block v-else>
					<view class="vip" v-if="vipList && vipList.length >= 1 && rongkang != 'ZQ1VK5oc17I387E'"
						@click="checkUpdate('mine/vip/vip')">
						<image :src="picUrlss + 'blue/vip_bg.png'" class="vipbg"></image>
						<view class="vipc dflex">
							<view class="dflex flex" v-if="userinfovip.levelGrade > 0 && !userinfovip.end">
								<!-- <image :src="userinfovip.icon"></image> -->
								<image src="/static/pages/images/hg_ico1.png" class="vipimg"></image>
								<view class="huiyuan">{{ userinfovip.levelName }}</view>
								<!-- <text class="level" >{{userinfovip.levelGrade}}</text> -->
							</view>
							<view class="dflex flex" v-else>
								<image src="/static/pages/images/hg_ico1.png" class="vipimg"></image>
								<text class="huiyuan">会员立享专属权益</text>
							</view>
							<view class="cheng" v-if="userinfovip.levelGrade > 0 && !userinfovip.end">
								{{ userinfovip.expireTime }} 到期
							</view>
							<view class="ling" v-else>立即开通</view>
						</view>
					</view>
				</block>
			</block>
			<view class="vip" v-else @click="goToVip()">
				<image :src="picUrlss + 'blue/vip_bg.png'" class="vipbg"></image>
				<view class="vipc dflex">
					<view class="dflex flex">
						<image src="/static/pages/images/hg_ico1.png" class="vipimg"></image>
						<text class="huiyuan">会员立享专属权益</text>
					</view>
					<view class="ling">立即开通</view>
				</view>
			</view>
		</view>

		<view class="con">
			<view class="order">
				<navigator url="" hover-class="none" class="tits dflex" @click="jumpUrl('mine/order/order')">
					<view class="flex">我的订单</view>
					查看全部
					<image src="/static/pages/images/rico.png" class="rico"></image>
				</navigator>
				<view class="list1">
					<navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order')">
						<block v-if="showPageIcon">
							<image v-if="config.mainIconPath" :src="picUrlss +config.mainIconPath+ 'ddico0.png'"
								mode="aspectFit"></image>
							<image v-else :src="picUrlss + 'blue/ddico0.png'"></image>
						</block>
						<block v-else>
							<image src=""></image>
						</block>
						<view>全部订单</view>
					</navigator>
					<navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order?state=1')">
						<block v-if="showPageIcon">
							<image v-if="config.mainIconPath" :src="picUrlss +config.mainIconPath+ 'ddico1.png'"
								mode="aspectFit"></image>
							<image v-else :src="picUrlss + 'blue/ddico1.png'"></image>
						</block>
						<block v-else>
							<image src=""></image>
						</block>
						<text class="new" v-if="quantityCensus.toBePaid > 0">{{ quantityCensus.toBePaid }}</text>
						<view>待付款</view>
					</navigator>
					<!-- <navigator url="" hover-class="none" class="li" @click="jumpUrl('service/secondCard/secondCard')"> -->
					<!-- <navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order?typeState=4')">
						<image :src="picUrlss + 'blue/ddico_dsy.png'"></image>
						<text class="new" v-if="quantityCensus.toBeWrittenOff > 0">{{ quantityCensus.toBeWrittenOff }}</text>
						<view>待核销</view>
					</navigator> -->
					<navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order?state=3')">
						<block v-if="showPageIcon">
							<image v-if="config.mainIconPath" :src="picUrlss +config.mainIconPath+ 'ddico2.png'"
								mode="aspectFit"></image>
							<image v-else :src="picUrlss + 'blue/ddico2.png'"></image>
						</block>
						<block v-else>
							<image src=""></image>
						</block>
						<text class="new" v-if="quantityCensus.toBeShipped > 0">{{ quantityCensus.toBeShipped }}</text>
						<view>待发货</view>
					</navigator>
					<!-- <navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order?typeState=3')">
						<image :src="picUrlss + 'blue/ddico0.png'"></image>
						<text class="new" v-if="quantityCensus.toBeWithdrawn > 0">{{ quantityCensus.toBeWithdrawn }}</text>
						<view>待自提</view>
					</navigator> -->
					<navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order?state=5')">
						<block v-if="showPageIcon">
							<image v-if="config.mainIconPath" :src="picUrlss +config.mainIconPath+ 'ddico3.png'"
								mode="aspectFit"></image>
							<image v-else :src="picUrlss + 'blue/ddico3.png'"></image>
						</block>
						<block v-else>
							<image src=""></image>
						</block>
						<text class="new"
							v-if="quantityCensus.toBeSignedIn > 0">{{ quantityCensus.toBeSignedIn }}</text>
						<view>待收货</view>
					</navigator>
					<navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order?state=7')">
						<block v-if="showPageIcon">
							<image v-if="config.mainIconPath" :src="picUrlss +config.mainIconPath+ 'ddico0_1.png'"
								mode="aspectFit"></image>
							<image v-else :src="picUrlss + 'blue/ddico0_1.png'"></image>
						</block>
						<block v-else>
							<image src=""></image>
						</block>
						<text class="new" v-if="quantityCensus.completed > 0">{{ quantityCensus.completed }}</text>
						<view>已完成</view>
					</navigator>
					<!-- <navigator url="" hover-class="none" class="li" @click="jumpUrl('mine/order/order?typeState=7')">
						<image :src="picUrlss + 'blue/ddico0_1.png'"></image>
						<text class="new" v-if="quantityCensus.afterSales > 0">{{ quantityCensus.afterSales }}</text>
						<view>退款/售后</view>
					</navigator> -->
				</view>
			</view>
		</view>
		<!-- <view class="guwen" v-if="isShowAssistant">
			<view class="gw-tit">有问题？专属顾问来帮你~</view>
			<view class="gw-info ddflex">
				<image :src="assistant.avatar ? assistant.avatar : '../../static/pages/images/userimg.png'" mode="aspectFill"></image>
				<view class="fflex">
					<view class="gw-name">{{ assistant.nickName }}</view>
					<text class="gw-zc">{{ assistant.mobile }}</text>
				</view>
				<view class="gw-btn" @click="callAssistant()">联系他</view>
			</view>
			<view class="gw-tag ddflex">
				<image :src="picUrlss + 'scrm/gw_bg.png'" class="gw-bg"></image>
				<view>金牌顾问在线解答</view>
			</view>
		</view>
		<view class="hongbao ddflex" @click="jumpUrl('topic/redEnvelope/index')">
			<image :src="picUrlss + 'scrm/hb_img.png'" class="hb-img"></image>
			<view class="hb-info fflex">你有1条录入线索成为有效商机</view>
			<image :src="picUrlss + 'scrm/hb_rico.png'" class="hb-rico"></image>
		</view> -->
		<!-- 店铺 -->
		<view style="display: none;" class="order shopname" v-if="
				(userInfos.listMerchant && userInfos.listMerchant != null && userInfos.listMerchant.length > 0) ||
					(is_open_shop == 1 && userInfos.listShopBase && userInfos.listShopBase != null && userInfos.listShopBase.length > 0) ||
					userInfos.merchantId != null
			">
			<image src="/static/pages/images/md_ic_bg.png" class="md_ic_bg"></image>
			<navigator url="" hover-class="none" class="tits dflex" @click="jumpMerchantManage()">
				<view class="ddflex fflex">
					<image src="/static/pages/images/position_b_icon.png" class="bico"></image>
					<view class="fflex tover" v-if="!userInfos.listShopBase || !userInfos.listMerchant">门店管理</view>
					<block v-else>
						<view class="fflex tover"
							v-if="userInfos.listMerchant.length > 0 && userInfos.listShopBase.length < 1">
							{{ userInfos.listMerchant[0].title ? userInfos.listMerchant[0].title : '门店管理' }}
						</view>
						<view class="fflex tover" v-else-if="userInfos.listShopBase.length > 0">
							{{ userInfos.listShopBase[0].title ? userInfos.listShopBase[0].title : '门店管理' }}
						</view>
						<!-- {{!listShopBase?listMerchant[0].title:listShopBase.length==0?listMerchant[0].title:listShopBase[0].title}} -->
					</block>
				</view>
				查看更多
				<image src="/static/pages/images/rico.png" class="rico"></image>
			</navigator>
			<view class="datasw dflex">
				<navigator url="" hover-class="none" class="li" @click="jumpMerchantManage()">
					全部订单
					<text>{{ statistics.total }}</text>
				</navigator>
				<navigator url="" hover-class="none" class="li" @click="jumpMerchantManage()">
					待发货
					<text>{{ statistics.t3 }}</text>
				</navigator>
				<navigator url="" hover-class="none" class="li" @click="jumpMerchantManage()">
					待核销
					<text>{{ statistics.toBeWrittenOff }}</text>
				</navigator>
				<navigator url="" hover-class="none" class="li" @click="jumpMerchantManage()">
					待提货
					<text>{{ statistics.t4 }}</text>
				</navigator>
			</view>
		</view>
		<view class="order" v-if="distr.distributionIsOpen==1&&userInfos.isDistriUser == 2">
			<navigator url="/promote/index/index" hover-class="none" class="tits dflex">
				<view class="flex">推广合伙人</view>
				<image src="/static/pages/images/rico.png" class="rico"></image>
			</navigator>
			<view class="tuiguang">
				<view class="tuan-money ddflex">
					<view class="blance fflex" @click="jumpUrl('promote/index/index')">
						<view>{{commission.estimate ? commission.estimate : 0}}</view>累计收益
					</view>
					<view class="txbtn" @click="jumpUrl('promote/withdrawal/index/index')">我要提现</view>
				</view>
				<view class="tuan-all ddflex">
					<view class="li" @click="jumpUrl('promote/index/index')">
						<text>待结算</text>{{commission.settled ? commission.settled : 0}}
					</view>
					<view class="li" @click="jumpUrl('promote/index/index')">
						<text>可提现</text>{{commission.withdrawal ? commission.withdrawal : 0}}
					</view>
				</view>
				<view class="dingyue ddflex" v-if="isShowDing && !isSubscribe">
					<view class="fflex">订阅收益提醒消息</view>
					<view class="guan" @click="showAttention">订阅</view>
					<image src="../../static/pages/images/close1.png" class="ding-close" @click="closeDing"></image>
				</view>
				<view class="ceng" v-if="isShowAttention" @click="hideAttention()"></view>
				<view class="pop-att" v-if="isShowAttention">
					<image src="../../static/pages/images/close.png" class="att-close" @click="hideAttention()"></image>
					<view class="att-tit">订阅收益提醒消息</view>
					<view class="att-tip">即可接受团购提醒、新订单等通知</view>
					<view class="att-btn" @click="attentionWe()">立即订阅</view>
				</view>
			</view>
			<view class="list3">
				<view class="service-item border-top-solid" @click="jumpUrl('promote/invite/invite')">
					<view class="fflex">生成推广海报</view>
					<image :src="picUrlss+'blue/tg_ma.png'" class="service-icon"></image>
					<image src="/static/pages/images/rico.png" class="service-more"></image>
				</view>
			</view>
		</view>
		<block v-if="isLogin">
			<block v-if="distr.distributionIsOpen==1&&config.is_hide_distribution_entry != 1">
				<navigator url="" hover-class="none" class="order tuig" v-if="userInfos.isDistriUser==1"
					@click="jumpUrl('promote/status/status')">
					<view class="tits dflex">
						<view class="flex">全民推广</view>
					</view>
					<image :src="picUrlss+'fenxiao.png'" class="fenxiao"></image>
				</navigator>
				<navigator url="" hover-class="none" class="order tuig"
					v-if="userInfos.isDistriUser!=2 && userInfos.isDistriUser!=1" @click="jumpUrl('promote/info/info')">
					<view class="tits dflex">
						<view class="flex">全民推广</view>
					</view>
					<image :src="picUrlss+'fenxiao.png'" class="fenxiao"></image>
				</navigator>
			</block>
		</block>
		<navigator url="" hover-class="none" class="order tuig" @click="jumpUrl('promote/apply/apply')"
			v-if="!isLogin&&config.is_hide_distribution_entry != 1">
			<view class="tits dflex">
				<view class="flex">全民推广</view>
			</view>
			<image :src="picUrlss+'fenxiao.png'" class="fenxiao"></image>
		</navigator>
		<view class="box mlist">
			<!-- <view class="li ddflex" @click="jumpUrl('mine/activity/activity')">
				<image :src="picUrlss + 'scrm/mico_hd.png'" class="mico"></image>
				<view class="fflex">我的报名</view>
				<image src="../../static/pages/images/more.png" class="rico"></image>
			</view> -->
			<!-- <navigator class="li ddflex" url="/promote/invite/invite" hover-class="none">
				<image :src="picUrlss + 'scrm/mico_fx.png'" class="mico"></image>
				<view class="fflex">推荐给朋友</view>
				<image src="../../static/pages/images/more.png" class="rico"></image>
			</navigator> -->
			<view class="li ddflex">
				<view class="fflex">
					<contact-button class-name="ddflex" :img-url="picUrlss+'scrm/mico_kf.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" url="/pages/about/about" hover-class="none">
				<image :src="picUrlss + 'scrm/mico_about.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/feedback/feedback" hover-class="none">
				<image :src="picUrlss + 'scrm/mico_fk.png'" class="mico"></image>
				<view class="fflex">建议与反馈</view>
				<image src="../../static/pages/images/more.png" class="rico"></image>
			</navigator>
			<view class="li ddflex" @click="jumpUrl('mine/set/index')">
				<image :src="picUrlss + 'scrm/mico_set.png'" class="mico"></image>
				<view class="fflex">设置</view>
				<image src="../../static/pages/images/more.png" class="rico"></image>
			</view>
		</view>
		<footer-copyright></footer-copyright>
		<foot channel="user" :isUpdate="isUpdate"></foot>
		<update-userinfo :update-info="isUpdateInfo" :update-mobile="isUpdateMobile" :is-update="true"
			v-if="isShowUpdate" @closeUpdate="closeUpdate" @updateMobileInfo="updateMobileInfo"></update-userinfo>
	</view>
</template>

<script>
	// pages/user/user.js
	const app = getApp();
	const req = require('../../utils/request.js');
	const api = require('../../utils/api.js');
	const route = require('../../utils/route');
	import foot from '../../components/nav-bar/index';
	import footerCopyright from '../../components/footer-copyright/footer-copyright';
	// let disp = require("../../hxChatSDK/utils/broadcast");

	export default {
		data() {
			return {
				mainStyle: app.globalData.mainStyle,
				skinNotColor: req.public.skinNotColor,
				picUrlss: req.public.picUrls,
				bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
				// merchantId: '',
				iconSrc: req.public.iconSrc,
				//头部页面背景链接
				isUpdate: false,
				//是否隐藏注册会员弹窗
				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: {},
				userInfos: {},
				isShowAssistant: false, //是否显示顾问
				assistant: '',

				quantityCensus: '',
				commission: {},
				sessionKey: '',

				systems: '',
				showPageIcon: false,

				unReadSpotNum: 0,
				isShowUpdate: false, //是否显示更新信息弹窗
				isUpdateInfo: false, //更新用户信息
				isUpdateMobile: false, //绑定手机号

				cardInfo: '', //名片信息
			};
		},

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

		async onLoad(options) {
			// 如果是tab页面不往下执行跳转tab缓存页面
			await this.getConfig().then(async res => {
				if (req.isTabPage('user', this.config.solution_name)) {
					req.toTabBar('user', options)
					return false
				} else {
					this.onLoadPage(options)
				}
			});
		},

		onShow: async function() {
			// 如果是tab页面不往下执行跳转tab缓存页面
			await this.getConfig().then(async res => {
				if (req.isTabPage('user', this.config.solution_name)) {
					return false
				} else {
					this.onShowPage()
				}
			});
		},
		methods: {
			onLoadPage(options) {
				//发起获取未读消息通知
				// disp.fire("em.main.ready");
				// //监听未读消息数
				// disp.on("em.unreadspot", this.onChatPageUnreadspot);

				app.globalData.getCheckSessoin(json => {
					this.sessionKey = json.session_key;
				});
				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
					});
				}

				app.globalData.getCheckSessoin(json => {
					this.sessionKey = json.session_key;
				});
			},

			async onShowPage() {
				await this.getAbout();
				this.setData({
					isUpdate: !this.isUpdate
				});
				let userInfo = req.getStorage('userInfo');
				if (userInfo) {
					this.isLogin = true;
				}
				console.log('userInfo》》》》》',userInfo);
				
				// this.isLogin = true;
				if (this.isLogin) {
					await this.getMy();
					this.getRule();
					this.onChatPageUnreadspot()
					this.noLogin = true;
				} else {
					this.noLogin = false;
				}
			},
			// 消息
			onChatPageUnreadspot(message) {
				this.unReadSpotNum = getApp().globalData.unReadMessageNum > 99 ?
					"99+" : getApp().globalData.unReadMessageNum;
				// setTimeout(()=>{
				// 	console.log('-------------------------------->onChatPageUnreadspot<---------------------------')
				// 	this.unReadSpotNum = 2
				// 	this.isShowNews = true
				// },1000)
			},
			jumpSingleChatRoom() {
				// #ifdef MP-WEIXIN
				if (!this.getUpdate()) return false;
				// #endif
				if (this.advisor) {
					req.jumpSingleChatRoom(this.advisor.id, this.advisor.headUrl, this.advisor
						.realName);
				}
			},
			jumpConversation() {
				// #ifdef MP-WEIXIN
				if (!this.getUpdate()) return false;
				// #endif
				req.jumpConversation();
			},
			jumpUrlInfo() {
				if (req.isLogins(true)) {
					// #ifdef MP-WEIXIN
					if (!this.userInfos.avatar || this.userInfos.avatar.indexOf('thirdwx.qlogo') > -1 || this.userInfos
						.nickName.indexOf('用户') > -1) {
						this.isShowUpdate = true;
						this.isUpdateInfo = true;
					} else {
						app.globalData.navigateTo('mine/userinfo/userinfo');
					}
					// #endif
					// #ifndef MP-WEIXIN
					app.globalData.navigateTo('mine/userinfo/userinfo');
					// #endif
				}
			},
			jumpUrl(url) {
				if (!req.isLogins(true)) {
					return false;
				}
				app.globalData.navigateTo(url);
			},

			jumpMerchantManage() {
				// jumpUrl('pages/web/web')
				let token = req.getStorage('AUTH_TOKEN');
				this.jumpUrl('merchant/index?appId=' + req.header.appId + '&token=' + token);
			},
			// 是否签到{}
			isSignFun() {
				req.getRequest('/api/integral/isSign', {}, res => {
					this.setData({
						isSign: res
					});
				});
			},

			gouserInfo() {
				app.globalData.navigateTo('mine/userinfo/userinfo');
			},

			getQuantityCensus() {
				req.getRequest('/api/order/quantityCensus', {}, res => {
					this.quantityCensus = res;
				});
			},

			getDistributionConfig() {
				req.postRequest('/api/distribution/config', {}, res => {
					this.setData({
						distr: res
					});
					if (res.distributionIsOpen == 1) {
						this.getAssistant();
					}
				});
			},
			getAssistant() {
				req.getRequest('/api/v3/assistant/exclusiveConsultant', {}, data => {
					this.assistant = data;
					if (data) {
						this.isShowAssistant = true;
					}
				});
			},
			// 签到
			signFun() {
				req.postRequest('/api/integral/sign', {}, data => {
					if (data) {
						req.msg('连续签到' + data.continuityDay + '天' + ',获得' + data.IntegralChange + '积分');
						this.setData({
							sign: 1
						});
						this.getOpenPonints();
					}
				});
			},
			getuserVip() {
				req.getRequest('/api/user/levelDetails', {}, data => {
					let expireTime = Array;

					if (data.expireTime) {
						expireTime = data.expireTime.split(' ');
						data.expireTime = data.expireTime.replace(/-/g, '/');
					} // 解决苹果不兼容---日期
					// data.expireTime=data.expireTime.replace(/-/g, '/')

					let nowTime = new Date().getTime();
					let endTime = new Date(data.expireTime).getTime();
					let times = parseInt((endTime - nowTime) / 1000); // var expireTime= new Date(data.expireTime)
					// var time1=expireTime.getTime();

					// console.log(times, nowTime, endTime, data.expireTime);
					this.setData({
						userinfovip: data,
						['userinfovip.expireTime']: expireTime[0]
					});

					if (times <= 0) {
						this.setData({
							['userinfovip.end']: true
						});
					} else {
						this.setData({
							['userinfovip.end']: false
						});
					}

					// console.log(data);
				});
			},
			getOpenPonints() {
				req.getRequest('/api/integral/returnIntegral', {}, res => {
					this.setData({
						integral: res
					});
				});
			},
			getMy() {
				let that = this;
				if (req.getStorage('userInfo')) this.userInfos = req.getStorage('userInfo');
				return new Promise((resolve, reject) => {
					req.getRequest('/api/user/my', {}, data => {
						// data.merchantId = req.getStorage('userInfo').merchantId
						data.nickName = req.excludeSpecial(data.nickName);
						if (data.avatar || data.mobile || data.nickName) {
							let userInfo = req.getStorage('userInfo');
							if (userInfo) {
								userInfo.avatar = data.avatar;
								userInfo.mobile = data.mobile;
								userInfo.nickName = data.nickName;
							} else {
								userInfo = data;
							}
							req.setStorage('userInfo', userInfo)
						}
						this.userInfos = data;
						// that.setData(data); // this.isbindmobile();
						console.log('userinfo==' + JSON.stringify(data));
						this.isSignFun();
						this.getstatistics(data);
						this.getQuantityCensus();
						this.getDistributionConfig();
						this.getuserVip();
						this.getuserMoney();
						this.getVip();
						this.getOpenPonints();
						this.getCommission();
						this.getCardInfo();
						// console.log(this);
						resolve();
					});
				})

			},

			getuserMoney() {
				let is_open_wallet = JSON.parse(req.getStorage('configRes')).is_open_wallet;

				if (is_open_wallet) {
					if (JSON.parse(is_open_wallet).isOpenWallet == 1) {
						route.extendNew({}, res => {
							// console.log(parseFloat(res.all).toFixed(2));
							if (res)
								this.setData({
									userMoney: parseFloat(res.all).toFixed(2)
								});
						});
					}
				}
			},
			getConfig() {
				var _this = this;
				return new Promise((resolve, reject) => {
					if (req.getStorage('configRes')) {
						_this.config = JSON.parse(req.getStorage('configRes'));
						resolve();
					} else {
						req.getRequest('/api/config', {}, data => {
							req.setStorage('configRes', JSON.stringify(data));
							this.config = data;
							resolve(data);
						});
					}
				});
			},
			getAbout() {
				var _this = this;
				if (req.getStorage('configRes')) {
					_this.config = JSON.parse(req.getStorage('configRes'));
					_this.showPageIcon = true
					_this.getOtherConfig(JSON.parse(req.getStorage('configRes')));
				} else {
					return new Promise((resolve, reject) => {
						req.getRequest('/api/config', {}, function(res) {
							_this.config = res;
							_this.showPageIcon = true
							_this.getOtherConfig(res);
							resolve();
						});
					})
				}
				// 是否开启积分商城
				req.getRequest(
					'/api/params/value', {
						type: 'Open_Points_Mall'
					},
					res => {
						this.setData({
							Open_Points_Mall: res
						});
					}
				);
			},
			getOtherConfig(res) {
				let _this = this;
				_this.phone = res.CONFIG_SERVICE_HOT_MOBILE;
				_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;
				}

				if (res.user_bind_mobile == '1') {
					// 获取用户手机号
					let userInfo = req.getStorage('userInfo');

					if (userInfo && (userInfo.mobile == null || userInfo.mobile == '')) {
						// console.log("获取用户手机号===============================");
						// app.globalData.openPage('pages/authorize/authorize?bindmobile=1');
					}
				}
			},

			callPhone() {
				if (!req.isLogin()) return false;
				uni.makePhoneCall({
					phoneNumber: this.phone
				});
			},

			goUrl() {
				app.globalData.openPage('mine/vip/vip');
			},

			// 门店统计
			getstatistics(data) {
				let from = {};

				if (data.listShopBase && data.listShopBase != null && data.listShopBase.length > 0) {
					from.shopId = data.listShopBase[0].id;
				}

				if (data.listMerchant && data.listMerchant != null && data.listMerchant.length > 0 && data.listShopBase
					.length < 1) {
					from.merchantId = data.listMerchant[0].id;
				}

				req.getRequest('/api/order/statistics', from, data => {
					this.setData({
						statistics: data
					});
					console.log(data);
				});
			},
			getRule() {
				let that = this;
				req.getRequest('/api/integral/config', {}, res => {
					if (res && res.length > 0) {
						res.map(it => {
							if (it.illustrate && it.illustrate.indexOf('签到') > -1) {
								if (it.state == 2) {
									that.isShowSign = true;
								}
							}
						});
					}
				});
			},
			getVipListOrg() {
				if (this.vipList && this.userinfovip) {
					if (!this.userinfovip.levelGrade) {
						this.vipList.map((it, index) => {
							this.vipList[0].isShowInfo = true;
						});
					} else {
						this.vipList.map((it, index) => {
							if (this.userinfovip.level == it.id) {
								if (index < this.vipList.length - 1) {
									this.vipList[index + 1].isShowInfo = true;
								}
							}
						});
					}
				}
			},
			getVip() {
				req.getRequest('/api/levelStrategy/userLevelList', {}, data => {
					if (data && data.length > 0) {
						data.map((it, index) => {
							it.upgradeTerm = JSON.parse(it.upgradeTerm);
							it.isShowInfo = false;
							// if(index == 0) it.isShowInfo = true;
							return it;
						});
						this.vipList = data;
						this.getVipListOrg();
					}
				});
			},
			getCommission() {
				req.getRequest('/api/v3/distribution/commission/data', {}, data => {
					this.commission = data;
				})
			},
			showInfo(index) {
				if (!this.vipList[index].isShowInfo) {
					this.vipList.map(it => {
						it.isShowInfo = false;
						return it;
					});
				}
				this.vipList[index].isShowInfo = !this.vipList[index].isShowInfo;
			},
			callAssistant() {
				uni.makePhoneCall({
					phoneNumber: this.assistant.mobile
				});
			},
			getPhoneNumber(event) {
				const _ts = this;
				const detail = event.detail;
				if (!detail || !detail.encryptedData || !detail.iv) return false;
				req.postRequest('/api/weixin/mobile', {
					encryptedData: detail.encryptedData,
					iv: detail.iv,
					sessionKey: _ts.sessionKey
				}, res => {
					_ts.getMy();
					let userInfo = req.getStorage('userInfo');
					userInfo.mobile = res.mobile;
					req.setStorage('userInfo', userInfo);
					_ts.jumpUrl('mine/vip/vip');
				});
			},


			goToVip() {
				if (req.isLogins(true)) {
					this.getMy();
					this.jumpUrl('mine/vip/vip');
				}
			},

			scanCode() {
				var _this = this; // 允许从相机和相册扫码
				uni.scanCode({
					success: res => {
						console.log('扫码结果1111==', res)
						let path = res.path.split('?scene=')[0];
						let scene = res.path.split('?scene=')[1];
						let paths = '/' + path + '?scene=' + encodeURIComponent(scene);
						console.log('paths===', paths)
						uni.switchTab({
							url: paths
						}); // this.scene = '1290926887903780865';
					}
				});
			},
			getUpdate() {
				let userInfos = this.userInfos;
				if (!userInfos.mobile) {
					console.log('没有手机号')
					this.isShowUpdate = true;
					this.isUpdateMobile = true;
					req.setStorage('isShowUpdateMobile', true)
					return false;
				}
				if (!userInfos.avatar || userInfos.avatar.indexOf('thirdwx.qlogo') > -1 || userInfos.nickName.indexOf(
						'用户') > -1) {
					console.log('没有昵称')
					this.isShowUpdate = true;
					this.isUpdateInfo = true;
					req.setStorage('isShowUpdateInfo', true)
					return false;
				}
				return true;
			},
			showUpdate() {
				// #ifdef H5
				this.jumpUrlInfo();
				// #endif
				// #ifdef MP-WEIXIN
				this.isShowUpdate = true;
				this.isUpdateInfo = true;
				// #endif
			},
			checkUpdate(url) {
				if (!req.isLogins(true)) {
					return false;
				}
				// #ifdef MP-WEIXIN
				if (this.getUpdate()) {
					this.jumpUrl(url);
				}
				// #endif
				// #ifndef MP-WEIXIN
				this.jumpUrl(url);
				// #endif

			},
			closeUpdate() {
				this.isShowUpdate = false
				this.isUpdateInfo = false;
				this.isUpdateMobile = false;
			},
			updateMobileInfo(e) {
				this.getMy();
			},
			getCardInfo() {
				return new Promise((resolve, reject) => {
					req.getRequest(api.card_userInfo, {}, data => {
						this.cardInfo = data;
						resolve(data)
					})
				})
			},
			async jumpCardUrl() {
				console.log('this.cardInfo==', this.cardInfo)
				let cardInfo = this.cardInfo;
				if (cardInfo) this.jumpUrl('card/index/index');
				else {
					cardInfo = await this.getCardInfo()
					if (cardInfo) this.jumpUrl('card/index/index');
					else this.jumpUrl('card/not/not');
				}
			},
			closeDing() {
				this.isShowDing = false;
			},
			showAttention() {
				this.isShowAttention = true;
			},
			hideAttention() {
				this.isShowAttention = false;
			},
			attentionWe() {
				this.isShowAttention = false;
				uni.navigateTo({
					url: '/pages/webview/web?webUrl=https://mp.weixin.qq.com/s/HDpeIZXQR-MTBrNI6v6E4A'
				})
			},
		},
		beforeMount() {
			const systemInfo = uni.getSystemInfoSync();
			console.log('systemInfo==', systemInfo)
			// 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 scoped>
	@import './user.css';
</style>