<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>
    <!-- header -->
    <view class="div order-header">
        <view class="ul">
            <view
                    class="li item"
                    v-for="item in orderNav"
                    v-bind:key="item.id"
                    v-bind:class="{ active: bill_state == item.id }"
                    v-on:click="setOrderNavActive(item.id)"
            >
                {{ item.name }}
            </view>
        </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"  v-if="billList && billList.length">
            <view class="div settle-item" v-for="bill in billList" :key="bill.ob_no">
                <view class="div title">{{$moment.unix(bill.ob_startdate).format('YYYY年MM月DD日')}}~{{$moment.unix(bill.ob_enddate).format('YYYY年MM月DD日')}}</view>
                <view class="div content">

                    <view class="div item">
                        <view class="div mt">订单金额</view>
                        <view class="div mc income"><text class="span strong">{{parseFloat(bill.ob_order_totals)}}</text>元</view>
                    </view>
                    <view class="div item">
                        <view class="div mt">退还佣金</view>
                        <view class="div mc income"><text class="span strong">{{parseFloat(bill.ob_commis_return_totals)}}</text>元</view>
                    </view>
                    <view class="div item">
                        <view class="div mt">平台代金券</view>
                        <view class="div mc income"><text class="span strong">{{parseFloat(bill.ob_mall_voucher_totals)}}</text>元</view>
                    </view>
                    <view class="div item">
                        <view class="div mt">退单金额</view>
                        <view class="div mc outlay"><text class="span strong">{{parseFloat(bill.ob_order_return_totals)}}</text>元</view>
                    </view>
                    <view class="div item">
                        <view class="div mt">佣金金额</view>
                        <view class="div mc outlay"><text class="span strong">{{parseFloat(bill.ob_commis_totals)}}</text>元</view>
                    </view>
                    <view class="div item">
                        <view class="div mt">分销佣金</view>
                        <view class="div mc outlay"><text class="span strong">{{parseFloat(bill.ob_inviter_totals)}}</text>元</view>
                    </view>
                    <view class="div item">
                        <view class="div mt">促销费用</view>
                        <view class="div mc outlay"><text class="span strong">{{parseFloat(bill.ob_store_cost_totals)}}</text>元</view>
                    </view>
                </view>
                <view class="div payment-account">
                    <text class="span">应收：{{parseFloat(bill.ob_result_totals)}}</text>
                    <view v-if="bill.ob_state==1" @click="confirmBill(bill.ob_no)" class="div common-btn ds-button-small default btn">确认</view>
                    <view v-else class="div common-btn ds-button-small default btn">{{bill.ob_states}}</view>
                </view>
            </view>
        </view>
        <empty-record v-else-if="billList && !billList.length"></empty-record>
    </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 { getBillList,confirmBill } from '../../../api/sellerBill'
export default {
  name: 'BillList',
  components:{
    TitleHeader,
    SellerBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      billList: false, // 商品列表
      ob_no: '',
      bill_state: '',
      orderNav: [
        {
          'name': '全部',
          'id': ''
        },
        {
          'name': '已出账',
          'id': '1'
        },
        {
          'name': '已确认',
          'id': '2'
        },
        {
          'name': '已完成',
          'id': '4'
        }
      ]
    }
  },
  created () {
    this.loadMore()
  },
  mounted(){
  // #ifdef  MP-WEIXIN
  this.navHeight = uni.getMenuButtonBoundingClientRect().height
  // #endif
  },
  methods:{
    goBack(){uni.navigateBack({delta:1})},
    setOrderNavActive (index) {
      this.bill_state = index
      this.reload()
    },
    confirmBill (ob_no) {
      confirmBill(ob_no).then(res => {
		uni.showToast({icon:'none',title: res.message})
        this.reload()
      }).catch(function (error) {
        uni.showToast({icon:'none',title: error.message})
      })
    },
    getBillList (ispush) {
      uni.showLoading({ title: '加载中' })
      let params = this.params
      getBillList(params, this.ob_no, this.bill_state).then(res => {
        uni.hideLoading()

            if (ispush && this.billList) {
              this.billList = this.billList.concat(res.result.bill_list)
            } else {
              this.billList = res.result.bill_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.getBillList(true)
      }
    },
    reload () {
      // 重新加载数据
      this.params.page = 0
      this.isMore = true
      this.billList = false
      this.loadMore()
    }
  }
}
</script>

<style scoped lang="scss">
	.scroll-view-wrapper{display: flex;flex-direction: column;}
	.scroll-view{flex:1}
    .order-header {
        height: 2.2rem;
    .ul {
        list-style: none;
        width: auto;
        display: flex;
        justify-content: space-around;
        align-content: center;
        align-items: center;
        height: 100%;
        background: rgba(255, 255, 255, 1);
        border-bottom: 1px solid #e8eaed;
    .li {
        font-size:$subFontSize;
        color: #333;
        height: 100%;
        text-align: center;
        line-height: 2.2rem;
        border-bottom: 0.1rem solid transparent;
    &.active {
         color: $primaryColor;
         border-bottom-color: $primaryColor;
     }
    }
    }
    }
    .settle-item {
        background: #fff;
        margin-top: .5rem;
        border-top: 1px solid #eee;
        border-bottom: 1px solid #eee;
        padding:.5rem;
        .title {
            font-size:.8rem;
            border-bottom: 1px solid #eee;
            color: #333;
            line-height: 2;
            .settle-state {
                float: right;
            }
            .state-check {
                color: orangered
            }
        }
        .content {
            padding: .5rem 0;
            display: flex;
            line-height: 1.5;
			flex-wrap: wrap;
			justify-content: space-between;
            .item {
                width: 33%;
                text-align: center;
                .mt {
                    font-size:$fontSize;
                    color: #999
                }
                .mc {
                    font-size:$fontSize;
                    color: #000;

                    .strong {
                        font-size:$subFontSize;
                    }
                }
                .mc.income {
                    color: #4caf50
                }
                .mc.outlay {
                    color: #f31c47
                }
            }

        }
        .payment-account{font-size:$subFontSize;color:#333;padding:.5rem 0;border-top:1px solid #eee;display:flex;
            .span{flex:1;line-height:1.65rem;padding-right:.5rem}
            .btn{min-width:4rem}
        }
		
    }
</style>
