<template>
	<view id="topId">
		<view :style="'min-height:' + systems.windowHeight +'rpx;'">
		<block v-if="jsonContent && jsonContent.length > 0" v-for="(item, index) in jsonContent" :key="index">
			<view class="ban" v-if="item.key == 'banner'">
				<swiper class="swiper" @change="swiperChange" autoplay="true" interval="5000" duration="300">
					<block v-for="(it, idx) in item.value.imageList" :key="idx">
						<swiper-item>
							<image lazy-load="true" :src="it.src" mode="aspectFill" @click="clickBanner(item)"></image>
						</swiper-item>
					</block>
				</swiper>
				<view class="dots ddflex">
					<block v-for="(it, idx) in item.value.imageList" :key="idx">
						<view :class="['dot', idx == swiperCurrent ? 'active' : '']"></view>
					</block>
				</view>
			</view>
			<view class="form" v-if="item.key == 'applicationForm'">
				<view class="form-title" v-if="item.value.title.isShow">{{ item.value.title.value }}</view>
				<view class="form-list" id="form">
					<view class="li ddflex" v-for="(it, idx) in item.value.formItemList" :key="idx">
						<!-- <view class="label">{{it.label}}</view> -->
						<block v-if="it.type == 1">
							<input v-if="it.dataType == 1" v-model="it.fieldValue" :placeholder="'请填写' + it.label"
								placeholder-class="placeholder" maxlength="11" class="ipt fflex" />
							<input v-else v-model="it.fieldValue" :placeholder="'请填写' + it.label"
								placeholder-class="placeholder" class="ipt fflex" />
						</block>
						<textarea v-model="it.fieldValue" :placeholder="'请填写' + it.label"
							placeholder-class="placeholder" class="textarea fflex" v-else-if="it.type == 4"></textarea>
						<picker :range="it.option" class="pickers fflex" @change="changeOptions($event, idx)"
							v-else-if="it.type == 5">
							<view v-if="it.fieldValue">{{ it.fieldValue }}</view>
							<view class="placeholder" v-else>请选择{{ it.label }}</view>
						</picker>
					</view>
				</view>
				<view class="form-btn view-box" @click="formSubmit(item.value)">{{ item.value.buttonName }}</view>
			</view>
			<view class="richText" v-if="item.key == 'text'"><rich-text :nodes="item.value.content"></rich-text></view>
			<block v-if="item.key == 'product'">
				<view class="product" v-if="item.value.layoutNum == 1">
					<view class="li ddflex" v-for="(it, idx) in item.value.productList" :key="idx"
						@click="jumpUrlProduct('/product/detail/detail?id=' + it.id)" v-if="!it.isFixedNode">
						<image :src="it.pic" mode="aspectFill" class="pro-img"></image>
						<view class="pro-info fflex">
							<view class="pro-name tovers">{{ it.title }}</view>
							<view class="pro-bri tover" v-if="it.brief">{{ it.brief }}</view>
							<view class="pro-opt ddflex">
								<view class="money">
									￥{{ it.minSalePrice }}
									<!-- <text>/起</text> -->
								</view>
								<view class="pro-btn">立即购买</view>
							</view>
						</view>
					</view>
				</view>
				<view class="product2 ddflex" v-if="item.value.layoutNum == 2">
					<view class="li" v-for="(it, idx) in item.value.productList" :key="idx"
						@click="jumpUrlProduct('/product/detail/detail?id=' + it.id)" v-if="!it.isFixedNode">
						<image :src="it.pic" mode="aspectFill" class="pro-img"></image>
						<view class="pro-info fflex">
							<view class="pro-name tovers">{{ it.title }}</view>
							<view class="pro-opt ddflex">
								<view class="money">
									￥{{ it.minSalePrice }}
									<!-- <text>/起</text> -->
								</view>
								<view class="pro-cart">
									<image src="../../static/pages/images/jia.png"></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="product product3" v-if="item.value.layoutNum == 3">
					<scroll-view scroll-x="true">
						<view class="li" v-for="(it, idx) in item.value.productList" :key="idx"
							@click="jumpUrlProduct('/product/detail/detail?id=' + it.id)" v-if="!it.isFixedNode">
							<view class="ddflex">
								<image :src="it.pic" mode="aspectFill" class="pro-img"></image>
								<view class="pro-info fflex">
									<view class="pro-name tovers">{{ it.title }}</view>
									<view class="pro-bri tover" v-if="it.brief">{{ it.brief }}</view>
									<view class="pro-opt ddflex">
										<view class="money">
											￥{{ it.minSalePrice }}
											<!-- <text>/起</text> -->
										</view>
										<view class="pro-btn">立即购买</view>
									</view>
								</view>
							</view>
						</view>
					</scroll-view>
				</view>
			</block>
			<view class="images" v-if="item.key == 'images'">
				<image :src="item.value.src" mode="widthFix"></image>
			</view>
			<block v-if="item.key == 'customerService'"></block>
			<!-- 企微客服 -->
			<view class="contact ddflex" @click="customerServiceChat(item.value)" v-if="item.value.type == '1'">
				<image src="../../static/pages/images/kfico.png"></image>
				客服
			</view>
			<!-- 第三方客服 -->
			<view class="contact ddflex" @click="jumpHref(item.value)" v-if="item.value.type == '2'">
				<image src="../../static/pages/images/kfico.png"></image>
				客服
			</view>
			<!-- 微信客服、内置客服页面 -->
			<view @click="jumpUrlCS()" class="contact ddflex" v-if="item.value.type == '0' || item.value.type == '3'">
				<image src="../../static/pages/images/kfico.png"></image>
				客服
			</view>

			<view class="coupon" v-if="item.key == 'coupon'">
				<!-- <view class="tag">免费领取</view> -->
				<view class="form-title">
					<view>
						<text>{{ item.value.couponTitle }}</text>
					</view>
				</view>
				<view class="coupon-list">
					<view class="li" v-for="(it, indexx) in item.value.couponList" :key="indexx" v-if="!it.isFixedNode">
						<view class="info ddflex">
							<view class="left-pic">
								<image :src="it.couponIcon" mode="aspectFill" v-if="it.couponIcon"></image>
							</view>
							<view class="fflex">
								<view class="title">{{ it.couponTitle }}</view>
								<view class="time">{{ getDateFormat(it.couponStart) }}-{{ getDateFormat(it.couponEnd) }}
								</view>
							</view>
							<view class="info-r">
								<view class="money">
									<text>￥</text>
									{{ it.couponAmount }}
								</view>
								<view class="man">{{ it.couponBrief }}</view>
							</view>
						</view>
						<view class="li-bot ddflex">
							<view class="check ddflex fflex" @click.stop="checks(it)">
								查看详情
								<image v-if="!it.isShow" src="../../static/pages/images/bico.png"></image>
								<image v-else src="../../static/pages/images/bico.png" class="bico_h"></image>
							</view>
							<!-- <image src="../../static/images/ma_dark.png" class="yong-ma"></image> -->
							<block v-if="it.userCount >= it.userReceive && it.userCount != 0 && it.userReceive != -1">
								<view class="yong ddflex" @click="jumpUrl('/mine/coupons/coupons')">去使用</view>
							</block>
							<block v-else>
								<view @click="getCoupon(it)" class="yong ddflex"
									v-if="item.value.btnBackground.length == 2"
									:style="'background: linear-gradient(90deg, ' + item.value.btnBackground[0] + ' 0%, ' + item.value.btnBackground[1] + ' 100%);'">
									{{ item.value.buttonName }}
								</view>
								<view @click="getCoupon(it)" class="yong ddflex"
									v-else-if="item.value.btnBackground.length == 1"
									:style="'background: ' + item.value.btnBackground[0] + ';'">
									{{ item.value.buttonName }}
								</view>
								<view class="yong ddflex" v-else @click="getCoupon(it)">{{ item.value.buttonName }}
								</view>
							</block>
						</view>
						<view class="infos" v-if="it.isShow">
							<view>使用范围：{{ it.couponBrief }}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="coupon coupon-recharge" id="recharge" v-if="item.key == 'recharge'">
				<view class="tag">快捷充值</view>
				<view class="form-title">
					<view>
						<text>{{ item.value.rechargeTitle }}</text>
					</view>
				</view>
				<view class="recharge">
					<view :class="'dflex rechargeId' + (isInt ? ' on' : '')">
						<text v-if="item.value.showSymbol">￥</text>
						<input :placeholder="item.value.placeholderText ? item.value.placeholderText : '点击输入充值金额'"
							placeholder-class="placeholder" v-model="pay" type="digit" @input="amount" @focus="focus"
							@blur="onBlur" />
					</view>
					<view class="rechargeMoney" v-if="TabList && TabList.length > 0">快捷充值</view>
					<view class="rechargeul dflex" v-if="TabList && TabList.length > 0">
						<!--选中 加class active -->
						<view :class="'rechargeli ' + (it.active ? 'active' : '')" v-for="(it, index) in TabList"
							:key="index" @tap="switchTab(it, index)">
							<view :class="'wealth ' + (item.active ? 'awealth' : '')">充{{ it.rechargeAmount }}元</view>
							<!-- <view class="give awealth">
								送40元
							</view> -->
						</view>
					</view>
				</view>
				<view class="chongzhi view-box" @click="remainder()"
					:style="item.value.mainColor ? 'background-color: ' + item.value.mainColor + ';border: 1px solid ' + item.value.mainColor + ';' : ''">
					{{ item.value.buttonName }}
				</view>
			</view>
			<block v-if="item.key == 'fixedNode'">
				<block v-if="item.value.type == 'applicationForm' || item.value.type == 'recharge'">
					<block v-if="isShowBotFixed">
						<view style="height: 140rpx;"></view>
						<view class="bot-fixed">
							<view :class="'btn'+(item.value.type == 'recharge' ? ' btn-red':'')" @click="anchor(item.value.type == 'applicationForm' ? 'form':'recharge')">{{item.value.contentObj.value.buttonName}}</view>
						</view>
					</block>
				</block>
				<block v-if="item.value.type == 'product'">
					<view style="height: 160rpx;"></view>
					<block v-for="(it, idx) in item.value.contentObj.value.productList" :key="idx">
						<view class="product-fixed ddflex" v-if="it.isFixedNode" @click="jumpUrlProduct('/product/detail/detail?id=' + it.id)">
							<image :src="it.pic" mode="aspectFill"></image>
							<view class="fflex">
								<view class="product-tit tover">{{it.title}}</view>
								<view class="product-opt ddflex">
									<view class="product-price">￥{{ it.minSalePrice }}
									<!-- <text>/起</text> -->
									</view>
									<view class="product-btn">立即购买</view>
								</view>
							</view>
						</view>
					</block>
				</block>
				<block v-if="item.value.type == 'coupon'">
					<view style="height: 140rpx;"></view>
					<block v-for="(it, idx) in item.value.contentObj.value.couponList" :key="idx">
						<view class="coupon-fixed ddflex" v-if="it.isFixedNode">
							<image :src="it.couponIcon" mode="aspectFill" v-if="it.couponIcon"></image>
							<view class="fflex">
								<view class="title tover">{{it.couponTitle}}</view>
								<view class="money">
									<text>￥</text>
									{{ it.couponAmount }}
								</view>
							</view>
							<block v-if="it.userCount >= it.userReceive && it.userCount != 0 && it.userReceive != -1">
								<view class="yong ddflex" @click="jumpUrl('/mine/coupons/coupons')">去使用</view>
							</block>
							<block v-else>
								<view @click="getCoupon(it)" class="yong ddflex"
									v-if="item.value.contentObj.value.btnBackground.length == 2"
									:style="'background: linear-gradient(90deg, ' + item.value.contentObj.value.btnBackground[0] + ' 0%, ' + item.value.contentObj.value.btnBackground[1] + ' 100%);'">
									{{ item.value.contentObj.value.buttonName }}
								</view>
								<view @click="getCoupon(it)" class="yong ddflex"
									v-else-if="item.value.contentObj.value.btnBackground.length == 1"
									:style="'background: ' + item.value.contentObj.value.btnBackground[0] + ';'">
									{{ item.value.contentObj.value.buttonName }}
								</view>
								<view class="yong ddflex" v-else @click="getCoupon(it)">{{ item.value.contentObj.value.buttonName }}
								</view>
							</block>
						</view>
					</block>
				</block>
			</block>
		</block>

		<!-- 注册成为会员 -->
		<!-- <view class="mask" v-if="isShowBindMobileView" @tap="hintBindMobileView()"></view>
		<view class="regi" v-if="isShowBindMobileView">
			<view class="regi-tit">{{ isCoupon ? '绑定手机号领取' : '绑定手机号' }}</view>
			<view class="phone dflex">
				<input v-model="phoneNumberValue" maxlength="11" type="number" placeholder="输入当前使用的手机号" placeholder-class="placeholder" class="flex" />
			</view>
			<view class="ddflex" style="justify-content: space-between;">
				<view class="regi-btn regi-btn1" @click="hintBindMobileView()">取消</view>
				<view class="regi-btn" @click="confirmBundMoble()">{{ isCoupon ? '确定领取' : '确定' }}</view>
			</view>
		</view> -->
		<view class="mask" v-if="isShowMask"></view>
		<!-- <view class="guide" :style="'top:'+37+'rpx;'">
			<view class="guide-tit">点这里更多操作</view>
			<view class="guide-tip">领取优惠不迷路</view>
			<view class="guide-s ddflex"><image src="../../static/images/cz_jia.png"></image>添加到桌面</view>
			<view class="guide-s ddflex"><image src="../../static/images/cz_home.png"></image>返回首页</view>
			<view class="guide-btn">我知道了</view>
		</view> -->

		<view class="popup" v-if="isShowBMDialogView">
			<image src="../../static/images/popup_tip.png" class="popup-img"></image>
			<view class="popup-tip">提交成功</view>
			<view class="popup-tips">你的信息已提交，会有专业人员联系你，请耐心等待</view>
			<view class="popup-btns ddflex">
				<!-- <view class="back-home ddflex" @click="goHome()">去首页</view> -->
				<!-- <view class="check-btn ddflex" @click="hintDialogView()">关闭</view> -->
			</view>
			<image src="../../static/images/popup_close.png" class="popup-close" @click="hintDialogView()"></image>
		</view>

		<view class="popup" v-if="isShowRemainderDialogView">
			<image src="../../static/images/popup_tip.png" class="popup-img"></image>
			<view class="popup-tip">充值成功</view>
			<view class="popup-tips">充值已成功，可前往“我的钱包”查看余额</view>
			<view class="popup-btns ddflex">
				<!-- <view class="back-home ddflex" @click="goHome()">去首页</view> -->
				<!-- <view class="check-btn ddflex" @click="jumpUrl('/wallet/index/index')">查看余额</view> -->
				 <!-- <view class="check-btn ddflex" @click="hintDialogView()">关闭</view> -->
			</view>
			<image src="../../static/images/popup_close.png" class="popup-close" @click="hintDialogView()"></image>
		</view>

		<view class="popup" v-if="isShowCouponDialogView">
			<image src="../../static/images/popup_tip.png" class="popup-img"></image>
			<view class="popup-tip">领取成功</view>
			<view class="popup-tips">已存入“我的优惠券”中，可前往查看使用</view>
			<view class="popup-btns ddflex">
				<!-- <view class="back-home ddflex" @click="jumpUrl('/mine/coupons/coupons')">我的优惠券</view>
				<view class="check-btn ddflex" @click="createCode()">立即使用</view> -->
				<!-- <view class="check-btn ddflex" @click="hintDialogView()">关闭</view> -->
			</view>
			<image src="../../static/images/popup_close.png" class="popup-close" @click="hintDialogView()"></image>
		</view>

		<view class="popup" v-if="isShowBindMobileView">
			<view class="popup-tip">验证手机号</view>
			<view class="popup-tips">该手机号仅用于线下核销验证请放心填写</view>
			<input v-model="phoneNumberValue" maxlength="11" type="number" placeholder="请输入手机号"
				placeholder-class="placeholder" class="popup-ipt" @input="phoneNumberInput" />
			<view class="yzm-box ddflex" v-if="isPhoneNumber">
				<input v-model="verifyCode" type="number" maxlength="6" placeholder="请输入短信验证码"
					placeholder-class="placeholder" class="yzm-ipt fflex" />
				<view :class="'yzm '+(isGetCodeDisabled?'active':'')" @click="getCode()" v-text="sendMsg"></view>
			</view>
			<view class="popup-btns ddflex" style="margin-top: 60rpx">
				<view class="back-home ddflex" @click="hintBindMobileView()">取消</view>
				<view class="check-btn ddflex" @click="confirmBundMoble()">确定</view>
			</view>
			<image src="../../static/images/popup_close.png" class="popup-close" @click="hintDialogView()"></image>
		</view>

		<view class="ceng" v-if="isShowCard" @click="hideCardPop"></view>
		<view class="qrcode" v-if="isShowCard">
			<view class="hintt">{{ currentCard.couponTitle }}</view>
			<view class="qr-code ddflex">
				<!-- <u-qrcode ref="qrcode" canvas-id="qrcode" :value="currentCard.id" size="200"></u-qrcode> -->
				<image class="code-image" :src="currentCard.qrCodeUri"></image>
			</view>
			<view class="code ddflex">
				<text>{{ currentCard.id }}</text>
				<view class="copy" @click="copyCode()">复制</view>
			</view>
			<view class="hittext">- 请将二维码出示给店员核销使用 -</view>
			<!-- <view @click="scanCode">扫码</view> -->
			<image src="../../static/pages/images/close2.png" class="close" @click="hideCardPop"></image>
		</view>
		</view>
		
		<!-- <view class="ruzhu ddflex" v-if="ruzhuItem" @click="jumpUrlN('/pages/enter/index?code='+ruzhuItem.code)">
			<text>—— 我也要</text>
			<text class="rz-text">{{ruzhuItem.title}}</text>
			<text>——</text>
		</view> -->
		
		
		<button class="right-share dflex" :class="specClass" open-type="share">
			<image src="../../static/images/share1.png"></image>
			<view style="text-align: center;">分享</view>
		</button>
	</view>
