<template>
	<view v-if="allShow">
		<!--group/detail/detail.wxml-->
		<view class="banner">
			<swiper class="swiper" @change="swiperChange" :current="current" autoplay="true" circular="true"
				duration="1000">
				<block v-for="(item, index) in bannerUrls" :key="index">
					<swiper-item autoplay="true">
						<image :src="item + '?x-oss-process=style/w750-auto'" mode="aspectFit"></image>
					</swiper-item>
				</block>
			</swiper>
			<view class="dots dflex">
				<block v-for="(item, index) in bannerUrls" :key="index">
					<view :class="'dot ' + (index == swiperCurrent ? ' active' : '')" :data-current="index"
						@tap="dotEvent"></view>
				</block>
			</view>
		</view>
		<!-- <view class="notification_bar" wx:if="{{isNotice}}">
	<swiper class="swiper_container" vertical="true" autoplay="true" circular="false" duration="1000" interval="5000" easing-function="easeInOutCubic" class="bar_box dflex">
		<swiper-item class="bar_con dflex" wx:for="{{contentList}}" wx:key="item">
			<view class="bar dflex">
				<image class="bar_left" src="{{item.pic}}" />
				<text class="bar_text">最新订单来自</text>
				<text class="bar_text">{{item.name}}，</text>
				<text class="bar_text">{{item.time}}</text>
			</view>
		</swiper-item>
	</swiper>
</view> -->
		<view class="group">
			<image src="/activity/static/activity/images/ptbg.png" class="ptbg" v-if="act.start"></image>
			<image src="/activity/static/activity/images/msyybg.png" class="ptbg" v-else></image>
			<view class="groups dflex">
				<view class="left">
					<view class="price">拼团价￥<text>{{act.money}}</text></view>
					<view class="pin"><text class="origin" v-if="act.marketPrice<act.money&&act.marketPrice!=0">原价
							{{act.marketPrice}}</text>
						<block v-if="act.marketPrice<act.money&&act.marketPrice!=0"> | </block>{{count? count:0}}人已拼
						{{act.activityMainEntity.numberPeople}}人团
					</view>
				</view>
				<view class="right">
					<image src="/static/pages/images/tuan.png" class="tuan"></image>
					<view class="endtime dflex">
						<view>{{isStates==0?'距开始':isStates==1?'距结束':'已结束'}}</view>
						<block v-if="timer.length==4">
							<block v-if="timer[0] !=0"><text>{{timer[0]}}</text>天</block>
							<text>{{timer[1]}}</text>:
							<text>{{timer[2]}}</text>:
							<text>{{timer[3]}}</text>
						</block>
						<block v-else>
							<text>{{timer[0]}}</text>:
							<text>{{timer[1]}}</text>:
							<text>{{timer[2]}}</text>
						</block>
						<!-- <block wx:if="{{timer&&timer.length>0}}">
				<text>{{timer[0]}}</text>天</block>
				<text>{{timer[1]}}</text>:
				<text>{{timer[2]}}</text>:
				<text>{{timer[3]}}</text> -->
					</view>
				</view>
			</view>
		</view>
		<view class="text">
			{{product.brandName ? product.brandName : ''}} {{product.brief ?  product.brief : ''}}
		</view>
		<view class="info bgfff">
			<view class="infos dflex">
				<view class="title flex">{{pro.title?pro.title:'0'}}</view>
				<view class="share" @tap="showShare">
					<image src="/static/pages/images/fxico.png"></image>分享
				</view>
			</view>
			<view class="guarantee dflex" v-if="guarantee.length>0">
				<view class="cont dflex">
					<view v-for="(item, index) in guarantee" :key="index" class="dflex li">
						<image src="/activity/static/activity/images/guarantee.png"></image>{{item}}
					</view>
				</view>
			</view>
		</view>

		<view class="detinfo mt20 bgfff">
			<!-- isOtc 0 默认 1 处方药 2 非处方药 3 医疗器械 4 食品类 5 海外购 -->
			<block v-if="act.isOtc!=5">
			<block v-if="is_open_shop == 1 && ascription">
			<view class="xiaodian dflex malr20" v-if="((act.isMeCommission != 1 || act.isMeCommission != '1') && act.oneCommission>0) || ((act.isMeCommission == 1 || act.isMeCommission == '1') && act.twoCommission>0) || act.serviceShopRate">
				<image src="/static/pages/images/xdbg1.png" class="xdbg"></image>
				<view class="shouyi flex" v-if="((act.isMeCommission != 1 || act.isMeCommission != '1') && act.oneCommission>0) || ((act.isMeCommission == 1 || act.isMeCommission == '1') && act.twoCommission>0)">
					<text>分销收益</text>
					<view v-if="act.isMeCommission == 0"><text>￥</text>{{act.oneCommission}}</view>
					<view v-else><text>￥</text>{{act.twoCommission}}</view>
				</view>
				<view class="shouyi flex" v-if="act.serviceShopRate">
					<text>小店服务费</text>
					<view><text>￥</text>{{act.serviceShopRate}}</view>
				</view>
				<view class="dflex" v-if="act.isJoinShop">
					<view class="fenxiang" @tap="showShare">分享推广</view>
					<navigator :url="url" hover-class="none" class="goShop">去小店</navigator>
				</view>
				<view class="addshop" @tap="addShop" v-else>添加到小店</view>
			</view>
			</block>
			<block v-else>
			<view class="xiaodian dflex malr20" v-if="((act.isMeCommission != 1 || act.isMeCommission != '1') && act.oneCommission>0) || ((act.isMeCommission == 1 || act.isMeCommission == '1') && act.twoCommission>0)">
				<image src="/static/pages/images/xdbg1.png" class="xdbg"></image>
				<view class="shouyi flex">
					<text>分销收益</text>
					<view v-if="act.isMeCommission == 0"><text>￥</text>{{act.oneCommission}}</view>
					<view v-else><text>￥</text>{{act.twoCommission}}</view>
				</view>
				<navigator url="/promote/apply/apply" hover-class="none" class="fenxiang" v-if="isDistriUser != 2">我要推广</navigator>
				<view class="fenxiang" @tap="showShare" v-else>分享推广</view>
			</view>
			</block>
			</block>
			<!-- <view class="item dflex">
		<label>优惠券</label>
		<view class="quan flex dflex">
			<view class="flex dflex">
				<text>满500减50</text>
				<text>满200减10</text>
			</view>
			<view class="ling dflex">领券<image src="/pages/images/more3.png"></image>
			</view>
		</view>
	</view> -->
			<view class="item pro-sel dflex" v-if="pro.propertiesList && pro.propertiesList.length > 0"
				@click="pro.stock > 0 ? addShopCart() : ''">
				<label>已选</label>
				<view class="flex">{{pro.properties}}</view>
				<image src="/static/pages/images/more.png" class="mrico"></image>
			</view>
			<view class="item dflex">
				<label>配送至</label>
				<view class="flex" @tap="toAddress">
					<view class="address">{{address.address?address.address:''}}{{address.house?address.house:''}}
					</view>
					<view class="huo" v-if="pro.isTimely == 1"><text>现货</text>，现在下单，预计2小时后送达</view>
				</view>
				<image src="/static/pages/images/more2.png" class="more" @tap="toAddress"></image>
			</view>
			<view class="item dflex">
				<label>门店</label>
				<view class="flex" @tap="toMerchant">
					<view class="address">{{merchant.title}}</view>
				</view>
			</view>
		</view>
		<!-- 参团情况 -->
		<!-- <view class="cantuan bgfff mt20">
	<view class="can-info">{{act.activityMainEntity.numberPeople}}人团，还差<text>{{act.activityMainEntity.numberPeople-(act.activityPurchaseRecordEntitys?act.activityPurchaseRecordEntitys.length:0)}}人</text></view>
	<view class="can-infos dflex" wx:for="{{act.activityPurchaseRecordEntitys}}">
		<view class="li">
			<image src="/pages/images/bar.png" mode="aspectFit"></image>
			<text>团长</text>
		</view>
		<view class="li">
			<image src="/pages/images/bar.png" mode="aspectFit"></image>
		</view>
		<view class="li">
			<image src="/pages/images/cha.png"></image>
		</view>
		<view class="li">
			<image src="/pages/images/cha.png"></image>
		</view>
	</view>
	<view class="can-btn mbglinear">我要参团</view>
