<template>
  <view class="couponStyle" :style="{ height: contentHeight }">
    <u-tabs
      :list="list"
      :is-scroll="false"
      :current="current"
      @change="change"
      :active-color="mainColor"
      
    ></u-tabs>
    <u-empty v-if="g.length == 0" text="暂无相关卡券" mode="order"></u-empty>
	<!-- <error v-if="g.length == 0" type="2" ></error> -->

    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh - 50px);
        width: calc(100vw);
        overflow: hidden;
        padding-top: 10px;
      "
    >
      <scroll-view
        :scroll-y="true"
        :enable-back-to-top="true"
        :enable-flex="true"
        @scrolltolower="lower"
        :style="{ height: '100%' }"
      >
        <view class="orderList">
          <!-- TODO 样式暂无知道啥样的 -->
        </view>
        <u-divider
          contentPosition="center"
          v-if="isover"
          :margin-top="20"
          :margin-bottom="20"
          bg-color="#f3f4f6"
          >没有更多卡券了</u-divider
        >
      </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= 'goback'></auth>
  </view>
</template>

<script>
import error from '../../../components/error/error.vue';
import auth from "../../../components/auth/index.vue";
export default {
  components: {
    error,
	auth
  },
  data() {
    return {
      pageTitle: "我的卡券",
      current: 0,
	  showAuth: false,
      list: [
        { name: "未使用" },
        { name: "已使用" },
        { name: "已过期" },
      ],
      mainColor: "",
      contentHeight: 0,
      page: 1,
      page_count: 1,
      g: [],
      loading: false,
      showModal: false,
      item: "",
      index: 0,
      isover: false,
	  u:{},
    };
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
	this.u = uni.getStorageSync("mall_UserInfo");
	if (!this.u) {
	  this.u = {
		nickName: "未登录",
		avatarUrl: ""
	  };
	  this.showAuth = true;
	}	else{
		this.loading = true;
		this.init();
	}
  },
  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,
    });
  },
  methods: {
    change(index) {
		
      this.current = index;
      this.page = 1;
      this.g = [];
      this.loading = true;
      this.init();
    },
    init() {
      this.isover = false;
      let h = this.apiheader();
	  this.loading = false;
    //   this.request(
    //     {
    //       url: "",
    //       header: h,
    //       data: {
    //         r: "api/card/user-card",
    //         status: this.current+1,
    //         page: this.page,
    //       },
    //     },
    //     (res) => {
    //       this.loading = false;
		  
		  // if(res.data.list.length>0){
			 //  this.g = this.g.concat(res.data.list);
			 // // TODO 这里没返一共多少页 注意下
			 // // this.page_count = res.data.pagination.page_count;
			 // // if (this.page_count == 1) {
			 // //   this.isover = true;
			 // // }
			  
		  // }
    //     }
    //   );
    },
    lower(e) {
      if (this.page < this.page_count) {
        this.page++;
        this.init();
      } else {
        this.isover = true;
      }
    },
	reloadUserinfo() {
	  this.u = uni.getStorageSync("mall_UserInfo");
	  // this.showAuth = false;
	  this.loading = true;
	  this.init();
	},
	goback(){
		uni.navigateBack()
	},
  },
};
</script>
<style>
.couponStyle {
  width: 100%;
  height: 100%;
  background: #f3f4f6;
}

.couponStyle .loading {
  width: 200rpx;
  height: 200rpx;
  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;
}

</style>
