<template>
  <div class="form-wrap">
    <div class="searchBox">
      <el-form
        ref="form"
        :model="form"
        :inline="true"
        label-width="150px">
        <el-form-item
          label="下单起始时间"
          prop="createTimeBegin">
          <el-date-picker
            v-model="form.createTimeBegin"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="下单截止时间"
          prop="createTimeEnd">
          <el-date-picker
            v-model="form.createTimeEnd"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="游玩开始时间"
          prop="playDateBegin">
          <el-date-picker
            v-model="form.playDateBegin"
            type="date"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="游玩结束时间"
          prop="playDateEnd">
          <el-date-picker
            v-model="form.playDateEnd"
            type="date"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="关键字"
          prop="searchKeywords">
          <el-input
            v-model="form.searchKeywords"
            placeholder="订单号/票号/姓名/电话/证件号"></el-input>
        </el-form-item>
        <el-form-item
          label="合作方订单号"
          prop="partnerOrderNo">
          <el-input v-model="form.partnerOrderNo"></el-input>
        </el-form-item>
        <el-form-item
          label="票号"
          prop="ticketNo">
          <el-input v-model="form.ticketNo"></el-input>
        </el-form-item>
        <el-form-item
          label="分销商名称"
          prop="otaSourceNameList">
          <el-select
            v-model="form.otaSourceNameList"
            multiple
            clearable
            placeholder="请选择"
            filterable>
            <el-option
              v-for="item in otaSourceList"
              :key="item.id"
              :label="item.otaSourceName"
              :value="item.otaSourceName">
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item
          label="票种"
          prop="keyWords8">
          <el-select
            filterable
            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="orderStatus">
          <el-select
            v-model="form.orderStatus"
            clearable
            placeholder="请选择">
            <el-option
              value=""
              label="全部"></el-option>
            <el-option
              v-for="(value, key) in orderStatusDic"
              :key="key"
              :label="value.label"
              :value="key">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="门票状态"
          prop="ticketStatus">
          <el-select
            v-model="form.ticketStatus"
            clearable
            placeholder="请选择">
            <el-option
              value=""
              label="全部"></el-option>
            <el-option
              v-for="(value, key) in ticketStatusDic"
              :key="key"
              :label="value.label"
              :value="value.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="btn-wrap">
        <el-button
          @click="reset">重置</el-button>
        <el-button
          type="primary"
          @click="getOrderList($event,true)">搜索</el-button>
        <el-button
          type="primary"
          @click="reportExport">导出</el-button>
      </div>
    </div>

    <div class="tableBox">
      <!-- <div class="block-title">
        查询信息
      </div> -->
      <el-table
        :data="tableData"
        stripe
        border
        row-class-name="is-center"
        v-loading="loading">
        <el-table-column type="expand">
          <template
            slot-scope="scope"
            v-if="scope.row.ticketList && scope.row.ticketList.length > 0">
            <el-table
              :data="scope.row.ticketList"
              border>
              <el-table-column
                min-width="260"
                prop="ticketInfo"
                label="票信息">
                <template slot-scope="scope">
                  <div class=""><span>票号：</span>{{ scope.row.ticketNo }}</div>
                  <div class=""><span>票种：</span>{{ scope.row.ticketTypeName }}</div>
                  <div class=""><span>产品ID：</span>{{ scope.row.otaProductId }}</div>
                  <div class=""><span>售卖价：</span>{{ scope.row.price }}</div>
                  <div class=""><span>结算价：</span>{{ scope.row.settlementPrice }}</div>
                  <div class=""><span>状态：</span>
                    <el-tag :type="ticketStatus[scope.row.status]&&ticketStatus[scope.row.status].color">
                      {{ ticketStatus[scope.row.status]&&ticketStatus[scope.row.status].label }}
                    </el-tag>
                  </div>
                  <!-- <div class=""><span>票号二维码图片地址：</span>{{ scope.row.qrcodeUrl }}</div> -->
                </template>
              </el-table-column>
              <el-table-column
                prop="playDateBegin"
                width="180"
                label="游玩时间">
                <template slot-scope="scope">
                  <div v-if="scope.row.batchConfigName"><span>场次：</span>{{ scope.row.batchConfigName }}</div>
                  <div>
                    {{ scope.row.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
                  </div>
                </template>
              </el-table-column>
              <!-- <el-table-column
                prop="buyTime"
                label="付款时间">
              </el-table-column> -->
              <el-table-column
                min-width="210"
                prop="guestInfo"
                label="游客信息">
                <template slot-scope="scope">
                  <div class=""><span>姓名：</span>{{ scope.row.guestName }}</div>
                  <div class=""><span>手机号：</span>{{ scope.row.guestPhone }}</div>
                  <div class=""><span>证件类型：</span>{{ papersType[scope.row.guestIdentifyType] }}</div>
                  <div class=""><span>证件号码：</span>{{ scope.row.guestIdentify }}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="260"
                prop="ticketCheckInfo"
                label="检票信息">
                <template slot-scope="scope">
                  <div class=""><span>检票人数：</span>{{ scope.row.checkNum }}</div>
                  <div class=""><span>首次检票时间：</span>{{ scope.row.firstCheckTime }}</div>
                  <!-- <div class=""><span>最近一次检票时间：</span>{{ scope.row.checkTime }}</div> -->
                  <div class=""><span>核销通知：</span>{{ scope.row.isCheckSend ? '已通知' : '未通知' }}</div>
                  <div class=""><span>通知成功时间：</span>{{ scope.row.checkSendTime }}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="260"
                prop="ticketRefundInfo"
                label="退票信息">
                <template slot-scope="scope">
                  <div class=""><span>退款操作人：</span>{{ scope.row.cancelAdminName || '' }}</div>
                  <div class=""><span>退款金额：</span>{{ scope.row.cancelPrice || '' }}</div>
                  <div class=""><span>退款申请时间：</span>{{ scope.row.cancelSubmitTime || '' }}</div>
                  <div class=""><span>退款完成时间：</span>{{ scope.row.cancelCompleteTime || '' }}</div>
                  <div class=""><span>是否强制取消：</span>{{ scope.row.isForceCancel ? '是' : '否' }}</div>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column
          prop="otaSourceName"
          min-width="120"
          label="订单来源渠道">
        </el-table-column>
        <el-table-column
          prop="orderNo"
          min-width="190"
          label="订单号">
        </el-table-column>
        <el-table-column
          prop="partnerOrderNo"
          min-width="220"
          label="合作方订单号">
        </el-table-column>
        <el-table-column
          prop="ticketTypeName"
          width="120"
          label="票种">
          <template slot-scope="scope">
            {{ getTicketTypeName(scope.row) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="buyerName"
          min-width="90"
          label="购买方名称">
        </el-table-column>
        <el-table-column
          prop="buyerPhone"
          width="100"
          label="购买方电话">
        </el-table-column>
        <el-table-column
          prop="buyerIdentify"
          width="150"
          label="购买方证件号">
        </el-table-column>
        <el-table-column
          prop="payStatus"
          width="100"
          label="支付状态">
          <template slot-scope="scope">
            <el-tag
              :type="getPayStatus(scope.row.payStatus,'type')"
              size="normal"
            >
              {{ getPayStatus(scope.row.payStatus) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="status"
          width="100"
          label="订单状态">
          <template slot-scope="scope">
            <el-tag
              :type="getOrderStatus(scope.row.status, 'color')"
              size="normal"
            >
              {{ getOrderStatus(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          width="140"
          label="订单总价">
          <template slot-scope="scope">
            <div>售卖价：{{ scope.row.price }}</div>
            <div>结算价：{{ scope.row.settlementPrice }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          width="135"
          label="下单时间">
        </el-table-column>
        <el-table-column
          prop="payTime"
          width="135"
          label="支付时间">
        </el-table-column>
        <el-table-column
          prop="closeTime"
          width="135"
          label="关闭时间">
        </el-table-column>
        <el-table-column
          prop="otaCreateStatus"
          width="100"
          label="创建状态">
          <template slot-scope="scope">
            {{ scope.row.otaCreateStatus === 1 ? '创建成功' : '初始化' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="isSelfOrder"
          width="70"
          label="是否自营">
          <template slot-scope="scope">
            {{ scope.row.isSelfOrder === 1 ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="otaCreateMsg"
          min-width="120"
          show-overflow-tooltip
          label="订单创建信息">
        </el-table-column>
        <!-- <el-table-column
          label="状态">
          <template slot-scope="scope">
            <el-tag :type="orderStatusDic[scope.row.status] && orderStatusDic[scope.row.status].color || ''">
              {{ orderStatusDic[scope.row.status] && orderStatusDic[scope.row.status].label || scope.row.status }}
            </el-tag>
          </template>
        </el-table-column> -->
        <el-table-column
          width="120"
          label="操作">
          <template slot-scope="scope">
            <!-- <el-button
              type="text"
              @click="showOrderInfo(scope.row)">订单详情</el-button>
            <el-button
              type="text"
              @click="$refs.ticketInfo.show(scope.row.tickets)">门票详情</el-button>
            <el-button
              type="text"
              @click="showGuestInfo(scope.row)">游客信息</el-button> -->
            <el-button
              type="text"
              v-if="scope.row.isSelfOrder === 0 && hasPermission('order-cancel')"
              @click="showRefundOrder(scope.row)">退单</el-button>
            <el-button
              type="text"
              v-if="scope.row.isSelfOrder === 0 && hasPermission('order-manual-check')"
              @click="showManualCheckOrder(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>
    </div>

    <ElDialog
      :title="type==='cancel'?'退单':'订单详情'"
      width="760px"
      v-model="orderDialogVisible"
    >
      <OrderDialog
        :current-item="currentItem"
        @updateList="getOrderList"
        :type="type"></OrderDialog>
    </ElDialog>
    <ElDialog
      title="游客信息"
      width="760px"
      v-model="guestDialogVisible">
      <GuestDialog
        :current-item="currentItem"></GuestDialog>
    </ElDialog>
    <ElDialog
      title="退单"
      v-model="refundOrderDialogVisible"
      width="80%"
      @close="refundOrderDialogVisible=false;ticketNoSearch=''">
      <div
        class="search-area"
        style="margin: 20px;display: flex;align-items: center;justify-content: space-between;">
        <div class="name">
          <span style="margin-right: 10px;">票号搜索</span>
          <el-input v-model="ticketNoSearch"></el-input>
        </div>
      </div>
      <div
        class="table-wrap"
        style="padding: 20px;">
        <el-table
          border
          :data="(currentItem.ticketList || []).filter(v => v.ticketNo.includes(ticketNoSearch))"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            fixed
            :selectable="isRowSelectable"
            width="55">
          </el-table-column>
          <el-table-column
            min-width="260"
            prop="ticketInfo"
            label="票信息">
            <template slot-scope="scope">
              <div class=""><span>票号：</span>{{ scope.row.ticketNo }}</div>
              <div class=""><span>票种：</span>{{ scope.row.ticketTypeName }}</div>
              <div class=""><span>金额：</span>{{ scope.row.price }}</div>
              <div class=""><span>状态：</span>
                <el-tag :type="ticketStatus[scope.row.status]&&ticketStatus[scope.row.status].color">
                  {{ ticketStatus[scope.row.status]&&ticketStatus[scope.row.status].label }}
                </el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="playDateBegin"
            width="180"
            label="游玩时间">
            <template slot-scope="scope">
              {{ scope.row.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
            </template>
          </el-table-column>
          <el-table-column
            min-width="210"
            prop="guestInfo"
            label="游客信息">
            <template slot-scope="scope">
              <div class=""><span>姓名：</span>{{ scope.row.guestName }}</div>
              <div class=""><span>手机号：</span>{{ scope.row.guestPhone }}</div>
              <div class=""><span>证件类型：</span>{{ papersType[scope.row.guestIdentifyType] }}</div>
              <div class=""><span>证件号码：</span>{{ scope.row.guestIdentify }}</div>
            </template>
          </el-table-column>
          <el-table-column
            min-width="260"
            prop="ticketCheckInfo"
            label="检票信息">
            <template slot-scope="scope">
              <div class=""><span>检票人数：</span>{{ scope.row.checkNum }}</div>
              <div class=""><span>首次检票时间：</span>{{ scope.row.firstCheckTime }}</div>
              <div class=""><span>核销通知：</span>{{ scope.row.isCheckSend ? '已通知' : '未通知' }}</div>
              <div class=""><span>通知成功时间：</span>{{ scope.row.checkSendTime }}</div>
            </template>
          </el-table-column>
          <el-table-column
            min-width="260"
            prop="ticketRefundInfo"
            label="退票信息">
            <template slot-scope="scope">
              <div class=""><span>退款操作人：</span>{{ scope.row.cancelAdminName || '' }}</div>
              <div class=""><span>退款金额：</span>{{ scope.row.cancelPrice || '' }}</div>
              <div class=""><span>退款申请时间：</span>{{ scope.row.cancelSubmitTime || '' }}</div>
              <div class=""><span>退款完成时间：</span>{{ scope.row.cancelCompleteTime || '' }}</div>
              <div class=""><span>是否强制取消：</span>{{ scope.row.isForceCancel ? '是' : '否' }}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div
        class="dialog-footer"
        style="padding: 20px; text-align: right;">
        <el-button @click="refundOrderDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="submitRefundOrder">确定</el-button>
      </div>
    </ElDialog>

    <ElDialog
      title="核销"
      v-model="manualCheckDialogVisible"
      width="80%"
      @close="manualCheckDialogVisible=false;manualCheckTicketNoSearch=''">
      <div
        class="search-area"
        style="margin: 20px;display: flex;align-items: center;justify-content: space-between;">
        <div class="name">
          <span style="margin-right: 10px;">票号搜索</span>
          <el-input v-model="manualCheckTicketNoSearch"></el-input>
        </div>
      </div>
      <div
        class="table-wrap"
        style="padding: 20px;">
        <el-table
          border
          :data="(currentItem.ticketList || []).filter(v => v.ticketNo.includes(manualCheckTicketNoSearch))"
          @selection-change="handleManualCheckSelectionChange">
          <el-table-column
            type="selection"
            fixed
            :selectable="isManualCheckRowSelectable"
            width="55">
          </el-table-column>
          <el-table-column
            min-width="260"
            prop="ticketInfo"
            label="票信息">
            <template slot-scope="scope">
              <div class=""><span>票号：</span>{{ scope.row.ticketNo }}</div>
              <div class=""><span>票种：</span>{{ scope.row.ticketTypeName }}</div>
              <div class=""><span>金额：</span>{{ scope.row.price }}</div>
              <div class=""><span>状态：</span>
                <el-tag :type="ticketStatus[scope.row.status]&&ticketStatus[scope.row.status].color">
                  {{ ticketStatus[scope.row.status]&&ticketStatus[scope.row.status].label }}
                </el-tag>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="playDateBegin"
            width="180"
            label="游玩时间">
            <template slot-scope="scope">
              {{ scope.row.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
            </template>
          </el-table-column>
          <el-table-column
            min-width="210"
            prop="guestInfo"
            label="游客信息">
            <template slot-scope="scope">
              <div class=""><span>姓名：</span>{{ scope.row.guestName }}</div>
              <div class=""><span>手机号：</span>{{ scope.row.guestPhone }}</div>
              <div class=""><span>证件类型：</span>{{ papersType[scope.row.guestIdentifyType] }}</div>
              <div class=""><span>证件号码：</span>{{ scope.row.guestIdentify }}</div>
            </template>
          </el-table-column>
          <el-table-column
            min-width="260"
            prop="ticketCheckInfo"
            label="检票信息">
            <template slot-scope="scope">
              <div class=""><span>检票人数：</span>{{ scope.row.checkNum }}</div>
              <div class=""><span>首次检票时间：</span>{{ scope.row.firstCheckTime }}</div>
              <div class=""><span>核销通知：</span>{{ scope.row.isCheckSend ? '已通知' : '未通知' }}</div>
              <div class=""><span>通知成功时间：</span>{{ scope.row.checkSendTime }}</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div
        class="dialog-footer"
        style="padding: 20px; text-align: right;">
        <el-button @click="manualCheckDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="submitManualCheckOrder">确定</el-button>
      </div>
    </ElDialog>

    <TicketInfo ref="ticketInfo"></TicketInfo>
  </div>
</template>
<script>
import { getOrderList, getOtaSourceList, cancelOrder, checkTicket } from '@/api/order'
import { getTicketTypeList } from '@/api/ticketType'
import ElDialog from '@/components/Dialog'
import OrderDialog from './orderList/OrderDialog'
import GuestDialog from './orderList/GuestDialog'
import TicketInfo from './orderList/TicketInfo'
import { ORDER_STATUS, ticketStatusDic, ticketStatus, IDENTIFY_TYPES } from '@/const'
import moment from 'moment'
import { getPayStatus, getOrderStatus } from '@/utils'

export default {
  name: 'orderList',
  components: {
    ElDialog,
    OrderDialog,
    GuestDialog,
    TicketInfo
  },
  data () {
    return {
      refundOrderDialogVisible: false,
      manualCheckDialogVisible: false,
      refundOrderInfo: {
        ticketCancelRequestList: []
      },
      ticketNoSearch: '',
      manualCheckTicketNoSearch: '',
      multipleSelection: [],
      manualCheckSelection: [],
      papersType: IDENTIFY_TYPES,
      ticketTypeList: [],
      otaSourceList: [],
      projectName: localStorage.getItem('otaProject'),
      totalObj: {},
      type: '', // 操作状态 cancel退订单
      form: {
        searchKeywords: '', // 关键字搜索
        createTimeBegin: moment().subtract(7, 'days').startOf('day'),
        createTimeEnd: moment().endOf('day'),
        otaSourceNameList: [], // 分销商名称
        partnerOrderNo: '', // ota订单号
        visitorName: '', // 预订姓名
        visitorPhone: '', // 预订人手机
        visitorIdentify: '', // 预订人身份证
        orderStatus: '', // 状态
        orderNo: '', // 线下订单号
        ticketStatus: '', // 票状态
        playDateBegin: '', // 游玩开始日期
        playDateEnd: '', // 游玩结束日期
        ticketNo: '', // 票号
        pageNum: 1,
        pageSize: 10
      },
      orderStatusDic: ORDER_STATUS,
      ticketStatusDic,
      ticketStatus,
      loading: false,
      tableData: [],
      total: 0,
      currentItem: {},
      orderDialogVisible: false,
      guestDialogVisible: false
    }
  },
  created () {
    this.getTicketTypeList()
    this.getOtaSourceList()
    this.getOrderList()
  },
  computed: {
    queryClear () {
      return this.$store.state.user.permissionList.includes('stats:clearwx_query')
    },
    otaList () {
      const list = JSON.parse(localStorage.getItem('otaList'))
      return this.projectName === 'YINXIANGMAZU' && !this.queryClear ? list.filter(item => item.otaSourceCode !== 'CLEARWX') : list
    },
    permissionList () {
      return this.$store.state.user.menuList || []
    }
  },
  methods: {
    getPayStatus,
    getOrderStatus,
    hasPermission (key) {
      return !!this.permissionList.some(item => item.code === key)
    },
    getTicketTypeName (row) {
      const ticket = row.ticketList && row.ticketList.length > 0 && row.ticketList[0]
      return ticket ? ticket.ticketTypeName : ''
    },
    reset () {
      this.$refs.form.resetFields()
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    getTicketTypeList () {
      getTicketTypeList({
        pageNum: 1,
        pageSize: -1
      }).then(res => {
        this.ticketTypeList = res.data.records || []
      })
    },
    getOtaSourceList () {
      getOtaSourceList({
        pageNum: 1,
        pageSize: -1
      }).then(res => {
        this.otaSourceList = res.data.records || []
      })
    },
    getOrderList (e, goFirst) {
      this.loading = true
      if (goFirst) { this.form.pageNum = 1 }

      if (this.form.createTimeBegin && this.form.createTimeEnd && this.form.createTimeBegin > this.form.createTimeEnd) {
        this.$message.error('下单起始时间不能大于下单截止时间')
        this.loading = false
        return
      }

      if (this.form.playDateBegin && this.form.playDateEnd && this.form.playDateBegin > this.form.playDateEnd) {
        this.$message.error('游玩开始时间不能大于游玩结束时间')
        this.loading = false
        return
      }

      if (this.form.createTimeBegin) {
        this.form.createTimeBegin = moment(this.form.createTimeBegin).format('YYYY-MM-DD HH:mm:ss')
      }

      if (this.form.createTimeEnd) {
        this.form.createTimeEnd = moment(this.form.createTimeEnd).format('YYYY-MM-DD HH:mm:ss')
      }

      if (this.form.playDateBegin) {
        this.form.playDateBegin = moment(this.form.playDateBegin).format('YYYY-MM-DD')
      }

      if (this.form.playDateEnd) {
        this.form.playDateEnd = moment(this.form.playDateEnd).format('YYYY-MM-DD')
      }

      getOrderList(this.form).then(res => {
        this.total = res.data.total || 0
        this.tableData = res.data.records || []
        console.log('this.tableData', this.tableData)
        this.loading = false
      })
    },
    showOrderInfo (item, type) {
      if ((item.otaSourceCode === 'CLEARWX' || item.otaSourceCode === 'CLEARWXDEV') && type === 'cancel') return this.$message.info('自营平台订单请到自营后台办理退票')
      this.currentItem = item
      this.type = type
      this.orderDialogVisible = true
    },
    isRowSelectable (row, index) {
      return true
    },
    isManualCheckRowSelectable (row, index) {
      return true
      // return row.status === 'WAIT_USE' || row.status === 'PART_USE'
    },
    showRefundOrder (item) {
      this.currentItem = item
      this.refundOrderDialogVisible = true
      this.ticketNoSearch = ''
      this.multipleSelection = []
    },
    showManualCheckOrder (item) {
      this.currentItem = item
      this.manualCheckDialogVisible = true
      this.manualCheckTicketNoSearch = ''
      this.manualCheckSelection = []
    },
    submitRefundOrder (item) {
      this.$confirm('确定退票?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        let ticketList = this.multipleSelection.map(v => {
          return {
            ticketId: v.id
          }
        })

        cancelOrder({
          orderId: item.id,
          ticketCancelRequestList: ticketList
        }).then(res => {
          this.loading = false
          this.$message.success('退票成功')
          this.refundOrderDialogVisible = false
          this.ticketNoSearch = ''
          this.getOrderList('', true)
        })
      })
    },
    handleManualCheckSelectionChange (val) {
      this.manualCheckSelection = val
    },
    submitManualCheckOrder () {
      if (!this.currentItem || !this.currentItem.id) return
      if (!this.manualCheckSelection.length) {
        this.$message.warning('请选择需要核销的门票')
        return
      }
      this.$confirm('确定核销?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        const ticketList = this.manualCheckSelection.map(v => {
          return {
            ticketId: v.id
          }
        })

        checkTicket({
          orderId: this.currentItem.id,
          ticketManualCheckRequestList: ticketList
        }).then(() => {
          this.loading = false
          this.$message.success('核销成功')
          this.manualCheckDialogVisible = false
          this.manualCheckTicketNoSearch = ''
          this.getOrderList('', true)
        }).catch(() => {
          this.loading = false
        })
      })
    },
    showGuestInfo (item) {
      this.currentItem = item
      this.guestDialogVisible = true
    },
    reportExport () {
      this.$confirm(`是否要导出明细数据`, '确认提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      }).then(() => {
        this.handelExport({
          ...this.form,
          export: true,
          exportDetail: true
        })
      }).catch(() => {
        this.handelExport({
          ...this.form,
          export: true,
          exportDetail: false
        })
      })
    },
    handelExport (params) {
      this.form.export = true
      getOrderList(params).then(res => {
        this.$confirm('导出成功，是否去下载页', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$router.push('/queryReport/reportExport')
        }).catch(() => {})
      }, () => {
        this.$notify.error({
          title: '提示',
          message: '导出失败'
        })
      })
      this.form.export = false
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
