<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="datetime"
            default-time="00:00:00"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="售票截止时间"
          prop="endDate">
          <el-date-picker
            v-model="form.endDate"
            type="datetime"
            default-time="23:59:59"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="检票起始时间"
          prop="keyWords1">
          <el-date-picker
            v-model="form.keyWords1"
            type="datetime"
            default-time="00:00:00"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="检票截止时间"
          prop="keyWords2">
          <el-date-picker
            v-model="form.keyWords2"
            type="datetime"
            default-time="23:59:59"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="首次检票起始时间"
          prop="keyWords9">
          <el-date-picker
            v-model="form.keyWords9"
            type="datetime"
            default-time="00:00:00"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="首次检票截止时间"
          prop="keyWords10">
          <el-date-picker
            v-model="form.keyWords10"
            type="datetime"
            default-time="23:59:59"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="分销商名称"
          prop="keyWords4">
          <el-select
            v-model="form.keyWords4"
            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="票种"
          prop="keyWords5">
          <el-select
            v-model="form.keyWords5"
            filterable
            clearable
            placeholder="请选择">
            <el-option
              label="全部"
              value="">
            </el-option>
            <el-option
              v-for="item in ticketTypeList"
              :key="item.id"
              :label="item.name"
              :value="item.ticketTypeId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="检票员"
          prop="keyWords3">
          <el-input v-model="form.keyWords3"></el-input>
        </el-form-item>
      </el-form>
      <div class="btn-wrap">
        <el-button @click="reset">重置</el-button>
        <el-button
          type="primary"
          @click="getList($event,true)">搜索</el-button>
      </div>
    </div>

    <div class="tableBox">
      <div class="block-title">
        查询信息
      </div>
      <el-table
        :data="tableData"
        v-loading="loading">
        <el-table-column
          prop="order_no"
          label="订单号">
        </el-table-column>
        <el-table-column
          prop="ota_order_no"
          label="分销商订单号">
        </el-table-column>
        <el-table-column
          prop="ticketTypeName"
          label="票种">
        </el-table-column>
        <el-table-column
          width="80"
          prop="price"
          label="价格">
        </el-table-column>
        <el-table-column
          prop="otaSourceName"
          label="分销商">
        </el-table-column>
        <el-table-column
          width="100"
          prop="buyer_name"
          label="客户姓名">
        </el-table-column>
        <el-table-column
          width="100"
          prop="buyer_phone"
          label="手机号">
        </el-table-column>
        <el-table-column
          width="80"
          prop="saleNum"
          label="总票数">
        </el-table-column>
        <el-table-column
          width="80"
          prop="check_count"
          label="已检">
        </el-table-column>
        <el-table-column
          width="160"
          prop="check_time"
          label="检票时间">
          <template slot-scope="scope">
            {{ scope.row.check_time | formatTime }}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        @current-change="getList"
        layout="total, prev, pager, next"
        :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getTicketTypeList } from '@/api/ticketType'
import { getCheckList } from '@/api/queryReport'
import moment from 'moment'

export default {
  name: 'checkQuery',
  data () {
    return {
      projectName: localStorage.getItem('otaProject'),
      form: {
        keyWords1: new Date(moment().startOf('day').valueOf()), // 检票起始时间
        keyWords2: new Date(moment().endOf('day').valueOf()), // 检票截止时间
        keyWords3: '', // 检票员
        keyWords4: '', // 分销商
        keyWords5: '', // 票种
        keyWords6: 'order', // 按订单or票
        keyWords9: '', // 首次检票起始时间
        keyWords10: '', // 首次检票截止时间
        startDate: new Date(moment().startOf('day').valueOf()),
        endDate: new Date(moment().endOf('day').valueOf()),
        pageNum: 1,
        pageSize: 10
      },
      scenicList: [],
      ticketTypeList: [],
      tableData: [],
      currentPage: 1,
      total: 0,
      loading: false
    }
  },
  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.getTicketTypeList()
    this.getList()
    if (this.projectName === 'YINXIANGMAZU' && !this.queryClear) {
      this.form.keyWords4 = this.otaList[0].otaSourceName
    }
  },
  methods: {
    reset () {
      this.$refs.form.resetFields()
    },
    getTicketTypeList () {
      getTicketTypeList({}).then(res => {
        this.ticketTypeList = res.list
      })
    },
    getList (e, goFirst) {
      this.loading = true
      if (goFirst) { this.form.pageNum = 1 }
      getCheckList(this.form).then(res => {
        this.tableData = res.list
        this.total = res.total
        this.loading = false
      })
    }
  }
}
</script>
