<template>
  <div class="table-box">
    <div class="title">门票销售数据</div>
    <el-table
      border
      stripe
      v-loading="loading"
      :data="OrderStatistics"
      :row-class-name="totalRowClassName">
      <el-table-column
        prop="otaSourceName"
        label="销售渠道">
      </el-table-column>
      <el-table-column
        prop="saleNum"
        label="张数">
      </el-table-column>
      <el-table-column
        prop="saleCheckNum"
        label="人数">
      </el-table-column>
      <el-table-column
        prop="actualPrice"
        label="金额">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import moment from 'moment'
import { totalRowClassName } from '@/utils'
import { getOrderStatistics } from '@/api/order.js'

const fmt = 'YYYY-MM-DD HH:mm:ss'

export default {
  props: {
    dataDate: {
      type: String,
      default: 'today'
    }
  },

  data () {
    return {
      totalRowClassName,
      loading: false,
      OrderStatistics: [], // 按售票渠道今日门票销售数据
      startDate: moment().startOf('day').format(fmt),
      endDate: moment().endOf('day').format(fmt)
    }
  },
  created () {
    this.getOrderStatistics()
  },
  methods: {
    getData () {
      switch (this.dataDate) {
        case 'yesterday':
          this.startDate = moment().subtract(1, 'days').startOf('day').format(fmt)
          this.endDate = moment().subtract(1, 'days').endOf('day').format(fmt)
          break
        case 'week':
          this.startDate = moment().subtract(7, 'days').startOf('day').format(fmt)
          this.endDate = moment().endOf('day').format(fmt)
          break
        case 'month':
          this.startDate = moment().subtract(30, 'days').startOf('day').format(fmt)
          this.endDate = moment().endOf('day').format(fmt)
          break
        default:
          this.startDate = moment().startOf('day').format(fmt)
          this.endDate = moment().endOf('day').format(fmt)
          break
      }

      this.getOrderStatistics()
    },
    getOrderStatistics () {
      this.loading = true
      getOrderStatistics({
        pageSize: -1,
        pageNum: 1,
        timeBegin: this.startDate,
        timeEnd: this.endDate,
        adminIdList: [],
        payChannelList: [],
        groupByList: ['otaSourceName']
      }).then(res => {
        console.log(res)
        this.OrderStatistics = res.data
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.table-box {
  .title {
    color: $blue;
    font-size: 16px;
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #eee;
  }
}
</style>
