<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
    <seller-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 mt-5" @scrolltolower="loadMore" scroll-y="true">
            <view class="div item mb-5" v-for="item in costList" :key="item.cost_id">
                <view class="div info">
                    <view class="p content">{{item.storecost_remark}}<text class="em ml-5">({{storecost_state(item.storecost_state)}})</text></view>
                    <view class="p time">{{ $moment.unix(item.storecost_time).format('YYYY-MM-DD h:mm:ss') }}</view>
                </view>
                <view class="div price">{{item.storecost_price}}</view>
            </view>
        </scroll-view>
    </view>
</view>
</seller-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import SellerBase from '../SellerBase'

import EmptyRecord from '../../EmptyRecord'
import { getSellerCostList } from '../../../api/seller'
export default {
  name: 'CostList',
  components:{
    TitleHeader,
    SellerBase,
    EmptyRecord
  },
  data(){
    return {
      navHeight: 0,
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      costList: false // 记录列表
    }
  },
  computed:{
    fontSize(){
      return getFontSize()
    },
    storecost_state () {
      return function (state) {
        if (state === 0) {
          return '未结算'
        } else {
          return '已结算'
        }
      }
    }
  },
  created () {
    this.loadMore()
  },
  mounted(){
  // #ifdef  MP-WEIXIN
  this.navHeight = uni.getMenuButtonBoundingClientRect().height
  // #endif
  },
  methods:{
    goBack(){uni.navigateBack({delta:1})},
    getCostList (ispush) {
      uni.showLoading({ title: '加载中' })
      let params = this.params
      getSellerCostList(params).then(res => {
        uni.hideLoading()

            if (ispush && this.costList) {
              this.costList = this.costList.concat(res.result.cost_list)
            } else {
              this.costList = res.result.cost_list
            }
            if (res.result.hasmore) {
              this.isMore = true
            } else {
              this.isMore = false
            }

      }).catch(error=>{
          uni.hideLoading()
          uni.showToast({icon:'none',title: error.message})
      })
    },
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore) {
        this.loading = false
        this.getCostList(true)
      }
    }
  }
}
</script>

<style scoped lang="scss">
	.scroll-view-wrapper{display: flex;flex-direction: column;}
	.scroll-view{flex:1}
    .item{padding:.5rem;background:#fff;height:3rem;}
    .item .info{float:left;width:80%;}
    .item .info .p{line-height:1.5rem;font-size:$subFontSize;}
    .item .info .content .em{}
    .item .price{float:left;width:20%;line-height:3rem;text-align:right;color:red;font-weight:bold;}
</style>
