<template>
	<view>
		<view :class="(about.greyTheme==1?'grayTheme':'')">
			<view class="bg">
				<image :src="about.INDEX_PIC"></image>
			</view>
			<view v-if="!recommendCard">
				<view class="top-title ddflex" :style="'height: '+ systems.navigationHeight + 'rpx;top:' + systems.ktxStatusHeight + 'rpx;'">
					<image :src="about.CONFIG_PROJECT_LOGO" mode="heightFix"></image>
					{{about.CONFIG_PROJECT_TITLE?about.CONFIG_PROJECT_TITLE:''}}
				</view>
			</view>
			<view class="service-person" :style="'top:' + systems.ktxStatusHeight + 'rpx;'" v-if="recommendCard">
				<view class="ddflex" @click="jumpUrl('/card/index/index?cardId='+recommendCard.id)">
					<image class="service-person-header"
						:src="recommendCard.avatar?recommendCard.avatar:'../../static/pages/images/userimg.png'"></image>
					<view>
						<view class="service-person-name ddflex">
							<view>{{recommendCard.realName}}的微页</view>
							<image src="/static/images/rico2.png" class="rico"></image>
						</view>
						<view class="service-person-number">(工号:{{recommendCard.jobNumber}}) <text v-if="recommendCard&&userInfo.id!=recommendCard.userId">欢迎您来到我的微页</text></view>
					</view>
				</view>
				<view style="margin: 20rpx 30rpx 0;justify-content: space-between;" class="ddflex">
					<view>
						<view class="ddflex">
							<view class="service-person-tag">{{recommendCard.companyName}}</view>
							<view class="service-person-tag">{{recommendCard.jobName}}</view>
						</view>
						<view class="service-person-options ddflex">
							<view class="service-person-option ddflex">
								<image src="/static/pages/images/dz.png"></image>
								<view>{{recommendCard.favorableComment}}%</view>
							</view>
							<view class="service-person-option ddflex">
								<image src="/static/pages/images/cy.png"></image>
								<view>入司{{recommendCard.inDate?monthDayDiff(recommendCard.inDate):'1年'}}</view>
							</view>
							<view class="service-person-option ddflex">
								<image src="/static/pages/images/fw.png"></image>
								<view>为{{recommendCard.cntCust?recommendCard.cntCust:0}}人服务</view>
							</view>
						</view>
					</view>
					<view class="ddflex">
						<view class="service-person-phone" v-if="recommendCard.phone"
							@click="callPhone(recommendCard.phone)">
							<image src="../../static/pages/images/dh.png"></image>
							<view>电话</view>
						</view>
						<view class="service-person-phone" v-if="recommendCard.wechat||recommendCard.wechatCode||recommendCard.wechatCompanyCode" @click="showCodePop()">
							<image src="../../static/pages/images/wx.png"></image>
							<view>微信</view>
						</view>
					</view>
				</view>
			</view>
			<view style="height: 610rpx;"></view>
			<view v-for="(item, index) in contact" :key="index">
				<!-- 弹窗广告 -->
				<view style="position: absolute;top:290rpx;left: 0;right: 0;" v-if="bannerList&&bannerList.length>0">
					<banner v-if="item == 'ad' && bannerShow" :bannerList="bannerList" :url="site" :web="url"
						:config="about" :couponList="couponList" :officeList="officeList"
						:districtTemplate="districtTemplate"></banner>
				</view>
				<district v-if="item == 'king_kong_district' && districtShow" :url="site" :web="url"
					:districtTemplate="districtTemplate"></district>
			
			</view>
			
			<view class="index-box" style="margin-top: 10rpx;" v-if="hotActivityList.length>0">
				<view class="index-box-title">热门活动</view>
				<view class="ddflex" style="margin-top: 20rpx;">
					<view style="margin-right: 20rpx;">
						<image class="pic230" :src="hotActivityList[0].pic" @click="getUrlHot(hotActivityList[0])"></image>
						<image class="pic230" style="margin-top: 20rpx;" :src="hotActivityList[1].pic" @click="getUrlHot(hotActivityList[1])"></image>
					</view>
					<image class="pic480" :src="hotActivityList[2].pic" @click="getUrlHot(hotActivityList[2])"></image>
				</view>
			</view>
			
			<!-- 参与活动 -->
			<view class="index-box" style="margin-top: 50rpx;" v-if="matchList.length>0">
				<view class="index-box-title">更多活动</view>
				<view class="map-ac">
					<scroll-view scroll-x="true" class="map-acs">
						<view class="li" v-for="(item,index) in matchList" :key="index"
							@click="jumpUrl('/match/activityDetail/activityDetail?id='+item.id)">
							<view style="position: relative;border-radius: 20rpx;overflow: hidden;">
								<image :src="item.pic ? item.pic : '/static/images/def_zw1.png'" mode="aspectFill"></image>
								<view class="ac-type" v-if="item.categoryName">{{ item.categoryName }}</view>
							</view>
							<view class="ac-title tovers">{{ item.title }}</view>
						</view>
					</scroll-view>
				</view>
			</view>
			
			<!-- 投保案例 -->
			<view class="index-box" style="margin:0;padding: 30rpx;background-color: #f5f5f5;" v-if="tbalList.length>0">
				<view class="index-box-title">{{tbalName}}</view>
				<view>
					<view class="tbal-nav ddflex">
						<view :class="'tbal-nav-item '+(tbalIndex==index?'tbal-nav-item-active':'' )"
							v-for="item,index in tbalList" @click="changeTbalTab(index)" :key="index">
							<view>{{item.name}}</view>
							<view class="tbal-nav-label" v-if="index==0">20~30岁</view>
							<view class="tbal-nav-label" v-else-if="index==1">25-35岁</view>
							<view class="tbal-nav-label" v-else-if="index==2">30-50岁</view>
							<view class="tbal-nav-label" v-else-if="index==3">50-65岁</view>
						</view>
					</view>
			
					<block v-if="tbalContentList.length>0">
						<view class="tbal-item ddflex" v-for="it in tbalContentList"
							@click="jumpUrl('/topic/content/content?id='+it.id)">
							<!-- @click="jumpUrl('/topic/alContent/alContent?id='+it.id)" -->
							<image class="tbal-pic" :src="it.pic?it.pic:'/static/images/lj_img.png'" mode="aspectFill"></image>
							<view class="flex">
								<view class="tbal-title">{{it.title}}</view>
								<view class="ddflex">
									<view class="flex">
										<view class="tbal-price">
											{{it.fieldValues&&it.fieldValues.yearMoney?it.fieldValues.yearMoney:'0'}}
										</view>
										<view class="tbal-price-text">年缴费</view>
									</view>
									<view class="tbal-line"></view>
									<view class="flex">
										<view class="tbal-price">
											{{it.fieldValues&&it.fieldValues.allMoney?it.fieldValues.allMoney:'0'}}
										</view>
										<view class="tbal-price-text">总保额 </view>
									</view>
								</view>
								<view class="tbal-btn">去看看</view>
							</view>
							<view class="tbal-tag" v-if="it.fieldValues&&it.fieldValues.version">{{it.fieldValues.version}}
							</view>
						</view>
					</block>
					<view class="nodata" v-else style="padding-top: 0rpx;">
						<image :src="picUrlss+'empty_dd.png'"></image>
						<text>暂无数据</text>
					</view>
				</view>
			</view>
			
			<!-- 真实理赔故事 -->
			<view class="index-box" v-if="lpalList.length>0">
				<view class="index-box-title ddflex">
					<text class="fflex">{{lpalName}}</text>
					<view class="fx-header-more ddflex"
						@click="jumpUrl('/topic/contentList/contentList?code='+lpalCode+'&title='+lpalName)">
						更多
						<image src="/static/pages/images/more.png"></image>
					</view>
				</view>
				<view class="map-ac">
					<scroll-view scroll-x="true" class="map-acs ddflex" style="height: 502rpx;">
						<view class="lpgs-item" v-for="items,indexs in lpalList ">
							<image class="lpgs-icon" src="../../static/images/lpgs_icon.png"></image>
							<view :class="'lpgs-header '+(indexs%2==0?'':'lpgs-header-c')">
								<view>{{items.name}}</view>
							</view>
							<view class="lpgs-content" v-if="items.contentList&&items.contentList.length>0">
								<view class="lpgs-item-content ddflex" v-for="item,index in items.contentList" :key="index"
									@click="jumpUrl('/topic/content/content?id='+item.id)">
									<view class="flex" style="min-width: 0;">
										<view class="lpgs-item-content-title tovers3">{{item.title}}</view>
										<view class="lpgs-item-content-look ddflex">
											<image src="/static/images/eyes.png"></image>
											<view>{{unitFormat(item.browse)}}</view>
										</view>
									</view>
									<image class="lpgs-item-content-pic"
										:src="item.pic?item.pic:'/static/images/lj_img.png'"></image>
								</view>
							</view>
							<view class="lpgs-content" v-else>
								<view class="nodata" style="padding-top: 40rpx;padding-bottom: 40rpx;">
									<image :src="picUrlss+'empty_dd.png'" style="margin: 0 auto 0rpx;width: 208rpx;height: 139rpx;" mode="aspectFill"></image>
									<text>暂无数据</text>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
			
			<!-- 发现 -->
			<view class="index-box" style="margin:0;padding: 30rpx;background-color: #f5f5f5;" v-if="fxList.length>0">
				<view class="map-ac">
					<scroll-view scroll-x="true" class="map-acs ddflex" style="height: 70rpx;">
						<view :class="'fx-nav '+(fxIndex==index?'fx-nav-active':'')" v-for="item,index in fxList"
							@click="changeFxTab(index)">
							<view class="fx-dot" v-if="item.addToday>0 && !getReadFindCode()[item.code]"></view>
							{{item.name}}
						</view>
					</scroll-view>
				</view>
				<view class="fx-bar">
					<view class="fx-header ddflex">
						<view class="ddflex">
							<view class="fx-header-title">{{fxList[fxIndex].name}}</view>
							<view class="fx-header-more">{{unitFormat(fxList[fxIndex].shareCount?fxList[fxIndex].shareCount:0)}}人浏览</view>
						</view>
						<view class="fx-header-more ddflex"
							@click="jumpUrl('/topic/contentList/contentList?code='+fxList[fxIndex].code+'&title='+fxList[fxIndex].name)">
							更多
							<image src="/static/pages/images/more.png"></image>
						</view>
					</view>
					<view v-if="fxContentList.length>0">
						<view class="fx-item ddflex" v-for="item in fxContentList"
							@click="jumpUrl('/topic/content/content?id='+item.id)">
							<view class="flex" style="min-width: 0;">
								<view class="fx-item-title tovers3">{{item.title}}</view>
								<view class="ddflex" style="margin-top: 24rpx;">
									<view class="fx-item-time">{{formatTime(item.createDate)}}</view>
									<view class="fx-item-look ddflex">
										<image src="/static/images/eyes.png"></image>
										<view>{{unitFormat(item.browse)}}</view>
									</view>
								</view>
							</view>
							<image class="fx-item-pic" :src="item.pic?item.pic:'../../static/images/lj_img.png'" mode="aspectFill"></image>
						</view>
					</view>
					<view class="nodata" v-else style="padding-top: 0rpx;padding-bottom: 40rpx;">
						<image :src="picUrlss+'empty_dd.png'" style="margin: 0 auto 0rpx;width: 208rpx;height: 139rpx;" mode="aspectFill"></image>
						<text>暂无数据</text>
					</view>
				</view>
			</view>
			
			<!-- <component v-for="(item,index) in contact" ></component> -->
			<!-- <ad></ad> -->
			<block v-if="contactShow">
				<view class="spinner">
					<view class="spinner-container container1">
						<view class="circle1"></view>
						<view class="circle2"></view>
						<view class="circle3"></view>
						<view class="circle4"></view>
					</view>
					<view class="spinner-container container2">
						<view class="circle1"></view>
						<view class="circle2"></view>
						<view class="circle3"></view>
						<view class="circle4"></view>
					</view>
					<view class="spinner-container container3">
						<view class="circle1"></view>
						<view class="circle2"></view>
						<view class="circle3"></view>
						<view class="circle4"></view>
					</view>
				</view>
				<view class="lond">加载中···</view>
			</block>
			<view class="foot-logo">
				<image src="/static/images/zgrs_logo.png"></image>
			</view>
			<!-- <footer-copyright v-if="logo"></footer-copyright> -->
			<!-- <contact-button img-url="/static/pages/images/kfico1_1.png" class-name="contact_index" button-text="客服"></contact-button> -->
			<!-- <view class="guide" @tap="hideGuide" v-if="first">
				<image src="/static/pages/images/guide.png" mode="widthFix"></image>
			</view> -->
		</view>
		<!-- <view class="placeholder-view" :style="'height:' + (bottomBlankHeight + 115) + 'rpx'"></view> -->
		<foot channel="home" :isUpdate="isUpdate"></foot>


		<view class="ceng2" v-if="isShowCodePop" @click="isShowCodePop = false" @touchmove.stop.prevent="moveHandle">
		</view>
		<view :class="'code-pop ' +(about.greyTheme==1?'grayTheme':'')" 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>
		<msgNumber :bottom="recommendCard&&userInfo.id!=recommendCard.userId?'350rpx':'230rpx'"></msgNumber>
		<!-- <view class="chat-fixed" v-if="recommendCard">
			<view class="chat-box ddflex" @click="jumpSingleChatRoom()">
				<image :src="recommendCard.avatar?recommendCard.avatar:'../../static/pages/images/userimg.png'"></image>
				<view class="chat-lyl">聊一聊</view>
			</view>
		</view> -->
		<view :class="'chat-fixed '+(chatShow?'chat-fixed-long':'')" v-if="recommendCard&&userInfo.id!=recommendCard.userId">
			<view class="chat-box ddflex" @click="jumpSingleChatRoom()">
				<image :src="recommendCard.avatar?recommendCard.avatar:'../../static/pages/images/userimg.png'"></image>
				<view v-if="chatShowText" class="fflex tover"
					style="font-size: 24rpx;color: #333333;margin-left: 20rpx;">您好，我是{{recommendCard.realName}}，欢迎访问我的微页
				</view>
				<view :class="'chat-lyl '+(!chatShowText?'chat-lyl2':'')">聊一聊</view>
			</view>
		</view>
			
		<!-- <to-userinfo v-if="isShowUpdate" @closeUpdate="closeUpdate"></to-userinfo> -->
		<update-userinfonew :update-info="isUpdateInfo" :update-mobile="isUpdateMobile" v-if="isShowUpdate" @closeUpdate="closeUpdate" @updateInfo="updateInfo" @updateMobile="updateMobile"></update-userinfonew>
	</view>