</view> -->
		<!-- 组团情况 -->
		<view class="zutuan bgfff mt20">
			<view
				v-if="(activityPurchaseRecordListDTO&&activityPurchaseRecordListDTO.length>0)||(act.activityPurchaseRecordListDTO.length>0&&act.activityPurchaseRecordListDTO)"
				class="zu-tit dflex">
				{{act.activityPurchaseRecordListDTO.length}}人正在组团，可直接参与<icon class="icon iconfont icon-bottom"
					@tap="activityPurchaseRecordListDTO.length>1&&activityDot.length>0?clickmore():''">
				</icon>
			</view>
			<view class="zu-list">
				<view v-for="(item, index) in activityPurchaseRecordListDTO" :key="index" class="li dflex">
					<image :src="item.groupMainP.uavatar" mode="aspectFit"></image>
					<view class="zu-name flex">{{item.groupMainP.unickName}}</view>
					<view class="zu-ren">
						<view class="cha"
							v-if="(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">
							{{act.activityMainEntity.numberPeople}}人成团，还差<text>{{(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0?(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0)):0}}人</text>
						</view>
						<view class="zu-time"
							v-if="item.isGroup&&(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">
							剩余<text>{{item.times}}</text></view>
						<block v-else>
							<view
								v-if="!item.isGroup&&(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">
								拼团失败</view>
							<view
								v-if="(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))<=0">
								<text>{{item.groupMainP.state==1?'拼团完成':'拼团待支付'}}</text>
							</view>
						</block>
					</view>
					<view class="zu-btn mbglinear" :data-index="index" @tap="toGoGroup"
						v-if="(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">去参团
					</view>
					<view class="zu-btn mbglinear" :data-index="index" @tap="toGoGroup" v-else>查看详情</view>

				</view>
			</view>
		</view>

		<!-- 拼团玩法 -->
		<view class="wanfa bgfff mt20">
			<view class="wan-tit">拼团玩法</view>
			<view class="wan-info dflex">
				<view class="li dflex">
					<icon class="icon iconfont icon-zhifu"></icon>
					<view class="flex">支付开团<text>或参团</text></view>
				</view>
				<icon class="icon iconfont icon-right"></icon>
				<view class="li dflex">
					<icon class="icon iconfont icon-haoyou"></icon>
					<view class="flex">邀请好友<text>拼团</text></view>
				</view>
				<icon class="icon iconfont icon-right"></icon>
				<view class="li dflex">
					<icon class="icon iconfont icon-dingdan"></icon>
					<view class="flex">达到人数拼团成功<text>人数不足拼团失败</text></view>
				</view>
			</view>
		</view>


		<!--  商品详情等页面 -->
		<product-footer ref="list" id="list" :detail="nodes" :imgs="imgs" :proId="pro.id" v-if="pro.id" :form="form"
			@showTab="showTab" @scoreTab="scoreTab" @freshen="freshenFun"></product-footer>

		<v-share :hide-toast="hideShare" :product="pro" :code-url="codeUrl" :a-type="'3'" @onFather="click"></v-share>

		<view class="placeholder-view" :style="'height:' + (bottomBlankHeight + 140) + 'rpx'"></view>
		<view class="bot fixed bgfff dflex" :style="'padding-bottom: ' + (bottomBlankHeight + 20) + 'rpx'">
			<contact-button img-url="/static/pages/images/kfico.png" class-name="botbtn" button-text="在线客服"></contact-button>
			<!-- <navigator class="botbtn" open-type="switchTab" url="/pages/cart/cart" hover-class="none">
		<image src="/pages/images/gwc.png"></image>购物车<text class="message" wx:if="{{pro.count > 0}}">{{pro.count}}</text>
	</navigator> -->
			<!-- <view class="botbtn" bindtap="clickCollect">
		<image src="/pages/images/shoucang_h.png" wx:if="{{pro.isCollect}}"></image>
		<image src="/pages/images/shoucang.png" wx:else></image>收藏
	</view> -->
			<!-- <view class="addcart">加入购物车</view> -->
			<block v-if="isStates!=0">
				<view class="gmbtn" @tap="atOnceBuy">￥{{salePrice}} 单独购买</view>

				<!-- <view class="ctbtn mbglinear">我要参团</view>官方组团按钮 -->
				<!-- 自由组团按钮 -->
				<view class="ctbtn mbglinear" @tap="createGroup" v-if="isStates==1&&myActData.state!=1&&!activityEnd">
					￥{{ act.money}}发起拼团</view>
				<view class="ctbtn mbglinear" @tap="createGroup" v-if="myActData.state==1">查看拼团</view>
				<view class="ctbtn end" v-if="(isStates==2&&myActData.state!=1)||activityEnd">活动已结束</view>

			</block>
			<block v-if="isStates==0">
				<view class="cancel-yy dflex" @tap="cancelActivityRemind" v-if="isRemind">
					<icon class="icon iconfont icon-yugao"></icon>取消提醒
				</view>
				<view class="yybtn mbggreen dflex" @tap="addActivityRemind" v-else>
					<icon class="icon iconfont icon-yugao"></icon>预约提醒
				</view>
			</block>
		</view>

		<!-- 商品规格 -->
		<block v-if="isShow">
			<product-popup :product="popup" :activityId="act.id" :is-cart="isCart" order-type="4" @hidePopup="hidePopup"
				@addCartSuccess="addCartSuccess" :order-type="orderType" :merchant="merchant"
				:merchant-id="query.merchantId" :shop-id="query.shopId"></product-popup>
		</block>

		<view class="contact_index" @tap="goTop">
			<image src="/static/pages/images/backtop.png"></image>顶部
		</view>



		<!-- 查看更多 -->
		<view class="mask" @tap="eliminate" v-if="show" catchtouchmove="true"></view>
		<view class="page" :style="'margin:-' + (windowHeight/2) + 'px 0 0 -' + (windowWidth/2) + 'px'">
			<view class="ptuanmode" catchtouchmove="true" v-if="show">
				<view class="zu-list">
					<view class="pttop">正在拼团</view>
					<scroll-view scroll-y="true" style="max-height: 550rpx;">
						<view v-for="(item, index) in activityDot" :key="index" class="li dflex">
							<image :src="item.groupMainP.uavatar" mode="aspectFit"></image>
							<view class="zu-name flex">{{item.groupMainP.unickName}}</view>
							<view class="zu-ren">
								<view class="cha"
									v-if="(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">
									{{act.activityMainEntity.numberPeople}}人成团，还差<text>{{(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0?(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0)):0}}人</text>
								</view>
								<view class="zu-time"
									v-if="item.isGroup&&(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">
									剩余<text>{{item.times}}</text></view>
								<block v-else>
									<view
										v-if="!item.isGroup&&(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">
										拼团失败</view>
									<view
										v-if="(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))<=0">
										<text>{{item.groupMainP.state==1?'拼团完成':'拼团待支付'}}</text>
									</view>
								</block>
							</view>
							<view class="zu-btn mbglinear" :data-index="index" data-type="1" @tap="toGoGroup"
								v-if="(act.activityMainEntity.numberPeople-(item.groupList?item.groupList.length:0))>0">
								去参团</view>
							<view class="zu-btn mbglinear" :data-index="index" @tap="toGoGroup" :data-type="1" v-else>
								查看详情</view>
						</view>
					</scroll-view>
					<view class="tole" v-if="activityDot.length==21">--仅显示20个正在拼团的人--</view>
				</view>
			</view>
		</view>

		<!-- 添加到小店成功 -->
		<view class="mask" :hidden="isHide" @tap="hidePop"></view>
		<view class="suc" :hidden="isHide">
			<image src="/static/pages/images/tjcg1.png" class="tjcg1"></image>
			<image src="/static/pages/images/tjcg.png" class="tjcg"></image>
			<text>快去我的小店看看吧</text>
			<view class="shopcc dflex">
				<view class="shop" @tap="showShare">分享推广</view>
				<navigator :url="url" hover-class="none" class="shop" >我的小店</navigator>
			</view>
			<!-- <view class="share-btn dflex">
				<button class="wxfriend dflex" open-type="share">
					<image src="/static/pages/images/wechat.png"></image>
					微信好友
				</button>
				<view class="wxposter dflex" @tap="generatePoster">
					<image src="/static/pages/images/poster.png"></image>
					生成海报
				</view>
			</view> -->
			<image src="/static/pages/images/close2.png" class="suc-close" @tap="hidePop"></image>
		</view>
		<block v-if="isPopupLogin">
			<product-login :about="about" @hidePopupLogin="hidePopupLogin"></product-login>
		</block>
	</view>
