<style>
	.viewContent{
		width:100%;
		height:100%;
		padding:15px;
	}
	.avtive_TopImg{
		width:100%;
		height:200px;
		border-radius: 6px;
		overflow: hidden;
		box-shadow:0 6px 10px 1px #F2F2F2;
	}
	.active_Title{
		color:#111111;
		font-size:13px;
		margin:15px 0;
		font-weight: bold;
	}
	.avtice_Sperate{
		padding:3px 8px;
		font-size:13px;
		display:inline-block;
		margin-right:8px;
		color:#FF4048;
		text-align: center;
		border:1px solid #FF4048;
	}
	.active_Inner{
		color:#777777;
		font-size:13px;
	}
	.active_PrizeImage{
		margin:10px 0 20px 0;
		width:100%;
		height:270px;
	}
	.avtive_Title{
		font-size: 16px;
		color:#111111;
		font-weight: bold;
		margin-top:10px;
	}
	.active_RangeName{
		padding:3px 8px;
		display: inline-block;
		border:1px solid #FF4048;
		color:#FF4048;
		font-size: 13px;
		margin-right:8px;
	}
	.active_good{
		width: 100%;
		padding-bottom:10px ;
		overflow-x: auto!important;
		display: flex;
		flex-direction: row;
	}
	.active_good-s{
		width: 100%;
		padding-bottom:10px ;
		display: flex;
		flex-direction: column;
	}
	.active_good_item{
		width: 100px;
		margin-right: 15px;
		border-radius: 4px;
		box-shadow:0 6px 10px 1px #F2F2F2;
		
	}
	.active_good_item-s{
		width: 100%;
		height: 80px;
		border-radius: 5px;
		box-shadow:0 6px 10px 1px #F2F2F2;
		background: #FFF;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 10px;
	}
	.active_text{
		width: 100%;
		padding:0 10px;
		font-size: 12px;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		
	}
	.active_text-s{
		width: 1px;
		flex: 1;
		height: 80px;
		padding: 10px;
		font-size: 12px;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 4;
		-webkit-box-orient: vertical;
		
	}
