<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="log_list && log_list.length"
    >
      <view
        class="div point-list"
        v-for="(item, index) in log_list"
        :key="item.marketmanagelog_id"
      >
        <view class="div info">
          <view class="div title">{{ item.marketmanagelog_remark }}</view>
          <view class="div time">{{ $moment.unix(item.marketmanagelog_time).format('YYYY.MM.DD') }}</view>
        </view>
        <view class="div right" :class="item.marketmanagelog_win>0?'number':'diture'">{{ item.marketmanagelog_win>0?'已中奖':'未中奖' }}</view>
      </view>
    </view>
    <empty-record v-else-if="log_list && !log_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 { getMarketmanagelog } from '../../../api/homeMarketmanage'
import EmptyRecord from '../../EmptyRecord'
export default {
  name: 'BalanceHistory',
  components:{
    TitleHeader,
    MemberBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      params: { 'page': 0, 'per_page': 20 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      wrapperHeight: 0,

      log_list: false
    }
  },
  created () {

  this.loadMore()

  },

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

      getMarketmanagelog(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.log_list) {
            this.log_list = temp
          } else {
            this.log_list = this.log_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 {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  .point-list {
    background-color: #fff;
    border-bottom: 1px solid #e8eaed;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.55rem 0.75rem;
    .right{width:2.5rem;}
    .info {
      flex:1;
      .title {
        font-size:$subFontSize;
        color: #333;
      }
      .time {
        font-size:$fontSize;
        color: #999;
        margin-top:0.25rem;
      }
    }
    .number {
      font-size:$h2;
      color:$primaryColor;
    }
    .diture {
      font-size:$h2;
      color: rgba(102, 102, 102, 1);
    }
  }
}
</style>
