<template>
  <div class="pa-3 white fullscreen border-box">
    <StatisticsList ref="second" :apis="apis" :search-items="searchConfig"></StatisticsList>
  </div>
</template>

<script>
import {
  getAccumulatePointStatisticsSummary,
  getAccumulatePointStatisticsTop
} from '@/api/accumulatePoint'
import StatisticsList from '@/components/StatisticsList'
import { mapGetters } from 'vuex'
export default {
  name: 'accumulatePointsStatistics',
  components: {
    StatisticsList
  },
  data () {
    return {
      apis: [
        (query) => {
          return new Promise((resolve, reject) => {
            getAccumulatePointStatisticsSummary({ avge: false, ...query }).then(resolve).catch(reject)
          })
        },
        (query) => {
          return new Promise((resolve, reject) => {
            getAccumulatePointStatisticsSummary({ avge: true, ...query }).then(resolve).catch(reject)
          })
        }
      ]
    }
  },
  computed: {
    ...mapGetters(['organizationTree']),
    searchConfig () {
      return [
        {
          label: '上级机构',
          type: 'cascader',
          prop: 'parentOrganizationNo',
          options: {
            filterable: true,
            clearable: false,
            placeholder: '请选择上级机构',
            options: this.organizationTree,
            showAllLevels: false,
            props: {
              emitPath: false,
              checkStrictly: true,
              value: 'organizationNo',
              label: 'organizationName',
              children: 'child'
            }
          }
        }
      ]
    }
  },
  mounted () {
    this.$refs.second.onSetValue({
      parentOrganizationNo: this.organizationTree[0].organizationNo
    })
    this.$refs.second.onInit((items) => {
      return new Promise((resolve, reject) => {
        items.forEach(ele => {
          ele.drillFn = this.drillFn
        })
        resolve()
      })
    })
  },
  methods: {
    drillFn (e) {
      return new Promise((resolve, reject) => {
        getAccumulatePointStatisticsTop({
          organizationNo: e.data.organizationNo
        }).then(resolve).catch(reject)
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
