<template>
  <div id="orderInvoiecDetailList">
    <div class="content">
      <!-- <van-pull-refresh class="list" ref="supplierList" v-model="isRefreshing" @refresh="onRefresh">
        <van-list
          v-model="isLoading"
          :finished="finished"
          finished-text="没有更多了"
          :error.sync="error"
          error-text="请求失败，点击重新加载"
          @load="onLoad"> -->
          <div class="invoiceItem" @click="gotoDetail(item)"
            v-for="(item, index) in invoiceItem.goodsInfos"
            :key="index">
              <order-invoiec-list-item :item="item"/>
          </div>
        <!-- </van-list>
      </van-pull-refresh> -->
    </div>
  </div>
</template>

<script>
// 引入接口
import { getMyInvoiceList } from '@/api/myInvoice'
import orderInvoiecListItem from './orderInvoiecListItem.vue'
export default {
  name: 'OrderInvoiecDetailList',
  components: {
    orderInvoiecListItem
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      isRefreshing: false,
      isLoading: false,
      finished: false,
      error: false,
      logInfoShow: false,
      invoiceList: [],
      // invoiceItem: {},
      sphImage: require('@/assets/img/u48.png'),
    }
  },
  props: {
    invoiceItem: {
      type: Object,
      default: () => {
        return {
        }
      }
    }
  },
  computed: {
    linkInfo () {
      return this.$store.state.linkInfo
    },
    routKey() {
      return this.$route.path
    },
    searchTime() {
      let time = this.time.start + '/' + this.time.end
      return time
    }
  },
  mounted() {
    // this.onLoad()
  },
  methods: {
    gotoDetail(model) {
      // console.log(model)
      this.$emit('gotoDetail', model)
    },
    onRefresh() {
      this.currentPage = 1
      this.isRefreshing = true
      this.getPostData()
    },
    onLoad() {
      this.isLoading = true
      this.getPostData()
    },
    getPostData() {
      let _this = this
      let data = {
        'dbName': 'erp_test_shaphar-上药控股有限公司-204-23528', // 'erp_ogg_shaphar',
        'start': _this.currentPage,
        'length': _this.pageSize,
        'goods': ''
      }
      getMyInvoiceList(data).then(rt => {
        if (rt.code === 1 || rt.code === '1') {
          if (_this.isRefreshing) {
            _this.invoiceList = rt.data
          } else if (rt.data || rt.data.length > 0) {
            _this.invoiceList = _this.invoiceList.concat(rt.data)
          }
          // 重置刷新提示
          _this.isRefreshing = false
          // 重置加载更多提示
          _this.isLoading = false
          if (rt.data.length < 10) {
            _this.finished = true
          } else {
            // 加载成功后下一页自增1
            _this.currentPage++
          }
        } else {
          _this.$toast(rt.message)
          _this.isRefreshing = false
          _this.error = true
          _this.finished = false
        }
        // 加载状态结束
        _this.isLoading = false
      }).catch(e => {
        this.$toast('获取信息失败！')
        _this.isRefreshing = false
        _this.isLoading = false
        _this.error = true
        _this.finished = true
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  #orderInvoiecDetailList {
    height: 100%;
    .content{
      height: 100%;
      overflow-x: hidden;
      overflow-y: auto;
      margin: 10PX;
      .invoiceItem{
        height: 230PX;
        background-color: white;
        margin-bottom: 10PX;
        border-radius: 10PX;
        font-size: 14PX;
        color: #333333;
      }
    }
  }
</style>
