<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 pb-30"
      v-if="predeposit_list && predeposit_list.length"

    >
      <view
        class="div container"
        v-for="(item, index) in predeposit_list"
        :key="item.rcblog_id"
      >
        <label
          class="title"
          v-bind:class="item.available_amount > 0 ? 'income' : 'expend'"
          >{{ item.available_amount }}</label
        >
        <label class="subtitle">{{ item.rcblog_description }}</label>
        <label class="date">{{ item.add_time_text }}</label>
      </view>
    </view>
    <empty-record v-else-if="predeposit_list && !predeposit_list.length"></empty-record>
    </scroll-view>
	<view class='common-add-btn-wrapper'><view class="div common-btn common-add-btn"  @click="addRecharge">充值</view></view>
</view>
  </view>
<uni-popup background-color="#fff" ref="confirm" type="dialog">
    <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content" :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
</uni-popup>
</member-base>
</template>

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

  this.loadMore()

  },

  mounted(){
    // #ifdef  MP-WEIXIN
    this.navHeight = uni.getMenuButtonBoundingClientRect().height
    // #endif
    this.wrapperHeight = uni.getSystemInfoSync().windowHeight - 90
  },
  methods:{
    closeDialog(){
    },
    confirmDialog(value){
        if (value) {
          addRechargeCard(value).then(res => {
            uni.showToast({icon:'none',title: res.message})
            this.params={ 'page': 0, 'per_page': 10 }
            this.loading=false
            this.isMore= true
            this.predeposit_list=false
            this.loadMore()
          }).catch(function (error) {
            uni.showToast({icon:'none',title: error.message})
          })
        }
    },
    addRecharge(){
      this.dialog={mode:'input',content:'充值卡号'}
      this.$refs.confirm.open()
    },
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore) {
        this.loading = false
        this.getRechargeCardList(true)
      }
    },
    goBack () {
      uni.navigateBack({delta:1})
    },
    getRechargeCardList () {
      uni.showLoading({ title: '加载中' })

          getRechargeCardList(this.params).then(res => {
            uni.hideLoading()
            if (res.result.hasmore) {
              this.isMore = true
            } else {
              this.isMore = false
            }

            let temp = res.result.log_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}
.common-header{
        .btn{background: #000;color: #fff;box-shadow: 0px 2px 4px #d2d2d2;}
    }
.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 {
	.container {
	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: #666666;
	}
	.subtitle {
	font-size:$fontSize;
	color: #999999;
	margin-left: 0.7rem;
	margin-top: 0.4rem;
	margin-bottom: 0.5rem;
	}
	.date {
	color: #999999;
	font-size:$subFontSize;
	position: absolute;
	top: 0.9rem;
	right: 0.7rem;
	}
}
</style>
