<template>
  <div>
    <!-- 建行B扫C的退票状态下的弹窗 -->
    <!-- Nested Dialog: If a Dialog is nested in another Dialog, append-to-body is required. -->
    <el-dialog
      ref="b2cModal"
      title="查询退款信息"
      width="80%"
      :visible.sync="b2cModalvisible"
      append-to-body>
      <!-- <span>建行B扫C退款情况</span> -->
      <el-form
        label-width="120px"
        inline
        class="dialog-info">
        <div class="block-title">
          订单基本信息
        </div>
        <el-form-item
          label="订单ID"
        >
          {{ b2cForm.orderId }}
        </el-form-item>
        <el-form-item
          label="支付类型"
        >
          {{ this.getPayTypeName(b2cForm.payType) }}
        </el-form-item>
        <el-form-item label="总价">
          {{ b2cForm.price }}
          <!-- {{ orderData.price }} -->
        </el-form-item>
        <el-form-item
          label="状态"
        >
          <!-- {{ b2cForm.ticketStatus | ticketStatus }} -->
          <el-tag :type="b2cForm.ticketStatus | ticketStatusColor">
            {{ b2cForm.ticketStatus | ticketStatus }}
          </el-tag>
        </el-form-item>
        <div class="block-title">
          支付信息
        </div>
        <el-form-item label="支付方式">
          {{ b2cForm.payChannel }}
        </el-form-item>
        <div class="block-title">
          退款信息
        </div>
        <div
          class="table-box">
          <el-table
            border
            :data="b2cRefundTickets">
            <el-table-column
              prop="id"
              label="ID"
            >
            </el-table-column>
            <el-table-column
              prop="refundStatus"
              label="退款状态"
            >
              <template slot-scope="scope">
                <el-tag :type="scope.row.refundStatus | b2cRefundStatusColor">
                  {{ scope.row.refundStatus | b2cRefundStatus }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column
              prop="price"
              label="价格"
            >
            </el-table-column>
            <el-table-column
              prop="createTime"
              label="创建时间"
              width="140"
            >
              <template slot-scope="scope">
                {{ scope.row.createTime | formatTime }}
              </template>
            </el-table-column>
            <el-table-column
              width="120"
              fixed="right"
              label="操作">
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  @click="handleDoRefundRetry(scope.row)">
                  退款重试
                </el-link>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button @click="() => b2cModalvisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="() => { b2cModalvisible = false; }">确认</el-button>
      </span>
    </el-dialog>
    <!-- 门票列表对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="visible"
      :before-close="handleClose"
      title="门票信息"
      width="80%">
      <div class="table-box">
        <el-form
          :inline="true"
          label-width="120"
          label-position="right"
          class="buyer-info">
          <el-form-item
            label="旅行社"
            v-if="orderData.groupIndividual === 2"
          >
            <span>{{ orderData.travelAgencyName }}</span>
          </el-form-item>
          <el-form-item :label="orderData.groupIndividual === 1 ? '预订人' : '导游'">
            {{ orderData.buyerName || '暂无' }}
          </el-form-item>
          <el-form-item label="手机号">
            {{ orderData.buyerPhone || '暂无' }}
          </el-form-item>
          <el-form-item label="证件类型">
            {{ orderData.buyerIdentifyType | paperType }}
          </el-form-item>
          <el-form-item label="购买人证件号">
            {{ orderData.buyerIdentify || '暂无' }}
          </el-form-item>
          <br>
          <el-form-item
            label="票号搜索"
          >
            <el-input v-model="filterText"></el-input>
          </el-form-item>
          <el-form-item
            label="状态"
          >
            <el-select
              v-model="status"
              clearable
              placeholder="请选择"
            >
              <el-option
                label="全部"
                value=""></el-option>
              <el-option
                v-for="item in currentTicketStatus"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-button
            :disabled="selectedTicket.length===0"
            @click="cancelTicketList">
            批量退票
          </el-button>
        </el-form>

        <el-table
          border
          :data="filterOrderData"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            :selectable="selectable"
            width="55">
          </el-table-column>
          <el-table-column
            width="80"
            label="序号"
            prop="id"
          >
            <template slot-scope="scope">
              {{ scope.row.id.toString().padStart(8,'0') }}
            </template>
          </el-table-column>
          <el-table-column
            prop="ticketNo"
            label="票号"
          >
          </el-table-column>

          <!-- orderData.tickets[0].order_id -->
          <!-- <el-table-column
            prop="order_id"
            label="B扫C的order_id"
          >
          </el-table-column> -->

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

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

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

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

          <el-table-column
            width="80"
            label="票价"
          >
            <template slot-scope="scope">
              {{ (scope.row.price/scope.row.checkNum).toFixed(2) }}
            </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="checkNum"
            label="检票人数"
          >
          </el-table-column>
          <el-table-column
            width="100"
            prop="payDateBegin"
            label="游玩时间"
          >
            <template slot-scope="scope">
              {{ scope.row.isNeedPlaytime?scope.row.payDateBegin:'无限制' }}
            </template>
          </el-table-column>
          <el-table-column
            width="80"
            label="状态"
          >
            <template slot-scope="scope">
              <el-tag :type="scope.row.status | ticketStatusColor">
                {{ scope.row.status | ticketStatus }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            width="80"
            prop="price"
            label="小计"
          >
          </el-table-column>
          <el-table-column
            width="220"
            prop="cancel_remark"
            label="备注"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.cancel_remark"
                v-if="checkRefundVisible(scope.row)&& orderData.saleChannelId!==2"></el-input>
              <span v-else>{{ scope.row.cancel_remark }}</span>
            </template>
          </el-table-column>
          <el-table-column
            width="120"
            label="操作"
          >
            <template
              slot-scope="scope"
            >
              <div style="display: flex;">
                <el-button
                  type="text"
                  v-if="checkRefundVisible(scope.row) && orderData.saleChannelId!==2&& !isRefunding && !loading"
                  @click="refundTicket(scope.row)">
                  退票
                </el-button>
                <span
                  v-if="checkRefundVisible(scope.row) && orderData.saleChannelId!==2&& (isRefunding || loading)"
                  style="margin-right:5px">正在处理</span>
                <el-button
                  type="text"
                  v-if="checkPartRefundVisible(scope.row)&&orderData.saleChannelId!==2&&scope.row.status!=='CANCELED'"
                  @click="partRefundTicket(scope.row)">
                  部分退款
                </el-button>
                <el-button
                  type="text"
                  v-if="scope.row.status === 'REFUNDING'"
                  @click="b2cModalSearch(scope.row)">
                  <!-- @click="() => { b2cModalvisible = true; this.b2cModalSearch(scope.row.order_id); }"> -->
                  <!-- {{ scope.row.order_id }} -->
                  查询退款信息
                </el-button>
              </div>
            </template>
          <!-- <template
            slot-scope="scope"
            v-if="checkPartRefundVisible(scope.row)&&orderData.saleChannelId!==2">
            <el-button
              type="text"
              @click="partRscope.row)">
              部分退票
            </el-button>
          </template> -->
          </el-table-column>
        </el-table>
      </div>

      <SalesList
        ref="salesList"
        :default-payment="orderData.payChannel"
        @change="handleGetSaleId"></SalesList>

      <RefundPrice
        ref="refundPrice"
        @change="refindPrice"
      ></RefundPrice>

      <QueryPos
        ref="queryPos"
        type="refund"
        :preorder-info="orderData.bocTradeNo"
        @confirm="handleQueryPos"></QueryPos>
    </el-dialog>
  </div>
</template>

<script>
import { apiOrder } from '@/api/order'
import { getRefundNeedRetryInfo, doRefundRetry } from '@/api/b2cRefund.js'
import { cancelValueCardSingleTicket, cancelValueCardCheckedTicket } from '@/api/valueCard'
import checkPermission from '@/utils/checkPermission'
import posMixin from '@/pages/common/posMixin'
import QueryPos from '../common/QueryPos'
import SalesList from './SalesList'
import RefundPrice from './RefundPrice'
import { refundPOS } from '@/api/pay'
import { isJSON } from '@/utils'
import { getPayResponse } from '@/utils/posUtils'
import choosePay from '@/utils/choosePay'

const posPayArray = ['银行卡', '银联扫码', '银联钱包', '银联二维码', '支付宝', '微信', '龙支付']

const payTypeMap = {
  'POS': 'POS机',
  'VALUECARD': '存值卡',
  'B_SCAN_C_PAY': 'B扫C支付',
  'NOPAY': '无需支付'
}

export default {
  mixins: [posMixin],
  computed: {
    payChannelOptions () {
      return this.$store.state.app.payChannelOptions
    },
    scenicName () {
      return this.$localStore.get('scenicName') || this.$store.state.user.scenicName
    },
    showPosQuery () {
      return (this.scenicName === '狼山景区' || this.scenicName === '军山景区') && this.orderData.payChannel && (this.orderData.payChannel.indexOf('中行') > -1 || posPayArray.indexOf(this.orderData.payChannel) > -1) && this.orderData.status !== 'CANCELED'
    },
    // 票种和状态搜索
    filterOrderData () {
      if (this.orderData && this.orderData.tickets) {
        return this.orderData.tickets.filter(t =>
          (!this.filterText || t.ticketNo.indexOf(this.filterText) !== -1) && (!this.status || t.status === this.status)
        )
      } else {
        return []
      }
    },
    // 列表当前所有的票的状态
    currentTicketStatus () {
      if (this.orderData && this.orderData.tickets) {
        let orderDataTickets = this.orderData.tickets.map((item) => {
          return this.ticketStatus.find(i => i.value === item.status)
        })

        let currentTicketStatus = orderDataTickets.reduce((pre, item, index) => {
          pre.some(row => row.value === item.value) || pre.push(item)
          return pre
        }, [])
        return currentTicketStatus
      } else {
        return []
      }
    }
  },
  components: {
    SalesList,
    QueryPos,
    RefundPrice
  },
  data () {
    return {
      allowUnusedCancle: false,
      visible: false,
      orderData: {},
      currentTicket: null,
      cancel_pay_channel: '',
      cancel_manager: null,
      isRefundPosInfo: null,
      loading: false,
      isRefunding: false,
      filterText: '', // 单号搜索
      status: '',
      b2cModalvisible: false,
      payTypeMap,
      b2cForm: {
        /* 待传的参数 */
        orderId: '', // 要查的建行B2C退款中的订单号
        payType: '',
        type: 'TICKET', // 没找到type来源，暂时写死
        price: '',
        ticketStatus: '',
        payChannel: ''
      },
      b2cRefundTickets: [], // 查出来的b扫c退款信息数组
      ticketStatus: [
        {
          label: '未检票',
          value: 'WAIT_USE'
        },
        {
          label: '部分检票',
          value: 'PART_USE'
        },
        {
          label: '已检票',
          value: 'USED'
        },
        {
          label: '已完成',
          value: 'COMPLETE'
        },
        {
          label: '已退票',
          value: 'CANCELED'
        },
        {
          label: '已过期',
          value: 'OUTOFDATE'
        },
        {
          label: '退款中',
          value: 'REFUNDING'
        }
      ],
      selectable: function (row, index) {
        if (row.status === 'CANCELED') {
          return false
        } else {
          return true
        }
      },
      selectedTicket: []
    }
  },
  methods: {
    getPayTypeName (type) {
      return this.payTypeMap.hasOwnProperty(type) ? this.payTypeMap[type] : type
    },
    checkRefundVisible (item) {
      if (this.$localStore.get('showRefundBtnAlways')) return true
      // 不支持部分退的景区
      const arr = ['东方绿舟']

      if (arr.indexOf(this.scenicName) > -1) return false

      if (item.status !== 'USED' && item.status !== 'CANCELED') return true
      if (item.status === 'CANCELED') return false
      return (item.status === 'USED') && checkPermission('ticket_sale:refund_checked')
    },
    checkPartRefundVisible (item) {
      // return item.status === 'USED' && checkPermission('ticket_sale:part_refund')
      return (item.status === 'USED' || this.allowUnusedCancle) && checkPermission('ticket_sale:part_refund')
    },
    show (data, allowUnusedCancle) {
      this.filterText = ''
      this.status = ''
      this.visible = true
      this.allowUnusedCancle = allowUnusedCancle === '1'
      this.orderData = JSON.parse(JSON.stringify(data))

      this.cancel_pay_channel = ''
    },
    handleClose () {
      if (this.isRefunding) {
        this.$confirm('正在退款，是否强制退出？', '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$log.info('退款被强制终止。')
          this.visible = false
          this.killAllPosProcess()
        }).catch(() => {})
        return
      }

      this.visible = false
      this.killAllPosProcess()
    },
    handleGetSaleId ({ cancel_manager, cancel_pay_channel, cancel_password }) {
      this.cancel_manager = cancel_manager
      this.cancel_pay_channel = cancel_pay_channel
      this.cancel_password = cancel_password
      if (this.selectedTicket.length) {
        this.cancelTicketList()
      } else {
        this.refundTicket(this.currentTicket)
      }
    },
    refindPrice () {
      this.visible = false
      this.$emit('updateList')
    },

    partRefundTicket (data) {
      console.log(data)
      this.$refs.refundPrice.show(data)
    },
    setb2cFormFromRow (row) {
      this.b2cForm.orderId = row.order_id // orderId：row.order_id
      this.b2cForm.payType = this.orderData.pay_type // payType: this.orderData.pay_type
      this.b2cForm.type = 'TICKET' // 没找到type来源，暂时写死
      this.b2cForm.price = row.price // price: row.price
      this.b2cForm.ticketStatus = row.status // ticketStatus: row.status
      this.b2cForm.payChannel = this.orderData.payChannel // payChannel: this.orderData.payChannel
    },
    async b2cModalSearch (row) {
      this.b2cModalvisible = true
      this.setb2cFormFromRow(row) // 设置b2cForm表单中待查询的数据，这里要传入row参数
      /*
        测试数据 02230510101955185533
        let demoParams = {
          'orderId': row.order_id,
          'payType': this.orderData.pay_type,
          'type': 'TICKET', // 没找到type来源，暂时写死
          'price': this.b2cForm.price,
          'ticketStatus': row.status,
          'payChannel': this.orderData.payChannel
        }
      */
      let res = await getRefundNeedRetryInfo(this.b2cForm)
      if (res.resCode === 200) {
        // res?.data为查出来的B扫C退款信息数组，res?.data[0]里有create_time，refundStatus等参数
        this.b2cRefundTickets = res?.data // 这里把返回结果赋给b2cRefundTickets用来弹窗展示
      }
      console.log('查询退款信息结果为：', JSON.stringify(res?.data)) // 退款出问题时，方便查看
      console.log('查询退款信息查询参数为：', JSON.stringify(this.b2cForm))
    },
    async handleDoRefundRetry (row) {
      // console.log('本行参数：', JSON.stringify(row))
      let doRefundRetryParams = {
        'taskId': row.id,
        'payType': this.b2cForm.payType,
        'type': 'TICKET', // 目前type写死为'TICKET'
        'price': row.price,
        'ticketStatus': this.b2cForm.ticketStatus,
        'payChannel': this.b2cForm.payChannel
      }
      console.log('params:', doRefundRetryParams)
      let res = await doRefundRetry(doRefundRetryParams)
      if (res.resCode === 200) {
        this.$message.success(res?.data)
      } else {
        this.$message.error(res.errInfo)
      }
      this.$alert('退款重试信息：' + res.resCode === 200 ? res?.data : res.errInfo, '退款重试结果', {
        confirmButtonText: '确定',
        callback: action => {
          this.$message({
            type: 'info',
            message: `action: ${action}`
          })
        }
      })
      console.log('退款重试信息:', JSON.stringify(res))
    },
    handleSelectionChange (e) {
      console.log('%c [ e ]-608', 'font-size:13px; background:pink; color:#bf2c9f;', e)
      this.selectedTicket = e
    },
    cancelTicketList () {
      if (this.selectedTicket.some(item => item.status !== this.selectedTicket[0].status)) {
        this.$message.error('门票状态不一致，无法进行批量操作')
        return
      }
      const data = this.selectedTicket
      const price = data.reduce((a, b) => a + b.price, 0)
      if (!this.cancel_manager) {
        this.$refs.salesList.show(this.orderData.managerId, data[0].status, price)
        return
      }
      const ticket_no_list = data.map(item => {
        return `<p>票号：${item.ticketNo}</p>`
      })
      console.log('%c [ ticket_no_list ]-630', 'font-size:13px; background:pink; color:#bf2c9f;', ticket_no_list)
      let str = `<div>
        <p>退款金额：<b style="font-size: 20px; color:red">${price}</b></p>
        <p>退款方式：<b style="font-size: 20px;color:red">${this.cancel_pay_channel}</b></p>
        <p style="${this.cancel_manager ? '' : 'display:none'}">售票员：<b style="font-size: 20px; color:red">${this.cancel_manager && this.cancel_manager.nickName}</b></p>
        ${ticket_no_list.join('')}
        <p>确认退票 ？</p>
      </div>`
      this.$confirm(str, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        this.cancelTicket(data)
      }).catch(() => {
        this.cancel_manager = null
      })
    },
    refundTicket (data) {
      // 昭苏 强退已检票必填退票原因
      if (['昭苏'].includes(this.scenicName) && data.status === 'USED') {
        if (!data.cancel_remark) {
          return this.$message.error('退已检票请填写退票原因')
        }
      }
      this.currentTicket = data

      if (!this.cancel_manager) {
        this.$refs.salesList.show(this.orderData.managerId, data.status, data.price)
        return
      }

      let str = `<div>
        <p>票号：${data.ticketNo}</p>
        <p>退款金额：<b style="font-size: 20px; color:red">${data.price}</b></p>
        <p>退款方式：<b style="font-size: 20px;color:red">${this.cancel_pay_channel}</b></p>
        <p style="${this.cancel_manager ? '' : 'display:none'}">售票员：<b style="font-size: 20px; color:red">${this.cancel_manager && this.cancel_manager.nickName}</b></p>
        <p>确认退票 ？</p>
      </div>`
      this.$confirm(str, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        switch (true) {
          case this.cancel_pay_channel.indexOf('中行') > -1 || posPayArray.indexOf(this.cancel_pay_channel) > -1:
            let params = JSON.parse(JSON.stringify(this.orderData))
            // 设置可退金额
            params.price = data.price

            // 有已退款信息时，直接取消门票
            if (this.isRefundPosInfo) {
              this.cancelTicket(data)
            } else {
              if (data.status !== 'CANCELED') this.cancelTicket(data, true)
              this.handlePosPay(params, data)
            }
            break
          case this.cancel_pay_channel.indexOf('储值') > -1 && this.scenicName.indexOf('西宁') > -1:
            this.handleValueCardRefund(data)
            break
          default:
            this.cancelTicket(data)
        }
      }).catch(() => {
        this.cancel_manager = null
      })
    },
    // 储值卡退单
    handleValueCardRefund (data) {
      let ticket = {
        id: data.id,
        cancelPrice: data.price,
        cancel_pay_channel: this.cancel_pay_channel,
        cancel_remark: data.cancel_remark
      }
      // 添加售票员id
      ticket.cancel_managerId = this.cancel_manager.id
      if (data.status === 'USED') {
        cancelValueCardCheckedTicket({
          cardNo: this.orderData.changyi_valuecardNo,
          cardVendor: 'CHANGYI',
          ticketList: [ticket]
        })
          .then(this.handleSuccess)
          .finally(() => {
            this.isRefunding = false
          })
      } else {
        cancelValueCardSingleTicket({
          cardNo: this.orderData.changyi_valuecardNo,
          cardVendor: 'CHANGYI',
          ticket
        })
          .then(this.handleSuccess)
          .finally(() => {
            this.isRefunding = false
            this.$forceUpdate()
          })
      }
    },
    /**
     * data: 当前要退款的票
     */
    handlePosPay (params, ticket) {
      params.tickets = [ticket]
      this.$log.info('中行退款')
      this.isRefunding = true
      // 'C'代表消费，’R‘代表退货
      choosePay('refund', params, this).then(data => {
        if (data) {
          this.$message.success('退款成功')
          this.$log.info('退款成功')
          // this.cancelTicket(ticket)
          if (isJSON(data)) {
            params.bocTradeNo = data
            params.bocPosId = JSON.parse(data).terminal || JSON.parse(data).terminalID
            // 设置本地pos终端号
            this.refundPOS(params)
            this.$localStore.set('termId', JSON.parse(data).terminal)
          } else {
            params.bocTradeNo = data
            params.bocPosId = getPayResponse(data).terminalNo
            this.refundPOS(params)
            this.$localStore.set('termId', JSON.parse(data).terminal)
          }
        }
      }).finally(() => {
        this.isRefunding = false
        this.handleClose()
      })
    },
    refundPOS (params) {
      refundPOS({
        list: params.tickets.map(i => { return { id: i.id } }),
        refund_info: params.bocTradeNo,
        refund_pos_id: params.bocPosId,
        type: 'TICKET'
      }).then(res => {
        this.$emit('updateList')
      })
    },
    handleSuccess (isPospay) {
      this.$log.info('退票成功')
      this.$message.success('退票成功')

      // 修复退票成功后状态未更新
      setTimeout(() => {
        this.$emit('updateList')
      }, 1000)

      if (!isPospay) {
        this.handleClose()
      }
    },
    cancelTicket (data, isPospay) {
      let ticket
      if (data.length > 0) {
        ticket = data.map(item => {
          return {
            id: item.id,
            cancelPrice: item.price,
            cancel_pay_channel: this.cancel_pay_channel,
            cancel_password: this.cancel_password ? this.cancel_password : undefined,
            cancel_remark: item.cancel_remark,
            // 添加售票员id
            cancel_managerId: this.cancel_manager.id ? this.cancel_manager.id : undefined
          }
        })
      } else {
        ticket = {
          id: data.id,
          cancelPrice: data.price,
          cancel_pay_channel: this.cancel_pay_channel,
          cancel_password: this.cancel_password ? this.cancel_password : undefined,
          cancel_remark: data.cancel_remark,
          // 添加售票员id
          cancel_managerId: this.cancel_manager.id ? this.cancel_manager.id : undefined
        }
      }

      this.loading = true
      const ticketList = data.length > 0 ? ticket : [ticket]
      if ((data.length > 0 && data[0].status === 'USED') || data.status === 'USED') {
        apiOrder('cancelCheckedTicket', {
          ticketList: ticketList
        })
          .then(this.handleSuccess(isPospay))
          .finally(() => {
            this.loading = false
            // 更新旅行社余额
            this.orderData.payChannel === '旅行社余额' && (this.$store.dispatch('getAgencyList'))

            this.cancel_manager = null
          })
      } else if (data.length > 0) {
        apiOrder('cancelMultiTicket', ticket)
          .then(this.handleSuccess(isPospay))
          .finally(() => {
            this.loading = false
            // 更新旅行社余额
            this.orderData.payChannel === '旅行社余额' && (this.$store.dispatch('getAgencyList'))

            this.cancel_manager = null
            this.$forceUpdate()
          })
      } else {
        apiOrder('cancelSingleTicket', ticket)
          .then(this.handleSuccess(isPospay))
          .finally(() => {
            this.loading = false
            // 更新旅行社余额
            this.orderData.payChannel === '旅行社余额' && (this.$store.dispatch('getAgencyList'))

            this.cancel_manager = null
            this.$forceUpdate()
          })
      }
    },
    handleQueryPos (posInfo) {
      console.log(posInfo)

      if ((posInfo.amount / 100).toFixed(2) !== this.currentTicket.price + '') {
        this.$message.error('退款金额不一致。')
        return
      }

      this.isRefundPosInfo = posInfo
      this.refundTicket(this.currentTicket)
    }
  },
  beforeDestroy () {
    this.killAllPosProcess()
  }
}
</script>

<style lang="scss" scoped>

</style>
