<template>
  <div v-loading="loading">
    <el-row type="flex" style="justify-content: space-between">
<!--      <el-date-picker-->
<!--        v-model="computedMonth"-->
<!--        type="month"-->
<!--        placeholder="选择月"-->
<!--        @change="getData"-->
<!--        :clearable="false"-->
<!--      />-->
      <date-range-picker
        :start-date.sync="queryParams.payDateStart"
        :end-date.sync="queryParams.payDateEnd"
        @change="getData"
      />
      <div>
        收入
        <span style="font-size: 26px">{{totalIncome | money}}</span>
        元
      </div>
    </el-row>
    <single-line-chart name="收入（元）" :chart-data="chartData" :labels="labels" height="250px"/>
  </div>
</template>

<script>
import { mchRechargeCount } from '@/api/mch/recharge'
import SingleLineChart from '@/components/SingleLineChart/index.vue'
import RangePicker from '@/components/RangePicker/index.vue'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import { getLastMonthDateStr } from '@/utils'
import { appGetBonusDailyAmount } from '@/api/app/dashboard'

export default {
  name: 'MchRechargeCountReport',
  components: { DateRangePicker, RangePicker, SingleLineChart },
  data() {
    return {
      queryParams: {
        payDateStart: getLastMonthDateStr(1),
        payDateEnd: getLastMonthDateStr(0),
      },
      data: [],
      loading: false,
    }
  },
  computed: {
    // 数据列表
    chartData() {
      return this.data.map(item => item.value);
    },
    labels() {
      return this.data.map(item => item.key);
    },
    totalIncome() {
      if (this.data == null) {
        return 0;
      }
      return this.data.reduce((pre, cur) => pre + cur.value, 0);
    }
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      this.loading = true;
      appGetBonusDailyAmount(this.queryParams).then(res => {
        this.data = res.data;
      }).finally(() => {
        this.loading = false;
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
