<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
      label-width="100px"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="下单时间"
        prop="createTime">
        <el-date-picker
          v-model="form.createTime"
          style="width:240px"
          type="daterange"
          format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="游玩时间"
        prop="playDate">
        <el-date-picker
          v-model="form.playDate"
          style="width:240px"
          type="daterange"
          format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="关键词"
        prop="searchKeywords"
      >
        <ReaderInput
          style="width:320px !important"
          v-model="form.searchKeywords"
          placeholder="订单号/票号/游客姓名/电话/证件号"
          clearable
          @change="form.searchKeywords=$event.IDNumber,form.name=$event.Name"
          @input="setSearchKeywords"
        ></ReaderInput>
      </el-form-item>
      <el-form-item
        label="合作方订单号"
        prop="partnerOrderNo"
      >
        <el-input
          v-model="form.partnerOrderNo"
          clearable></el-input>
      </el-form-item>
      <el-form-item
        label="票号"
        prop="ticketNo"
      >
        <el-input
          v-model="form.ticketNo"
          clearable></el-input>
      </el-form-item>
      <el-form-item
        label="支付方式"
        prop="payChannelList">
        <el-select
          v-model="form.payChannelList"
          multiple
          clearable
          filterable>
          <el-option
            v-for="item in payChannelOptions"
            :key="item"
            :label="item"
            :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="销售来源"
        prop="otaSourceNameList">
        <el-select
          v-model="form.otaSourceNameList"
          multiple
          clearable
          filterable>
          <el-option
            v-for="item in otaSourceList"
            :key="item"
            :label="item"
            :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="订单状态"
        prop="orderStatus"
      >
        <el-select
          v-model="form.orderStatus"
          clearable
          placeholder="请选择"
        >
          <el-option
            label="全部"
            value=""></el-option>
          <el-option
            v-for="item in orderStatusDic"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="门票状态"
        prop="ticketStatus"
      >
        <el-select
          v-model="form.ticketStatus"
          clearable
          placeholder="请选择"
        >
          <el-option
            label="全部"
            value=""></el-option>
          <el-option
            v-for="item in ticketStatusDic"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="订单类型"
        prop="orderCategory"
      >
        <el-select
          v-model="form.orderCategory"
          placeholder="请选择"
          clearable
          filterable>
          <el-option
            v-for="item in orderCategories"
            :key="item.id"
            :value="item.id"
            :label="item.name">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="票种"
        prop="ticketTypeIdList"
      >
        <el-select
          v-model="form.ticketTypeIdList"
          placeholder="请选择"
          multiple
          clearable
          filterable>
          <el-option
            v-for="item in ticketTypeList"
            :key="item.id"
            :value="item.id"
            :label="item.name">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="景点"
        prop="scenicIdList"
      >
        <el-select
          v-model="form.scenicIdList"
          placeholder="请选择"
          multiple
          clearable
          filterable>
          <el-option
            v-for="(item, idx) in scenicList"
            :key="`scene-${idx}`"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        label="售票员"
        prop="adminIdList"
      >
        <el-select
          v-model="form.adminIdList"
          multiple
          clearable
          placeholder="请选择"
          filterable>
          <el-option
            v-for="item in accountList"
            :key="item.id"
            :value="item.id"
            :label="item.loginName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="售卖自助机"
        prop="saleTermIdList"
      >
        <el-select
          v-model="form.saleTermIdList"
          multiple
          clearable
          placeholder="请选择"
          filterable>
          <el-option
            v-for="item in termList"
            :key="item.id"
            :value="item.id"
            :label="item.name">
          </el-option>
        </el-select>
      </el-form-item>
      <div class="btn-wrap">
        <el-button
          @click="reset"
        >
          重置
        </el-button>
        <el-button
          :disabled="loading"
          type="primary"
          @click="getOrderList(true)"
        >
          搜索
        </el-button>
        <el-dropdown @command="reportExport" style="margin-left: 10px;">
          <el-button type="primary">
            导出<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="order">订单级别</el-dropdown-item>
            <el-dropdown-item command="ticket">门票级别</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

        <i class="el-icon-setting" style="cursor: pointer; margin-left: 10px;" title="设置显示列" @click="showColumnConfig" />
      </div>
    </el-form>

    <div class="table-box">
      <!-- <div class="block-title">
        统计信息
      </div> -->
      <el-table
        stripe
        border
        v-loading="loading"
        :data="tableData">
        <el-table-column
          width="300"
          prop="orderNo"
          label="订单"
          fixed="left"
        >
          <template slot-scope="scope">
            <div
              class="order-info-item">
              <div class="label">
                订单号：
              </div>
              <div class="value">
                {{ scope.row.orderNo }}
              </div>
            </div>
            <div
              class="order-info-item">
              <div class="label">
                合作方订单号：
              </div>
              <div class="value">
                {{ scope.row.partnerOrderNo }}
              </div>
            </div>
            <!-- <el-tag
              type="primary"
              size="small"
              style="position: absolute; top: 0; right: 10px;"
            >
              {{ scope.row.firstTicketTypeName }}
            </el-tag> -->
          </template>
        </el-table-column>
        <el-table-column
          width="160"
          prop="firstTicketTypeName"
          show-overflow-tooltip
          label="票种"
        >
        </el-table-column>
        <!-- <el-table-column
          width="75"
          prop="orderCategory"
          label="订单类型"
        >
          <template slot-scope="scope">
            {{ scope.row.orderCategory | filterOrderCategory }}
          </template>
        </el-table-column> -->
        <el-table-column
          width="150"
          prop="isOnlineOrder"
          label="渠道"
        >
          <template slot-scope="scope">
            <div class="order-info-item">
              <div class="label">
                销售来源：{{ scope.row.isOnlineOrder === 1 ? '线上' : '线下' }}
              </div>
            </div>
            <div
              class="order-info-item">
              <div class="label">
                销售渠道：{{ scope.row.otaSourceName }}
              </div>
            </div>
            <div
              class="order-info-item">
              <div class="label">
                支付渠道：{{ scope.row.payChannel }}
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="支付状态"
          width="100"
          fixed="right"
        >
          <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
          label="支付时间"
          width="140"
          prop="payTime">
        </el-table-column>
        <el-table-column
          label="票种"
          min-width="120">
          <template slot-scope="scope">
            <Ellipsis
              type="tooltip"
              :content="scope.row.ticketsName"
              :length="15"></Ellipsis>
          </template>
        </el-table-column> -->
        <el-table-column
          width="140"
          label="售票"
        >
          <template slot-scope="scope">
            <div>
              {{ scope.row.saleAdminName }}
            </div>
            <div>
              {{ scope.row.createTime | formatTime }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          width="160"
          label="购买方"
        >
          <template slot-scope="scope">
            <div>
              {{ scope.row.buyerName }}
            </div>
            <div>
              {{ scope.row.buyerPhone }}
            </div>
            <div>
              {{ scope.row.buyerIdentify }}
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column
          width="120"
          prop="buyerName"
          label="购买方名称"
        ></el-table-column>
        <el-table-column
          width="110"
          prop="buyerPhone"
          label="购买方手机">
        </el-table-column>
        <el-table-column
          width="140"
          prop="buyerIdentify"
          label="购买方证件号">
        </el-table-column> -->
        <el-table-column
          width="80"
          prop="ticketNum"
          label="所含票数"
        >
        </el-table-column>
        <!-- <el-table-column
          width="80"
          label="人数"
        >
          <template slot-scope="scope">
            {{ reduceCheckNum(scope.row.ticketList) }}
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="游客信息"
          prop="guestName">
        </el-table-column>
        <el-table-column
          width="80"
          label="使用状态"
          prop="ticketStatus">
        </el-table-column> -->
        <el-table-column
          width="80"
          label="总价(￥)"
        >
          <template slot-scope="scope">
            {{ scope.row.price }}
          </template>
        </el-table-column>
        <el-table-column
          width="100"
          label="订单状态"
          fixed="right"
        >
          <template slot-scope="scope">
            <OrderStatusTag :value="scope.row.status"></OrderStatusTag>
          </template>
        </el-table-column>
        <el-table-column
          label="下单备注"
          show-overflow-tooltip
          prop="createOrderRemark">
        </el-table-column>
        <el-table-column
          label="操作"
          fixed="right"
          width="220"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="showOrderDetail(scope.row)">
              详情
            </el-link>
            <el-link
              type="primary"
              v-if="hasPermission('order-update')"
              @click="editOrder(scope.row)">
              修改
            </el-link>
            <el-link
              type="primary"
              v-if="hasPermission('manual-print')"
              @click="printOrder(scope.row)">
              取票
            </el-link>
            <br>
            <el-link
              type="primary"
              v-if="hasPermission('manual-check')"
              @click="checkOrder(scope.row)">
              核销
            </el-link>
            <el-link
              type="primary"
              v-if="hasPermission('manual-cancel')"
              @click="refundOrder(scope.row)">
              退单
            </el-link>
            <el-link
              type="primary"
              v-if="hasPermission('manual-second-print')"
              @click="secondPrint(scope.row)">
              补打
            </el-link>
            <!--
            <el-link
              type="primary"
              v-if="scope.row.tickets.some(v=>v.is_invoice_picked===0&&v.status==='USED')&&scope.row.otaSourceName!=='自营售票'"
              @click="showPickInvoice(scope.row)">
              开票
            </el-link>
            -->
            <!-- <el-link
              type="primary"
              v-if="scenicName==='昭苏' && scope.row.ticketList.some(v=>v.is_invoice_picked===0&&v.status==='USED')&&scope.row.otaSourceName!=='自营售票'"
              @click="showPickInvoice(scope.row)">
              开票
            </el-link>
            <el-link
              type="primary"
              v-if="scenicName!=='昭苏' && scope.row.ticketList.some(v=>v.is_invoice_picked===0&&v.status==='USED')"
              @click="showPickInvoice(scope.row)">
              开票
            </el-link> -->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        @current-change="getOrderList()"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <OrderDetail ref="orderDetail"></OrderDetail>

    <el-dialog
      title="选择导出列"
      :visible.sync="dialogVisible"
      append-to-body>
      <div
        v-for="group in columnGroups"
        :key="group.name"
        style="margin-bottom: 12px;">
        <div style="font-weight: 600; margin-bottom: 6px;">
          {{ group.name }}
        </div>
        <el-checkbox-group v-model="tempSelectedFields">
          <el-checkbox
            v-for="field in group.fields"
            :key="field.key"
            :label="field.key">
            {{ field.label }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="saveUserConfig">
          确 定
        </el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="开票"
      :visible.sync="visible"
      width="80%"
      @close="visible=false">
      <el-table
        ref="multipleTable"
        :data="currentOrder.ticketList"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          :selectable="selectable"
          width="55">
        </el-table-column>
        <el-table-column
          prop="ticketNo"
          label="票号"
        >
        </el-table-column>

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

        <el-table-column
          width="80"
          label="单价(￥)"
        >
          <template slot-scope="scope">
            {{ scope.row.checkNum ? scope.row.price/scope.row.checkNum : scope.row.price }}
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          prop="price"
          label="小计"
        >
        </el-table-column>
        <el-table-column
          prop="guestIdentifyType"
          label="证件类型"
        >
          <template slot-scope="scope">
            {{ papersType[scope.row.guestIdentifyType] }}
          </template>
        </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.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="取票状态"
        >
          <template slot-scope="scope">
            <el-tag :type="scope.row.isPrint?'success':'info'">
              {{ scope.row.isPrint?'已取票':'未取票' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="状态"
        >
          <template slot-scope="scope">
            <OrderStatusTag :value="scope.row.status"></OrderStatusTag>
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="是否已开票"
        >
          <template slot-scope="scope">
            {{ scope.row.is_invoice_picked===1?'已开':'未开' }}
          </template>
        </el-table-column>
      </el-table>
      {{ formEl.invoiceType }}
      <el-form
        class="search-box"
        ref="formEl"
        :model="formEl"
        :inline="true"
        label-width="200px"
        style="background: transparent"
      >
        <!-- 九龙湖只能固定一种开票方式 -->
        <el-form-item
          v-if="['九龙湖','demo'].includes(scenicName)"
          label="开票方式"
          prop="invoiceType"
        >
          <!-- <el-radio
            v-if="false"
            v-model="formEl.invoiceType"
            :label="1">
            扫码开票
          </el-radio> -->
          <el-radio
            v-model="formEl.invoiceType"
            :label="0">
            普通开票
          </el-radio>
        </el-form-item>

        <el-form-item
          v-else
          verify
          label="开票方式"
          prop="invoiceType"
        >
          <el-radio
            v-model="formEl.invoiceType"
            :label="1">
            扫码开票
          </el-radio>
          <el-radio
            v-model="formEl.invoiceType"
            :label="0">
            普通开票
          </el-radio>
        </el-form-item>
        <el-form-item
          v-if="!formEl.invoiceType"
          verify
          label="购买方"
          prop="invoiceBuyer"
        >
          <el-input
            v-model="formEl.invoiceBuyer"
            style="width:100%"></el-input>
        </el-form-item>
        <el-form-item
          v-if="!formEl.invoiceType"
          label="纳税⼈识别号"
          prop="invoiceBuyerTaxNum"
          :rules="rules.invoiceBuyerTaxNum"
        >
          <el-input
            v-model="formEl.invoiceBuyerTaxNum"
            style="width:100%"></el-input>
        </el-form-item>
        <el-form-item
          v-if="!formEl.invoiceType"
          label="纳税⼈邮箱"
          prop="invoiceBuyerEmail"
          :rules="[
            { required: false, message: '请输入邮箱', trigger: 'blur' },
            { type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
          ]"
        >
          <el-input
            v-model="formEl.invoiceBuyerEmail"
            style="width:100%"></el-input>
        </el-form-item>
        <el-form-item
          v-if="!formEl.invoiceType"
          label="纳税⼈手机号"
          prop="invoiceBuyerPhone"
          :rules="[
            { required: false, message: '请输入手机号', trigger: 'blur' },
            { pattern: /^1[3456789]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
          ]"
        >
          <el-input
            v-model="formEl.invoiceBuyerPhone"
            style="width:100%"></el-input>
        </el-form-item>
        <el-form-item
          v-if="!formEl.invoiceType"
          label="购买方地址"
          prop="invoiceBuyerAddress"
        >
          <el-input
            v-model="formEl.invoiceBuyerAddress"
            style="width:100%"></el-input>
        </el-form-item>
        <el-form-item
          v-if="!formEl.invoiceType"
          label="购买方银行开户行及账号"
          prop="invoiceBuyerBankAccount"
        >
          <el-input
            v-model="formEl.invoiceBuyerBankAccount"
            style="width:100%"></el-input>
        </el-form-item>
        <el-form-item
          v-if="!formEl.invoiceType"
          label="备注"
          prop="remark"
        >
          <el-input
            v-model="formEl.remark"
            style="width:100%"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button
          type="primary"
          @click="submitPickInvoice">确定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="核销"
      :visible.sync="checkOrderDialogVisible"
      width="80%"
      @close="checkOrderDialogVisible=false;ticketNoSearch=''">
      <div
        class="search-area"
        style="margin: 20px;display: flex;align-items: center;justify-content: space-between;">
        <el-checkbox
          v-if="hasPermission('manual-force-check')"
          label="强制核销"
          v-model="checkOrderInfo.force"></el-checkbox>
        <div class="name">
          <span style="margin-right: 10px;">票号搜索</span>
          <el-input v-model="ticketNoSearch"></el-input>
        </div>
      </div>
      <el-table
        border
        :data="(currentOrder.ticketList || []).filter(v => v.ticketNo.includes(ticketNoSearch))"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          fixed
          :selectable="selectable"
          width="55">
        </el-table-column>
        <el-table-column type="expand">
          <template slot-scope="props">
            <div class="title">检票景点</div>
            <el-table :data="props.row.ticketCheckScenicList" :max-height="200">
              <el-table-column
                prop="scenicName"
                label="景点"
              ></el-table-column>
              <el-table-column
                prop="checkLimitTimes"
                label="可检票次数"
              >
                <template slot-scope="scope">
                  {{ scope.row.checkLimitTimes === -1 ? "无限制" : scope.row.checkLimitTimes }}
                </template>
              </el-table-column>
              <el-table-column
                prop="checkedTimes"
                label="已检票次数"
              ></el-table-column>
              <el-table-column
                prop="singleDayLimitTimes"
                label="单日可检票次数"
              ></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column width="160" prop="ticketNo" label="票号"> </el-table-column>
        <el-table-column width="100" prop="ticketTypeName" label="票种"> </el-table-column>
        <el-table-column width="80" prop="price" label="单价(￥)">
          <template slot-scope="scope">
            {{ scope.row.checkNum ? scope.row.price / scope.row.checkNum : scope.row.price }}
          </template>
        </el-table-column>
        <el-table-column width="80" prop="price" label="小计"></el-table-column>
        <el-table-column width="100" prop="status" label="状态">
          <template slot-scope="scope">
            <TicketStatusTag :value="scope.row.status"></TicketStatusTag>
          </template>
        </el-table-column>
        <el-table-column 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 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.checkerName }}</div>
          </template>
        </el-table-column>
        <el-table-column width="260" prop="ticketPrintInfo" label="取票信息">
          <template slot-scope="scope">
            <div class=""><span>取票状态：</span>
              <el-tag :type="scope.row.isPrint ? 'success' : 'info'">
                {{ scope.row.isPrint ? "已取票" : "未取票" }}
              </el-tag>
            </div>
            <div class=""><span>取票时间：</span>{{ scope.row.printTime }}</div>
            <div class=""><span>取票人：</span>{{ scope.row.printAdminName }}</div>
            <div class=""><span>取票自助机：</span>{{ scope.row.printTermName }}</div>
          </template>
        </el-table-column>
        <el-table-column 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-column width="160" prop="playDateBegin" label="游玩时间">
          <template slot-scope="scope">
            <div v-if="scope.row.batchConfigName"><span>场次：</span>{{ scope.row.batchConfigName || '' }}</div>
            {{ scope.row.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
          </template>
        </el-table-column>
        <el-table-column min-width="180" label="检票景点">
          <template slot-scope="scope">
            {{ scope.row.ticketCheckScenicList.map(item => item.scenicName).join(',') }}
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketCardInfo" label="卡信息">
          <template slot-scope="scope" v-if="scope.row.card">
            <div class=""><span>卡片编号：</span>{{ scope.row.card.cardNo }}</div>
            <div class=""><span>有效时间：</span>{{ scope.row.card.validDateStart }} - {{ scope.row.card.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.card.status | filterCardStatus }}</div>
            <div class="" v-if="scope.row.card.status === 1"><span>开卡时间：</span>{{ scope.row.card.activeTime }}</div>
            <div class="" v-if="scope.row.card.status === 0"><span>退卡时间：</span>{{ scope.row.card.cardNo }}</div>
            <div class="" v-if="scope.row.card.status === 2"><span>挂失时间：</span>{{ scope.row.card.repealTime }}</div>
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketFaceInfo" label="人脸信息">
          <template slot-scope="scope" v-if="scope.row.face">
            <div class=""><span>有效时间：</span>{{ scope.row.face.validDateStart }} - {{ scope.row.face.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.face.status === 0 ? '可用' : '不可用' }}</div>
            <div class=""><span>图片地址：</span>{{ scope.row.face.imageUrl }}</div>
            <div class=""><span>base64：</span>{{ scope.row.face.faceData }}</div>
            <div class=""><span>注册状态：</span>{{ scope.row.face.registerStatus === 0 ? '未注册' : '已注册' }}</div>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer">
        <el-button @click="checkOrderDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="submitCheckOrder">确定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="退单"
      :visible.sync="refundOrderDialogVisible"
      width="80%"
      @close="refundOrderDialogVisible=false;ticketNoSearch=''">
      <div
        class="search-area"
        style="margin: 20px;display: flex;align-items: center;justify-content: space-between;">
        <el-checkbox
          v-if="hasPermission('manual-force-cancel')"
          label="强制退单"
          v-model="refundOrderInfo.force"></el-checkbox>
        <div class="name">
          <span style="margin-right: 10px;">票号搜索</span>
          <el-input v-model="ticketNoSearch"></el-input>
        </div>
      </div>
      <!-- <div class="">
        <div class="tag">退票金额</div>
        <el-input-number
          v-model="refundOrderInfo.cancelPrice"
          :min="0"
          :precision="0.01"></el-input-number>
      </div> -->
      <el-table
        border
        :data="(currentOrder.ticketList || []).filter(v => v.ticketNo.includes(ticketNoSearch))"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          fixed
          :selectable="selectable"
          width="55">
        </el-table-column>
        <el-table-column type="expand">
          <template slot-scope="props">
            <div class="title">检票景点</div>
            <el-table :data="props.row.ticketCheckScenicList" :max-height="200">
              <el-table-column
                prop="scenicName"
                label="景点"
              ></el-table-column>
              <el-table-column
                prop="checkLimitTimes"
                label="可检票次数"
              >
                <template slot-scope="scope">
                  {{ scope.row.checkLimitTimes === -1 ? "无限制" : scope.row.checkLimitTimes }}
                </template>
              </el-table-column>
              <el-table-column
                prop="checkedTimes"
                label="已检票次数"
              ></el-table-column>
              <el-table-column
                prop="singleDayLimitTimes"
                label="单日可检票次数"
              ></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column width="160" prop="ticketNo" label="票号"> </el-table-column>
        <el-table-column width="100" prop="ticketTypeName" label="票种"> </el-table-column>
        <el-table-column width="80" prop="price" label="单价(￥)">
          <template slot-scope="scope">
            {{ scope.row.checkNum ? scope.row.price / scope.row.checkNum : scope.row.price }}
          </template>
        </el-table-column>
        <el-table-column width="80" prop="price" label="小计"></el-table-column>
        <el-table-column width="100" prop="status" label="状态">
          <template slot-scope="scope">
            <TicketStatusTag :value="scope.row.status"></TicketStatusTag>
          </template>
        </el-table-column>
        <el-table-column 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 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.checkerName }}</div>
          </template>
        </el-table-column>
        <el-table-column width="260" prop="ticketPrintInfo" label="取票信息">
          <template slot-scope="scope">
            <div class=""><span>取票状态：</span>
              <el-tag :type="scope.row.isPrint ? 'success' : 'info'">
                {{ scope.row.isPrint ? "已取票" : "未取票" }}
              </el-tag>
            </div>
            <div class=""><span>取票时间：</span>{{ scope.row.printTime }}</div>
            <div class=""><span>取票人：</span>{{ scope.row.printAdminName }}</div>
            <div class=""><span>取票自助机：</span>{{ scope.row.printTermName }}</div>
          </template>
        </el-table-column>
        <el-table-column 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-column width="160" prop="playDateBegin" label="游玩时间">
          <template slot-scope="scope">
            <div v-if="scope.row.batchConfigName"><span>场次：</span>{{ scope.row.batchConfigName || '' }}</div>
            {{ scope.row.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
          </template>
        </el-table-column>
        <el-table-column min-width="180" label="检票景点">
          <template slot-scope="scope">
            {{ scope.row.ticketCheckScenicList.map(item => item.scenicName).join(',') }}
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketCardInfo" label="卡信息">
          <template slot-scope="scope" v-if="scope.row.card">
            <div class=""><span>卡片编号：</span>{{ scope.row.card.cardNo }}</div>
            <div class=""><span>有效时间：</span>{{ scope.row.card.validDateStart }} - {{ scope.row.card.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.card.status | filterCardStatus }}</div>
            <div class="" v-if="scope.row.card.status === 1"><span>开卡时间：</span>{{ scope.row.card.activeTime }}</div>
            <div class="" v-if="scope.row.card.status === 0"><span>退卡时间：</span>{{ scope.row.card.cardNo }}</div>
            <div class="" v-if="scope.row.card.status === 2"><span>挂失时间：</span>{{ scope.row.card.repealTime }}</div>
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketFaceInfo" label="人脸信息">
          <template slot-scope="scope" v-if="scope.row.face">
            <div class=""><span>有效时间：</span>{{ scope.row.face.validDateStart }} - {{ scope.row.face.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.face.status === 0 ? '可用' : '不可用' }}</div>
            <div class=""><span>图片地址：</span>{{ scope.row.face.imageUrl }}</div>
            <div class=""><span>base64：</span>{{ scope.row.face.faceData }}</div>
            <div class=""><span>注册状态：</span>{{ scope.row.face.registerStatus === 0 ? '未注册' : '已注册' }}</div>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer">
        <el-button @click="refundOrderDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="submitRefundOrder">确定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="补打"
      :visible.sync="secondPrintDialogVisible"
      width="80%"
      @close="secondPrintDialogVisible=false;ticketNoSearch=''">
      <!-- <div class="">
        <div class="tag">退票金额</div>
        <el-input-number
          v-model="refundOrderInfo.cancelPrice"
          :min="0"
          :precision="0.01"></el-input-number>
      </div> -->
      <div
        class="search-area"
        style="margin: 20px;display: flex;align-items: center;">
        <div class="name" style="margin-right: 10px;">票号搜索</div>
        <el-input v-model="ticketNoSearch"></el-input>
      </div>
      <el-table
        border
        :data="(currentOrder.ticketList || []).filter(v => v.ticketNo.includes(ticketNoSearch))"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          fixed
          :selectable="selectable"
          width="55">
        </el-table-column>
        <el-table-column type="expand">
          <template slot-scope="props">
            <div class="title">检票景点</div>
            <el-table :data="props.row.ticketCheckScenicList" :max-height="200">
              <el-table-column
                prop="scenicName"
                label="景点"
              ></el-table-column>
              <el-table-column
                prop="checkLimitTimes"
                label="可检票次数"
              >
                <template slot-scope="scope">
                  {{ scope.row.checkLimitTimes === -1 ? "无限制" : scope.row.checkLimitTimes }}
                </template>
              </el-table-column>
              <el-table-column
                prop="checkedTimes"
                label="已检票次数"
              ></el-table-column>
              <el-table-column
                prop="singleDayLimitTimes"
                label="单日可检票次数"
              ></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column width="160" prop="ticketNo" label="票号"> </el-table-column>
        <el-table-column width="100" prop="ticketTypeName" label="票种"> </el-table-column>
        <el-table-column width="80" prop="price" label="单价(￥)">
          <template slot-scope="scope">
            {{ scope.row.checkNum ? scope.row.price / scope.row.checkNum : scope.row.price }}
          </template>
        </el-table-column>
        <el-table-column width="80" prop="price" label="小计"></el-table-column>
        <el-table-column width="100" prop="status" label="状态">
          <template slot-scope="scope">
            <TicketStatusTag :value="scope.row.status"></TicketStatusTag>
          </template>
        </el-table-column>
        <el-table-column 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 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.checkerName }}</div>
          </template>
        </el-table-column>
        <el-table-column width="260" prop="ticketPrintInfo" label="取票信息">
          <template slot-scope="scope">
            <div class=""><span>取票状态：</span>
              <el-tag :type="scope.row.isPrint ? 'success' : 'info'">
                {{ scope.row.isPrint ? "已取票" : "未取票" }}
              </el-tag>
            </div>
            <div class=""><span>取票时间：</span>{{ scope.row.printTime }}</div>
            <div class=""><span>取票人：</span>{{ scope.row.printAdminName }}</div>
            <div class=""><span>取票自助机：</span>{{ scope.row.printTermName }}</div>
          </template>
        </el-table-column>
        <el-table-column 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-column width="160" prop="playDateBegin" label="游玩时间">
          <template slot-scope="scope">
            <div v-if="scope.row.batchConfigName"><span>场次：</span>{{ scope.row.batchConfigName || '' }}</div>
            {{ scope.row.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
          </template>
        </el-table-column>
        <el-table-column min-width="180" label="检票景点">
          <template slot-scope="scope">
            {{ scope.row.ticketCheckScenicList.map(item => item.scenicName).join(',') }}
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketCardInfo" label="卡信息">
          <template slot-scope="scope" v-if="scope.row.card">
            <div class=""><span>卡片编号：</span>{{ scope.row.card.cardNo }}</div>
            <div class=""><span>有效时间：</span>{{ scope.row.card.validDateStart }} - {{ scope.row.card.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.card.status | filterCardStatus }}</div>
            <div class="" v-if="scope.row.card.status === 1"><span>开卡时间：</span>{{ scope.row.card.activeTime }}</div>
            <div class="" v-if="scope.row.card.status === 0"><span>退卡时间：</span>{{ scope.row.card.cardNo }}</div>
            <div class="" v-if="scope.row.card.status === 2"><span>挂失时间：</span>{{ scope.row.card.repealTime }}</div>
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketFaceInfo" label="人脸信息">
          <template slot-scope="scope" v-if="scope.row.face">
            <div class=""><span>有效时间：</span>{{ scope.row.face.validDateStart }} - {{ scope.row.face.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.face.status === 0 ? '可用' : '不可用' }}</div>
            <div class=""><span>图片地址：</span>{{ scope.row.face.imageUrl }}</div>
            <div class=""><span>base64：</span>{{ scope.row.face.faceData }}</div>
            <div class=""><span>注册状态：</span>{{ scope.row.face.registerStatus === 0 ? '未注册' : '已注册' }}</div>
          </template>
        </el-table-column>
        <el-table-column width="80" label="操作">
          <template slot-scope="scope">
            <el-button type="primary" @click="printSingleTicket(scope.row)">
              打印
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div
        class="opt-area"
        style="margin-top: 20px;width: 100%;text-align: center;">
        <el-button
          type="primary"
          @click="submitSecondPrint">
          全部打印
        </el-button>
        <el-button
          type="primary"
          @click="submitSecondPrint">
          打印小票
        </el-button>
      </div>
      <span slot="footer">
        <el-button @click="secondPrintDialogVisible = false">取消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="取票"
      :visible.sync="printOrderDialogVisible"
      width="80%"
      @close="printOrderDialogVisible=false;ticketNoSearch=''">
      <div
        class="search-area"
        style="margin: 20px;display: flex;align-items: center;">
        <div class="name" style="margin-right: 10px;">票号搜索</div>
        <el-input v-model="ticketNoSearch"></el-input>
      </div>
      <el-table
        border
        :data="(currentOrder.ticketList || []).filter(v => v.ticketNo.includes(ticketNoSearch))"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          fixed
          :selectable="selectable"
          width="55">
        </el-table-column>
        <el-table-column type="expand">
          <template slot-scope="props">
            <div class="title">检票景点</div>
            <el-table :data="props.row.ticketCheckScenicList" :max-height="200">
              <el-table-column
                prop="scenicName"
                label="景点"
              ></el-table-column>
              <el-table-column
                prop="checkLimitTimes"
                label="可检票次数"
              >
                <template slot-scope="scope">
                  {{ scope.row.checkLimitTimes === -1 ? "无限制" : scope.row.checkLimitTimes }}
                </template>
              </el-table-column>
              <el-table-column
                prop="checkedTimes"
                label="已检票次数"
              ></el-table-column>
              <el-table-column
                prop="singleDayLimitTimes"
                label="单日可检票次数"
              ></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column width="160" prop="ticketNo" label="票号"> </el-table-column>
        <el-table-column width="100" prop="ticketTypeName" label="票种"> </el-table-column>
        <el-table-column width="80" prop="price" label="单价(￥)">
          <template slot-scope="scope">
            {{ scope.row.checkNum ? scope.row.price / scope.row.checkNum : scope.row.price }}
          </template>
        </el-table-column>
        <el-table-column width="80" prop="price" label="小计"></el-table-column>
        <el-table-column width="100" prop="status" label="状态">
          <template slot-scope="scope">
            <TicketStatusTag :value="scope.row.status"></TicketStatusTag>
          </template>
        </el-table-column>
        <el-table-column 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 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.checkerName }}</div>
          </template>
        </el-table-column>
        <el-table-column width="260" prop="ticketPrintInfo" label="取票信息">
          <template slot-scope="scope">
            <div class=""><span>取票状态：</span>
              <el-tag :type="scope.row.isPrint ? 'success' : 'info'">
                {{ scope.row.isPrint ? "已取票" : "未取票" }}
              </el-tag>
            </div>
            <div class=""><span>取票时间：</span>{{ scope.row.printTime }}</div>
            <div class=""><span>取票人：</span>{{ scope.row.printAdminName }}</div>
            <div class=""><span>取票自助机：</span>{{ scope.row.printTermName }}</div>
          </template>
        </el-table-column>
        <el-table-column 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-column width="160" prop="playDateBegin" label="游玩时间">
          <template slot-scope="scope">
            <div v-if="scope.row.batchConfigName"><span>场次：</span>{{ scope.row.batchConfigName || '' }}</div>
            {{ scope.row.playDateBegin || scope.row.playDateEnd ? `${scope.row.playDateBegin || ''} - ${scope.row.playDateEnd || ''}` : "无限制" }}
          </template>
        </el-table-column>
        <el-table-column min-width="180" label="检票景点">
          <template slot-scope="scope">
            {{ scope.row.ticketCheckScenicList.map(item => item.scenicName).join(',') }}
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketCardInfo" label="卡信息">
          <template slot-scope="scope" v-if="scope.row.card">
            <div class=""><span>卡片编号：</span>{{ scope.row.card.cardNo }}</div>
            <div class=""><span>有效时间：</span>{{ scope.row.card.validDateStart }} - {{ scope.row.card.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.card.status | filterCardStatus }}</div>
            <div class="" v-if="scope.row.card.status === 1"><span>开卡时间：</span>{{ scope.row.card.activeTime }}</div>
            <div class="" v-if="scope.row.card.status === 0"><span>退卡时间：</span>{{ scope.row.card.cardNo }}</div>
            <div class="" v-if="scope.row.card.status === 2"><span>挂失时间：</span>{{ scope.row.card.repealTime }}</div>
          </template>
        </el-table-column>
        <el-table-column width="240" prop="ticketFaceInfo" label="人脸信息">
          <template slot-scope="scope" v-if="scope.row.face">
            <div class=""><span>有效时间：</span>{{ scope.row.face.validDateStart }} - {{ scope.row.face.validDateEnd }}</div>
            <div class=""><span>卡片状态：</span>{{ scope.row.face.status === 0 ? '可用' : '不可用' }}</div>
            <div class=""><span>图片地址：</span>{{ scope.row.face.imageUrl }}</div>
            <div class=""><span>base64：</span>{{ scope.row.face.faceData }}</div>
            <div class=""><span>注册状态：</span>{{ scope.row.face.registerStatus === 0 ? '未注册' : '已注册' }}</div>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer">
        <el-button @click="printOrderDialogVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click="submitPrintOrder">确定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="修改"
      :visible.sync="editOrderDialogVisible"
      mini-height="500"
      @close="cancelEdit">
      <el-form
        class="form-box"
        ref="formEl"
        :model="editOrderInfo"
        :inline="true"
        label-width="100px">
        <el-form-item
          label="修改类型"
          prop="updateType"
        >
          <el-select
            v-model="editOrderInfo.updateType"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in updateTypes"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="editOrderInfo.updateType === 'updateOrderPayChannel'"
          label="原支付方式"
          prop="payChannel"
        >
          {{ currentOrder.payChannel }}
        </el-form-item>
        <el-form-item
          v-if="editOrderInfo.updateType === 'updateOrderPayChannel'"
          label="支付方式"
          prop="payChannel"
        >
          <el-radio-group
            border
            fill="#379143"
            class="tags-btn"
            v-model="editOrderInfo.payChannel">
            <el-radio
              border
              v-for="val in payChannelOptions"
              :key="val"
              :value="val"
              :label="val"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-if="editOrderInfo.updateType === 'updatePlayDate'"
          label="选择门票"
          prop="playDateBegin">
          <el-select
            v-model="editOrderInfo.ticketIds"
            multiple>
            <el-option
              v-for="item in currentOrder.ticketList"
              :key="item.id"
              :label="item.ticketNo"
              :value="item.id">
              <span style="">{{ item.ticketNo }}</span>-
              <span style="color: #8492a6; font-size: 13px">{{ item.ticketTypeName }}</span>
              (<span style="color: #849822; font-size: 13px">
                {{ item.playDateBegin || item.playDateEnd ? `${item.playDateBegin || ''} - ${item.playDateEnd || ''}` : "无限制" }}
              </span>)
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="editOrderInfo.updateType === 'updatePlayDate'"
          label="起始时间"
          prop="playDateBegin">
          <el-date-picker
            v-model="editOrderInfo.playDateBegin"
            type="date"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item
          v-if="editOrderInfo.updateType === 'updatePlayDate'"
          label="截止时间"
          prop="playDateEnd">
          <el-date-picker
            v-model="editOrderInfo.playDateEnd"
            type="date"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <div class="table-box" v-if="editOrderInfo.updateType === 'updateScenicTimes'">
          <div class="tips">
            <i class="el-icon-info"></i>
            -1代表不限制 如果当前景点为群组景点 该次数为群组景点的检票次数总和
          </div>
          <el-table
            border
            stripe
            height="500"
            :data="editOrderInfo.ticketList">
            <el-table-column type="expand">
              <template slot-scope="props">
                <div class="title">检票景点明细</div>
                <el-table :data="props.row.ticketCheckScenicList" :max-height="200">
                  <el-table-column
                    prop="scenicName"
                    label="景点"
                  ></el-table-column>
                  <el-table-column
                    prop="checkLimitTimes"
                    label="可检票次数"
                  >
                    <template slot-scope="scope">
                      {{ scope.row.checkLimitTimes === -1 ? "无限制" : scope.row.checkLimitTimes }}
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="checkedTimes"
                    label="已检票次数"
                  ></el-table-column>
                </el-table>
              </template>
            </el-table-column>
            <el-table-column width="160" prop="ticketNo" label="票号"> </el-table-column>
            <el-table-column width="100" prop="ticketTypeName" label="票种"> </el-table-column>
            <el-table-column min-width="180" label="检票景点">
              <template slot-scope="scope">
                {{ scope.row.ticketCheckScenicList.map(item => item.scenicName).join(',') }}
              </template>
            </el-table-column>
            <el-table-column
              label="景点的限制检票次数"
              min-width="90">
              <template slot-scope="scope">
                <el-input-number
                  controls-position="right"
                  :min="-1"
                  :precision="0"
                  v-model="scope.row.checkLimitTimes"
                ></el-input-number>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <span slot="footer">
        <el-button @click="cancelEdit">取消</el-button>
        <el-button
          type="primary"
          @click="submitEditOrder">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
/* eslint-disable no-unused-vars */
import { apiOrderList, pickInvoice, getInvoice, cancelOrder, reprintTicket, checkTickets, updateOrder, getSaleChannelList, getSingleOrder, printTickets } from '@/api/order'
import { orderStatusDic, ticketStatusDic, channelList, papersType, orderCategories } from '@/assets/staticData'
import { getPayStatus } from '@/utils/index'
// import Ellipsis from '@/components/Ellipsis'
import ReaderInput from '@/components/ReaderInput'
import moment from 'moment'
import { payPOS } from '@/api/pay'
import { getSelf } from '@/api/systemSetting/account'
import { getSystemConfigList } from '@/api/systemConfig'
import { addUserConfig, getUserConfig } from '@/api/configSetting'
import { EventBus } from '@/utils/eventBus'

const COLUMN_SCHEMA = [
  { key: 'orderCategory', label: '订单类型', group: '订单', column: 'extra', apiKey: 'orderCategory' },
  { key: 'firstTicketTypeName', label: '票种名称', group: '票种', column: 'firstTicketTypeName', apiKey: 'ticketTypeName' },
  { key: 'orderNo', label: '订单号', group: '订单', column: 'orderNo', apiKey: 'orderNo' },
  { key: 'partnerOrderNo', label: '合作方订单号', group: '订单', column: 'orderNo', apiKey: 'partnerOrderNo' },
  { key: 'ticketNo', label: '票号', group: '票务', column: 'extra', apiKey: 'ticketNo' },
  { key: 'payChannel', label: '支付方式', group: '渠道', column: 'isOnlineOrder', apiKey: 'payChannel' },
  { key: 'payTime', label: '支付时间', group: '支付', column: 'extra', apiKey: 'payTime' },
  { key: 'teamName', label: '团体名称', group: '订单', column: 'extra', apiKey: 'teamName' },
  { key: 'guideName', label: '导游名称', group: '订单', column: 'extra', apiKey: 'guideName' },
  { key: 'otaSourceName', label: '订单来源渠道', group: '渠道', column: 'isOnlineOrder', apiKey: 'otaSourceName' },
  { key: 'saleAdminName', label: '售卖人名称', group: '售票', column: 'saleInfo', apiKey: 'saleAdminName' },
  { key: 'buyerName', label: '购买方名称', group: '购买方', column: 'buyerInfo', apiKey: 'buyerName' },
  { key: 'buyerPhone', label: '购买方电话', group: '购买方', column: 'buyerInfo', apiKey: 'buyerPhone' },
  { key: 'buyerIdentify', label: '购买方证件号', group: '购买方', column: 'buyerInfo', apiKey: 'buyerIdentify' },
  { key: 'price', label: '订单总额', group: '订单', column: 'price', apiKey: 'orderPrice' },
  { key: 'ticketNum', label: '包含的票数量', group: '票务', column: 'ticketNum', apiKey: 'ticketNum' },
  { key: 'status', label: '订单状态', group: '订单', column: 'status', apiKey: 'orderStatus' },
  { key: 'isOnlineOrder', label: '是否是线上订单', group: '渠道', column: 'isOnlineOrder', apiKey: 'isOnlineOrder' },
  { key: 'createOrderRemark', label: '下单备注', group: '订单', column: 'createOrderRemark', apiKey: 'createOrderRemark' },
  { key: 'discountDescription', label: '优惠说明', group: '优惠', column: 'extra', apiKey: 'discountDescription' },
  { key: 'adminRemark', label: '管理员备注', group: '订单', column: 'extra', apiKey: 'adminRemark' },
  { key: 'checkNum', label: '售票人数', group: '票务', column: 'extra', apiKey: 'checkNum' },
  { key: 'isPrint', label: '是否已取票', group: '取票', column: 'extra', apiKey: 'isPrint' },
  { key: 'printAdminName', label: '取票操作人', group: '取票', column: 'extra', apiKey: 'printAdminName' },
  { key: 'printTime', label: '取票时间', group: '取票', column: 'extra', apiKey: 'printTime' },
  { key: 'printTermName', label: '取票自助机', group: '取票', column: 'extra', apiKey: 'printTermName' },
  { key: 'ticketStatus', label: '门票状态', group: '票务', column: 'extra', apiKey: 'ticketStatus' },
  { key: 'unitPrice', label: '门票单价', group: '票务', column: 'extra', apiKey: 'unitPrice' },
  { key: 'ticketPrice', label: '门票价格', group: '票务', column: 'extra', apiKey: 'ticketPrice' },
  { key: 'originalPrice', label: '门票原价', group: '票务', column: 'extra', apiKey: 'originalPrice' },
  { key: 'discountPrice', label: '门票调整价格', group: '票务', column: 'extra', apiKey: 'discountPrice' },
  { key: 'settlementPrice', label: '门票结算价格', group: '票务', column: 'extra', apiKey: 'settlementPrice' },
  { key: 'guestName', label: '游客姓名', group: '游客', column: 'extra', apiKey: 'guestName' },
  { key: 'guestPhone', label: '游客电话', group: '游客', column: 'extra', apiKey: 'guestPhone' },
  { key: 'guestIdentify', label: '游客证件号', group: '游客', column: 'extra', apiKey: 'guestIdentify' },
  { key: 'playDateBegin', label: '游玩时间', group: '游玩', column: 'extra', apiKey: 'playDateBegin' },
  { key: 'playDateEnd', label: '游玩时间', group: '游玩', column: 'extra', apiKey: 'playDateEnd' },
  { key: 'batchConfigName', label: '场次名称', group: '游玩', column: 'extra', apiKey: 'batchConfigName' },
  { key: 'buyTime', label: '付款时间', group: '支付', column: 'extra', apiKey: 'buyTime' },
  { key: 'firstCheckTime', label: '首次检票时间', group: '检票', column: 'extra', apiKey: 'firstCheckTime' },
  { key: 'checkTime', label: '最后检票时间', group: '检票', column: 'extra', apiKey: 'checkTime' },
  { key: 'checkerName', label: '最近一次检票设备', group: '检票', column: 'extra', apiKey: 'checkerName' },
  { key: 'cancelSubmitTime', label: '申请退款时间', group: '退款', column: 'extra', apiKey: 'cancelSubmitTime' },
  { key: 'cancelPrice', label: '退款金额', group: '退款', column: 'extra', apiKey: 'cancelPrice' },
  { key: 'cancelAdminName', label: '退款操作人', group: '退款', column: 'extra', apiKey: 'cancelAdminName' },
  { key: 'cancelCompleteTime', label: '退款完成时间', group: '退款', column: 'extra', apiKey: 'cancelCompleteTime' },
  { key: 'isForceCancel', label: '是否强制取消', group: '退款', column: 'extra', apiKey: 'isForceCancel' }
]

const API_KEY_TO_FIELD = COLUMN_SCHEMA.reduce((acc, item) => {
  acc[item.apiKey] = item.key
  return acc
}, {})

const COLUMN_FIELD_MAP = COLUMN_SCHEMA.reduce((acc, item) => {
  if (!acc[item.column]) acc[item.column] = []
  acc[item.column].push(item.key)
  return acc
}, {})

const DEFAULT_FIELD_KEYS = COLUMN_SCHEMA.map(item => item.key)

const STAT_KEY = 'orderDetail'

export default {
  name: 'salesQuery',
  computed: {
    scenicName () {
      return this.$localStore.get('scenicName') || this.$store.state.user.scenicName
    },
    salesList () {
      return this.$store.state.user.salesList
    },
    accountList () {
      return this.$store.state.app.accountList
    },
    termList () {
      return this.$store.state.app.termList
    },
    saleChannel () {
      return this.$store.state.app.saleChannel
    },
    payChannelOptions () {
      return this.$store.getters.payChannelOptions
    },
    ticketTypeList () {
      const { ticketTypeList } = this.$store.state.app
      const { orderCategory } = this.form
      return orderCategory ? ticketTypeList.filter(item => item.category === orderCategory) : ticketTypeList
    },
    scenicList () {
      return this.$store.state.app.scenicList
    },
    permissionList () {
      return this.$store.state.user.menuList || []
    },
    columnGroups () {
      const groupList = []
      const groupMap = {}
      COLUMN_SCHEMA.forEach(item => {
        if (!groupMap[item.group]) {
          groupMap[item.group] = { name: item.group, fields: [] }
          groupList.push(groupMap[item.group])
        }
        groupMap[item.group].fields.push({ key: item.key, label: item.label })
      })
      return groupList
    }
  },
  components: {
    ReaderInput
    // Ellipsis
  },
  data () {
    return {
      projecticketTypeName: process.env.VUE_APP_PROJECT,
      channelList,
      otaSourceList: [],
      orderStatusDic,
      ticketStatusDic,
      papersType,
      isDev: process.env.NODE_ENV === 'development',
      orderCategories,
      form: {
        searchKeywords: '', // 搜索关键字
        partnerOrderNo: '', // OTA订单号
        ticketNo: '', // 票号
        otaOrderNo: '', // 渠道订单号
        orderNo: '', // 订单号
        createTime: [new Date(moment().subtract(7, 'day').format('YYYY-MM-DD')), new Date(moment().format('YYYY-MM-DD'))], // 下单时间
        createTimeBegin: '',
        createTimeEnd: '',
        orderCategory: '',
        playDate: ['', ''], // 游玩时间
        playDateBegin: '',
        playDateEnd: '',
        payChannelList: [], // 支付方式
        otaSourceNameList: [], // 销售来源
        adminIdList: [], // 售票员
        saleTermIdList: [], // 售卖自助机
        orderStatus: '', // 订单状态
        ticketStatus: '', // 门票状态
        visitorName: '', // 游客姓名
        visitorPhone: '', // 游客手机
        visitorIdentify: '', // 游客身份证
        ticketTypeIdList: [], // 票种列表
        scenicIdList: [], // 景点列表
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      invoiceType: 0,
      formEl: {
        invoiceType: 1,
        invoiceBuyer: '',
        invoiceBuyerTaxNum: '',
        invoiceBuyerEmail: '',
        invoiceBuyerPhone: '',
        invoiceBuyerAddress: '',
        invoiceBuyerBankAccount: '',
        remark: ''
      },
      rules: {
        invoiceBuyerTaxNum: [
          { required: false, message: '请输入纳税人识别号', trigger: 'blur' },
          { pattern: /^[A-Za-z0-9]{15,20}$/, message: '纳税人识别号格式不正确', trigger: 'blur' }
        ]
      },
      currentOrder: {},
      multipleSelection: [],
      order_tag_list: [],
      visible: false,
      refundOrderDialogVisible: false,
      refundOrderInfo: {
        force: false,
        orderId: '',
        ticketCancelRequestList: []
      },
      checkOrderDialogVisible: false,
      checkOrderInfo: {
        force: false,
        orderId: '',
        ticketIdList: []
      },
      printOrderDialogVisible: false,
      secondPrintDialogVisible: false,
      secondPrintInfo: {
        orderId: '',
        ticketIdList: []
      },
      updateTypes: [
        { value: 'updateOrderPayChannel', label: '支付方式' },
        { value: 'updatePlayDate', label: '游玩日期' },
        { value: 'updateScenicTimes', label: '检票次数' }
      ],
      dialogVisible: false,
      columnSchema: COLUMN_SCHEMA,
      columnFieldMap: COLUMN_FIELD_MAP,
      selectedFields: [...DEFAULT_FIELD_KEYS],
      tempSelectedFields: [...DEFAULT_FIELD_KEYS],
      editOrderDialogVisible: false,
      editOrderInfo: {
        orderId: '',
        updateType: '',
        payChannel: '',
        playDateBegin: '',
        playDateEnd: '',
        ticketIds: [],
        ticketList: [],
        ticketCheckScenicUpdateRequestList: []
      },
      ticketNoSearch: ''
    }
  },
  filters: {
    filterChannel (n) {
      switch (n) {
        case 1:
          return '线下'
        case 2:
          return '线上'
        case 3:
          return '自助机'
      }
    },
    filterOrderCategory (n) {
      return orderCategories.find(item => item.id === n).name
    }
  },
  async created () {
    const searchParams = JSON.parse(sessionStorage.getItem('统计表-售票记录-查询条件'))
    if (searchParams) {
    // 如果存在查询条件，则设置到组件的数据中
      this.form = searchParams // 记住上次搜索条件
    }
    this.loadUserConfig()
    // this.getSaleChannelList()
    // this.getOrderList()
  },
  mounted () {
    this.getSaleChannelList()
    this.getOrderList()

    EventBus.$on('activeTag', (tag) => {
      if (tag === '/queryReport/salesQuery') {
        this.getOrderList()
      }
    })
  },
  methods: {
    getPayStatus,
    showColumnConfig () {
      this.dialogVisible = true
      this.loadUserConfig(false)
    },
    loadUserConfig (applyToTable = true) {
      getUserConfig({ statKey: STAT_KEY }).then(config => {
        const fields = config?.data?.fields || config?.fields || config?.data?.columns || config?.columns || config?.data || []
        let nextSelected = []
        if (Array.isArray(fields) && fields.length) {
          nextSelected = fields
            .filter(i => Number(i.isShow) === 1)
            .map(i => API_KEY_TO_FIELD[i.fieldKey] || i.fieldKey)
            .filter(key => DEFAULT_FIELD_KEYS.includes(key))
        } else {
          nextSelected = [...DEFAULT_FIELD_KEYS]
        }
        if (applyToTable) {
          this.selectedFields = nextSelected
        }
        this.tempSelectedFields = [...nextSelected]
      }).catch(() => {
        const nextSelected = [...DEFAULT_FIELD_KEYS]
        if (applyToTable) {
          this.selectedFields = nextSelected
        }
        this.tempSelectedFields = [...nextSelected]
      })
    },
    saveUserConfig () {
      const fields = this.columnSchema
        .filter(item => item.apiKey)
        .map(item => ({
          fieldKey: item.apiKey,
          fieldName: item.label,
          isShow: this.tempSelectedFields.includes(item.key) ? 1 : 0
        }))
      addUserConfig({ statKey: STAT_KEY, fields }).then(() => {
        this.selectedFields = [...this.tempSelectedFields]
        this.dialogVisible = false
      })
    },
    hasPermission (key) {
      return !!this.permissionList.some(item => item.code === key)
    },
    reset () {
      this.$refs.form.resetFields()
      this.getOrderList(true)
    },
    setSearchKeywords (val) {
      this.form.searchKeywords = val
    },
    // 取票状态
    checkPrintStatus (ticketList) {
      let tempArr = ticketList.filter(i => i.isPrint)
      if (tempArr.length) {
        if (tempArr.length === ticketList.length) {
          return { type: 'success', text: '已取票' }
        } else {
          return { type: 'warning', text: '部分取票' }
        }
      } else {
        return { type: 'info', text: '未取票' }
      }
    },
    toggleSelection (rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    selectable (row, index) {
      return true
    },
    showPickInvoice (order) {
      this.visible = true
      this.currentOrder = order
      if (['九龙湖', 'demo'].includes(this.scenicName)) {
        this.formEl.invoiceType = 0 // 九龙湖只能普通开票
      }
    },
    submitPickInvoice () {
      if (!this.multipleSelection.length) return this.$message.error('请选择门票')
      this.$refs.formEl.validate(valid => {
        if (!valid) return
        if (this.formEl.invoiceType) {
          this.formEl.invoiceBuyer = ''
          this.formEl.invoiceBuyerTaxNum = ''
          this.formEl.invoiceBuyerEmail = ''
          this.formEl.invoiceBuyerPhone = ''
          this.formEl.invoiceBuyerAddress = ''
          this.formEl.invoiceBuyerBankAccount = ''
          this.formEl.remark = ''
        }
        pickInvoice([this.currentOrder.id], this.multipleSelection.map(v => v.id), this.formEl.invoiceType, this.formEl.invoiceBuyer, this.formEl.invoiceBuyerTaxNum, this.formEl.invoiceBuyerEmail, this.formEl.invoiceBuyerPhone, this.formEl.invoiceBuyerAddress, this.formEl.invoiceBuyerBankAccount, this.formEl.remark).then(res => {
          this.$message.success('操作成功')
          this.getOrderList()
          this.visible = false
          this.currentOrder = {}
          this.formEl = {
            invoiceType: 1,
            invoiceBuyer: '',
            invoiceBuyerTaxNum: '',
            invoiceBuyerEmail: '',
            invoiceBuyerPhone: '',
            invoiceBuyerAddress: '',
            invoiceBuyerBankAccount: '',
            remark: ''
          }
          this.$confirm('发票已生成，是否跳转到发票下载页？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$router.push('/queryReport/invoiceRecord')
          })
        })
      })
    },
    confirmPOS (record) {
      this.$confirm('请确认该订单已付款,将手动更新订单状态为已支付', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        getSelf().then(response => {
          const params = {
            managerId: response.id,
            id: record.id,
            payChannel: record.payChannel,
            posId: this.$localStore.get('termId'),
            tradeInfo: '',
            type: 'TICKET'
          }
          payPOS(params).then(res => {
            this.$message.success('操作成功')
            this.getOrderList()
            this.$confirm('门票状态已修改,是否跳转补打门票页面？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.$router.push({ name: 'printTicket' })
            }).catch(() => {
            })
          })
        })
      }).catch(() => {
      })
    },
    getSaleChannelList () {
      getSaleChannelList().then(res => {
        this.otaSourceList = res.data
      })
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getOrderList()
    },
    dataExport () {
      this.form.export = true
      // this.form.exportDetail = true
      apiOrderList(this.form).then(() => {
        this.$message.success('导出成功。')
        this.goToDownload()
      }, () => {
        this.$message.success('导出失败。')
      })
      this.reset()
    },
    reportExport (exportType) {
      this.$confirm(`是否要导出明细数据`, '确认提示', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning'
      }).then(() => {
        this.handleExport({
          ...this.form,
          exportType: exportType || 'ticket',
          export: true,
          exportDetail: true
        })
      }).catch(() => {
        this.handleExport({
          ...this.form,
          exportType: exportType || 'ticket',
          export: true,
          exportDetail: false
        })
      })
    },
    handleExport (params) {
      apiOrderList(params).then(() => {
        this.$message.success('导出成功。')
        this.goToDownload()
      }, () => {
        this.$message.success('导出失败。')
      })
    },
    getOrderList (goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)

      const [s, e] = this.form.createTime || []
      this.form.createTimeBegin = s ? moment(s).startOf('day').format('YYYY-MM-DD HH:mm:ss') : ''
      this.form.createTimeEnd = e ? moment(e).endOf('day').format('YYYY-MM-DD HH:mm:ss') : ''

      const [s1, e1] = this.form.playDate || []
      this.form.playDateBegin = s1 ? moment(s1).format('YYYY-MM-DD') : ''
      this.form.playDateEnd = e1 ? moment(e1).format('YYYY-MM-DD') : ''

      apiOrderList(this.form).then(res => {
        this.total = res.data.total

        // const list = []
        res.data.records.forEach(item => {
          let ticketsName = []
          item.ticketsName = ticketsName.join('，')
        })

        this.tableData = res.data.records
        // this.tableData.forEach(v => {
        //   if (v.price === 0 && v.payChannel === '现金') {
        //     v.payChannel = '免票'
        //   }
        // })

        console.log(this.tableData, 'tableData')
      }).finally(() => {
        this.loading = false
      })
      sessionStorage.setItem('统计表-售票记录-查询条件', JSON.stringify(this.form)) // 下次记住
    },
    reduceCheckNum (list) {
      if (!list) return 0
      return list.reduce((prev, item) => {
        return prev + item.checkNum
      }, 0)
    },
    async getOrderDetail (order) {
      const res = await getSingleOrder(order.id)
      this.currentOrder = res?.data || order
    },
    async refundOrder (order) {
      await this.getOrderDetail(order)
      this.refundOrderDialogVisible = true
      this.refundOrderInfo.orderId = order.id
    },
    async secondPrint (order) {
      await this.getOrderDetail(order)
      this.secondPrintDialogVisible = true
      this.secondPrintInfo.orderId = order.id
    },
    submitRefundOrder () {
      if (!this.multipleSelection?.length) {
        return this.$message.error('请选择门票')
      }

      this.refundOrderInfo.ticketCancelRequestList = this.multipleSelection.map(v => {
        return {
          ticketId: v.id,
          cancelPrice: v.price
        }
      })

      this.$confirm('确定要退单吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        cancelOrder(this.refundOrderInfo).then(res => {
          if (res.code === '999999') {
            this.$message.warning(res.msg || '操作失败')
            return
          }
          this.$message.success('操作成功')
          this.refundOrderDialogVisible = false
          this.getOrderList()
        })
      })
    },
    submitSecondPrint () {
      if (!this.multipleSelection?.length) {
        return this.$message.error('请选印门票')
      }

      this.secondPrintInfo.ticketIdList = this.multipleSelection.map(v => v.id)

      this.$confirm('确定要打印吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        reprintTicket(this.secondPrintInfo).then(res => {
          if (res.code === '999999') {
            this.$message.warning(res.msg || '操作失败')
            return
          }
          // TODO 调用打印
          if (this.currentOrder) {
            this.$print(this.currentOrder)
          }

          this.$message.success('操作成功')
          this.secondPrintDialogVisible = false
          this.getOrderList()
        })
      })
    },
    async showOrderDetail (order) {
      await this.getOrderDetail(order)
      this.$refs.orderDetail.show(this.currentOrder)
    },
    // 核销
    async checkOrder (order) {
      await this.getOrderDetail(order)
      this.checkOrderDialogVisible = true
      this.checkOrderInfo.orderId = order.id
    },
    submitCheckOrder () {
      if (!this.multipleSelection?.length) {
        return this.$message.error('请选择门票')
      }

      this.checkOrderInfo.ticketIdList = this.multipleSelection.map(v => v.id)

      this.$confirm('确定要核销吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        checkTickets(this.checkOrderInfo).then(res => {
          if (res.code === '999999') {
            this.$message.warning(res.msg || '操作失败')
            return
          }
          this.$message.success('操作成功')
          this.checkOrderDialogVisible = false
          this.getOrderList()
        })
      })
    },
    async printOrder (order) {
      await this.getOrderDetail(order)
      this.printOrderDialogVisible = true
    },
    submitPrintOrder () {
      if (!this.multipleSelection?.length) {
        return this.$message.error('请选择门票')
      }

      const ticketIdList = this.multipleSelection.map(v => v.id)

      this.$confirm('确定要取票吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        printTickets(ticketIdList).then(res => {
          if (res.code === '999999') {
            this.$message.warning(res.msg || '操作失败')
            return
          }
          this.$message.success('操作成功')
          this.checkOrderDialogVisible = false
          this.getOrderList()
        })
      })
    },
    printSingleTicket (order) {
      const ticketIdList = [order.id]

      this.$confirm('确定要取票吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        printTickets(ticketIdList).then(res => {
          if (res.code === '200') {
            this.$message.success('操作成功')
          }
        })
      })
    },
    // 修改
    async editOrder (order) {
      await this.getOrderDetail(order)
      this.editOrderDialogVisible = true
      this.editOrderInfo.orderId = order.id
      this.editOrderInfo.payChannel = order.payChannel
      this.editOrderInfo.playDateBegin = order.playDateBegin
      this.editOrderInfo.playDateEnd = order.playDateEnd

      this.editOrderInfo.ticketCheckScenicUpdateRequestList = []
      this.editOrderInfo.ticketList = []
      this.currentOrder.ticketList.forEach(v => {
        this.editOrderInfo.ticketList.push({
          ...v,
          checkLimitTimes: -1 // 默认不限制
        })
        // this.editOrderInfo.ticketCheckScenicUpdateRequestList.push(...v.ticketCheckScenicList)
      })
    },
    cancelEdit () {
      this.editOrderDialogVisible = false
      this.editOrderInfo = {
        orderId: '',
        updateType: '',
        payChannel: '',
        playDateBegin: '',
        playDateEnd: '',
        ticketIds: [],
        ticketList: [],
        ticketCheckScenicUpdateRequestList: []
      }
    },
    submitEditOrder () {
      if (this.editOrderInfo.updateType === '') {
        return this.$message.error('请选择修改类型')
      }
      if (this.editOrderInfo.updateType === 'updateOrderPayChannel' && !this.editOrderInfo.payChannel) {
        return this.$message.error('请选择支付方式')
      }
      if (this.editOrderInfo.updateType === 'updatePlayDate' && (!this.editOrderInfo.playDateBegin || !this.editOrderInfo.playDateEnd)) {
        return this.$message.error('请选择游玩日期')
      }

      this.editOrderInfo.ticketCheckScenicUpdateRequestList = []

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

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

      if (this.editOrderInfo.updateType === 'updateScenicTimes') {
        this.editOrderInfo.ticketIds = this.editOrderInfo.ticketList.map(item => item.id)
        this.editOrderInfo.ticketList.forEach(item => {
          item.ticketCheckScenicList.forEach(scenic => {
            this.editOrderInfo.ticketCheckScenicUpdateRequestList.push({
              id: scenic.id,
              checkedTimes: scenic.checkedTimes,
              checkLimitTimes: item.checkLimitTimes
            })
          })
        })
      }

      updateOrder(this.editOrderInfo).then(res => {
        if (res.code === '999999') {
          this.$message.warning(res.msg || '修改失败')
          return
        }
        this.$message.success('修改成功')
        this.editOrderDialogVisible = false
        this.getOrderList()
      })
    }
  },
  beforeDestroy () {
    EventBus.$off('activeTag')
  }
}
</script>

<style lang="scss" scoped>
.el-dialog__body {
  min-height: 300px;
}
</style>
