<template>
  <div>
      <!--发票情况列表-->
      <data-table :sourceData.sync="sourceData"
                  :columns="columns"
                  show-summary
                  :border="true"
                  :stripe="true"
                  :summary-method="getSummaries"
                  operateBtnLayout=""
                  :showPage="false"
                  :queryParas="searchFormQueryParas" :menuFlag="true">

      </data-table>
  </div>
</template>

<script>
import { DialogEdit, DataTable, authButton } from 'newepoch-components'
export default {
  name: 'taskDialog',
  components: {
    DialogEdit,
    DataTable,
    authButton
  },
  data () {
    return {
      isFootView: false,
      form: {},
      api: {},
      searchFormQueryParas: {}
    }
  },
  props: {
    sourceData: {
      type: Array
    },
    columns: {
      type: Array
    },
    visible: {
      type: Boolean,
      default: function () {
        return false
      }
    }
  },
  computed: {
    dialogVisible: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  methods: {
    // arraySpanMethod ({ row, column, rowIndex, columnIndex }) {
    //   if (rowIndex % 2 === 0) {
    //     if (columnIndex === 0) {
    //       return [1, 2]
    //     } else if (columnIndex === 1) {
    //       return [0, 0]
    //     }
    //   }
    // }
    getSummaries (param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = this.$i18n.messages[this.$i18n.locale].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>

<style scoped>
    @import '~@/styles/tracemgr/factoringCommissioner/taskTable/chinaClear/invoiceList.scss'
</style>