</template>

<script>
	const app = getApp();
	const req = require("../../../utils/request.js");
	const utils = require("../../../utils/util.js");
	var QQMapWX = require("../../../utils/qqmap.js");
	const requsetmessage = require("../../../utils/requestmessage.js");
	const route = require("../../../utils/route");
	const api = require("../../../utils/api.js");
	import productFooter from "../../../components/product_footer/index";
	import productPopup from "../../../components/product-popup/index";
	import vShare from "../../../components/share/share";
	import productLogin from "../../../components/product-login/index";

	export default {
		data() {
			return {
				bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
				swiperCurrent: 0,
				bannerUrls: [],
				isShow: false,
				pro: {},
				timer: [],
				isRemind: false,
				hideShare: true,
				codeUrl: '',
				start: false,
				activityPurchaseRecordListDTO: [],
				activityDot: [],
				act: {},
				isGroup: true,
				hideShop: true,
				//隐藏添加到小店
				isHide: true,
				//添加小店成功弹窗
				contentList: [{
					pic: "/static/pages/images/bar.png",
					name: '好风依旧',
					time: '4秒前'
				}, {
					pic: "/static/pages/images/bar.png",
					name: '杨鑫',
					time: '20秒前'
				}, {
					pic: "/static/pages/images/bar.png",
					name: '杨鑫',
					time: '5秒前'
				}],
				isNotice: false,
				form: {
					page: 1,
					limit: 10
				},
				freshen: true //是否更新页面
					,
				current: "",
				query: "",
				merchant: "",
				merchantId: "",
				shopId: "",
				imgs: "",
				nodes: "",
				salePrice: "",
				activityEnd: false,
				isStates: 0,
				address: {},
				popup: "",
				myActData: "",
				count: "",
				show: false,
				tabIndex: "",
				guarantee: "",
				is_open_comments: "",
				switch: true,
				about: {},
				allShow: false,
				url:'',
				is_open_shop: '',//商户是否开启分销
				ascription: false,//是否开启小店
				isDistriUser: 0, // 判断用户是否是分销员 2为分销员
				isPopupLogin: false
			};
		},

		components: {
			productFooter,
			productPopup,
			vShare,
			productLogin
		},
		props: {},
		onLoad: function(options) {
			// console.log(options);
			this.query = options;
			this.setData({
				query: options
			});

			if (options.scene) {
				this.scene = options.scene;
			}

			if (options.isShare) {
				this.query.id = options.id;
				this.query.acid = options.acid;
				req.setStorage('pidCode', options.userId);
				req.setStorage('pidCode', options.userId);
				let params = {
					userId: options.userId,
					merchantId: options.merchantId ? options.merchantId : '',
				}
				this.bindUser(params);
			}

			if (options.hideShop) {
				this.setData({
					hideShop: this.query.hideShop
				});
			} else {
				this.setData({
					hideShop: 'true'
				});
			} // this.isShop()


			setInterval(() => {
				this.setData({
					isNotice: true
				});
			}, 10000);
			// this.getuserInfo()
		},
		onShow: async function() {
			let that = this
			if (this.freshen) {
				await this.loadCodeParams();
				if(that.scene){
					await that.bindUser(that.query);
				}
				// this.loadDefaultAddress();
				this.groupCount();
				this.getGuarantee().then(data => {
					if (this.switch) {
						api.getMerchant(this.query, req, data => {
							that.loadDefaultAddress();
							if (data == 1) {
								api.locationShow()
							} else {
								that.getuserInfos(data);
								if (data.type == 5) {
									that.query.merchantId = data.merchantDTO.id
									that.query.shopId = data.id
								} else {
									that.query.merchantId = data.id
								}
								if (req.getStorage('userInfo') && that.merchant.id != data.id) {
									this.loadProudct();
									let pages = getCurrentPages();
									var prevPage = pages[pages.length - 2];
									if (prevPage) {
										prevPage.$vm.setData({
											freshen: true
										});
									}
								} else {
									this.loadProudct();
								}
								that.merchant = data
							}
						})
					}
				})
				await this.browsRecound(this.query.id); // let merchant = req.getStorage('defaultMerchant');
				// this.setData({ merchant: merchant });
				// this.getMerchant();
			}
		},
		onUnload() {
			if (this.timer) clearInterval(this.timer);
			this.clearAllTimer();
		},

		onShareAppMessage: function() {
			let merchantId = '';
			let path = '/activity/group/detail/detail?id=' + this.query.id + '&acid=' + this.query.acid + '&isShare=' +
				true;
			// console.log(!req.getStorage('userInfo').id);

			if (!req.getStorage('userInfo').id) {} else {
				path += '&userId=' + req.getStorage('userInfo').id;
			}

			// console.log(this.query.merchantId);
			let shopId = '';


			if (req.getStorage('MERCHANT') && req.getStorage('MERCHANT').id != null) {
				path += '&merchantId=' + req.getStorage('MERCHANT').id;
				merchantId = req.getStorage('MERCHANT').id;

				if (req.getStorage('smallShop') && req.getStorage('MERCHANT').id != null) {
					path += '&shopId=' + req.getStorage('smallShop').id;
					shopId = req.getStorage('smallShop').id;
					merchantId = req.getStorage('smallShop').merchantDTO.id;
				}
			}
			// console.log(path)
			route.share(1, req.getStorage('userInfo').id, path, merchantId, shopId, 7, this.query.acid + '_' + this
				.query.id);
			return {
				title: this.pro.title,
				imageUrl: this.pro.pic,
				path: path
			}; // return {
			//   title: this.data.pro.title,
			//   imageUrl: this.data.pro.pic,
			//   path: 'activity/group/detail/detail?acid=' + this.query.acid + "&id=" + this.query.id + '&isShare=' + true + '&userId=' + req.getStorage('userInfo').id + '&merchantId=' + this.data.query.merchantId
			//   // path: '/product/groupDetail/groupDetail?id=' + this.query.id + '&acid=' + this.query.acid + '&isShare=' + true + '&userId=' + req.getStorage('userInfo').id
			// }
		},

		onReachBottom() {
			if (this.is_open_comments == 1 && this.tabIndex == 2) {
				this.form.page++;
				this.setData({
					['form.page']: this.form.page
				});
				// this.selectComponent("#list").loadScore(this.current);
				this.$refs.list.loadScore(this.current);
			}
		},

		onHide() {
			this.clearAllTimer();
		},

		methods: {
			bindUser(par){
				let userInfo = req.getStorage('userInfo');
				if(!userInfo){
					// uni.login({
					// 	success(res) {
					// 		let params = {
					// 			code: res.code,
					// 			parentId: par.userId,
					// 			merchantId: par.merchantId ? par.merchantId : par.shopId ? par.shopId : ''
					// 		}
					// 		return new Promise((resolve,reject)=>{
					// 			req.postRequest('/api/v2/login', params, data => {
					// 				resolve();
					// 			});
					// 		})
					// 	}
					// });
					// this.isPopupLogin = true;
					req.silenceLogin(par.userId, par.merchantId ? par.merchantId : par.shopId ? par.shopId : '');
				}
			},
			// 获取用户信息
			getuserInfo() {
				let userInfo = req.getStorage('userInfo');
				if (userInfo && userInfo.listShopBase && userInfo.listShopBase != null && userInfo.listShopBase.length >
					0) {
					if (userInfo.listShopBase[0].merchant_id) {
						let url = '/mine/shop/shop?merchantId=' + userInfo.listShopBase[0].merchant_id + '&shopId=' +
							userInfo.listShopBase[
								0].id;
						this.setData({
							url: url
						});
					}
					console.log(this.url)
				}
			},
			click(e) {
				// console.log(e)
				this.hideShare = e
			},
			showShare() {
				// #ifndef H5
				req.isLogin().then(success => {
					if (success) {
						this.setData({
							hideShare: false
						});
						this.getCodeUrl()
					}
				});
				// #endif
			},

			/**
			 * 轮播切换
			 */
			swiperChange({
				detail
			}) {
				if (this.current == 0 && this.swiperCurrent > 1) {
					//卡死时，重置current为正确索引
					this.setData({
						current: this.swiperCurrent
					});
				} else {
					//正常轮转时，记录正确页码索引
					this.setData({
						swiperCurrent: detail.current
					});
				}
			},

			dotEvent(e) {
				this.setData({
					current: e.currentTarget.dataset.current
				});
			},

			browsRecound(id) {
				let from = {
					bindId: id,
					type: 7,
					page: '/activity/group/detail/detail?id=' + this.query.id + '&acid=' + this.query.acid
				};
				if (this.query.isShare) {
					from.shareType = 1;
					from.page = '/activity/group/detail/detail?id=' + this.query.id + '&acid=' + this.query.acid +
						'&isShare=' + true;

					if (!this.query.userId) {} else {
						from.page += '&userId=' + this.query.userId;
					}

					if (!this.query.merchantId) {} else {
						from.merchantId = this.query.merchantId;
					}

					if (!this.query.shopId) {} else {
						from.shopId = this.query.shopId;
					}

					if (!this.query.userId) {} else {
						from.uid = this.query.userId;
					}
				}

				if (this.query.isShareTimeline) {
					from.shareType = 2;
					from.page = '/activity/group/detail/detail?id=' + this.query.id + '&acid=' + this.query.acid +
						'&isShareTimeline=' +
						true;

					if (!this.query.userId) {} else {
						from.page += '&userId=' + this.query.userId;
					}

					if (!this.query.merchantId) {} else {
						from.merchantId = this.query.merchantId;
					}

					if (!this.query.shopId) {} else {
						from.shopId = this.query.shopId;
					}

					if (!this.query.userId) {} else {
						from.uid = this.query.userId;
					}
				}
				return new Promise((resolve,reject)=>{
					req.postRequest('/api/browse', from, data => {resolve()});
				})
			},

			loadCodeParams() {
				let _ts = this;

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

					req.getRequest('/api/code/params', {
						scene: _ts.scene
					}, data => {
						this.query.id = data.scene.split('_')[0];
						this.query.acid = data.scene.split('_')[1];
						this.query.merchantId = data.scene.split('_')[2];
						this.query.shopId = data.scene.split('_')[3];
						this.query.userId = data.userId;
						req.setStorage('pidCode', data.userId);
						resolve();
					});
				});
			},

			getCodeUrl() {
				let that = this; //获取小程序码
				const query = this.query;
				let scene = that.pro.id + '_' + query.acid;
				if (req.getStorage('MERCHANT') && req.getStorage('MERCHANT').id != null) {
					scene += '_' + req.getStorage('MERCHANT').id;
					if (req.getStorage('smallShop') && req.getStorage('MERCHANT').id != null) {
						scene += '_' + req.getStorage('smallShop').id;
					}
				}
				// console.log(scene); //获取小程序码
				const params = {
					page: 'activity/group/detail/detail',
					scene: scene
				};
				req.getRequest('/api/program/codev', params, url => {
					that.setData({
						codeUrl: url
					});
				});
			},

			async loadProudct() {
				let that = this;
				await that.loadActivity();
				const query = that.query;
				let isShowLoading = false;

				if (!isShowLoading) {
					req.loadIng('加载中');
					isShowLoading = true;
				}
				req.getRequest('/api/product/detail', {
					id: query.id
				}, data => {
					//富文本图片放大
					var nodes = data.detail;

					// if (nodes) {
					// 	if (nodes.indexOf("src") >= 0) {
					// 		//正则匹配所有图片路径
					// 		var imgs = [];
					// 		nodes = nodes.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function(match, capture) {
					// 			imgs.push(capture);
					// 			that.setData({
					// 				imgs: imgs
					// 			});
					// 			return '';
					// 		});
					// 	}
					// }
					let propertiesList = []
					if (data.propertiesList && data.propertiesList.length > 0) {
						data.propertiesList.map(it => {
							propertiesList.push(it.value);
						})
					}
					data.properties = propertiesList.join(' / ')
					that.setData({
						bannerUrls: data.images,
						pro: data,
						nodes: nodes,
						// 'pro.stock': this.act.quantity,
						'pro.stock': this.act.quantity - this.act.payQuantity,
						salePrice: data.salePrice,
						'pro.payQuantity': this.act.payQuantity,
						'pro.maxBuy': this.act.maxBuy,
						'pro.salePrice': this.act.money,
						allShow: true
					});
					if (isShowLoading) {
						uni.hideLoading();
						isShowLoading = false;
					}
					// console.log(this.pro);
					// that.getCodeUrl();
				});
			},

			loadActivity() {
				const query = this.query;
				return new Promise((resolve, reject) => {
					let from = {
						id: query.acid,
						type: 3
					}
					if (!this.query.merchantId) {} else {
						from.merchantId = this.query.merchantId
					}
					let userInfo = req.getStorage('userInfo');
					if(userInfo.listShopBase && userInfo.listShopBase.length >0 ){
						from.shopId = userInfo.listShopBase[0].id;
					}
					req.getRequest('/api/activity/detailNew', from, data => {
						/**
						 * 判断活动是否结束，结束，2秒后为用户跳转至该商品的详情页面
						 */
						// if (data.end) {
						//   this.setData({ start: data.end })
						//   console.log(this.data.start)
						//   wx.showToast({
						//     title: '活动已结束，两秒后将为您跳转至该商品页面',
						//     icon: 'none',
						//     success: function () {
						//       setTimeout(function () {
						//         wx.redirectTo({ url: '/product/detail/detail?id=' + data.productId })
						//       }, 2000);
						//     }
						//   })
						// }
						// data.activityPurchaseRecordListDTO.content(data.activityPurchaseRecordListDTO)
						// let arr=data.activityPurchaseRecordListDTO.filter(ele=>console.log(ele))
						this.getMy();
						if (!data || data == 2001) {
							this.setData({
								activityEnd: true
							});
							return false;
						} else {
							let activityPurchaseRecordListDTO;
							let arr;

							if (data.activityPurchaseRecordListDTO) {
								activityPurchaseRecordListDTO = data.activityPurchaseRecordListDTO.slice(0,
									2);
								arr = data.activityPurchaseRecordListDTO.slice(0, 21);
								// console.log(arr,"789");
							}

							// console.log(data.activityPurchaseRecordListDTO);
							this.setData({
								act: data,
								isRemind: data.remindId
							});
							this.setData({
								activityPurchaseRecordListDTO: activityPurchaseRecordListDTO,
								activityDot: arr
							});
							// console.log(this.activityPurchaseRecordListDTO, this
							// 	.activityPurchaseRecordListDTO);
							this.checkMyIsGroup();
							this.initTimer(data);
							this.groupItemTimer(1);
							this.groupItemTimer();
						}

						resolve();
					});
				});
			},
			// 获取用户信息
			getuserInfos(data) {
				let userInfo = req.getStorage('userInfo');
				if (userInfo && userInfo.listShopBase && userInfo.listShopBase != null && userInfo.listShopBase.length >
					0) {
					if (userInfo.listShopBase[0].merchant_id == data.id && data.type != 5) {
						let url = '/mine/shop/shop?merchantId=' + userInfo.listShopBase[0].merchant_id + '&shopId=' + userInfo.listShopBase[0].id;
						this.url = url;
						this.ascription = true;
					}
				}
			},
			getMy() {
				let that = this;
				let userInfo = req.getStorage('userInfo');
				if(!userInfo || userInfo == null) return false;
				req.getRequest('/api/user/my', {}, data => {
					that.isDistriUser = data.isDistriUser;
				});
			},

			//组团倒计时
			groupItemTimer(type) {
				// this.clearAllTimer();
				//社区拼图定时器
				let _ts = this;

				let group;

				if (type == 1) {
					group = this.activityPurchaseRecordListDTO;
				} else {
					group = this.activityDot;
				}

				if (group && group.length > 0) {
					let pageList = group;

					for (let i = 0, len = pageList.length; i < len; i++) {
						let group = pageList[i]; // let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();

						let nowTime = new Date(this.act.nowTime.replace(/-/g, '/')).getTime();
						let endTime = new Date(group.endDate.replace(/-/g, '/'))
							.getTime(); // let actend=new Date(this.data.act.endTime.replace(/-/g, '/')).getTime();
						// if (!group.start) endTime = startTime;
						// let times
						// if(actend-endTime>0){
						//    times = parseInt((endTime - nowTime) / 1000);
						// }else{
						//   times = parseInt((actend - nowTime) / 1000);
						// }

						let times = parseInt((endTime - nowTime) / 1000);
						let timer = setInterval(() => {
							times--;
							let data = {};

							if (times < 0) {
								if (type == 1) {
									data['activityPurchaseRecordListDTO[' + i + '].isGroup'] = false;
								} else {
									data['activityDot[' + i + '].isGroup'] = false;
								} // this.setData({isGroup:false})

							} else if (times === 0) {
								//重新加载列表
								clearInterval(timer);
							} else {
								let n = utils.formatDayTimes(times);

								if (type == 1) {
									data['activityPurchaseRecordListDTO[' + i + '].times'] = n;
									data['activityPurchaseRecordListDTO[' + i + '].isGroup'] = true;
								} else {
									data['activityDot[' + i + '].times'] = n;
									data['activityDot[' + i + '].isGroup'] = true;
								}
							}

							_ts.setData(data);
						}, 1000);
						let fs = [];

						if (type == 1) {
							fs['activityPurchaseRecordListDTO[' + i + '].timer'] = timer;
						} else {
							fs['activityDot[' + i + '].timer'] = timer;
						}

						_ts.setData(fs);
					}
				}
			},

			clearAllTimer() {
				if (this.activityPurchaseRecordListDTO) {
					this.activityPurchaseRecordListDTO.forEach(it => {
						// console.log(it);
						clearInterval(it.timer);
						clearInterval(it.times);
					});
				}

				if (this.activityDot) {
					this.activityDot.forEach(it => {
						// console.log(it);
						clearInterval(it.timer);
						clearInterval(it.times);
					});
				}
			},

			initTimer(group) {
				//计时器
				let _ts = this;

				let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
				let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();
				let endTime = new Date(group.endTime.replace(/-/g, '/')).getTime();
				if (!group.start) endTime = startTime;
				let times = parseInt((endTime - nowTime) / 1000);
				let data = {}; //判断是否已开始

				if (nowTime - startTime > 0) {
					//开始了
					_ts.setData({
						isStates: 1
					});
				} else {
					//未开始
					_ts.setData({
						isStates: 0
					});
				}

				_ts.setData(data);

				if (times > 0) {
					this.timer = setInterval(() => {
						times--;

						if (times === 0) {
							//重新加载列表
							_ts.setData({
								'act.end': true
							});

							return false;
						}

						let n = utils.formatDayTimes(times);

						_ts.setData({
							timer: n.split(/:|天/g)
						});
					}, 1000);
				} else {
					_ts.setData({
						isStates: 2
					});
				}
			},


			loadDefaultAddress() {
				if (req.isAuth()) {
					req.g('/api/address/default', data => {
						if (data) this.setData({
							address: data
						});
						else this.pointLocation();
					}, true);
				} else {
					this.pointLocation();
				}
			},

			toAddress() {
				app.globalData.openPage('mine/address/address');
			},

			toMerchant() {
				if (this.about.User_Limit_Store == 1) {

				} else {
					app.globalData.openPage('pages/nearby/nearby?isChoose=true');
				}
			},


			pointLocation() {
				//定位当前位置
				let _ts = this;

				QQMapWX.initMap();
				req.getLocation(res => {
					QQMapWX.reverseGeocoder(res, data => {
						_ts.setData({
							['address.address']: data.address
						});
					});
				});
			},

			atOnceBuy() {
				//立即购买
				// console.log("立即购买"); // if (this.data.isStates == 0) return req.msg('活动还未开始');
				// if (this.data.isStates == 2) return req.msg('活动已结束');
				// if (this.data.start) return req.msg('活动已结束');

				let popup = this.pro;
				popup.salePrice = this.salePrice;
				popup.stock = this.pro.stock;
				this.setData({
					isShow: true,
					popup: popup
				});
			},

			//创建拼团
			createGroup() {
				req.isLogin().then(success => {});
				if (!req.getStorage('userInfo')) return false;
				// console.log(this.start);
				if (this.start) return req.msg(
					'活动已结束'); //state 1存在记录，2不存在，id创建团时存在则为已创建过团记录id，未创建则为-1    参与团id返回为传入的superiorId

				if (this.myActData.state == 1) {
					//存在拼团记录
					this.jumpGoGroup(this.myActData.id);
				} else {
					//不存在，去创建
					req.postRequest('/api/activity/carterActivityPurchaseRecords', {
						acpId: this.act.id,
						type: 3
					}, res => {
						// this.jumpGoGroup(res);
						// this.atOnceBuy(res)
						this.createGroupOrder(res);
					});
				}
			},

			createGroupOrder(aprId) {
				const params = {
					skuId: this.act.skuId,
					quantity: 1,
					productId: this.act.productId,
					aprId: aprId
				};

				if (this.merchant && this.merchant.type != 5) {
					params.merchantId = this.merchant.id;
				}

				if (this.merchant && this.merchant.type == 5) {
					params.merchantId = this.merchant.merchantDTO.id
					params.shopId = this.merchant.id;
				}

				if (this.act.id) params.activityId = this.act.id;
				req.postRequest('/api/purchase/direct/buy', params, res => {
					let redirect = '/product/subOrder/subOrder?ids=' + res;
					redirect += '&orderType=' + 4;
					redirect += '&aprId=' + aprId;
					redirect += '&activityId=' + this.act.id;

					if (params.merchantId) {
						redirect += '&merchantId=' + params.merchantId;
					}

					if (params.shopId) {
						redirect += '&shopId=' + params.shopId;
					}

					uni.navigateTo({
						url: redirect
					});
				});
			},

			//校验是否开团
			checkMyIsGroup() {
				req.getRequest('/api/activity/participationActivity', {
					acpId: this.act.id,
					actId: this.act.actId,
					productId: this.act.productId,
					type: 3,
					initOrPart: 1
				}, res => {
					this.setData({
						myActData: res
					});
				});
			},

			toGoGroup(event) {
				// req.isLogin().then(success => {
				// })
				const index = event.currentTarget.dataset.index;
				const type = event.currentTarget.dataset.type;
				let activityPurchaseRecord;

				if (type == 1) {
					activityPurchaseRecord = this.activityDot[index];
				} else {
					activityPurchaseRecord = this.activityPurchaseRecordListDTO[index];
				}

				// console.log(index, activityPurchaseRecord, type);
				this.jumpGoGroup(activityPurchaseRecord.id);
			},

			//跳入到平团详情
			jumpGoGroup(groupId) {
				app.globalData.openPage('activity/group/ptDetail/ptDetail?acid=' + this.act.id + "&id=" + groupId +
					"&merchantId=" +
					this.query.merchantId);
			},

			addActivityRemind() {

				req.postRequest('/api/activity/remind', {
					activityId: this.act.id
				}, res => {
					requsetmessage.remind();
					req.msg('订阅提醒成功');
					this.setData({
						isRemind: true
					});
				});
			},

			cancelActivityRemind(event) {
				if (req.header.appId == 'ZQ1VK5oc17I387E') {

				} else {
					req.postRequest('/api/activity/cancel/remind', {
						id: this.act.id
					}, res => {
						req.msg('取消提醒成功');
						this.setData({
							isRemind: false
						});
					});
				}
			},

			hidePopup() {
				this.setData({
					isShow: false
				});
			},
			hidePopupLogin(data) {
				this.isPopupLogin = false;
			},

			clickCollect() {
				let _ts = this;

				req.postRequest('/api/collect', {
					bindId: this.pro.id,
					type: 1
				}, data => {
					_ts.setData({
						'pro.isCollect': !_ts.pro.isCollect
					});
				});
			},

			goTop: function(e) {
				// 一键回到顶部
				if (uni.pageScrollTo) {
					uni.pageScrollTo({
						scrollTop: 0
					});
				} else {
					uni.showModal({
						title: '提示',
						content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
					});
				}
			},

			onShareTimeline() {
				let merchantId = '';
				let path = 'id=' + this.query.id + '&acid=' + this.query.acid + '&isShareTimeline=' + true;

				if (!req.getStorage('userInfo').id) {} else {
					path += '&userId=' + req.getStorage('userInfo').id;
				}
				let shopId = '';


				if (req.getStorage('MERCHANT') && req.getStorage('MERCHANT').id != null) {
					path += '&merchantId=' + req.getStorage('MERCHANT').id;
					merchantId = req.getStorage('MERCHANT').id;

					if (req.getStorage('smallShop') && req.getStorage('MERCHANT').id != null) {
						path += '&shopId=' + req.getStorage('smallShop').id;
						shopId = req.getStorage('smallShop').id;
						merchantId = req.getStorage('smallShop').merchantDTO.id;
					}
				}
				let url = '/activity/group/detail/detail?' + path;
				route.share(2, req.getStorage('userInfo').id, url, merchantId, shopId, 7, this.query.acid + '_' + this
					.query.id);
				return {
					title: (req.getStorage("userInfo").nickName ? req.getStorage("userInfo").nickName : '') + '邀请您参加拼团：' +
						this.pro.title,
					query: path,
					imageUrl: this.pro.pic
				}; // return {
				//   title: this.data.pro.title,
				//   imageUrl: this.data.pro.pic
				// }
			},

			// 获取参团活动总人数
			groupCount() {
				let param = {
					aprId: this.query.acid
				};
				req.getRequest('/api/activity/groupCount', param, data => {
					this.setData({
						count: data
					});
				});
			},

			// 是否开启小店
			isShop() {
				if (req.getStorage('distribution')) {
					dist = req.getStorage('distribution')
					this.setData({
						distr: dist
					})
					console.log(dist)
					if (dist.distributionSmallShopOpen == 1) {
						req.postRequest('/api/shopBase/isOpenShop', {}, data => {
							this.setData({
								isshop: data
							})
							console.log(data)
						})
					}
				}
			},
			addShop() { //添加到小店
				req.postRequest('/api/shopProduct/save', {
					productId: this.act.id,
					type: 4
				}, data => {
					this.act.isJoinShop = true;
					this.isHide = false;
				})
			},
			hidePop() { //添加到小店
				this.setData({
					isHide: true
				})
			},
			clickmore() {
				// let arrayShow = [];
				// let index = 0;
				// for (let i = index; i < index + 5; i++) {
				//   if (this.data.activityPurchaseRecordListDTO[i]) {
				//     arrayShow.push(this.data.activityPurchaseRecordListDTO[i]);
				//     index = i;
				//   }
				// }
				// index = index + 1;
				// if(arrayShow.length>=20){
				//   return req.msg("仅显示20个正在拼团的人")
				// }
				// this.setData({arrayShow:arrayShow})
				// this.groupItemTimer()
				// console.log("123",this.activityDot)
				this.getPage();
				this.setData({
					show: true
				});
			},

			eliminate() {
				this.setData({
					show: false
				});
			},

			getPage() {
				//获取系统信息:获取当前屏幕可见区域的宽和高
				let that = this;
				uni.getSystemInfo({
					success: function(res) {
						that.setData({
							"windowWidth": res.windowWidth,
							//可使用窗口宽度，单位px
							"windowHeight": res.windowHeight //可使用窗口高度，单位px

						});
						// console.log(res.windowWidth, that.windowWidth);
						// console.log(res.windowHeight, that.windowHeight);
					}
				});
			},

			showTab: function(e) {
				this.setData({
					tabIndex: e.detail
				});
			},
			scoreTab: function(e) {
				this.form.page = 0;
				this.setData({
					current: e.detail,
					['form.page']: 1
				});
			},
			freshenFun: function(e) {
				this.setData({
					freshen: e.detail
				});
			},

			// 获取品种保证
			getGuarantee() {
				return new Promise((data, rej) => {
					req.getRequest('/api/config', {}, res => {
						req.setStorage("configRes", JSON.stringify(res))
						this.about = res
						data(res)
						if (this.merchant && this.merchant.isDefault == 1 || this.query.acid) {
							// 切割;拿到数组，然后在过滤掉空值
							if (res.b2c_service_guarantee && res.b2c_service_guarantee != null) {
								this.setData({
									guarantee: res.b2c_service_guarantee.split(";").filter(it => {
										return it = it && it.trim();
									})
								});
							}
						} else {
							if (res.o2o_service_guarantee && res.b2c_service_guarantee != null) {
								this.setData({
									guarantee: res.o2o_service_guarantee.split(";").filter(it => {
										return it = it && it.trim();
									})
								});
							}
						} // if(res.Is_Store_Price_Stock){
						//   this.setData({Is_Store_Price_Stock:res.Is_Store_Price_Stock})
						// }
						if (res.is_open_shop) {
							this.is_open_shop = res.is_open_shop;
						}

						if (res.is_open_comments) {
							this.setData({
								is_open_comments: res.is_open_comments
							});
						} // this.setData({ show_membership_price: res.show_membership_price, Is_Store_Price_Stock: res.Is_Store_Price_Stock, is_open_shop: res.is_open_shop })

					});
				})
			}

		}
	};
</script>
<style>
	@import "./detail.css";
</style>
