<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
    <home-base :show="true"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div">
        <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" @scrolltolower="loadMore" scroll-y="true">
          <view class="goods-list double-column">
            <index-prod-item class="goods-item-wrapper" v-for="item in goodsList" :key="item.pgoods_id" :item="item">
            </index-prod-item>
          </view>
        </scroll-view>
        <empty-record  v-if="goodsList.length === 0"></empty-record>
		</view>
    </view></home-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import HomeBase from '../HomeBase'
import EmptyRecord from '../../EmptyRecord'
import IndexProdItem from './IndexProdItem'
import { getPointsgoodsList } from '../../../api/homePointsgoods'
export default {
  name: 'index',
  mounted(){
  // #ifdef  MP-WEIXIN
  this.navHeight = uni.getMenuButtonBoundingClientRect().height
  // #endif
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      pageTotal: 1, // 总页数
      goodsList: [] // 商品列表
    }
  },
  components:{
    TitleHeader,
    HomeBase,
    EmptyRecord,
      IndexProdItem
  },
  created () {
  this.loadMore()
  },
  methods:{
    goBack(){uni.navigateBack({delta:1})},
    getPointsgoodsList (ispush) {
      uni.showLoading({ title: '加载中' })
      let params = this.params
      getPointsgoodsList(params).then(res => {
        uni.hideLoading()

        if (ispush) {
          this.goodsList = this.goodsList.concat(res.result.goods_list)
        } else {
          this.goodsList = res.result.goods_list
        }
        this.pageTotal = res.result.page_total
        if (res.result.hasmore) {
          this.isMore = true
        } else {
          this.isMore = false
        }
      })
    },
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore && this.params.page <= this.pageTotal) {
        this.loading = false
        this.getPointsgoodsList(true)
      }
    },

  }
}
</script>

<style scoped lang="scss">
    .scroll-view-wrapper{display: flex;flex-direction: column;}
    .scroll-view{flex:1}
    .goods-list{padding-left:$pageSpace;}
    .goods-list.double-column {display: flex;-webkit-flex-wrap: wrap;flex-wrap: wrap;margin-top: 10px}
    .goods-list.double-column .goods-item-wrapper{width: 50%;padding-right:$pageSpace;box-sizing: border-box;}
</style>
