<template>
  <view class="integralDStyle" :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="list"></u-empty>

    <view
      v-if="g.length > 0"
      style="
        height: calc(100vh - 50px);
        width: calc(100vw);
        overflow: hidden;
        
      "
    >
      <scroll-view
        :scroll-y="true"
        :enable-back-to-top="true"
        :enable-flex="true"
        @scrolltolower="lower"
        :style="{ height: '100%' }"
      >
        <view class="interDList" v-for="(x, i) in g" :key="i">
			<Text>{{x.Description}}</Text>
			<view style="display: flex;align-items: center;justify-content: space-between;width: 100%;margin-top: 5px;">
				<Text :style="{color:x.Type==1?mainColor:secondary}">{{x.Type==1?'+':'-'}}{{x.Integral}}积分</Text>
				<Text style='font-size: 12px; color: #B5B5B5;'>时间：{{x.CreateDate}}</Text>
			</view>
        </view>
       <u-loadmore
         :status="status"
         :load-text="loadText"
         :font-size="24"
         :margin-top="20"
         :margin-bottom="20"
         bg-color="#f3f4f6"
       />
      </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: "积分明细",
      current: 0,
      list: [
        { name: "收入" },
        { name: "支出" },
        
      ],
	  showAuth:false,
	  msg:{
		  pageIndex: 1,
		  pageSize:10,
		  Type:0
	  },
      mainColor: "",
	  secondary:'',
      contentHeight: 0,
      page: 1,
      page_count: 1,
      g: [],
      loading: false,
      isover: false,
	  status: "loadmore",
	  loadText: {
	    loadmore: "轻轻上拉，加载更多",
	    loading: "努力加载中",
	    nomore: "没有更多了",
	  },
    };
  },
  created() {
    this.contentHeight = this.$utils.calcContentHeight(-40) + "px";
    this.mainColor = this.$uiConfig.mainColor;
	this.secondary = this.$uiConfig.secondary;
  },
  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(){
		this.u = uni.getStorageSync("mall_UserInfo");
		if (!this.u) {
		  this.u = {
			nickName: "未登录",
			avatarUrl: ""
		  };
		  this.showAuth = true;
		}	else{
			this.init();
		}
	},
  methods: {
    change(index) {
		
      this.current = index;
	  
      this.msg.pageIndex = 1;
      this.g = [];
      this.loading = true;
      this.init();
    },
    init() {
		this.loading = true;
		this.msg.Type = this.current+1
      this.request2(
      	{
      		url: '/api/AppletUser/GetMemberIntegralPageList',
      		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()
	}
  },
};
</script>
<style>
.integralDStyle {
  width: 100%;
  height: 100%;
  background: #f3f4f6;
}

.integralDStyle .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;
}
.integralDStyle .interDList{
	width:100% ;
	padding: 20px 15px;
	display: flex;
	flex-direction: column;
	background: #fff;
	border-top: 1px solid #f5f5f5;
	
}
</style>
