<template>
	<view class="page-view">
		<block v-if="jsonContent && jsonContent.length > 0" v-for="(item, index) in jsonContent" tid="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" tid="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" tid="idx"><view :class="['dot', idx == swiperCurrent ? 'active' : '']"></view></block>
				</view>
			</view>
			<view class="form" v-if="item.key == 'applicationForm'">
				<text class="form-title" v-if="item.value.title.isShow">{{ item.value.title.value }}</text>
				<view class="form-list">
					<view class="li ddflex" v-for="(it,idx) in item.value.formItemList" tid="idx">
						<block v-if="it.type == 1">
							<!-- <input value="{{it.fieldValue}}" placeholder="{{'请填写0' + it.label}}" placeholder-class="placeholder" class="ipt fflex" if="{{it.dataType == 1}}" data-item="{{it}}" @change="changeFieldValue"/>
							<block else> -->
									<!-- if="{{isInclude(it.label, '手机')}}" -->
								<input
								    v-if="it.dataType == 1"
								    :value="it.fieldValue"
									:placeholder="'请填写' + it.label"
									placeholder-class="placeholder"
									maxlength="11"
									:data-item="it"
									type="tel"
									@change="changeFieldValue"
									class="ipt fflex"
								/>
								<input v-else 
								:value="it.fieldValue"  
								:placeholder="'请填写' + it.label" 
								placeholder-class="placeholder" 
								class="ipt fflex" 
								:data-item="it"
								@change="changeFieldValue"/>
							<!-- </block> -->
						</block>
						<textarea
							:value="it.fieldValue"
							:placeholder="'请填写' + it.label"
							placeholder-class="placeholder"
							class="textarea fflex"
							v-else-if="it.type == 4"
							:data-item="it"
							@change="changeFieldValue"
						></textarea>
						<!-- <picker :range="it.option" class="pickers fflex" @change="changeOptions($event, idx)" v-else-if="it.type == 5">
							<text if="it.fieldValue">{{ it.fieldValue }}</text>
							<text class="placeholder" else>请选择{{ it.label }}</text>
						</picker> -->
					</view>
				</view>
				<view class="form-btn" id="view-box" @click="formSubmit(item.value)">{{ item.value.buttonName }}</view>
			</view>
			<view class="richText" v-if="item.key == 'text'">
				 <richtext type="html">{{item.value.content}}</richtext>
				</view>
			<block v-if="item.key == 'product'">
				<view class="product flex-col ddflex" v-if="item.value.layoutNum == 1">
					<view class="li ddflex" v-for="(it,idx) in item.value.productList" tid="idx" @click="jumpUrl('/product/detail', {id:it.id})">
						<image :src="it.pic" mode="aspectFill" class="pro-img"></image>
						<view class="pro-info fflex">
							<text class="pro-name tovers">{{ it.title }}</text>
							<text class="pro-bri tover" v-if="it.brief">{{ it.brief }}</text>
							<view class="pro-opt ddflex">
								<view class="money">
									<text>￥{{ it.minSalePrice }}</text>
									<text class="texts">/起</text>
								</view>
								<text class="pro-btn">立即购买</text>
							</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" tid="idx" @click="jumpUrl('/product/detail', {id:it.id})">
						<image :src="it.pic" mode="aspectFill" class="pro-img"></image>
						<view class="pro-info fflex">
							<text class="pro-name tovers">{{ it.title }}</text>
							<view class="pro-opt ddflex">
								<view class="money">
									<text>￥{{ it.minSalePrice }}</text>
									<text class="texts">/起</text>
								</view>
								<view class="pro-cart"><image src="../../assets/static/pages/images/jia.png"></image></view>
							</view>
						</view>
					</view>
				</view>
				<view class="product product3 flex-col ddflex" v-if="item.value.layoutNum == 3">
					<scroll-view scroll-x="true">
						<view class="li" v-for="(it,idx) in item.value.productList" tid="idx" @click="jumpUrl('/product/detail', {id:it.id})">
							<view class="ddflex">
								<image :src="it.pic" mode="aspectFill" class="pro-img"></image>
								<view class="pro-info fflex">
									<text class="pro-name tovers">{{ it.title }}</text>
									<text class="pro-bri tover" v-if="it.brief">{{ it.brief }}</text>
									<view class="pro-opt ddflex">
										<view class="money">
											<text>￥{{ it.minSalePrice }}</text>
											<text class="texts">/起</text>
										</view>
										<text class="pro-btn">立即购买</text>
									</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'">
				<!-- 企微客服 -->
				<view class="contact ddflex" @click="customerServiceChat(item.value)" v-if="item.value.type == '1'">
					<image src="../../assets/static/pages/images/kfico.png"></image>
					<text>客服</text>
				</view>
				<!-- 第三方客服 -->
				<view class="contact ddflex" @click="jumpHref(item.value)" v-if="item.value.type == '2'">
					<image src="../../static/pages/images/kfico.png"></image>客服
				</view>
				<!-- 微信客服、内置客服页面 -->
				<button open-type="contact" class="contact ddflex" v-if="item.value.type == '0' || item.value.type == '3'">
					<image src="../../assets/static/pages/images/kfico.png"></image>
					<text>客服</text>
				</button>
			</block>

			<view class="coupon flex-col ddflex" 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 flex-col ddflex">
					<view class="li flex-col ddflex" v-for="(it,indexx) in item.value.couponList" tid="indexx">
						<view class="info ddflex">
							<view class="left-pic"><image :src="it.couponIcon?it.couponIcon:'../../assets/static/pages/images/coup_logo.jpg'" mode="aspectFill"></image></view>
							<view class="fflex flex-col ddflex">
								<text class="title">{{ it.couponTitle }}</text>
								<text class="time">{{ getDateFormat(it.couponStart) }}-{{ getDateFormat(it.couponEnd) }}</text>
							</view>
							<view class="info-r flex-col ddflex">
								<view class="money">
									<text class="texts">￥</text>
									<text>{{ it.couponAmount }}</text>
								</view>
								<text class="man">{{ it.couponBrief }}</text>
							</view>
						</view>
						<view class="li-bot ddflex">
							<view class="check ddflex fflex" @click="checks(it)">
								<text>查看详情</text>
								<image v-if="!it.isShow" src="../../assets/static/pages/images/bico.png"></image>
								<image v-else src="../../assets/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">
								<text class="yong ddflex" @click="jumpUrl('pages/mine/coupons')">去使用</text>
							</block>
							<block v-else>
								<text
									@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 }}
								</text>
								<text
									@click="getCoupon(it)"
									class="yong ddflex"
									v-else-if="item.value.btnBackground.length == 1"
									:style="'background: ' + item.value.btnBackground[0] + ';'"
								>
									{{ item.value.buttonName }}
								</text>
								<text class="yong ddflex" v-else @click="getCoupon(it)">{{ item.value.buttonName }}</text>
							</block>
						</view>
						<view class="infos" v-if="it.isShow">
							<text>使用范围：{{ it.couponBrief }}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="coupon flex-col ddflex" v-if="item.key == 'recharge'">
				<text class="tag">快捷充值</text>
				<view class="form-title">
					<view>
						<text>{{ item.value.rechargeTitle }}</text>
					</view>
				</view>
				<view class="recharge flex-col ddflex">
					<view :class="'dflex rechargeId' + (isInt ? ' on' : '')">
						<text v-if="item.value.showSymbol">￥</text>
						<input
							:placeholder="item.value.placeholderText ? item.value.placeholderText : '点击输入充值金额'"
							placeholder-class="placeholder"
							:value="pay"
							type="number"
							@change="amount"
							@focus="focus"
						/>
					</view>
					<text class="rechargeMoney" v-if="TabList && TabList.length > 0">快捷充值</text>
					<view class="rechargeul dflex" v-if="TabList && TabList.length > 0">
						<!--选中 加class active -->
						<view :class="'rechargeli '+(it.active ?'rechargeli-active':'')" v-for="(it,index) in TabList" tid="index" @click="switchTab(it, index)">
							<text :class="'wealth '+ (item.active ?' awealth':'')">充{{ it.rechargeAmount }}元</text>
							<!-- <view class="give awealth">
								送40元
							</view> -->
						</view>
					</view>
				</view>
				<text
					class="chongzhi"
					id="view-box"
					@click="remainder()"
					:style="item.value.mainColor ? 'background-color: ' + item.value.mainColor + ';border: 1px solid ' + item.value.mainColor + ';' : ''"
				>
					{{ item.value.buttonName }}
				</text>
			</view>
		</block>

		<block v-if="jsonContent && jsonContent.length > 0" v-for="(item,index) in jsonContent" :key="index">
			<block v-if="item.key == 'fixedNode'">
				<block v-if="item.value.type == 'applicationForm' || item.value.type == 'recharge'">
					<block v-if="isShowBotFixed">
						<view style="height: 140px;"></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: 160px;"></view>
					<block v-for="(it,idx) in item.value.contentObj.value.productList" :key="idx">
						<view class="product-fixed ddflex" v-if="it.isFixedNode" @click="jumpUrl('pages/product/detail', {id:it.id})">
							<image :src="it.pic" mode="aspectFill"></image>
							<view class="fflex flex-col">
								<view class="product-tit tover">{{it.title}}</view>
								<view class="product-opt ddflex">
									<view class="product-price">
									<view class="product-price-m">￥{{ it.minSalePrice }}</view>
									<!-- <text class="product-price-t">/起</text> -->
									</view>
									<view class="product-btn">立即购买</view>
								</view>
							</view>
						</view>
					</block>
				</block>
				<block v-if="item.value.type == 'coupon'">
					<view style="height: 140px;"></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 flex-col">
								<view class="title tover">{{it.couponTitle}}</view>
								<view class="money">
									<view class="texts">￥</view>
									<view>{{ it.couponAmount }}</view>
								</view>
							</view>
							<block v-if="it.userCount >= it.userReceive && it.userCount != 0 && it.userReceive != -1">
								<view class="yong ddflex" @click="jumpUrl('pages/mine/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="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="popupPost" v-if="isShowBMDialogView">
			<view class="popup flex-col ddflex" v-if="isShowBMDialogView">
				<image src="../../assets/static/images/popup_tip.png" class="popup-img"></image>
				<text class="popup-tip">提交成功</text>
				<text class="popup-tips">你的信息已提交，会有专业人员联系你，请耐心等待</text>
				<view class="popup-btns ddflex">
					<text class="back-home ddflex" @click="goHome()">去首页</text>
					<text class="check-btn ddflex" @click="hintDialogView()">确定</text>
				</view>
				<view class="popup-closePost">
					<image src="../../assets/static/images/popup_close.png" class="popup-close" @click="hintDialogView()"></image>
				</view>
			</view>
		</view>

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

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

		<view class="popupPost" v-if="isShowBindMobileView">
			<view class="popup flex-col ddflex" v-if="isShowBindMobileView">
				<text class="popup-tip">验证手机号</text>
				<text class="popup-tips">该手机号仅用于线下核销验证请放心填写</text>
				<input :value="phoneNumberValue" maxlength="11" type="number" placeholder="请输入手机号" placeholder-class="placeholder" class="popup-ipt" @change="phoneNumberChange" />
				<view class="popup-btns ddflex" style="margin-top: 60rpx">
					<text class="back-home ddflex" @click="hintBindMobileView()">取消</text>
					<text class="check-btn ddflex" @click="confirmBundMoble()">确定</text>
				</view>
				<image src="../../assets/static/images/popup_close.png" class="popup-close" @click="hintDialogView()"></image>
			</view>
		</view>

		<view class="ceng" v-if="isShowCard" @click="hideCardPop()"></view>
		<view class="qrcodePost" v-if="isShowCard">
			<view class="qrcode flex-col ddflex" v-if="isShowCard">
			<text class="hintt">{{ currentCard.couponTitle }}</text>
			<view class="qr-code ddflex">
				<image class="code-image" :src="currentCard.qrCodeUri"></image>
			</view>
			<view class="code ddflex">
				<text>{{ currentCard.id }}</text>
				<text class="copy" @click="copyCode()">复制</text>
			</view>
			<text class="hittext">- 请将二维码出示给店员核销使用 -</text>
			<view class="closePost">
				<image src="../../assets/static/pages/images/close2.png" class="close" @click="hideCardPop()"></image>
			</view>
		</view>
		</view>
	</view>