</style>
<template>
  <view class="activeContent" :style="{ height: contentHeight }">
    <view
      style="
        height: calc(100vh );
        width: calc(100vw);
		padding-bottom: 10px;
      "
    >
     <view class="viewContent">
		 <view class="avtive_TopImg">
			 <img :src="dataList.CoverImage" mode='aspectFill' style="width:100%;height:100%;border-radius: 6px;" alt=""/>
		 </view>
		 <view class="avtive_Title">
			 {{dataList.ActivityName}}
		 </view>
		 <view class="active_Title">活动规则</view>
		 <view class="active_Inner">
			 <view v-if="dataList.Type==1" >
				 活动期间累计订单数量需满足{{dataList.OrderNum}}单
			 </view>
			 <view v-if="dataList.Type==2">
				 活动期间累计订单金额需满足{{dataList.OrderMoney}}元
			 </view>
			 <view v-if="dataList.Type==3">
				 活动期间累计商品数量需满足{{dataList.GoodsNum}}个
			 </view>
		 </view>
		 <view class="active_Title">活动对象</view>
		 <view>
		    <text class="avtice_Sperate" v-if="dataList.Tier==0 && dataList.ActiveObject==1">全部分销商</text>
			<text class="avtice_Sperate" v-if="dataList.Tier==1 && dataList.ActiveObject==1">一级分销商</text>
			<text class="avtice_Sperate" v-if="dataList.Tier==2 && dataList.ActiveObject==1">二级分销商</text>
			<text class="avtice_Sperate" v-if="dataList.Tier==3 && dataList.ActiveObject==1">三级分销商</text>
			<text class="avtice_Sperate" v-if="dataList.Tier==0 && dataList.ActiveObject==2">所有用户</text>
			<text class="avtice_Sperate" v-if="dataList.Tier==1 && dataList.ActiveObject==2">一级分销</text>
			<text class="avtice_Sperate" v-if="dataList.Tier==2 && dataList.ActiveObject==2">二级分销</text>
			<text class="avtice_Sperate" v-if="dataList.Tier==3 && dataList.ActiveObject==2">三级分销</text>
		 </view>
		 <view>
			 
		 </view>
		 <view class="active_Title">活动类型</view>
		 <view class="active_Inner">
			<view v-if="dataList.RangeType==1">活动分类</view>
			<view v-if="dataList.RangeType==2">指定商品</view>
		 </view>
		 <view style="margin-top:10px;" v-if="dataList.RangeType==1">
			<text v-for="item in dataList.RangeList" class="active_RangeName" @click="goitemize(item)">{{item.Name}}</text>
		 </view>
		 <view style="margin-top:10px;" v-if="dataList.RangeType==2">
			<view class="active_good" v-if="dataList.RangeList.length>3">
				<view class="active_good_item" v-for="(item,index) in dataList.RangeList" @click="goGood(item.Id)">
					<image :src="item.Image"
					 style="width: 100px;height: 100px;border-top-left-radius:4px ;border-top-right-radius:4px "></image>
					 <view class="active_text" >
						{{item.Name}}
					 </view>
				</view>
			</view>
			<view class="active_good-s" v-if="dataList.RangeList.length>0 && dataList.RangeList.length<4  ">
				<view class="active_good_item-s" v-for="(item,index) in dataList.RangeList" @click="goGood(item.Id)">
					<image :src="item.Image"
					 style="width: 120px;height: 80px;border-radius: 5px; "></image>
					 <view class="active_text-s" >
						{{item.Name}}
					 </view>
					 
				</view>
			</view>
		 </view>
		 <view class="active_Title">活动有效期</view>
		 <view class="active_Inner">
			 <view>{{dataList.StartTime}}<text style="margin:0 5px">至</text>{{dataList.EndTime}}</view>
		 </view>
		<!-- <view class="active_Title">领取方式</view>
		 <view class="active_Inner">
			 <text v-if="dataList.Way==1">线上</text>
			 <text v-if="dataList.Way==2">线下</text>
		 </view> -->
		 <view class="active_Title">兑换期限</view>
		 <view class="active_Inner">
			 <view>截止<text style="margin:0 5px">{{dataList.ReceiveTime}}</text>之前 
				<!-- <text style="margin-left: 10px;">兑换方式:{{dataList.Way==1?'线上':'线下'}}</text> -->
			 </view>
		 </view>
		 <view class="active_Title">活动说明</view>
		 <view class="active_Inner">
			 <view>{{dataList.Description}}</view>
		 </view>
		 <view class="active_Title">活动奖品</view>
		 <view class="active_Inner">
			 <view>{{dataList.PrizeName}}</view>
		 </view>
		 <view class="active_PrizeImage">
			 <img :src="dataList.PrizeImage" mode='aspectFill' style="width:100%;height:100%;margin-bottom: 50px;" alt=""/>
		 </view>
	 </view> 

   
    <!-- 取消提示 -->
    <u-toast ref="uToast" />
   <auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth>
   <coupon v-if="showCoupons" :coupon-message="couponMessage" :cform="ComeFrom" @goLook="goLook" @closeBtn="closeBtn"></coupon>
	</view>
  </view>
</template>