</template>

<script>
	const app = getApp();
	const req = require('../../utils/request.js');
	const util = require('../../utils/util.js');
	const route = require('../../utils/route.js');
	// const sysrequest = require('../../utils/sysrequest.js');
	let timer = ''
	export default {
		data() {
			return {
				systems: {},
				options: {},
				params: '',
				jsonContent: '',
				swiperCurrent: 0,
				hideShare: true,
				codeUrl: '',
				sessionKey: '',
				openid: '',
				userInfo: {},
				isShow: false,

				//充值
				TabList: [],
				money: '',
				id: '',
				pay: '',
				active: false,
				isInt: false,
				orderId: '',

				checkCoupon: '', //选中的优惠券
				// isOpenHuaweiMobile: '', //判断是否在华为上使用手机号授权

				isHuawei: false,
				isShowMask: false,
				isShowBMDialogView: false,
				isShowBindMobileView: false,
				phoneNumberValue: '',
				isShowRemainderDialogView: false,
				isShowCouponDialogView: false,

				isCoupon: false, //是否为优惠券
				isRemainder: false, //是否为充值
				//使用用券
				isShowCard: false,
				currentCard: {},

				isPhoneNumber: false, //手机号是否有效
				isGetCodeDisabled: false,
				sendMsg: '获取验证码',
				verifyCode: '',

				ruzhuItem: '',
				
				isShowBotFixed: true,//是否显示悬浮按钮
				windowHeight: '',
				
				specClass: 'hide',
				flag: false,
				isShowShare: false,
				bottomPositon: '-100%',
				
				userInfo:{}
			};
		},
		async onLoad(options) {
			this.options = options;
			this.id = options.id;
			if(options.shareId) req.setStorage('shareId',options.shareId)
			await  req.silenceLogin(options.userId, '');
			setTimeout(()=>{
				this.userInfo = req.getStorage('userInfo')
			},500)
			//缓存商户appid
			// var appid = options.appid;
			// if (appid) {
			// 	req.setStorageAppId(appid);
			// }
			// if (options.scene) {
			// 	await this.loadCodeParams();
			// }
			// this.getAbout();
			// this.getSysApply();
			await this.getParams();
			
		},
		onShow() {
			this.userInfo = req.getStorage('userInfo');
			if (this.orderId) {
				let i = 0;
				uni.showLoading({
					title: '载入中...'
				});
				let timer = setInterval(() => {
					route.balanceStare({
							logsId: this.orderId
						},
						res => {
							if (res.isSuccess || i === 4) {
								uni.hideLoading();
								this.orderId = '';
								this.pay = '';
								clearInterval(timer);
								if (res.isSuccess) {
									this.showRemainderDialogView();
								}
							} else {
								i++;
							}
						}
					);
				}, 300);
			}
		},
		onShareAppMessage() {
			this.userBehavior(6)
			return {
				title: this.params.title,
				imageUrl: this.params.pic,
				path: '/library/pageDetail/index?code=' + this.params.code +'&isShare=' + true+(this.userInfo.userType==1?('&shareId='+this.userInfo.saleNo):'')
			};
		},

		methods: {
			// 用户行为
			userBehavior(type) {
				var dataP = {};
				dataP.type =
					7 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
				dataP.behavior = type; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
				dataP.bindId = this.params.id;
				req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
				});
			},
			goHome() {
				this.hintDialogView();
				uni.switchTab({
					url: '/pages/list/index'
				});
			},

			jumpUrlN(url) {
				uni.navigateTo({
					url: url
				});
			},
			// getAbout() {
			// 	var _this = this;
			// 	req.getRequest('/api/config', {}, function(res) {
			// 		_this.isOpenHuaweiMobile = res.isOpenHuaweiMobile;
			// 	});
			// },

			// getSysApply() {
			// 	console.log('》》》》》getSysApply');
			// 	sysrequest.getSysApply(it => {
			// 		this.ruzhuItem = it;
			// 	})
			// },

			phoneNumberInput(ev) {
				if (!this.phoneNumberValue) {
					this.isPhoneNumber = false;
					return;
				}
				if (!util.isMobile(this.phoneNumberValue)) {
					this.isPhoneNumber = false;
					return;
				}
				this.isPhoneNumber = true;
			},

			// encrypt(message) {
			// 	var iv = ''; //偏移量
			// 	const keyHex = CryptoJS.enc.Utf8.parse(req.publics.desKey);
			// 	const encrypted = CryptoJS.DES.encrypt(message, keyHex, {
			// 		iv: CryptoJS.enc.Utf8.parse(iv),
			// 		mode: CryptoJS.mode.ECB,
			// 		padding: CryptoJS.pad.Pkcs7
			// 	});
			// 	return encrypted.toString();
			// },

			// //des解密
			// decryptByDESModeEBC(ciphertext) {
			// 	var key = req.publics.desKey;
			// 	var keyHex = CryptoJS.enc.Utf8.parse(key);
			// 	var decrypted = CryptoJS.DES.decrypt(
			// 		{
			// 			ciphertext: CryptoJS.enc.Hex.parse(ciphertext)
			// 		},
			// 		keyHex,
			// 		{
			// 			mode: CryptoJS.mode.ECB,
			// 			padding: CryptoJS.pad.Pkcs7
			// 		}
			// 	);
			// 	console.log('解密转码前》》', decrypted.toString());
			// 	var result_value = decrypted.toString(CryptoJS.enc.Utf8);
			// 	return result_value;
			// },

			// 余额充值
			remainder() {
				this.isCoupon = false; //是否为优惠券
				this.isRemainder = true; //是否为充值
				// #ifdef H5
				if (!req.isLogins(false)) {
					this.showBindMobileView();
					return;
				}
				// #endif
				let that = this;
				let from = {};
				if (this.pay && this.pay > 0) {
					from.money = this.pay;
				} else {
					return req.msg('输入的充值金额需大于0');
				}
				route.remainder(from, data => {
					that.orderId = data;
					if (!data) {
						return req.msg('充值下单失败');
					} else {
						route.balancePay(data, '4', that.pay, res => {
							if (res) {}
						});
					}
				});
			},

			switchTab(item, index) {
				this.TabList.map(it => {
					it.active = false;
				});
				this.TabList[index].active = true;
				this.pay = item.rechargeAmount;
			},

			// 输入金额根据输入金额获取赠送多少金额
			amount(e) {
				console.log('输入框中的金额>>>>', e.detail.value);
				let money = e.detail.value;
				this.pay = money;
			},

			focus(e) {
				this.isInt = true;
				this.TabList.map(it => {
					it.active = false;
				});
			},

			onBlur() {
				this.isInt = false;
			},

			getCouponBtnText(item, name) {
				return item.userCount >= item.userReceive && item.userCount != 0 && item.userReceive != -1 ? '已领取' :
					'name';
			},

			showBindMobileView() {
				this.isShowMask = true;
				this.isShowBindMobileView = true;
			},

			hintBindMobileView() {
				this.isShowMask = false;
				this.isShowBindMobileView = false;
			},

			showRemainderDialogView() {
				this.isShowMask = true;
				this.isShowRemainderDialogView = true;
			},

			hintRemainderDialogView() {
				this.isShowMask = false;
				this.isShowRemainderDialogView = false;
			},

			showCouponDialogView() {
				this.isShowMask = true;
				this.isShowCouponDialogView = true;
			},

			hintCouponDialogView() {
				this.isShowMask = false;
				this.isShowCouponDialogView = false;
			},

			showBMDialogView() {
				this.isShowMask = true;
				this.isShowBMDialogView = true;
			},

			hintBMDialogView() {
				this.isShowMask = false;
				this.isShowBMDialogView = false;
			},

			hintDialogView() {
				this.hintRemainderDialogView();
				this.hintBindMobileView();
				this.hintCouponDialogView();
				this.hintBMDialogView();
			},

			createCode() {
				if (this.currentCard) {
					this.isShowCard = true;
				} else {
					this.jumpUrl('/mine/coupons/coupons');
				}
				this.hintDialogView();
			},
			hideCardPop() {
				this.isShowCard = false;
			},

			copyCode() {
				uni.setClipboardData({
					data: this.currentCard.id,
					success() {
						req.msg('复制成功');
					}
				});
			},

			/**
			 * 确定设置手机号
			 */
			confirmBundMoble() {
				if (!this.phoneNumberValue) {
					req.msg('请输入手机号');
					return;
				}
				if (!util.isMobile(this.phoneNumberValue)) {
					req.msg('请输入11位有效手机号');
					return;
				}
				uni.showLoading({
					title: '加载中'
				});
				
				this.submitLogin();
				this.hintBindMobileView();
			},


			submitLogin() {
				var dataP = {};
				var apiUrl = '';
				if (!this.phoneNumberValue) {
					req.msg('请输入手机号');
					return;
				}
				if (!this.verifyCode) {
					req.msg('请输入验证码');
					return;
				}
				dataP = {
					mobile: this.phoneNumberValue,
					code: this.verifyCode
				};
				req.postRequest(
					'/api/mobileLogin',
					dataP,
					res => {
						this.userInfo = res;
						req.setStorage('AUTH_TOKEN', res.token);
						req.setStorage('userInfo', res);
						req.msg('手机号验证完成');
					},
					true
				);
			},


			/**
			 * 手机号登录
			 * @param {Object} mobile
			 */
			mobleLogin(mobile) {
				req.postRequest(
					'/api/v3/mobile/noCode/login', {
						mobile: mobile
					},
					res => {
						this.userInfo = res;
						req.setStorage('AUTH_TOKEN', res.token);
						req.setStorage('userInfo', res);
						// if (this.isCoupon) {
						// 	this.couponReceive();
						// } else {
						req.msg('手机号验证完成');
						// }
					},
					true
				);
			},

			/**
			 * 领取优惠券
			 * @param {Object} item
			 */
			getCoupon(item) {
				console.log('数据>>>>>>>>', item);
				this.isCoupon = true; //是否为优惠券
				this.isRemainder = false; //是否为充值
				this.checkCoupon = item;
				//H5单独走逻辑
				//判断是否登录
				if (!req.isLogins(false)) {
					this.showBindMobileView();
					return;
				}
				this.couponReceive();
			},

			couponReceive() {
				var that = this;
				if (this.checkCoupon.userReceive > -1 && this.checkCoupon.userCount >= this.checkCoupon.userReceive) {
					return req.msg('您已领取过了');
				}
				req.postRequest(
					'/api/coupon/receive', {
						id: this.checkCoupon.id
					},
					res => {
						this.currentCard = res;
						console.log('领取完成>>>>', this.currentCard);
						this.getParams();
						this.showCouponDialogView();
					},
					true
				);
			},

			/**
			 * 绑定手机号
			 */
			bundMoble(mobile) {
				req.postRequest(
					'/api/noCode/mobile', {
						mobile: mobile
					},
					res => {
						this.isShowBindMobileView = false;
						this.userInfo = res;
						req.setStorage('userInfo', res);
						uni.hideLoading();
						this.couponReceive();
					},
					true
				);
			},

			checks(item, index) {
				item.isShow = !item.isShow;
				this.$forceUpdate();
			},
			getParams() {
				let that = this;
				let params = {
					code: this.options.code
				};
				return new Promise((resolve, reject) => {
					req.getRequest(
						'/api/material/library/detail',
						params,
						data => {
							data.params.jsonContent.map(item => {
								if (item.key == 'applicationForm') {
									
								} else if (item.key == 'recharge') {
									//充值
									if (item.value.fastRechargeList && item.value.fastRechargeList
										.length > 0) {
										that.TabList = item.value.fastRechargeList.map(it => {
											var itm = {
												rechargeAmount: it,
												active: false
											};
											return itm;
										});
										if (that.TabList && that.TabList.length > 0) {
											that.TabList[0].active = true;
											that.pay = that.TabList[0].rechargeAmount;
										}
										console.log('TabList数据====', that.TabList);
									}
								}
								return item;
							});
							that.params = data;
							that.userBehavior(4)
							that.jsonContent = data.params.jsonContent;
							uni.setNavigationBarTitle({
								title: data.title
							});
							console.log('data.title==', data.title);
							resolve();
						},
						true
					);
				});
			},
			swiperChange(e) {
				this.swiperCurrent = e.detail.current;
			},
			jumpUrl(url) {
				this.hintDialogView();
				if (req.isLogins(true)) {
					uni.navigateTo({
						url: url
					});
				}
			},

			jumpUrlProduct(url) {
				if (!req.isLogins(false)) {
					this.showBindMobileView();
					return;
				}
				uni.navigateTo({
					url: url
				});

			},

			jumpUrlCS() {
				uni.navigateTo({
					url: '/pages/pageContent/page'
				});
			},

			customerServiceChat(item) {
				// #ifdef MP-WEIXIN
				wx.openCustomerServiceChat({
					extInfo: {
						url: item.target
					},
					corpId: item.id,
					success(res) {
						console.log('调用微信客服');
					},
					complete(res) {
						console.log('调用企微客服完成');
					}
				});
				// #endif
				// #ifdef APP-PLUS
				plus.runtime.openURL(item.target, function(res) {});
				// #endif
			},
			jumpHref(item) {
				window.location.href = item.target;
			},

			click(e) {
				this.hideShare = e;
			},

			getCode() {
				if (this.isGetCodeDisabled == true) return false;
				if (!this.phoneNumberValue) {
					req.msg('请输入手机号');
					return;
				}
				if (!util.isMobile(this.phoneNumberValue)) {
					req.msg('请输入11位有效手机号');
					return;
				}
				req.postRequest(
					'/api/sms/login', {
						mobile: this.phoneNumberValue
					},
					data => {
						req.msg('验证码获取成功');
						let time = 60;
						let interval = setInterval(() => {
							time--;
							if (time == 0) {
								this.isGetCodeDisabled = false;
								this.sendMsg = '获取验证码';
								clearInterval(interval);
							} else {
								this.isGetCodeDisabled = true;
								this.sendMsg = time + '秒再获取';
							}
						}, 1000);
					},
					true
				);
			},

			loadCodeParams() {
				let _ts = this;
				return new Promise((resolve, reject) => {
					let form = {
						scene: _ts.options.scene
					};
					if (!_ts.options.scene) {
						resolve();
						return false;
					}
					req.getRequest('/api/code/params', form, data => {
						let res = data.scene.split('_');
						this.options.code = res[0];
						req.setStorage('pidCode', data.userId);
						req.silenceLogin(data.userId, '');
						resolve();
					});
				});
			},

			isInclude(label, keytxt) {
				return label.indexOf(keytxt) != -1;
			},

			getPhoneNumber(e) {
				console.log('获取手机号', e);
				let that = this;
				let _params = {
					sessionKey: this.sessionKey,
					iv: e.detail.iv,
					encryptedData: e.detail.encryptedData
				};
				if (req.getStorage('pidCode')) {
					_params.parentId = req.getStorage('pidCode');
				}
				if (e.detail.errMsg == 'getPhoneNumber:ok') {
					req.postRequest('/api/weixin/mobile', _params, json => {
						// console.log(json);
						if (json.mobile) {
							var userInfo = req.getStorage('userInfo');
							userInfo.mobile = json.mobile;
							req.setStorage('userInfo', userInfo);
							this.phoneNumber = json.mobile;
						}
					});
				}
			},
			changeOptions(e, idx) {
				console.log('选择==', e);
				console.log('idx==', idx);
				this.jsonContent.map(item => {
					if (item.key == 'applicationForm') {
						item.value.formItemList.map((it, index) => {
							if (it.type == 5 && idx == index) {
								it.fieldValue = it.option[e.detail.value];
							}
						});
					}
					return item;
				});
				this.$forceUpdate();
			},
			checkRequire(formItemList) {
				for (var i = 0; i < formItemList.length; i++) {
					if (formItemList[i].required) {
						//不等于备注，并且为空时返回
						if (!this.isInclude(formItemList[i].label, '备注') && !formItemList[i].fieldValue) {
							req.msg('请填写' + formItemList[i].label);
							return false;
						}
						if (formItemList[i].type == 1 && this.isInclude(formItemList[i].label, '手机')) {
							if (!util.isMobile(formItemList[i].fieldValue)) {
								req.msg('请输入11位有效手机号');
								return false;
							}
						}
					}
				}
				return true;
			},

			/**
			 * 提交报名表单
			 * @param {Object} datas
			 */
			formSubmit(datas) {
				// if (!req.isLogins(true)) {
				// 	return;
				// }
				let params = {
					formId: datas.database
				};
				if (req.getStorage('userInfo').id) {
					params.belongUid = req.getStorage('userInfo').id;
				}
				let formItemList = datas.formItemList;
				let valueList = [];
				if (!this.checkRequire(formItemList)) return false;
				formItemList.map(it => {
					let obj = {
						fieldId: it.databaseLabel,
						fieldName: it.label,
						fieldType: it.type,
						fieldValue: it.fieldValue
					};
					valueList.push(obj);
				});
				params.valueList = valueList;
				console.log('表单提交==', params);
				req.postRequest(
					'/api/v3/custom/form/submit',
					params,
					data => {
						this.showBMDialogView();
					},
					true
				);
			},
			callPhone(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				});
			},
			// 时间格式化
			getDateFormat(date) {
				return util.formatTime(new Date(date)).t3;
			},
			// 锚点
			anchor(id) {
				this.$nextTick(() => {
					setTimeout(() => {
						uni.createSelectorQuery().select('#topId').boundingClientRect(data => {
							uni.createSelectorQuery().select("#" + id).boundingClientRect(res => {
								uni.pageScrollTo({
									duration: 100, //过渡时间
									scrollTop: res.top - data.top - 100, //返回顶部的top值
									success: () => {
										// req.msg("请选择商品")
									}
								})
							}).exec()
						}).exec();
					}, 50)
				})
			},
			showShare(){
				console.log('点击显示分享')
				this.isShowShare = true
				this.bottomPositon = 0
				this.$forceUpdate()
			},
			hideShareFn(){
				this.isShowShare = false
				this.bottomPositon = '-100%'
			},
		},
		mounted() {
			const systemInfo = uni.getSystemInfoSync();
			// px转换到rpx的比例
			let pxToRpxScale = 750 / systemInfo.windowWidth;
			let systems = {
				ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
				navigationHeight: 44 * pxToRpxScale ,// 导航栏的高度
				windowHeight: (systemInfo.windowHeight * pxToRpxScale - systemInfo.safeAreaInsets.bottom * pxToRpxScale) - 115
			};
			systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
			this.systems = systems;
			this.windowHeight = systemInfo.windowHeight;
		},
		onPageScroll(e) {
			var that = this;
			const query = uni.createSelectorQuery().in(this);
			query.selectAll('.' + "view-box").boundingClientRect(data => {
				let a = data
				for (let i = 0; i < a.length; i++) {
					// 判断top数值 向上滑动
					if (a[i].top <= 0) {
						that.isShowBotFixed = true;
					}
					// 向下滑动
					else if (a[i].top > that.windowHeight) {
						that.isShowBotFixed = true;
					}else{
						that.isShowBotFixed = false;
					}
				}
			}).exec();
			
			if (e.scrollTop > this.myScroll - 2) {
				this.isTop = 1;
			} else {
				this.isTop = 0;
			}
			// 只要滚动就清除状态
			clearTimeout(timer);
			// 告知标识 -> 开始滚动
			this.flag = false;
			this.specClass = 'show';
			// 检测是否停留了 N 秒
			// 如果停留则表示滚动结束
			// N: 500(定时器时间 毫秒) -> 0.5秒算停止滚动
			// 滚动后多长时间算停止滚动
			timer = setTimeout(() => {
				// console.log('结束滚动');
				// 告知标识 -> 结束滚动
				this.flag = true;
				this.specClass = 'hide';
			}, 50);
		},
	};
</script>

<style>
	@import './index.css';
</style>