<template>
<div>
  <div>
    <el-button type="text" @click="() => getDataOf(7)">最近7天</el-button>
    <el-button type="text" @click="() => getDataOf(30)">最近1月</el-button>
    <el-date-picker
      v-model="dateRange"
      type="daterange"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      style="margin-left: 16px">
    </el-date-picker>
    <el-button type="primary" icon="el-icon-search" style="margin-left: 32px" @click="search">查询</el-button>
  </div>
  <new-users mode="line" ref="chart"></new-users>
</div>
</template>

<script>
import dayjs from 'dayjs'

export default {
  components: {
    NewUsers: () => import('./components/NewUsers'),
  },
  data() {
    return {
      dateRange: [],
    };
  },
  methods: {
    search () {
      const [ startDate, endDate ] = this.dateRange || []
      this.$refs.chart.getData({ startDate, endDate })
    },
    getDataOf(days) {      
      const endDate = new Date()
      const startDate = dayjs().subtract(days, 'day').toDate()

      this.$refs.chart.getData({ startDate, endDate })
    },
  },
  mounted() {
  }
};
</script>

<style lang="scss" scoped>
</style>
