<template>
  <div class="form-wrap">
    <div class="searchBox">
      <el-form
        ref="form"
        :model="form"
        :inline="true"
        label-width="150px">
        <el-form-item
          label="起始时间"
          prop="startDate">
          <el-date-picker
            v-model="form.startDate"
            type="date"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="截止时间"
          prop="endDate">
          <el-date-picker
            v-model="form.endDate"
            type="date"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="游玩起始时间"
          prop="keyWords3">
          <el-date-picker
            v-model="form.keyWords3"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="游玩截止时间"
          prop="keyWords4">
          <el-date-picker
            v-model="form.keyWords4"
            type="date"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item
          label="分销商名称"
          prop="keyWords2">
          <el-select
            v-model="form.keyWords2"
            placeholder="请选择"
            filterable>
            <el-option
              v-if="projectName!=='YINXIANGMAZU'||queryClear"
              label="全部"
              value="">
            </el-option>
            <el-option
              v-for="item in otaList"
              :key="item.id"
              :label="item.otaSourceName"
              :value="item.otaSourceName">
            </el-option>
          </el-select>
        </el-form-item>

        <!-- <el-form-item label="类型">
          <el-select
            v-model="form.keyWords1"
            placeholder="">
            <el-option
              label="全部"
              value="">
            </el-option>
            <el-option
              label="自动接口下单"
              :value="1">
            </el-option>
            <el-option
              label="页面下单"
              :value="2">
            </el-option>
          </el-select>
        </el-form-item> -->

        <el-form-item label="票状态">
          <el-select
            v-model="form.keyWords5"
            clearable
            placeholder="请选择">
            <el-option
              value=""
              label="全部"></el-option>
            <el-option
              v-for="(value, key) in ticketStatus"
              :key="key"
              :label="value.label"
              :value="key">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="btn-wrap">
        <el-button @click="reset">重置</el-button>
        <el-button
          type="primary"
          @click="getData">搜索</el-button>
      </div>
    </div>

    <div class="tableBox">
      <div class="block-title">
        查询信息
      </div>
      <el-table
        :data="tableData"
        v-loading="loading"
        :row-class-name="totalRowClassName">
        <el-table-column
          label="日期"
          width="160"
          prop="stime">
        </el-table-column>
        <el-table-column
          label="销售数量"
          prop="saleNum">
        </el-table-column>
        <el-table-column
          label="退票数量"
          prop="refund_count">
        </el-table-column>
        <el-table-column
          label="实际售票数量"
          prop="actualNum">
        </el-table-column>
        <el-table-column
          label="售票金额"
          prop="salePrice">
        </el-table-column>
        <el-table-column
          label="退票金额"
          prop="refund_price">
        </el-table-column>
        <el-table-column
          label="实际售票金额"
          prop="actualPrice">
        </el-table-column>
      </el-table>
    </div>

  </div>
</template>
<script>
import { getStatisticsForReconciliation } from '@/api/order.js'
import { ticketStatus } from '@/const'
import moment from 'moment'

export default {
  name: 'orderReconciliation',
  data () {
    return {
      form: {
        startDate: new Date(moment().startOf('month')),
        endDate: new Date(moment().endOf('month')),
        keyWords1: '', // 下单类型
        keyWords2: '', // 分销商
        keyWords3: '', // 游玩开始时间
        keyWords4: '', // 游玩结束时间
        keyWords5: '' // 票状态
      },
      projectName: localStorage.getItem('otaProject'),
      tableData: [],
      total: 0,
      loading: false,
      currentItem: {},
      orderDialogVisible: false,
      guestDialogVisible: false,
      ticketStatus
    }
  },
  computed: {
    queryClear () {
      return this.$store.state.user.permissionList.includes('stats:clearwx_query')
    },
    otaList () {
      const list = JSON.parse(localStorage.getItem('otaList'))
      return this.projectName === 'YINXIANGMAZU' && !this.queryClear ? list.filter(item => item.otaSourceCode !== 'CLEARWX') : list
    }
  },
  created () {
    this.getData()
    if (this.projectName === 'YINXIANGMAZU' && !this.queryClear) {
      this.form.keyWords2 = this.otaList[0].otaSourceName
    }
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    getData () {
      this.loading = true
      let params = {...this.form}
      params.endDate = new Date(moment(params.endDate).format('YYYY-MM-DD') + ' 23:59:59')
      getStatisticsForReconciliation(params).then(res => {
        this.tableData = res.data.reverse().map(item => {
          if (item.stime === '小计') {
            item.stime = item.otaSourceName
          }
          return item
        })
        this.loading = false
      })
    }
  }
}
</script>
<style scoped>
.headerTitle{
  text-align:left;
}
</style>
