{"size": 1874, "ext": "js", "max_stars_repo_path": "src/mix/sum.js", "max_stars_repo_name": "liuwenai/vue-mall", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/mix/sum.js", "max_issues_repo_name": "liuwenai/vue-mall", "max_issues_repo_issues_event_min_datetime": "2021-03-10T15:36:09.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T03:30:42.000Z", "max_forks_repo_path": "src/mix/sum.js", "max_forks_repo_name": "liuwenai/vue-mall", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 25.3243243243, "max_line_length": 72, "alphanum_fraction": 0.4647812166}
import get from 'lodash/get'
import has from 'lodash/has'
import sumBy from 'lodash/sumBy'
import map from 'lodash/map'
import includes from 'lodash/includes'
import toNumber from 'lodash/toNumber'
import format from 'number-format.js'

export default {
  data () {
    return {
      sum: {},
      sumClient: {}
    }
  },
  methods: {
    // 服务端汇总
    getSum (param) {
      const { columns, data } = param
      const sums = []
      const summap = this.sum
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        if (has(summap, column.property)) {
          // sums[index] = get(summap,column.property)
          sums[index] = format('#,##0.00', get(summap, column.property))
        }
      })
      return sums
    },
    // 客户端数据汇总
    getSumClient (param) {
      const { columns, data } = param
      const sums = []
      const sumClient = this.sumClient
      const cols = map(columns, 'property')
      const isfjsj = includes(cols, 'fjs') // 是否分级数据
      cols.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        if (has(sumClient, column)) {
          // console.log(cols)
          // sums[index] = _.get(summap,column.property)
          if (isfjsj) {
            sums[index] = format(
              '#,##0.00',
              sumBy(data, item => {
                if (get(item, 'fmx') === 0) {
                  return 0
                } else {
                  return toNumber(item[column])
                }
              })
            )
          } else {
            //
            let sumje = 0
            map(data, (item) => {
              sumje += toNumber(item[column])
            })
            sums[index] = format('#,##0.00', sumje)
          }
        }
      })
      return sums
    }
  }
}
