<template>
  <view class="myVipList" :style="{ height: contentHeight }">

    <u-empty v-if="g.length == 0" text="暂无相关会员卡" mode="coupon"></u-empty>
		
    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh );
        width: calc(100vw);
        overflow: hidden;
		padding-bottom: 10px;
      "
    >
      <scroll-view
        :scroll-y="true"
        :enable-back-to-top="true"
        :enable-flex="true"
        @scrolltolower="lower"
        :style="{ height: '100%' }"
      >
        
		<view class="details" v-for="(x, i) in g" :key="i" @click="gocoupon(x)">
			<view class="d-t-box">
				<image mode="aspectFill" :src="x.CardBagIco" style="width: 100%;height: 100%;border-radius: 6px;"></image>
				<view class="bj"></view>
				<view class="btext">
					<text class="btext-l">{{x.CardNo}}</text>
					<text class="btext-r">{{x.Name}}</text>
				</view>
				<view class="bj2" v-if="x.IsOver==1"></view>
				<image   mode="aspectFill" v-if="x.IsOver==1" 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 class="loading" v-if="loading">
      <u-loading mode="flower" size="48">></u-loading>
      <Text style="color: #fff; margin-top: 10rpx;">加载中...</Text>
    </view>
	 <view v-if="show==true" class="pu" @click="show=false">
		 <view class="pu-box">
			 <image mode="widthFix" :src="selectobj.CardBagIco" style="width: 100%;height: 100%;"></image>
			 <view class="pu-btoom">
				 <view>{{selectobj.CardNo}}</view>
				 <view style="margin-top: 12px;font-size: 12px;display: flex;flex-direction: row;align-items: center;">
				 	<view style="margin-right: 10px;max-width: 100px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">{{useName}}</view>
				 		{{selectobj.EndDate.split('T')[0].split('-')[1]+'/'+selectobj.EndDate.split('T')[0].split('-')[0].toString().substr(2, 2)}}
				 </view>
			 </view>
		 </view>
	 </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:{},
	  show:false,
     
      mainColor: "",
      contentHeight: 0,
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
	  },
      page_count: 1,
      g: [],
      loading: false,
	  status: "loadmore",
	  loadText: {
	    loadmore: "轻轻上拉，加载更多",
	    loading: "努力加载中",
	    nomore: "没有更多了",
	  },
	  selectobj:{},
	  useName:'',
    };
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
	this.useName = uni.getStorageSync("mall_UserInfo")?uni.getStorageSync("mall_UserInfo").Name:''
  },
  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: {
   
    init() {
      
	  this.request2(
	  	{
	  		url: '/api/AppletStores/GetMemberCardBagList',
	  		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()
	},
	gocoupon(item){
		this.selectobj = item;
		this.show=true
		// if(item.IsOver==0){
		// 	uni.navigateTo({
		// 		url: "/pages/reserve/personal/vipDetail?ID="+item.ID,
		// 	})
		// }
		
	}
	
	
  },
};
</script>
<style>
.myVipList {
  width: 100%;
  height: 100%;
  background: #FFF;
  position: relative;
}

.myVipList .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;
}
.myVipList .details{
	width: 100%;
	padding:0 15px;
	margin-top: 15px;
	display: flex;
	flex-direction: column;
	align-items: center;
}
.d-t-box{
		width: 100%;
		height: 83px;
		border-radius: 6px;
		overflow: hidden;
		background-repeat: no-repeat;
		background-size: cover;
		position: relative;
	}
.bj {
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		background: rgba(0, 0, 0, 0.2);
		border-radius: 6px;
	}
	.btext{
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		font-size: 12px;
		padding: 15px;
		color: #FFF;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}
	.bj2{
		width: 100%;
		height: 100%;
		position: absolute;
		left: 0;
		top: 0;
		background: rgba(153, 153, 153, 0.6);
		border-radius: 6px;
	}


	.imgs{
		width: 55px; height: 52px;
		position: absolute;top: 0px;
		right: 0px;
	}
	.btext-l{
		width: 1;
		flex:1;
		margin-right: 20px;
		font-size: 18px;
	}
	.btext-r{
		width: 100px;
		text-align: right;
		overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
		
	}
	.myVipList .pu{
		width: 100%;
		height: 100%;
		background: rgba(255, 255, 255, 0.9);
		position: fixed;
		left: 0;
		top: 0;
		z-index: 999;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.pu-box{
		width: 100%;
		/* height: 230px; */
		position: relative;
	}
	.pu-btoom{
		width: 100%;
		height: 100%;
		color: #FFF;font-size: 15px;
		position: absolute;
		padding: 15px;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column;
		justify-content: flex-end;
	}

</style>
