<template>
  <div class="form-wrap">
    <div class="page-title">搜索条件</div>
    <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"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="截止时间"
        prop="endDate">
        <el-date-picker
          v-model="form.endDate"
          type="datetime"
          placeholder="选择日期时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="价格码代号"
        prop="nodata">
        <el-input v-model="form.nodata"></el-input>
      </el-form-item>
      <el-form-item
        label="分销商订单号"
        prop="keyWords1">
        <el-input v-model="form.keyWords1"></el-input>
      </el-form-item>
      <el-form-item
        label="线下订单号"
        prop="keyWords6">
        <el-input v-model="form.keyWords6"></el-input>
      </el-form-item>
      <el-form-item
        label="第三方订单号"
        prop="keyWords7">
        <el-input v-model="form.keyWords7"></el-input>
      </el-form-item>
      <el-form-item
        label="分销商名称"
        prop="keyWords9">
        <el-input v-model="form.keyWords9"></el-input>
      </el-form-item>
      <el-form-item
        label="票种"
        prop="keyWords8">
        <el-select
          v-model="form.keyWords8"
          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="keyWords5">
        <el-select
          v-model="form.keyWords5"
          clearable
          placeholder="请选择">
          <el-option
            v-for="(value, key) in orderStatusDic"
            :key="key"
            :label="value"
            :value="key">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="预订人姓名"
        prop="keyWords2">
        <el-input v-model="form.keyWords2"></el-input>
      </el-form-item>
      <el-form-item
        label="预订人手机"
        prop="keyWords3">
        <el-input v-model="form.keyWords3"></el-input>
      </el-form-item>
      <el-form-item
        label="预订人身份证"
        prop="keyWords4">
        <el-input v-model="form.keyWords4"></el-input>
      </el-form-item>
      <!-- <el-form-item
        label="下单类型"
        prop="keyWords6">
        <el-select
          v-model="form.keyWords6"
          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>
    <div class="btn-wrap">
      <el-button
        type="primary"
        @click="getOrderList">搜索</el-button>
    </div>
    <div
      class="page-title"
      style="margin-top:30px">
      查询信息
    </div>
    <el-table :data="tableData">
      <el-table-column
        width="120"
        prop="order_no"
        label="线下订单号">
      </el-table-column>
      <el-table-column
        width="120"
        prop="ota_order_no"
        label="分销商订单号">
      </el-table-column>
      <el-table-column
        prop="ticketTypeName"
        label="票种">
      </el-table-column>
      <el-table-column
        prop="price_code"
        label="价格码">
      </el-table-column>
      <el-table-column
        prop="otaSourceName"
        label="分销商">
      </el-table-column>
      <el-table-column
        prop="salePrice"
        label="合作价格">
      </el-table-column>
      <el-table-column
        prop="count"
        label="数量">
      </el-table-column>
      <el-table-column
        prop="price"
        label="总价">
      </el-table-column>
      <el-table-column
        width="160"
        prop="createTime"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="statusText"
        label="状态">
      </el-table-column>
      <el-table-column
        width="140"
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="showOrderInfo(scope.row)">订单详情</el-button>
          <el-button
            type="text"
            @click="showGuestInfo(scope.row)">游客信息</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page.sync="form.pageNum"
      @current-change="getOrderList"
      layout="total, prev, pager, next"
      :total="total">
    </el-pagination>
    <ElDialog
      title="订单详情"
      width="760px"
      v-model="orderDialogVisible">
      <OrderDialog
        :current-item="currentItem"></OrderDialog>
    </ElDialog>
    <ElDialog
      title="游客信息"
      width="760px"
      v-model="guestDialogVisible">
      <GuestDialog
        :current-item="currentItem"></GuestDialog>
    </ElDialog>
  </div>
</template>
<script>
import { getOrderList } from '@/api/order'
import { getTicketTypeList } from '@/api/ticketType'
import ElDialog from '@/components/Dialog'
import OrderDialog from './orderList/OrderDialog'
import GuestDialog from './orderList/GuestDialog'
import moment from 'moment'
export default {
  components: {
    ElDialog,
    OrderDialog,
    GuestDialog
  },
  data () {
    return {
      ticketTypeList: [],
      form: {
        startDate: new Date(moment().subtract(1, 'months').format('YYYY-MM-DD') + ' 00:00:00'),
        endDate: new Date(moment().format('YYYY-MM-DD') + ' 23:59:59'),
        keyWords1: '', // ota订单号
        keyWords2: '', // 预订姓名
        keyWords3: '', // 预订人手机
        keyWords4: '', // 预订人身份证
        keyWords5: '', // 状态
        keyWords6: '', // 线下订单号
        keyWords7: '', // 第三方订单号
        keyWords8: '', // 票种名称
        keyWords9: '', // 分销商名称
        pageNum: 1,
        pageSize: 10
      },
      orderStatusDic: {
        '': '全部',
        'WAIT_USE': '未检票',
        'PART_USE': '部分检票',
        'COMPLETE': '已检票',
        'CANCELED': '已退票'
      },
      ticketStatusDic: {
        'WAIT_USE': '未检票',
        'PART_USE': '部分检票',
        'USED': '已检票',
        'OUTOFDATE': '已过期',
        'CANCELED': '已退票'
      },
      paperTypeDic: {
        1: '身份证',
        2: '护照',
        3: '港澳居民来往内地通行证',
        4: '台胞证'
      },
      tableData: [],
      total: 0,
      currentItem: {},
      orderDialogVisible: false,
      guestDialogVisible: false
    }
  },
  created () {
    this.getTicketTypeList().then(() => {
      this.getOrderList()
    })
  },
  methods: {
    // 获取票种列表
    getTicketTypeList () {
      return getTicketTypeList({
        pageNum: 1,
        pageSize: 999
      }).then(res => {
        this.ticketTypeList = res.list
      })
    },
    getOrderList () {
      getOrderList(this.form).then(res => {
        this.total = res.total
        res.list.forEach(item => {
          if (item.tickets.length) {
            item.ticketTypeName = item.tickets[0].ticketTypeName
            item.salePrice = item.tickets[0].price
          }
          item.count = item.tickets.length
          item.createTime = this.formatTime(item.createTime)
          item.statusText = this.orderStatusDic[item.status] || ''
        })
        this.tableData = res.list
      })
    },
    formatTime (t) {
      return moment(t).format('YYYY-MM-DD HH:mm:ss')
    },
    showOrderInfo (item) {
      this.currentItem = item
      this.orderDialogVisible = true
    },
    showGuestInfo (item) {
      this.currentItem = item
      this.guestDialogVisible = true
    }
  }
}
</script>

<style scoped>

</style>
