<template>
  <div class="tableBox">
    <div class="title">门票销售数据</div>
    <el-table
      border
      stripe
      v-loading="loading"
      :data="OrderStatistics">
      <el-table-column
        prop="otaSourceName"
        label="销售渠道">
      </el-table-column>
      <el-table-column
        prop="ticketTypeName"
        label="票种">
      </el-table-column>
      <el-table-column
        prop="unitPrice"
        label="单价">
      </el-table-column>
      <el-table-column
        prop="saleNum"
        label="张数">
      </el-table-column>
      <el-table-column
        prop="salePrice"
        label="金额">
      </el-table-column>
      <el-table-column
        prop="cancelNum"
        label="退票张数">
      </el-table-column>
      <el-table-column
        prop="cancelPrice"
        label="退票金额">
      </el-table-column>
      <el-table-column
        prop="actualNum"
        label="实售数量">
      </el-table-column>
      <el-table-column
        prop="actualPrice"
        label="实售金额">
      </el-table-column>
    </el-table>
  </div>
</template>

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

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

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

  data () {
    return {
      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,
        ticketTypeIdList: [], // 票种ID
        otaSourceNameList: []
      }).then(res => {
        console.log(res)
        this.OrderStatistics = res.data
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.tableBox {
  .title {
    font-size: 16px;
    font-weight: bold;
    padding: 10px 0;
  }
}
</style>
