<template>
  <view class="cardList" :style="{ height: contentHeight }">
    <u-tabs
      :list="list"
      :is-scroll="false"
      :current="msg.UseState"
      @change="change"
      :active-color="mainColor"
    ></u-tabs>
    <u-empty v-if="g.length == 0" text="暂无相关套餐卡" mode="coupon"></u-empty>
		
    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh - 50px);
        width: calc(100vw);
        overflow: hidden;
		padding-bottom: 50px;
      "
    >
      <scroll-view
        :scroll-y="true"
        :enable-back-to-top="true"
        :enable-flex="true"
        @scrolltolower="lower"
        :style="{ height: '100%' }"
      >
        <view class="details">
			<view class="cd-t-box" v-for="(x, i) in g" :key="i" @click="gocoupon(x)"
				:style="{'background-image': msg.UseState ==0?'url(https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/cpoun.png)':'url(https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/cpounNo.png)'}"
			>
				<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<text :style="{'font-size': '12px','color':msg.UseState ==0? 'rgba(239, 220, 203, 0.6)':'rgba(153, 153, 153, 0.6)'}">{{x.Name}}</text>
					<view class="receivebtn"  v-if="msg.UseState ==0" @click.stop="gouseUrl(x)">去使用</view>
				</view>
				
				<text  class="cd-tt" :style="{'color':msg.UseState ==0? '#EFDCCB':'#999999'}">{{x.Describe}}</text>
				<text :style="{'font-size': '13px','color':msg.UseState ==0? '#EFDCCB':'#999999'}">核销次数:{{x.HeXiao}}次</text>
				<view class="setmeal-pl" v-if="msg.UseState ==0" style="left: -12px;"></view>
				<view class="setmeal-pl" v-if="msg.UseState ==0" style="right: -12px;"> </view>
				<image v-if="msg.UseState==1" mode="aspectFill" class="imgs" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/studycardsy.png" ></image>
				<image v-if="msg.UseState==2" mode="aspectFill" class="imgs" src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/studycardgq.png"  ></image>
			</view>
			  
        </view>
     
		<u-loadmore
		  :status="status"
		  :load-text="loadText"
		  :font-size="24"
		  :margin-top="20"
		  :margin-bottom="20"
		  bg-color="#FFF"
		/>
      </scroll-view>
    </view>
<!-- 	<view style="width: 100%;height: 50px;background: #FFFFFF;display: flex;align-items: center;justify-content: center;position: absolute;left: 0;bottom: 0;border-top: 1px solid #E1E1E1;" @click="goUrl">
			  <Text>去领取套餐卡</Text>
	</view> -->
    <!-- 加载中 -->
    <view class="loading" v-if="loading">
      <u-loading mode="flower" size="48">></u-loading>
      <Text style="color: #fff; margin-top: 10rpx;">加载中...</Text>
    </view>
    <!-- 取消提示 -->
    <u-toast ref="uToast" />
   <auth v-if="showAuth" @changeuserinfo="reloadUserinfo" @gbAuth= 'gbAuth'></auth>
  </view>
</template>

<script>
import auth from "@/components/auth/index.vue";
export default {
  components: {
    auth
  },
  data() {
    return {
      pageTitle: "套餐卡",
      showAuth:false,
	  u:{},
      list: [
        { name: "未使用" },
        { name: "已使用" },
        { name: "已过期" },
      ],
      mainColor: "",
      contentHeight: 0,
      
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
		  UseState:0
	  },
      page_count: 1,
      g: [],
      loading: false,
	  status: "loadmore",
	  loadText: {
	    loadmore: "轻轻上拉，加载更多",
	    loading: "努力加载中",
	    nomore: "没有更多了",
	  },
    };
  },
  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.u = uni.getStorageSync("mall_UserInfo");
    if (!this.u) {
      this.u = {
    	nickName: "未登录",
    	avatarUrl: ""
      };
      this.showAuth = true;
    }	else{
    	this.init();
    }
  },
  methods: {
    change(index) {
		
      this.msg.UseState = index;
      this.msg.pageIndex = 1;
      this.g = [];
      this.loading = true;
      this.init();
    },
    init() {
      
	  this.request2(
	  	{
	  		url: '/api/AppletStores/GetMemberCouponPageList',
	  		data: this.msg
	  	},
	  	res => {
	  		if(res.resultCode==1){
	  				this.loading = false;
	  				this.g = this.g.concat(res.data.pageData);
					 this.page_count = res.data.pageCount;
					 if (this.page_count == 1) {
					   this.status = "nomore";
				}
	  		}
	  	}
	  );
    },
    lower(e) {
      if (this.msg.pageIndex < this.page_count) {
        this.msg.pageIndex++;
		this.status = "loading";
        this.init();
      } else {
        
		this.status = "nomore";
      }
    },
	reloadUserinfo() {
	  this.u = uni.getStorageSync("mall_UserInfo");
	  // this.showAuth=false;
	  this.init();
	},
	//关闭登录窗口
	gbAuth(){
		uni.navigateBack()
	},
	gouseUrl(g){
		let data = []
		if(g.UseType==1 || g.UseType==2){
			g.ProductList.forEach(x=>{
				data.push(x.ProductId)
			})
			let id = data.toString()
			uni.redirectTo({ url: '/pages/goods/list?coupon_id='+ id+'&UseType='+g.UseType });
		}else{
			uni.redirectTo({ url: '/pages/goods/list'});
		}
	},
	gocoupon(item){//优惠券详情
		uni.navigateTo({
			url: "/pages/reserve/personal/couponDetail?ID="+item.ID,
		})
	},
	goUrl(){//领取套餐卡
		uni.navigateTo({
		  url: "/pages/reserve/personal/receivecard"
		});
	}
  },
};
</script>
<style>
.cardList {
  width: 100%;
  height: 100%;
  background: #FFF;
  position: relative;
}

.cardList .loading {
  width: 180rpx;
  height: 180rpx;
  background: #000000;
  opacity: 0.7;
  border-radius: 10rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: fixed;
  left: 50%;
  top: 30%;
  margin-left: -100rpx;
  z-index: 999;
}
.cardList .details{
	padding: 15px;
	display: flex;
	flex-direction: column;
}
.cardList .receivebtn{
	height: 25px;
	width: 60px;
	font-size: 11px;
	color: #221818;
	border-radius: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #FFF;
}



.cardList .details .imgs{
	width: 55px; height: 52px;
	position: absolute;top: 0px;
	right: 0px;
}
	.cardList .cd-t-box{
		width: 100%;
		height: 115px;
		
		background-repeat: no-repeat;
		background-size: cover ;
		padding:15px 20px;
		color:#EFDCCB ;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		border-radius: 6px;
		position: relative;
		box-shadow:0 4px 10px 1px #D2D2D2;
		margin-bottom: 15px;
	}
	.cardList .cd-tt{
		width: 100%;
		display: inline-block;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		line-clamp: 2;
		-webkit-box-orient: vertical;
		font-size: 15px;
		
	}
	.cardList .setmeal-pl{
		position: absolute;
		top:45.5px;
		width: 24px;
		height: 24px;
		border-radius: 12px;
		background: #FFF;
		
	}

.cardList .details .imgs{
	width: 55px; height: 52px;
	position: absolute;top: 0px;
	right: 0px;
}






</style>
