<style>
	.myRewardContent{
		height:auto;
		width:100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.reward_ImgDiv{
		width:120px;
		height:90px;
		border-radius: 5px;
		overflow: hidden;
		box-shadow: 2px 2px 8px #d2d2d2;
	}
	.reward_ImgDiv image{
		width:100%;
		height:100%;
	}
	.rewardTop{
		width:120px;
		color:#111111;
		font-size:13px;
	}
	.reDuihuan{
		color:#888888;
		font-size:12px;
	}
	.rewardStatus{
		padding:2px 10px;
		border:1px solid #999999;
		color:#999999;
		border-radius: 20px;
		font-size:13px;
	}
	.Chaochu{
		width:100%;
		white-space:nowrap;
		overflow:hidden;
		text-overflow:ellipsis;
		margin-top:5px;
	}
	.onlineWay{
		color:#FF4048;
		border:1px solid #FF4048;
		padding:2px 10px;
		border-radius: 20px;
		font-size:13px;
	}
</style>
<template>
  <view class="myreward" :style="{ height: contentHeight }">
    <u-empty v-if="dataList.length == 0" text="暂无奖励" mode="coupon"></u-empty>
    <view
     v-if="dataList.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 dataList" :key="i">
			<view class="myRewardContent">
				<view style="width:calc(100vw - 30px);display: flex;">
					<view class="reward_ImgDiv">
					  <image :src="x.PrizeImage" alt="" mode='aspectFill'/>
					</view>
					<view style="padding-left:10px;flex: 1;width: 1px;">
						<view class="rewardTop Chaochu">{{x.ActivityName}}</view>
						<view class="reDuihuan Chaochu" style="font-family: aa;" >截止{{x.ReceiveTime}}之前兑换</view>
						<view class="reDuihuan Chaochu">{{x.PrizeName}}</view>
						<view style="width:calc(100vw - 110px);display: flex;width: 100%;flex-direction: row;align-items: center;justify-content: space-between;">
							<view class="reDuihuan" style="display:flex;flex-direction: row;align-items: center;font-family: aa;">
								<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/tiaoxingma.png" style="width: 13px;height: 10px;margin-right: 5px;"></image>
							{{x.Code}}</view>
							<view>
								<view class="rewardStatus" v-if="x.Way==2">
									<text v-if="x.State==1">未兑换</text>
									<text v-if="x.State==2">已兑换</text>
									<text v-if="x.State==3">已过期</text>
								</view>
								<view v-if="x.Way==1" class="onlineWay">
									<text v-if="x.State==1">立即兑换</text>
								</view>
							</view>
						</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:{},
	  show:false,
     
      mainColor: "",
      contentHeight: 0,
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
		  State:0  //状态 1未兑换 2已兑换 3已过期	
	  },
      page_count: 1,
      dataList: [],
      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/AppletOrder/GetGoodsMyActivityPrizeList',
	  		data: this.msg
	  	},
	  	res => {
	  		if(res.resultCode==1){
				console.log(res,'数据');
				this.loading = false;
				this.dataList = this.dataList.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()
	},
  },
};
</script>
<style>
.myreward {
  width: 100%;
  height: 100%;
  background: #FFF;
  position: relative;
}

.myreward .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;
}
.myreward .details{
	width: 100%;
	padding:0 15px;
	margin-top: 15px;
	display: flex;
	flex-direction: column;
	align-items: center;
}
</style>