</template>

<script>
	//index.js
	//获取应用实例
	const app = getApp();
	const req = require('../../utils/request.js');
	const api = require('../../utils/api.js');
	const utils = require('../../utils/util.js');
	const mes = require('../../utils/requestmessage.js');
	const route = require('../../utils/route');
	const QQMapWX = require("../../utils/qqmap.js");
	import foot from '../../components/nav-bar/index';
	import footerCopyright from '../../components/footer-copyright/footer-copyright';
	import banner from '../../template/banner/banner';
	import district from '../../template/king_kong_district/king_kong_district';
	import msgNumber from '../../components/msg-number/index.vue';

	export default {
		data() {
			return {
				picUrlss: req.public.picUrls,
				skinNotColor: req.public.skinNotColor,
				systems: {},
				header: req.header,
				bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
				bannerList: [],
				//产品分类列表
				page: 1,
				//产品列表
				merchant: {},
				activityGroup: {
					products: []
				},
				couponList: {}, //优惠券,
				isUpdate: false,
				// 是否更新消息
				first: true,
				//是否显示提示加入我的小程序
				isLayerAd: true,
				//广告
				homeTemplate: [],
				//首页栏目配置
				storeShow: true,
				templateType: {
					module_ad: 'ad',
					//广告
					module_type_district: 'type_district',
					//分类导航
					module_king_kong_district: 'king_kong_district', //金刚区
				},
				isNotice: false,
				joingroupList: {
					products: []
				},
				//拼团
				bargainList: {
					products: []
				},
				//砍价
				customersList: {
					products: []
				},
				//新客
				freshen: true,
				url: '',
				web: '',
				site: '',
				districtTemplate: {},
				contact: [],
				seckillList: {
					products: []
				},
				about: {},
				Is_Store_Price_Stock: '',
				guarantee: [],
				animationData: '',
				content: '',
				popAdList: {},
				iscouponAd: false,
				logo: false,
				top: Boolean,
				top_type: Boolean,
				switchStoreShow: Boolean,
				contactShow: true,
				districtShow: false,
				bannerShow: false,
				officeList: [], //互动
				hotActivityList: [], //热门活动
				matchList: [], //活动列表
				
				tbalName:'',
				tbalList: [], //投保案例
				tbalIndex: 0, //投保案例tab
				tbalContentList: [],

				lpalName:'',
				lpalList: [], //理赔案例

				fxList: [], //发现
				fxIndex: 0,
				fxContentList: [],

				recommendCard: '', //销售

				isShowCodePop: false,

				lpalCode: req.public.lpalCode,

				chatShow: true,
				chatShowText: true,
				
				userInfo:{},
				
				isShowUpdate: false, //是否显示更新信息弹窗
				isUpdateInfo: false,//更新用户信息
				isUpdateMobile: false,//绑定手机号
				
				firstLoad:true,//第一次加载页面
			};
		},

		components: {
			foot,
			footerCopyright,
			banner,
			district,
			msgNumber
		},
		props: {},
		onPullDownRefresh() {
			req.removeStorage('shareId')
			setTimeout(()=>{
				uni.stopPullDownRefresh()
			},1000)
			this.getHotActivity()
			this.getMatchList()
			this.getTbal()
			this.getLpal()
			this.getFx()
			QQMapWX.initMap();
			req.getLocation(res => {
				const to = {
					latitude: res.latitude,
					longitude: res.longitude
				};
				QQMapWX.reverseGeocoder(to, resp => {});
				this.getRecommendCard(to)
			});
		},
		onLoad: async function(options) {
			// console.log("扫码进去参数===" + JSON.stringify(options));
			// if (options.scene) {
			//   // this.scene = options.scene || '1290926887903780865';
			//   this.scene = options.scene;
			//   await this.loadCodeParams();
			// }
			// wx.setNavigationBarColor({
			//   frontColor: '#ffffff',
			//   backgroundColor: req.public.titleTopBgColor,
			// })
			// this.getPopAd()
			this.query = options;
			// req.silenceLogin(options.userId, '');
			if (options.custom_params) {
				let obj = decodeURIComponent(opt.custom_params);
				obj = JSON.parse(obj);
				// console.log(obj)
				req.setStorage('pidCode', obj.userId);
			}
			if (options.isShare) {
				if (options.userId) {
					req.setStorage('pidCode', options.userId);
				}
			}
			setInterval(() => {
				this.setData({
					isNotice: true
				});
			}, 10000); // this.init();

			// QQMapWX.initMap();
			// req.getLocation(res => {
			// 	const to = {
			// 		latitude: res.latitude,
			// 		longitude: res.longitude
			// 	};
			// 	QQMapWX.reverseGeocoder(to, resp => {});
			// });
		},

		async onShow() {
			await req.silenceLogin(this.query.userId, '');
			let _ts = this;
			
			setTimeout(()=>{
				this.userInfo = req.getStorage('userInfo')
				
				console.log('onShow',req.getStorage('userInfo'))
				if (this.firstLoad==true) {
					req.saveBehaviorNew('',15,4)
				}
				this.getUpdate()
				this.firstLoad = false
			},500)
			
			
			await this.getConfig().then(res => {});
			await this.getHomeTemplateConfig();
			uni.setNavigationBarColor({
				frontColor: this.skinNotColor ? '#000' : '#ffffff',
				backgroundColor: req.public.titleTopBgColor
			});
			_ts.setData({
				isUpdate: !_ts.isUpdate
			});

			this.getHotActivity()
			this.getMatchList()
			this.getTbal()
			this.getLpal()
			this.getFx()
			QQMapWX.initMap();
			req.getLocation(res => {
				const to = {
					latitude: res.latitude,
					longitude: res.longitude
				};
				QQMapWX.reverseGeocoder(to, resp => {});
				this.getRecommendCard(to)
			});
			// console.log('this.freshen=='+this.freshen)
			let first = req.getStorage('first');
			if (first !== false)
				_ts.setData({
					first: true
				});
			else
				_ts.setData({
					first: false
				});
		},

		onUnload() {
			// this.isShowTime = false;
			this.clearAllTimer(1);
			this.clearAllTimer(2);
			this.clearAllTimer(3);
			this.clearAllTimer(4);
		},

		onHide() {
			// this.isShowTime = false;
			this.clearAllTimer(1);
			this.clearAllTimer(2);
			this.clearAllTimer(3);
			this.clearAllTimer(4);
		},
		onShareAppMessage: function() {

		},
		onShareTimeline() {

		},

		onReachBottom() {},

		methods: {

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

			},


			jumpUrl(url) {
				if (req.isLogins(false)) {
					uni.navigateTo({
						url: url
					})
				}
			},
			// 获取推荐销售
			getRecommendCard(loction) {
				let params = loction
				if(req.getStorage("shareId")){
					params.shareSaleNo = req.getStorage("shareId")
				}
				req.getRequest('/api/visiting/card/recommendCardInfo', params, res => {
					this.recommendCard = res
					console.log('获取推荐销售》》》》》', res);
					setTimeout(() => {
						this.chatShow = false
						setTimeout(() => {
							this.chatShowText = false
						}, 450)
					}, 2000)
					// 判断销售员是否离职
					this.getEmploymentState()
				})
			},
			getEmploymentState(){
				req.getRequest('/api/visiting/card/saleIsDepart',{},res=>{
					let userInfo = req.getStorage('userInfo')
					req.getRequest('/api/user/info', {}, suc => {
						userInfo.manageSaleNo = suc.manageSaleNo
						req.setStorage('userInfo',userInfo)
						this.userInfo.manageSaleNo = suc.manageSaleNo
					});
				})
			},
			// 获取热门活动
			getHotActivity() {
				req.getRequest('/api/banner', {
					code: 'index_hot_activity'
				}, res => {
					this.hotActivityList = res?res:[]
				})
			},
			// 获取更多活动
			getMatchList() {
				req.getRequest('/api/match/list', {
					page: 1,
					limit: 10,
					shareSaleNo:req.getStorage("shareId")?req.getStorage("shareId"):null
				}, res => {
					this.matchList = res
				})
			},
			// 获取投保案例
			async getTbal() {
				this.tbalName =await this.getContentName(req.public.tbalCode)
				this.tbalList = await this.getContentList(req.public.tbalCode)
				if(this.tbalList.length>0)
					this.tbalContentList = await this.getContentPageList(this.tbalList[this.tbalIndex]
						.code)
				this.$forceUpdate()
			},
			// 获取理赔案例
			async getLpal() {
				this.lpalName =await this.getContentName(req.public.lpalCode)
				if(this.lpalList.length==0){
					this.lpalList = await this.getContentList(req.public.lpalCode)
				}else{
					// 防止页面onShow时内容闪动
					let lpal = await this.getContentList(req.public.lpalCode)
					for(let i=0;i<lpal.length;i++){
						let item = lpal[i]
						for(let j=0;j<this.lpalList.length;j++){
							let it = this.lpalList[i]
							if(it.id==item.id){
								item.contentList = it.contentList?it.contentList:[]
							}
						}
						
					}
				}
				this.lpalList.map(async item => {
					item.contentList = await this.getContentPageList(item.code)
					this.$forceUpdate()
				})
			},
			// 获取发现
			async getFx() {
				this.fxList = await this.getContentList('faxian')
				this.getFxContenteList(this.fxList[this.fxIndex].code)
			},
			
			// 获取文章栏目名称
			getContentName(code) {
				return new Promise((r, j) => {
					req.getRequest('/api/content/category/detailByCode', {
						code: code
					}, res => {
						r(res ? res.name : '')
					})
				})
			},

			// 获取文章栏目列表
			getContentList(code) {
				return new Promise((r, j) => {
					req.getRequest('/api/content/category/list', {
						parentCode: code
					}, res => {
						r(res ? res : [])
					})
				})
			},

			// 获取文章列表
			getContentPageList(code) {
				return new Promise((r, j) => {
					req.getRequest('/api/content/list', {
						code: code,
						page: 1,
						limit: 2,
						shareSaleNo : req.getStorage("shareId")?req.getStorage("shareId"):null
					}, res => {
						r(res ? res : [])
					})
				})
			},

			// 获取发现文章列表
			getFxContenteList(code) {
				return new Promise((r, j) => {
					req.getRequest('/api/content/list', {
						code: code,
						page: 1,
						limit: 10,
						shareSaleNo : req.getStorage("shareId")?req.getStorage("shareId"):null
					}, res => {
						this.fxContentList = res ? res : []
						r(res ? res : [])
					})
				})
			},
			// 投保案例tab切换
			async changeTbalTab(index) {
				if (this.tbalIndex == index) return false;
				this.tbalIndex = index
				this.tbalContentList = await this.getContentPageList(this.tbalList[this.tbalIndex]
					.code)
				this.$forceUpdate()
			},
			// 发现tab切换
			changeFxTab(index) {
				if (this.fxIndex == index) return false;
				this.fxIndex = index
				this.getFxContenteList(this.fxList[this.fxIndex].code)
				
				
				if(this.fxList[this.fxIndex].addToday>0){
					let s = req.getStorage('readFindCode')
					let readObj = {
						date:utils.formatTime(new Date()).t2,
						readCode:(s &&　s.date == utils.formatTime(new Date()).t2)?s.readCode:{}
					}
					if(readObj.readCode[this.fxList[this.fxIndex].code]){
						
					}else{
						readObj.readCode[this.fxList[this.fxIndex].code] = true
					}
					req.setStorage('readFindCode',readObj)
				}
				this.isUpdate = !this.isUpdate
			},
			getReadFindCode(){
				let s = req.getStorage('readFindCode')
				if(s &&　s.date == utils.formatTime(new Date()).t2){
					return req.getStorage('readFindCode').readCode
				}else{
					return {}
				}
			},

			async getRqeDatas() {
				console.log('getRqeDatas');
				let that = this; //多门店

				// 金刚区
				let district = that.homeTemplate.filter(it => it.module == that.templateType
					.module_king_kong_district);
				if (district && district.length > 0 && district[0].state == 0) {
					let data = district[0];
					data.content = JSON.parse(district[0].content);
					that.districtTemplate = data;
					if (data.contentId == 2) {
						that.districtShow = true;
					}
					console.log(that.districtTemplate, '=============');
				}
				//顶部banner
				let ad = that.homeTemplate.filter(it => it.module == that.templateType.module_ad);
				if (ad && ad.length > 0 && ad[0].state == 0) {
					if (that.freshen) {
						await that.getBannerList(ad[0].module, ad[0].contentId);
					}
				}
				that.logo = true;
			},


			//获取首页模板配置
			getHomeTemplateConfig() {
				let _ts = this;
				let page = 'index';
				//荣康模板配置、小店产品==门店产品
				// if (this.merchant && this.merchant.type == 5 || this.shopId && this.merchantId) page = 'shopIndex'
				req.getRequest(
					'/api/template/getTemplate', {
						page: page
					},
					data => {
						let arr = [];
						data.forEach(it => {
							arr.push(it.module);
						});
						this.setData({
							contact: [...new Set(arr)],
							contactShow: false
						});
						if (this.contact.indexOf('sou') != -1 && this.contact.indexOf('store_options') != -1) {
							this.top = false;
						} else {
							this.top = true;
						}
						if (this.contact.indexOf('sou') != -1 && this.contact.indexOf('type_district') != -1) {
							this.top_type = false;
						} else {
							this.top_type = true;
						}

						console.log(this.contact.indexOf('sou') != -1, this.contact.indexOf('store_options') != -1,
							this.contact.indexOf('type_district') != -1, this.top);
						console.log(this.contact);
						this.setData({
							homeTemplate: data
						});

						this.getRqeDatas();
					}
				);
			},
			getConfig() {
				var _this = this;
				return new Promise((res, rej) => {
					req.g(
						'/api/other/config',
						data => {
							req.setStorage('configRes', JSON.stringify(data));
							this.about = data;
							if (!data.Index_Store_Confirm || data.Index_Store_Confirm == 0) {
								_this.setData({
									switchStoreShow: false,
									storeShow: false
								});
							} else {
								_this.setData({
									switchStoreShow: true
								});
							}
							// console.log(data.Index_Store_Confirm, "====", !data.Index_Store_Confirm, typeof(res
							// .Index_Store_Confirm))
							uni.setNavigationBarTitle({
								// title: res['CONFIG_PROJECT_TITLE'],
								title: data['CONFIG_PROJECT_TITLE']
							});
							// console.log(data.Is_Store_Price_Stock);

							if (data.Is_Store_Price_Stock) {
								this.Is_Store_Price_Stock = data.Is_Store_Price_Stock;
							}

							this.setData({
								Is_Store_Price_Stock: data.Is_Store_Price_Stock
							});

							if (data.b2c_service_guarantee && data.b2c_service_guarantee != null) {
								this.setData({
									guarantee: data.b2c_service_guarantee.split(';').filter(it => {
										return (it = it && it.trim());
									})
								});
							}

							req.setStorage('appName', data['CONFIG_PROJECT_TITLE']);
							req.setStorage('productDiy', data['Product_Foot-Diy']);
							res(data);
						},
						true
					);
				});
			},

			merchantFun() {
				app.globalData.openPage('pages/nearby/nearby');
			},

			saoma() {
				var _this = this; // 允许从相机和相册扫码

				uni.scanCode({
					success: res => {
						uni.navigateTo({
							url: '/' + res.path
						}); // this.scene = '1290926887903780865';

						this.loadCodeParams();
					}
				});
			},

			update(content) {
				var that = this;
				var animation = uni.createAnimation(); // 旧消息向上平移

				animation.translateY(-50).step({
					duration: 1000,
					timingFunction: 'ease-in'
				}); // 为了实现下一条新内容向上平移的效果，必须把内容很快平移到下方，并且不能被用户看见，这里其原理类似轮播图的思路。
				// 实现方法：动画时间设置为1ms，过渡效果设置为’动画第一帧就跳至结束状态直到结束‘

				animation
					.opacity(0)
					.translateY(50)
					.step({
						duration: 1000,
						timingFunction: 'step-start'
					}); // 新消息向上平移的同时恢复透明

				animation
					.opacity(1)
					.translateY(0)
					.step({
						duration: 1000,
						timingFunction: 'ease-out'
					});
				that.setData({
					animationData: animation.export()
				}); // 更新内容的延时必须大于第一步动画时间

				setTimeout(() => {
					that.setData({
						content: content
					});
				}, 500000);
			},

			loadCodeParams() {
				let _ts = this;

				return new Promise((resolve, reject) => {
					if (!_ts.scene) {
						resolve();
						return false;
					}

					req.getRequest(
						'/api/code/params', {
							scene: _ts.scene
						},
						data => {
							req.setStorage('pidCode', data.userId);
							resolve();
						}
					);
				});
			},

			getBannerList(module, contentId) {
				//banner图
				let that = this;
				return new Promise((resolve, reject) => {
					req.getRequest(
						'/api/banner', {
							groupId: contentId
						},
						data => {
							if (module == that.templateType.module_ad) {
								that.setData({
									bannerList: data,
									bannerShow: true
								});
							} else {
								that.setData({
									popAdList: data[0]
								});
							}
							resolve();
						}
					);
				})
			},


			clearAllTimer(type) {
				// console.log(this.activityGroup, this.joingroupList, this.bargainList, this.customersList);

				if (type == 1) {
					this.activityGroup.products.forEach(it => clearInterval(it.timer));
					this.activityGroup.products.forEach(it => clearInterval(it.times));
				} else if (type == 2) {
					this.joingroupList.products.forEach(it => clearInterval(it.timer));
					this.joingroupList.products.forEach(it => clearInterval(it.times));
				} else if (type == 3) {
					this.bargainList.products.forEach(it => clearInterval(it.timer));
					this.bargainList.products.forEach(it => clearInterval(it.times));
				} else if (type == 4) {
					this.customersList.products.forEach(it => clearInterval(it.timer));
					this.customersList.products.forEach(it => clearInterval(it.times));
				} else if (type == 5) {
					this.seckillList.products.forEach(it => clearInterval(it.timer));
					this.seckillList.products.forEach(it => clearInterval(it.times));
				}
			},

			hideGuide() {
				//关闭提示加入我的小程序
				this.setData({
					first: false
				});
				req.setStorage('first', false);
			},

			hideAd() {
				//关闭广告
				// if(this.data.first==false){
				this.setData({
					isLayerAd: false
				}); // }
				app.globalData.isLayerAd = false;
			},
			click(e) {
				// console.log(e)
				this.storeShow = e;
			},

			goUrl(event) {
				//跳转链接
				let url = event.currentTarget.dataset.url;
				app.globalData.openPage(url);
			},
			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('复制成功')
					}
				})
			},
			unitFormat(data) {
				return req.unitConverter(data).text
			},
			formatTime(date) {
				date = new Date(date.replace(/-/g, '/'))
				return utils.formatTime(date).t3
			},
			monthDayDiff(date) {
				return utils.monthDayDiff(date)
			},
			// 热门活动
			async getUrlHot(item) {
				console.log(item)
				var dt = item
				var url = "";
				var id = "";
				var acid = "";
			
				if (dt.content != "") {
					let conunt = dt.content.split("_");
					id = conunt[1];
					acid = conunt[0];
				}
			
				if (dt.type * 1 == 2 && dt.content != "") {
					url = "product/detail/detail?id=" + dt.content;
				} else if (dt.type * 1 == 3) {
					url = dt.content;
					console.log('url===',url)
					if(!url){
						req.msg('功能待接入')
						return false
					}
					if(url=='pages/index/index'||url=='pages/matchList/index'||url=='pages/interactive/index'||url=='pages/found/found'||url=='pages/user/user'){
						app.globalData.switchTab(url)
						return false
					}else{
						if(url.indexOf('http')!=-1){
							if(url.indexOf('${salesno}')!=-1){
								// 如果打开的分享的销售员微页
								if(req.getStorage('shareId')){
									url = url.replace(/\${salesno}/g,'salesno='+req.getStorage('shareId'))
								}else{
									// 如果自己是销售员
									if(req.getStorage('userInfo').saleNo){
										url = url.replace(/\${salesno}/g,'salesno='+req.getStorage('userInfo').saleNo)
									}else{
										//当前绑定的微页或推荐的微页
										let salesno = await new Promise((r,j)=>{
											req.getLocation(res => {
												const to = {
													latitude: res.latitude,
													longitude: res.longitude
												};
												req.getRequest('/api/visiting/card/recommendCardInfo', to, res => {
													r(res.jobNumber?res.jobNumber:'')
												})
											});
										})
										url = url.replace(/\${salesno}/g,'salesno='+salesno)
									}
								}
							}
							app.globalData.openPage('pages/web/web?url='+encodeURIComponent(url));
							return false
						}
					}
				} else if (dt.type * 1 == 4) {
					url = "product/groupDetail/groupDetail?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 5) {
					url = "product/coupon/coupon";
				} else if (dt.type * 1 == 6) {
					url = "pages/live/live";
				} else if (dt.type * 1 == 7) {
					url = "product/groupList/groupList" + dt.merchant;
				} else if (dt.type * 1 == 9 && dt.content != "") {
					url = "product/list/list?id=" + dt.content + '&title=' + dt.title + this.web;
				} else if (dt.type * 1 == 10) {
					url = "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + dt.content;
					// console.log(
					// url); // url=`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${dt.content}`
				} else if (dt.type * 1 == 11) {
					url = "activity/group/index/index" + dt.merchant;
				} else if (dt.type * 1 == 12) {
					url = "activity/seckill/seckill" + dt.merchant;
				} else if (dt.type * 1 == 13) {
					url = "activity/bargain/index/index" + dt.merchant;
				} else if (dt.type * 1 == 14) {
					url = "activity/newbornZone/newbornZone" + dt.merchant;
				} else if (dt.type * 1 == 15 && dt.content != "") {
					url = "activity/newbornDetails/newbornDetails?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 16 && dt.content != "") {
					url = "activity/seckillDetails/seckillDetails?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 17 && dt.content != "") {
					url = "activity/bargain/detail/detail?acid=" + acid + "&id=" + id;
				} else if (dt.type * 1 == 18 && dt.content != "") {
					url = "activity/group/detail/detail?acid=" + acid + "&id=" + id;
				}else if (dt.type * 1 == 19 && dt.content != "") {
					url = "topic/content/content?id=" + dt.content;
				}else if (dt.type * 1 == 27 && dt.content != "") {
					url = "match/activityDetail/activityDetail?id=" + dt.content;
				}else if (dt.type * 1 == 1 && dt.content != "") {
					console.log('dt.content',dt.content)
					uni.navigateToMiniProgram({
						appId: dt.content, // 目标小程序appid
						path: '', // 目标路径，例如‘pages/billManage/index’
						extraData: {}, // 跳转传参，例如'orderNo': 'xxx......'
						success(res) {
							uni.showToast({
								title: '跳转成功'
							})
						}
					})
				}  else {
					url = "";
				}
			
				if (dt.type * 1 == 6) app.globalData.switchTab(url);
				else app.globalData.openPage(url);
				this.hideAd();
			},
			
			closeUpdate(){
				this.isShowUpdate = false
			},
			updateInfo(e){
				this.isUpdateInfo = e;
			},
			updateMobile(e){
				this.isUpdateMobile = e;
			},
			getUpdate() {
				console.log('getUpdate')
				let userInfos = req.getStorage('userInfo')
				// if ((!userInfos.avatar || userInfos.avatar.indexOf('thirdwx.qlogo') > -1 || !userInfos.nickName || userInfos.nickName.indexOf('用户') > -1) ) {
				// 	console.log('没有昵称')
				// 	this.isShowUpdate = true;
				// 	this.isUpdateInfo = true;
				// 	return false;
				// }
				if(!userInfos.mobile){
					console.log('没有手机号')
					this.isShowUpdate = true
					this.isUpdateMobile = true
					return false;
				}
				return true;
			},
		},
		mounted() {
			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 './index.css';
</style>