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

    <div slot="right">
      <!-- 昭苏打折使用定制的表单 -->
      <div>
        <FormInfoZhaosu
          v-if="['昭苏'].includes(scenicName)"
          ref="formInfo"
          style="margin-bottom:10px"
          :current-ticket="currentTicket"
          :order-items="orderItems"></FormInfoZhaosu>
        <!-- 其他景区表单保持原样 -->
        <FormInfo
          v-else
          ref="formInfo"
          style="margin-bottom:10px"
          :current-ticket="currentTicket"
          :order-items="orderItems"></FormInfo>
      </div>

      <div>
        <!-- 铭投山庄定制的按订单总价打折 -->
        <OrderInfoMingtou
          v-if="['铭投山庄','大陈岛景区'].includes(scenicName)"
          style="margin-bottom:10px"
          @clear="handleClear"
          ref="orderInfo"
          v-model="orderItems"></OrderInfoMingtou>
        <!-- 昭苏定制的按每张票打x折 -->
        <OrderInfoZhaosu
          v-else-if="['昭苏'].includes(scenicName)"
          style="margin-bottom:10px"
          @clear="handleClear"
          ref="orderInfo"
          :current-ticket="currentTicket"
          v-model="orderItems"></OrderInfoZhaosu>
        <!-- 其他景点保持原样 -->
        <OrderInfo
          v-else
          style="margin-bottom:10px"
          @clear="handleClear"
          ref="orderInfo"
          v-model="orderItems"></OrderInfo>
      </div>

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

<script>
import SaleLayout from '@/layout/SaleLayout'
import TickList from './common/TicketList'
import QuickType from './common/QuickType'

import FormInfo from './retail/FormInfo'
import FormInfoZhaosu from './retail/FormInfoZhaosu'
import OrderInfo from './retail/OrderInfo'
import OrderInfoMingtou from './retail/OrderInfoMingtou'
import OrderInfoZhaosu from './retail/OrderInfoZhaosu'
import OrderRecord from './common/OrderRecord'

import handleKeyBind from './common/keyBind'

export default {
  data () {
    return {
      currentTicket: null,
      orderItems: []
    }
  },
  components: {
    SaleLayout,
    TickList,
    FormInfo,
    FormInfoZhaosu,
    QuickType,
    OrderInfo,
    OrderInfoMingtou,
    OrderInfoZhaosu,
    OrderRecord
  },
  computed: {
    scenicName () {
      return this.$localStore.get('scenicName') || this.$store.state.user.scenicName
    }
  },
  mounted () {
    this.keyBind = e => {
      handleKeyBind(e, this)
    }
    document.addEventListener('keydown', this.keyBind, true)
  },
  methods: {
    handleClear () {
      this.orderItems = []
      this.$refs.formInfo.$refs.form.clearValidate()
    }
  },
  beforeDestroy () {
    // 离开时，卸载事件
    document.removeEventListener('keydown', this.keyBind, true)
  }
}
</script>
