<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  <member-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container">
    <view class="div common-header-wrap">
      <view class="status-holder"></view>
      <view :style="'height:'+navHeight+'px'"></view>
      <view class="common-header-holder"></view>
      <view class="common-header-fixed">
      <title-header />
      <uni-nav-bar title="资金明细" class="common-header" left-icon="back" @clickLeft="goBack">
      </uni-nav-bar>
    </view>
    </view>
<view class="scroll-view div" style="position:relative">
    <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="div" @scrolltolower="loadMore" scroll-y="true">
    <view class="div list-wrapper" v-if="predeposit_list && predeposit_list.length">
      <view class="div item" v-for="(item, index) in predeposit_list" :key="item.lg_id">
        <label class="title" v-bind:class="item.lg_av_amount > 0 ? 'income' : 'expend'">{{ item.lg_av_amount }}</label>
        <label class="subtitle">{{ item.lg_desc }}</label>
        <label class="date">{{ item.lg_addtime_text }}</label>
      </view>
    </view>
    <empty-record v-else-if="predeposit_list && !predeposit_list.length"></empty-record>
    </scroll-view>
</view>
  </view></member-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import MemberBase from '../MemberBase'
import { getPredepositList } from '../../../api/memberPredeposit'
import EmptyRecord from '../../EmptyRecord'
export default {
  name: 'BalanceHistory',
  components:{
    TitleHeader,
    MemberBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      wrapperHeight: 0,
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      predeposit_list: false
    }
  },
  created () {

  this.loadMore()

  },

  mounted(){
    // #ifdef  MP-WEIXIN
    this.navHeight = uni.getMenuButtonBoundingClientRect().height
    // #endif
    this.wrapperHeight = uni.getSystemInfoSync().windowHeight - 90
  },
  methods: {
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore) {
        this.loading = false
        this.getPredepositList(true)
      }
    },
    goBack () {
      uni.navigateBack({delta:1})
    },
    getPredepositList () {
      uni.showLoading({ title: '加载中' })
      getPredepositList(this.params).then(res => {
        uni.hideLoading()
        if (res.result.hasmore) {
          this.isMore = true
        } else {
          this.isMore = false
        }

        let temp = res.result.list
        if (temp) {
          if (!this.predeposit_list) {
            this.predeposit_list = temp
          } else {
            this.predeposit_list = this.predeposit_list.concat(temp)
          }
        }
      }).catch(function (error) {
        uni.hideLoading()
        uni.showToast({icon:'none',title: error.message})
      })
    }
  }
}
</script>

<style scoped lang="scss">
.scroll-view-wrapper{display: flex;flex-direction: column;}
.scroll-view{flex:1}
.container {
  height: 100%;
  display: flex;
  position: relative;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;

}
.header {
  border-bottom: 1px solid #e8eaed;
}
.list-wrapper {
	.item {
	display: flex;
	position: relative;
	flex-direction: column;
	justify-content: flex-start;
	align-items: stretch;
	background-color: #fff;
	border-bottom: 1px solid #e8eaed;
	}
	.title {
	font-size:$h1;
	margin-left:0.7rem;
	margin-top:0.7rem;
	}
	.income {
	color: $primaryColor;
	}
	.expend {
	color: #333;
	}
	.subtitle {
	font-size:$fontSize;
	color: #666;
	margin-left:0.7rem;
	margin-top:0.4rem;
	margin-bottom:0.5rem;
	}
	.date {
	color: #666;
	font-size:$subFontSize;
	position: absolute;
	top:0.9rem;
	right: 0.7rem;
	}
}
</style>
