<template>
  <el-dialog
    :visible.sync="visible"
    :before-close="handleClose"
    title="订单信息"
    width="80%">
    <el-form
      :inline="true"
      label-width="120px"
      class="dialog-info"
      v-if="orderData">
      <div class="block-title">
        基本信息

        <el-tag
          effect="dark"
          :type="channelList[orderData.sale_channel_id].type">
          {{ channelList[orderData.sale_channel_id].label }}
        </el-tag>
      </div>
      <el-form-item label="创建时间">
        {{ orderData.create_time | formatTime }}
      </el-form-item>

      <el-form-item
        label="分销商"
        v-if="orderData.ota_name">
        {{ orderData.ota_name }}
      </el-form-item>

      <el-form-item
        label="分销商代号"
        v-if="orderData.ota_code">
        {{ orderData.ota_code }}
      </el-form-item>

      <el-form-item
        label="分销商订单号"
        v-if="orderData.ota_order_no">
        {{ orderData.ota_order_no }}
      </el-form-item>

      <el-form-item
        label="售票员"
        v-if="orderData.manager">
        {{ orderData.manager }}
      </el-form-item>

      <el-form-item label="线下订单号">
        {{ orderData.order_no }}
      </el-form-item>

      <el-form-item
        label="旅行社"
        v-if="orderData.travel_agency_name"
      >
        <span>{{ orderData.travel_agency_name }}</span>
      </el-form-item>

      <el-form-item label="总价">
        {{ orderData.price }}
      </el-form-item>

      <div class="block-title">
        支付信息
      </div>
      <el-form-item label="支付方式">
        {{ orderData.payChannel }}
      </el-form-item>
      <el-form-item
        label="银行交易流水号"
        v-if="orderData.boc_trade_no">
        {{ orderData.boc_trade_no }}
      </el-form-item>
      <el-form-item
        label="原交易要素"
        v-if="orderData.boc_trade_no">
        {{ trade_no }}
        <el-tooltip
          content="复制"
          placement="top"
          effect="dark">
          <i
            class="el-icon-document"
            v-clipboard="()=>getPayResponse(orderData.boc_trade_no)"
            v-clipboard:success="copySuccess"
            v-clipboard:error="copyError"></i>
        </el-tooltip>
      </el-form-item>

      <el-form-item
        label="备注"
        v-if="orderData.remark">
        {{ orderData.remark }}
      </el-form-item>

      <div class="block-title">
        购票人信息
      </div>
      <el-form-item :label="orderData.group_individual === 1 ? '预订人' : '导游'">
        {{ orderData.buyer_name || '暂无' }}
      </el-form-item>

      <el-form-item label="手机号">
        {{ orderData.buyer_phone || '暂无' }}
      </el-form-item>

      <el-form-item label="证件类型">
        {{ orderData.buyer_papers_type | paperType }}
      </el-form-item>

      <el-form-item label="购买人证件号">
        {{ orderData.buyer_identify || '暂无' }}
      </el-form-item>

      <el-form-item
        label="游客类型"
        v-if="orderData.customer_type">
        {{ orderData.customer_type }}
      </el-form-item>

      <el-form-item
        label="销售专员"
        v-if="orderData.customer_type">
        {{ orderData.salesperson }}
      </el-form-item>
    </el-form>

    <div
      class="tableBox"
      v-if="orderData">
      <el-table
        border
        :data="orderData.tickets">
        <el-table-column
          prop="ticket_no"
          label="票号"
        >
        </el-table-column>

        <el-table-column
          prop="tname"
          label="票种"
        >
        </el-table-column>

        <template v-if="orderData.tickets[0]">
          <el-table-column
            v-if="orderData.tickets[0].perform_name"
            label="节目"
          >
            <template slot-scope="scope">
              {{ scope.row.perform_name }}
            </template>
          </el-table-column>

          <el-table-column
            v-if="orderData.tickets[0].batch_config_name"
            label="场次"
          >
            <template slot-scope="scope">
              {{ scope.row.batch_config_name }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="orderData.tickets[0].seat_area_name"
            label="区域"
          >
            <template slot-scope="scope">
              {{ scope.row.seat_area_name }}
            </template>
          </el-table-column>

          <el-table-column
            v-if="orderData.tickets[0].seat_name"
            label="座位号"
          >
            <template slot-scope="scope">
              {{ `${scope.row.seat_name_new}${scope.row.seat_row_tag }排${scope.row.seat_name}座` }}
            </template>
          </el-table-column>
        </template>

        <el-table-column
          width="80"
          label="原价(￥)"
          v-if="orderData.customer_type"
        >
          <template slot-scope="scope">
            {{ scope.row.original_price/scope.row.check_num }}
          </template>
        </el-table-column>

        <el-table-column
          width="80"
          label="票价(￥)"
        >
          <template slot-scope="scope">
            {{ scope.row.price/scope.row.check_num }}
          </template>
        </el-table-column>

        <el-table-column
          width="80"
          label="折扣"
          v-if="orderData.customer_type"
        >
          <template slot-scope="scope">
            {{ scope.row.discount===100?'无': scope.row.discount/10+'折' }}
          </template>
        </el-table-column>

        <el-table-column
          prop="guestName"
          label="游客姓名"
        >
        </el-table-column>

        <el-table-column
          prop="guestIdentify"
          label="身份证"
        >
        </el-table-column>

        <el-table-column
          width="100"
          prop="check_num"
          label="检票人数"
        >
        </el-table-column>

        <el-table-column
          width="100"
          prop="payDateBegin"
          label="游玩时间"
        >
          <template slot-scope="scope">
            {{ scope.row.is_need_playtime?scope.row.payDateBegin:'无限制' }}
          </template>
        </el-table-column>

        <el-table-column
          width="80"
          label="状态"
        >
          <template slot-scope="scope">
            {{ scope.row.status | ticketStatus }}
          </template>
        </el-table-column>

        <el-table-column
          width="80"
          prop="price"
          label="小计"
        >
        </el-table-column>
      </el-table>
    </div>
  </el-dialog>
</template>

<script>
import { channelList } from '@/assets/staticData'
import { getPayResponse } from '@/utils'

export default {
  created () {
    this.posType = this.$localStore.get('posType')
  },
  computed: {
    trade_no () {
      if (!this.orderData.boc_trade_no) return ''

      let scenicName = this.$localStore.get('scenicName') || this.$store.state.user.scenicName
      if (scenicName === '西宁景区') {
        return getPayResponse(this.orderData.boc_trade_no)
      }
      if (scenicName === '狼山景区' || scenicName === '军山景区') {
        return getPayResponse(this.orderData.boc_trade_no, 'ordernum')
      }
      return ''
    }
  },
  data () {
    return {
      channelList,
      posType: '',
      orderData: null,
      visible: false
    }
  },
  methods: {
    getPayResponse,
    show (data) {
      this.visible = true
      this.orderData = data
      console.log('this.orderData', this.orderData)
    },
    handleClose () {
      this.visible = false
    },
    copySuccess () {
      this.$message.success('复制成功')
    },
    copyError () {
      this.$message.error('复制失败')
    }
  }
}
</script>

<style lang="scss" scoped>
.el-icon-document{
  cursor: pointer;
}
</style>
