<template>
  <view class="coupondetailsStyle" :style="{ height: contentHeight }">
		<view class="cd_box">
			<Text class='cd_name'>
				{{g.Name}}
			</Text>
			<!-- <Text class='sub_price'>
				￥{{g.sub_price}}
			</Text> -->
			<view style="display: flex;align-items: flex-end;">
				  <Text style='font-size: 32px;'>{{ g.DiscountsPrice }} </Text>
				  <Text style='font-size: 14px;'>{{g.CouponType==2?'折':""}}</Text> 
			</view>
			<Text class='condition'>
				满{{g.MinConsumePrice }}可用
			</Text>						
			<!-- <Text v-if='g.type==1'>优惠上限:￥{{Number(g.MaxDiscountsPrice) }}</Text> -->

			<view v-if='type==2 && g.IsReceive==0' class="receive" :style="{'background':mainColor}" @click="receive(g.CouponId)">
				<Text>
					 立即领取
				</Text>
			</view>
			<view v-if='type==1 || g.IsReceive==1' class="gouse"  @click="gouseUrl(g)">
				<Text>
					去使用
				</Text>
			</view>
			<view style="width: 100%;border-top: 1px dashed #f5f5f5;margin: 10px 0;"></view>
			<Text class='c_name' style='margin-top: 25px;'>有效期</Text>
			
			<Text class='cd_content' v-if='g.IndateType==1'>领取后{{g.IndateDay}}天内有效</Text>
			<Text class='cd_content' v-if='g.IndateType==2'>{{g.StartDate}}-{{g.EndDate}}</Text>
			<!-- <Text class='cd_content' >{{g.StartDate}}-{{g.EndDate}}</Text> -->
			<Text class='c_name' style='margin-top: 1px;'>使用规则</Text>
						
			<Text class='cd_content' v-if='g.UseType==1'>适用类别: <Text v-for="(item, index) in g.ProductList" :key="index">{{item.Relevance}}</Text> </Text>
			<Text class='cd_content' v-if='g.UseType==2'>适用商品: <Text v-for="(item, index) in g.ProductList" :key="index">{{item.Relevance}}</Text> </Text>
			<Text class='cd_content' v-if='g.UseType==3'>适用范围:全场通用</Text>
			<Text class='cd_content' v-if='g.UseType==4'>适用方式:当面付</Text>
			<Text class='c_name' style='margin-top: 1px;'>使用说明</Text>
			<Text class='cd_content'>{{g.Describe}}</Text>
		</view>

   
  </view>
</template>

<script>

export default {

  data() {
    return {
      pageTitle: "优惠券详情",
      mainColor: "",
      contentHeight: 0,
      g: [],
      loading: false,
	  coupon_id:0,
	  isreceive:false,
	  type:0
      
    };
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
  },
  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) {	
	  this.type = option.type
	  let item = JSON.parse(decodeURIComponent(option.item))
		this.g = item
    
  },
  methods: {
 
	init(coupon_id) {
	  uni.showNavigationBarLoading();
	  let h = this.apiheader();
	  this.request(
	    {
	      url: "",
	      header: h,
	      data: {
	        r: "api/coupon/detail",
			coupon_id:coupon_id
	      },
	    },
	    (res) => {
			this.g = res.data.list
		  uni.hideNavigationBarLoading();
	    }
	  );
	},
	receive(id){
		this.request2(
		{
			url: '/api/AppletUser/GrantCoupon',
			data: {
				CouponId:id
			}
		},
		  
		  (res) => {
			  if(res.resultCode==1){
			  	
			  	uni.showToast({
			  		title: res.message,
			  		icon: "none"
			  	});
				this.g.IsReceive=1;
			  }
			 
		  } 
		);
	},
	gouseUrl(g){
		let id
		if(this.type == 1){
			id = g.ID
			
		}else if(this.type == 2){
			id = g.CouponId
		}
		uni.redirectTo({ url: '/pages/goods/list?coupon_id='+ id});
	}
  },
 
};
</script>
<style>
.coupondetailsStyle {
  width: 100%;
  height: 100%;
  background: #f3f4f6;
  padding-top:10px ;
  
}
.coupondetailsStyle .cd_box{
	width: 94%;
	border-radius: 10rpx;
	background: #fff;
	
	margin-left: 3%;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 10px;
}
.cd_box .cd_name{
	font-size: 14px;
	color: #82848a;
	margin-top: 30px;
}
.cd_box .sub_price{
	font-size: 32px;
	margin-top: 10px;
}
.cd_box .condition{
	font-size: 16px;
	margin-top: 5px;
}
.cd_box .receive{
	width: 130px;
	height: 30px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 15px;
	color: #fff;
	margin-top: 15px;
	border-radius: 15px;
}
.cd_box .gouse{
	width: 130px;
	height: 30px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 15px;
	color: #fff;
	margin-top: 15px;
	border-radius: 15px;
	background: #6995EE;
}
.cd_box .c_name{
	width: 90%;
	font-size: 14px;
	color: #82848a;
}
.cd_box .cd_content{
	padding: 15px 0;
	width: 90%;
	font-size: 15px;
}
</style>