<script>
import auth from "@/components/auth/index.vue";
import coupon from "@/components/coupons/coupons";
export default {
  components: {
    auth,
	coupon
  },
  data() {
    return {
      pageTitle: "活动内容",
      showAuth:false,
	  u:{},
	  show:false,
     
      mainColor: "",
      contentHeight: 0,
	  msg:{
	     ActivityId:0
	  },
      dataList: {},
      loading: false,
	  showCoupons: false,
	  couponMessage: "",
    };
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
	this.useName = uni.getStorageSync("mall_UserInfo")?uni.getStorageSync("mall_UserInfo").Name:''
  },
  onShareTimeline() {
  	setTimeout(() => {
  		// console.log("分享朋友圈调用");
  		this.getReceive();
  	}, 2500);
  	let uid = uni.getStorageSync("mall_UserInfo") ?
  		uni.getStorageSync("mall_UserInfo").UserId :
  		0;
  	if (uid == 0) {
  		uid = uni.getStorageSync("pid") ? uni.getStorageSync("pid").pid : 0;
  	}
  	let SmallShopId = uni.getStorageSync("mall_UserInfo") ?
  		uni.getStorageSync("mall_UserInfo").SmallShopId :
  		0;
  	if (SmallShopId == 0) {
  		//如果微店id为0 去找所属微店id
  		SmallShopId = uni.getStorageSync("mall_UserInfo") ?
  			uni.getStorageSync("mall_UserInfo").UserSmallShopId :
  			0;
  	}
  
  	let Up = uni.getStorageSync("mall_UserInfo") ? uni.getStorageSync("mall_UserInfo").UserPageType : 0;
  	let activityid = this.msg.ActivityId;
  	let img = this.dataList.CoverImage?this.dataList.CoverImage:'';
  	let title = this.dataList.ActivityName? this.dataList.ActivityName:'活动';
  	return {
  		title: title,
  		query: "user_id=" + uid + "&SmallShopId=" + SmallShopId + "&Up=" + Up+ "&activityid=" + activityid,
  		imageUrl: img,
  	};
  },
  onShareAppMessage(res) {
  	setTimeout(() => {
  		// console.log("分享朋友调用");
  		this.getReceive();
  	}, 2500);
  	let uid = uni.getStorageSync("mall_UserInfo") ?
  		uni.getStorageSync("mall_UserInfo").UserId :
  		0;
  	if (uid == 0) {
  		uid = uni.getStorageSync("pid") ? uni.getStorageSync("pid").pid : 0;
  	}
  	let SmallShopId = uni.getStorageSync("mall_UserInfo") ?
  		uni.getStorageSync("mall_UserInfo").SmallShopId :
  		0;
  	if (SmallShopId == 0) {
  		//如果微店id为0 去找所属微店id
  		SmallShopId = uni.getStorageSync("mall_UserInfo") ?
  			uni.getStorageSync("mall_UserInfo").UserSmallShopId :
  			0;
  	}
  	let Up = uni.getStorageSync("mall_UserInfo") ? uni.getStorageSync("mall_UserInfo").UserPageType : 0;
  	let activityid = this.msg.ActivityId;
  	let img = this.dataList.CoverImage?this.dataList.CoverImage:'';
  	let title = this.dataList.ActivityName? this.dataList.ActivityName:'活动';
	console.log("/pages/index/index?user_id=" + uid + "&SmallShopId=" + SmallShopId + "&Up=" + Up+ "&activityid=" + activityid +'&JumpType=11')
  	return {
  		title: title,
  		path: "/pages/index/index?user_id=" + uid + "&SmallShopId=" + SmallShopId + "&Up=" + Up+ "&activityid=" + activityid +'&JumpType=11',
  		imageUrl: img,
  	};
  },
  mounted() {
    let currentPages = getCurrentPages();
    let u = "/" + currentPages[currentPages.length - 1].route;
    let pages = wx.getStorageSync("basedata")
      ? wx.getStorageSync("basedata").bar_title
      : [];
    pages.forEach((x) => {
      if (x.value == u) {
        this.pageTitle = x.new_name ? x.new_name : x.name;
      }
    });
    uni.setNavigationBarTitle({
      title: this.pageTitle,
    });
  },
  onLoad: function (option) {   
	  if(option && option.ActivityId){
		  this.msg.ActivityId = option.ActivityId;
	  }
	console.log(option,'optionss');
    this.u = uni.getStorageSync("mall_UserInfo");
    if (!this.u) {
      this.u = {
    	nickName: "未登录",
    	avatarUrl: ""
      };
      this.showAuth = true;
    }	else{
    	this.init();
    }
  },
  methods: {
    init() {
	  this.request2(
	  	{
	  		url: '/api/AppletOrder/GetGoosdActivityInfo',
	  		data: this.msg
	  	},
	  	res => {
	  		if(res.resultCode==1){
				console.log(res,'数据');
				this.dataList = res.data;
	  		}
	  	}
	  );
    },
	goGood(id){
		uni.navigateTo({
			url: "/pages/goods/goods?GoodsId=" +id
		});
	},
	goitemize(item){
		uni.navigateTo({ url: '/pages/goods/list?coupon_id='+ item.Id+'&UseType=1' });
	},
	getReceive() {
		//分享进入调取领券接口
		// 1-分享，2-购买并付款
		this.request2({
				url: "/api/AppletUser/ShareCoupon",
				data: {
					TriggerType: 1,
				},
			},
			(res) => {
				console.log(res, "res");
				if (res.couponResultCode == 1) {
					this.couponMessage = res.couponMessage;
					this.showCoupons = true;
				}
				
			},
			(failed)=>{
				
			}
		);
	},
	goLook() {
		this.showCoupons = false;
	},
	closeBtn() {
		this.showCoupons = false;
	},
	reloadUserinfo() {
	  this.u = uni.getStorageSync("mall_UserInfo");
	  this.init();
	},
	gbAuth(){
		uni.navigateBack()
	},
  },
};
</script>
