<template>
  <SaleLayout>
    <!-- 票种列表 -->
    <TickList
      ref="ticketList"
      type-id="2"
      slot="left"
      v-model="currentTicket"
    ></TickList>

    <div slot="right">
      <!-- 预订信息 -->
      <PreOrderInfo
        ref="preOrder"
        v-model="preOrderInfo"
        @batch="batch"
        style="margin-bottom:10px"></PreOrderInfo>

      <!-- 表单信息 -->
      <FormInfo
        ref="formInfo"
        style="margin-bottom:10px"
        :pre-order-info="preOrderInfo"
        :current-ticket="currentTicket"
        :order-items="orderItems"></FormInfo>

      <!--
      <OrderInfo
        style="margin-bottom:10px"
        :pre-order-info="preOrderInfo"
        @clear="orderItems=[]"
        ref="orderInfo"
        v-model="orderItems"></OrderInfo>
       -->
      <OrderInfo
        style="margin-bottom:10px"
        :pre-order-info="preOrderInfo"
        @clear="doClear"
        @reselect="doReselect"
        ref="orderInfo"
        v-model="orderItems"></OrderInfo>

      <!-- 售票记录 -->
      <OrderRecord ref="orderRecord"></OrderRecord>
    </div>
  </SaleLayout>
</template>

<script>
import SaleLayout from '@/layout/SaleLayout'
import TickList from './common/TicketList'
import PreOrderInfo from './preOrder/PreOrderInfo'
import FormInfo from './preOrder/FormInfo'
import OrderInfo from './preOrder/OrderInfo'
import OrderRecord from './common/OrderRecord'

import handleKeyBind from './common/keyBind'

export default {
  data () {
    return {
      currentTicket: null,
      preOrderInfo: null,
      orderItems: []
    }
  },
  components: {
    PreOrderInfo,
    SaleLayout,
    TickList,
    FormInfo,
    OrderInfo,
    OrderRecord
  },
  mounted () {
    this.keyBind = e => {
      handleKeyBind(e, this)
    }
    document.addEventListener('keydown', this.keyBind, true)
  },
  beforeDestroy () {
    // 离开时，卸载事件
    document.removeEventListener('keydown', this.keyBind, true)
  },
  methods: {
    doClear () {
      this.orderItems = []
      // 请选择已审核订单 @row-click="handleRowClick"
      // 或者模仿点击，或者清空已审核订单的选择
      // 要在清空订单时触发已审核订单的行选中，来重新请求游客数据
      this.$refs.preOrder.fakeSelectAuditRow()
    },
    doReselect () {
      this.$refs.preOrder.fakeSelectAuditRow()
    },
    batch (list) {
      this.orderItems = list
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
