<template>
    <div>
        <!--发票情况列表-->
        <data-table :sourceData.sync="sourceData"
                    :columns="columns"
                    :api="api"
                    :loadCount="loadCount"
                    :loadList="loadList"
                    show-summarys
                    :summary-method="getSummaries"
                    operateBtnLayout=""
                    :showPage="false"
                    :queryParas="searchFormQueryParas" :menuFlag="false">
        </data-table>
    </div>
</template>

<script>
import { DialogEdit, DataTable, authButton } from 'newepoch-components'
import tracemgrApi from '@/api/tracemgrApi.js'
export default {
  components: {
    DialogEdit,
    DataTable,
    authButton,
    tracemgrApi
  },
  data () {
    return {
      loadCount: 0,
      loadList: 'getInvoiceListByOrderId',
      isFootView: false,
      sourceData: [],
      searchFormQueryParas: {}
    }
  },
  props: {
    // sourceData: {
    //   type: Array
    // },
    columns: {
      type: Array
    },
    dialogVisible: {
      type: Boolean
    }
  },
  computed: {
    visible: {
      get () {
        return this.dialogVisible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    },
    getTitle: {
      get: function () {
        return this.title
      },
      set: function (val) {
        this.$emit('update:title', val)
      }
    },
    api () {
      return tracemgrApi['abnormalOrderListApi']
    }
  },
  watch: {
    visible (newValue, oldValue) {
      if (newValue) {
        this.handleFilter()
        // this.$nextTick(function () {
        //   this.handleFilter()
        // })
      }
    }
  },
  mounted () {
    this.handleFilter()
  },
  methods: {
    getComp: function () {
      if (!this.visible) {
        // return
      }
    },
    handleFilter: function () {
      this.loadCount = this.loadCount + 1
    },
    getSummaries (param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = this.$i18n.messages[this.$i18n.locale].enterpriseInfoManage.projCompanyInfoManage.total
          return
        }
        const values = data.map(item => Number(item[column.property]))
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          // sums[index] += ' 元'
        } else {
          sums[index] = ''
        }
      })

      return sums
    }
  }
}
</script>
