<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 pb-30" 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="recharge_list && recharge_list.length">
        <view
                class="div container"
                v-for="(item, index) in recharge_list"
                :key="item.pdr_id"
                @click="goToPay(item.pdr_payment_state,item.pdr_sn)"
        >
          <view class="div top-wrapper">
            <view class="div left-wrapper">
              <label class="status">{{item.pdr_payment_state_text}}</label>
              <label class="title">充值单号：{{ item.pdr_sn }}</label>
            </view>
            <view class="div right-wrapper">
              <label class="price">￥{{ item.pdr_amount }}</label>
              <label class="subtitle">充值金额</label>
            </view>
            <view class="div top-line"></view>
          </view>
          <view class="div center-wrapper">
            <label class="desc">创建时间：{{ item.pdr_addtime_text }}</label>
          </view>
        </view>
      </view>
      <empty-record v-else-if="recharge_list && !recharge_list.length"></empty-record>
    </scroll-view>
  </view>
	<view class='common-add-btn-wrapper'><view class="div common-btn common-add-btn"  @click="goAdd">充值</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 { urlencode } from '@/util/common'
import MemberBase from '../MemberBase'
import { getRechargeList, addRecharge } from '../../../api/memberRecharge'
import EmptyRecord from '../../EmptyRecord'
export default {
  name: 'BalanceHistory',
  components:{
    TitleHeader,
    MemberBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      if_pay:0,
      navHeight: 0,
      dialog:{},
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      wrapperHeight: 0,

      recharge_list: false

    }
  },
  onLoad (option) {
    this.if_pay=option.if_pay
  this.loadMore()
  },

  mounted(){
    // #ifdef  MP-WEIXIN
    this.navHeight = uni.getMenuButtonBoundingClientRect().top
    // #endif
    this.wrapperHeight = uni.getSystemInfoSync().windowHeight - 130
  },
  methods:{
    closeDialog(){
    },
    confirmDialog(value){
        addRecharge(value).then(res => {
          this.goToPay(0, res.result.pay_sn)
        }).catch(function (error) {
          uni.showToast({icon:'none',title: error.message})
        })
    },
    goAdd () {
      this.dialog={mode:'input',content:'请输入充值金额'}
      this.$refs.confirm.open()
    },
    goBack () {
      if(this.if_pay){
        uni.reLaunch({
          url:'/pages/member/index/Index'
        })
      }else{
        uni.navigateBack({delta:1})
      }
    },
    goToPay (state, paySn) {
      if (state == 0) {
        uni.navigateTo({ url: '/pages/member/buy/pay'+'?'+urlencode( { pay_sn: paySn, pay_type: 'pd_pay' } )})
      }
    },
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore) {
        this.loading = false
        this.getRechargeList(true)
      }
    },
    getRechargeList () {
      uni.showLoading({ title: '加载中' })

      getRechargeList(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.recharge_list) {
            this.recharge_list = temp
          } else {
            this.recharge_list = this.recharge_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;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    background-color: #fff;
  }
  .top-wrapper {
    position: relative;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: stretch;
  }
  .left-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
  }
  .right-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
  }
  .status {
    font-size:$subFontSize;
    color: #5296db;
    margin-left: 0.75rem;
    margin-top: 0.65rem;
  }
  .title {
    font-size:$fontSize;
    color: #666666;
    margin-left: 0.75rem;
    margin-top:0.25rem;
    margin-right: 0.5rem;
    margin-bottom: 0.2rem;
  }
  .price {
    font-size:$h1;
    color: $primaryColor;
    margin-right: 0.75rem;
    margin-top: 0.5rem;
    text-align: right;
  }
  .subtitle {
    // width: 4rem;
    font-size:$fontSize;
    color: #999999;
    margin-right: 0.75rem;
    margin-top:0.25rem;
    margin-bottom: 0.5rem;
    text-align: right;
  }
  .top-line {
    position: absolute;
    left: 0.75rem;
    bottom: 0;
    right: 0;
    height: 1px;
    background-color: #e8eaed;
  }
  .desc {
    color: #999999;
    font-size:$fontSize;
    margin-left: 0.75rem;
    margin-top:0.25rem;
  }
  .center-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    border-bottom: 1px solid #e8eaed;
    padding-bottom:0.25rem;
  }
}
</style>
