<template>
  <view class="orderStudy" :style="{ height: contentHeight }">
   
    <u-empty v-if="g.length == 0" text="暂无相关学习卡" mode="list"></u-empty>
		
    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh);
        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="item" v-for="(x, i) in g" :key="i" @click="gocourse(x)">
		    <view class="ticket">
				<image mode="aspectFill" :src="x.CarouselImage" style="width: 100%; height: 100%;border-top-left-radius: 5px;border-bottom-left-radius: 5px;" ></image>
		    </view>
		    <view class="detail">
		      <view class="coupond">
		        <view class="name">{{x.GoodsName}}</view>
		    	<view class="rule">
					<text v-if="x.SurplusNum==-1">未开始</text>
					<text v-if="x.SurplusNum==0">已看完</text>
					<text v-if="x.SurplusNum>0">剩余{{x.SurplusNum}}章未学习</text>
				</view>
		        
		      </view>
		  
			  
		    </view>
		  </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>
    <!-- 取消提示 -->
    <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:{},
     
      mainColor: "",
      contentHeight: 0,
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
	  },
      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() {
    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.msg.SmallShopId = this.u.UserSmallShopId
	  this.request2(
	  	{
	  		url: '/api/AppletEducation/GetMyOrderStudyRecordPageList',
	  		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";
      }
    },
	gocourse(item){
		uni.navigateTo({
			url:'/pages/school/courseContent?id='+item.GoodsId+'&name='+item.GoodsName+'&cover_pic='+item.CarouselImage+'&index=0'
		})
	},
	reloadUserinfo() {
	  this.u = uni.getStorageSync("mall_UserInfo");
	  // this.showAuth=false;
	  this.init();
	},
	//关闭登录窗口
	gbAuth(){
		uni.navigateBack()
	},	
  },
};
</script>
<style>
.orderStudy {
  width: 100%;
  height: 100%;
  background: #FFF;
  position: relative;
}

.orderStudy .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;
}
.orderStudy .details{
	padding: 15px;
	display: flex;
	flex-direction: column;
	position: relative;
}
.orderStudy  .item {
  display: flex;
  margin-bottom: 10px;
  align-items: flex-start;
  background: #fff;
  border-radius: 5px;
  box-shadow:0 4px 6px 1px rgba(76, 76, 76, 0.1);
}
.orderStudy .details .item .ticket {
	width: 104px;
	height: 78px;
}

.orderStudy .details .item .detail {
  width: 1px;
  flex: 1;
  background: #fff;
  padding: 10px;
  display: flex;
  align-items: center;
}
.orderStudy .details .item .detail .coupond {
  flex: 1;
}
.orderStudy .details .item .detail .coupond .name {
  font-size: 13px;
  font-weight: 600;
  color: #000;
  overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}
.orderStudy .details .item .detail .coupond .date {
  margin-top: 5px;
  font-size: 11px;
  color: #777;
}
.orderStudy .details .item .detail .coupond .rule{
    font-size: 11px;
    color:#777;
    margin-top: 5px;
	overflow: hidden;
	  text-overflow: ellipsis;
	  display: -webkit-box;
	  -webkit-line-clamp: 1;
	  -webkit-box-orient: vertical;
}
.orderStudy .details .item .detail .chosen {
  width: 60px;
  height: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  border-radius: 4px;
  color: #FFF;
  
}










</style>