</template>

<script>
import req from '../../utils/request.js'
import util from '../../utils/util.js'
import route from '../../utils/route.js'

export default {
	data() {
		return {
			code: '',
			systems: {},
			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: {},
			ruzhuItem: '',

			isShowBotFixed: true,//是否显示悬浮按钮
			windowHeight: '',
		}
	},
	async onLoad(options) {
		console.log(options)
		this.code = options.code
		this.getAbout();
		await this.getParams();
	},
	async onShow() {
		var userInfosStr = await req.getStorage('userInfo');
		if (userInfosStr) {
			this.userInfo = userInfosStr
		}
		if (this.orderId) {
			let i = 0;
			req.loadIng();
			let timer = setInterval(() => {
				route.balanceStare(
					{
						logsId: this.orderId
					},
					res => {
						if (res.isSuccess || i === 4) {
							req.hideLoading();
							this.orderId = '';
							this.pay = '';
							clearInterval(timer);
							if (res.isSuccess) {
								this.showRemainderDialogView();
							}
						} else {
							i++;
						}
					}
				);
			}, 300);
		}
	},
	methods: {
		goHome() {
			this.hintDialogView();
			uni.navigateBack()
		},
		getAbout() {
			var _this = this;
			req.getRequest('/api/other/config', {}, function (res) {
				_this.isOpenHuaweiMobile = res.isOpenHuaweiMobile;
			});
		},
		// 余额充值
		async remainder() {
			this.isCoupon = false; //是否为优惠券
			this.isRemainder = true; //是否为充值
			if (!await req.isLogins(true)) {
				return;
			}
			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.text);
			let money = e.text;
			this.pay = money;
		},
		
		focus(e) {
			this.isInt = true;
			this.TabList.map(it => {
				it.active = 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('pages/mine/coupons');
			}
			this.hintDialogView();
		},
		hideCardPop() {
			this.isShowCard = false;
		},
		
		copyCode() {
			uni.setClipboardData({
				data: this.currentCard.id,
				success: function(res) {
					req.msg('复制成功');
				}
			});
		},
		
		phoneNumberChange(ev) {
			this.phoneNumberValue = ev.text;
		},
		
		/**
		 * 确定设置手机号
		 */
		confirmBundMoble() {
			if (!this.phoneNumberValue) {
				req.msg('请输入手机号');
				return;
			}
			if (!util.isMobile(this.phoneNumberValue)) {
				req.msg('请输入11位有效手机号');
				return;
			}
			req.loadIng();
			this.bundMoble(this.phoneNumberValue);
			this.hintBindMobileView();
		},
		
		/**
		 * 领取优惠券
		 * @param {Object} item
		 */
		async getCoupon(item) {
			console.log('数据>>>>>>>>', item);
			this.isCoupon = true; //是否为优惠券
			this.isRemainder = false; //是否为充值
			this.checkCoupon = item;
			if (!await req.isLogins(true)) {
				return;
			}
			let _ts = this;
			if (!_ts.userInfo.mobile) {
				req.getPhoneNumber(res => {
					_ts.bundMoble(res);
				});
				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);
					req.hideLoading();
					this.couponReceive();
				},
				true
			);
		},
		
		checks(item, index) {
			item.isShow = !item.isShow;
			this.$forceUpdate();
		},
		getParams() {
				let that = this;
				let params = {
					code: this.code
				};
				return new Promise((resolve, reject) => {
					req.getRequest(
						'/api/material/library/detail',
						params,
						data => {
							data.params.jsonContent.map(item => {
								if (item.key == 'applicationForm') {
									//表单
									item.value.formItemList.map(it => {
										if (it.label.indexOf('姓名') > -1) {
											if (that.userInfo.nickName) {
												it.fieldValue = that.userInfo.nickName;
											}
										}
										if (it.label.indexOf('手机') > -1) {
											if (that.userInfo.mobile) {
												it.fieldValue = that.userInfo.mobile;
											}
										}
										if (it.type == 4) {
											//备注
											it.fieldValue = '';
										}
										if (it.type == 5) {
											it.option = ['大健康', '快销品'];
										}
									});
								} 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);
									}
								} else if (item.key == 'coupon') {
									if (item.value.couponList && item.value.couponList.length > 0) {
										item.value.couponList.map(itx => {
											itx.isShow = false;
											return itx;
										})
									}
								}
								return item;
							});
							that.params = data;
							that.jsonContent = data.params.jsonContent;
							uni.setNavigationBarTitle({
								title:data.title
							})
							console.log('data.title==', data.title);
							console.log('data.params.jsonContent==', data.params.jsonContent);
							resolve();
						},
						true
					);
				});
			},
		swiperChange(e) {
			this.swiperCurrent = e.index;
		},
		async jumpUrl(url) {
			this.hintDialogView();
			if (await req.isLogins(true)) {
				uni.navigateTo({
					url:url
				})
			}
		},
		
		jumpUrlCS() {
			// router.push({
			// 	uri: '/pages/pagecontent',
			// });
		},
		
		customerServiceChat(item) {
			wx.openCustomerServiceChat({
				extInfo: {
					url: item.target
				},
				corpId: item.id,
				success(res) {
					console.log('调用微信客服')
				}
			})
		},
		jumpHref(item) {
			window.location.href = item.target;
		},
		
		isInclude(label, keytxt) {
			return label.indexOf(keytxt) != -1;
		},
		
		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();
		},
		
		changeFieldValue(ev) {
			ev._currentTarget._dataset.item.fieldValue = ev.text;
		},
		
		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 (this.userInfo.id) {
				params.belongUid = this.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) {
				let that = this;
				let query = that.$element(id);
				let top = that.$element('topId');
				top.getBoundingClientRect({
					success: (data) => {
						query.getBoundingClientRect({
							success: (res) => {
								that.$page.scrollTo({top:res.top - data.top - 100, behavior:'smooth'})
							}
						});
					}
				});
			},
			getDevideInfo() {
				let that = this;
				device.getInfo({
					success: function (ret) {
						// px转换到rpx的比例
						let pxToRpxScale = 800 / ret.windowWidth;
						let systems = {
							ktxStatusHeight: ret.statusBarHeight * pxToRpxScale, // 状态栏的高度
							navigationHeight: 44 * pxToRpxScale // 导航栏的高度
						};
						systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
						that.systems = systems;
						that.windowHeight = ret.windowHeight;
						console.log('ret==',ret)
					}
				});
			},
	},
	onPageScroll(e) {
			console.log('滚动==',e)
			var that = this;
			let query = uni.createSelectorQuery().in(this).select('#view-box');
			if(query){
				query.boundingClientRect(data=>{
					console.log('data==',data.top,data.height)
					if (data.top <= 0) {
						that.isShowBotFixed = true;
					}else if (data.top-data.height > that.windowHeight) {// 向下滑动
						that.isShowBotFixed = true;
					}else{
						that.isShowBotFixed = false;
					}
				}).exec();
			}
		},
	mounted() {
		const systemInfo = uni.getSystemInfoSync();
		// px转换到rpx的比例
		let pxToRpxScale = 750 / systemInfo.windowWidth;
		let systems = {
			ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
			navigationHeight: 44 * pxToRpxScale ,// 导航栏的高度
			windowHeight:systemInfo.windowHeight
		};
		this.windowHeight = systemInfo.windowHeight
		systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
		this.systems = systems;
	}

	
};
</script>

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