<template>
  <page-meta :page-style="'overflow:' + (show ? 'hidden' : 'visible')"></page-meta>
  <view class="m-content">
    <view class="m-card m-card-one" v-if="overSituation">
      <view class="m-one-first-row">
        <view class="m-ticket-name">{{ ticket.ticketname }}</view>
        <view class="m-ticket-use-time" v-if="ticket && ticket.datesettings == 1">
          <view class="m-ticket-use-time-label">
            <img class="m-img" src="../static/img/predetermine_time1.svg" alt="" />
            使用有效期：
          </view>
          <view class="m-ticket-use-time-value" v-if="ticket && ticket.qmxId != null">{{
            parseArrTime(ticket.usevalidityStart) }}&nbsp;至&nbsp;{{ parseArrTime(ticket.usevalidityEnd) }}</view>
          <view class="m-ticket-use-time-value" v-else>{{ parseTime(ticket.usevalidityStart) }}&nbsp;至&nbsp;{{
            parseTime(ticket.usevalidityEnd)
            }}</view>
        </view>
        <view class="m-ticket-use-time" v-if="ticket && ticket.datesettings == 1">
          <view class="m-ticket-use-time-label">
            <img class="m-img" src="../static/img/predetermine_time2.svg" alt="" />
            使用时间段：
          </view>
          <view class="m-ticket-use-time-value">全天</view>
        </view>
        <view class="m-ticket-use-time" v-if="ticket && ticket.datesettings == 3">
          <view class="m-ticket-use-time-label">
            <img class="m-img" src="../static/img/predetermine_time2.svg" alt="" />
            使用时间段：
          </view>
          <view class="m-ticket-use-time-value">{{ ticket.usertimeslotStart }}-{{ ticket.usertimeslotEnd }}
          </view>
        </view>
      </view>
      <!-- <view class="m-one-second-row" v-if="ticket && ticket.qmxId == null && ticket.datesettings != 1"> -->
      <view class="m-one-second-row" v-if="ticket && ticket.datesettings != 1">
        <view class="m-row-title">选择日期</view>
        <view class="m-date-pick-box">
          <view class="scroll-view1">
            <view v-for="(date, index) in dates" :key="index"
              :class="['date-item', date.isAvailable ? 'available' : '']" @click="chooseDate(index, date)">
              <view :class="['date-box', { active: index === nowIndex }]">
                <text class="date-label">{{ date.label }}</text>
                <text class="date-date">{{ date.date }}</text>
                <text class="date-price">{{ date.price }}</text>
              </view>
            </view>
          </view>
          <view class="m-more-date" @click.stop="openCalendar">
            <span>更多日期</span>
            <uni-icons type="right" size="18"></uni-icons>
          </view>
        </view>
      </view>
      <view class="m-one-third-row">
        <view class="m-ticket-count">
          <view class="m-ticket-count-label">购票数量</view>
          <view class="m-ticket-count-value" v-if="ticket && ticket.qmxId == null">
            <uni-number-box v-if="maxNum == -1" :min="0" :max="maxBuyNums" v-model="ticket.num" :disabled="!ticket.date"
              @change="changeCount($event, ticket)" />
            <uni-number-box v-else :min="0" :max="maxNum" v-model="ticket.num" :disabled="!ticket.date"
              @change="changeCount($event, ticket)" />
          </view>
          <view class="m-ticket-count-value" v-else>
            <uni-number-box :min="ticket.qmxTicketInfoVO.minBuyNum ? ticket.qmxTicketInfoVO.minBuyNum:0"
              :max="ticket.qmxTicketInfoVO.maxBuyNum ? ticket.qmxTicketInfoVO.maxBuyNum :maxBuyNums"
              :disabled="!ticket.date" v-model="ticket.num" @change="changeCount($event, ticket)" />
          </view>
        </view>
      </view>
      <view class="m-one-fourth-row">
        <view class="m-ticket-count">
          <!-- <view class="m-ticket-count-label">成人票</view> -->
          <view class="m-ticket-count-value" @click.stop="openPop(1)">
            <span>购买须知</span>
            <uni-icons type="right" size="16"></uni-icons>
          </view>
        </view>
      </view>
    </view>
    <view class="m-card m-card-two" v-if="ticket && ticket.qmxId != null && ticket.num > 0">
      <view class="m-card-title">
        <view class="contact-user-box"
          v-if="ticket.qmxTicketInfoVO.needContactName != false || ticket.qmxTicketInfoVO.needContactPhone != false || ticket.qmxTicketInfoVO.needContactIdCard != false">
          <view class="m-title">联系人信息</view>
          <view class="content-box">
            <uni-row>
              <view class="content-box-row" v-if="ticket.qmxTicketInfoVO.needContactName != false">
                <uni-col :span="6">
                  <view class="content-box-label">联系人姓名</view>
                </uni-col>
                <uni-col class="content-box-col" :span="18">
                  <uni-easyinput :inputBorder="false" v-model="bookerusername" placeholder="请输入联系人姓名" />
                </uni-col>
              </view>
            </uni-row>
            <uni-row>
              <view class="content-box-row" v-if="ticket.qmxTicketInfoVO.needContactPhone != false">
                <uni-col :span="6">
                  <view class="content-box-label">联系人电话</view>
                </uni-col>
                <uni-col class="content-box-col" :span="18">
                  <uni-easyinput :inputBorder="false" v-model="bookerphone" placeholder="请输入联系人电话" />
                </uni-col>
              </view>
            </uni-row>
            <uni-row>
              <view class="content-box-row" v-if="ticket.qmxTicketInfoVO.needContactIdCard != false">
                <uni-col :span="6">
                  <view class="content-box-label">联系人身份证</view>
                </uni-col>
                <uni-col class="content-box-col" :span="18">
                  <uni-easyinput :inputBorder="false" v-model="bookeridcard" placeholder="请输入联系人身份证号" />
                </uni-col>
              </view>
            </uni-row>
          </view>
        </view>
      </view>
    </view>
    <view class="m-card m-card-two"
      v-if="ticket && ticket.touristInformation != 1 && ticket.date != null && ticket.num > 0">

      <view class="m-card-title">
        <view class="m-title">游客信息</view>
        <view class="m-title-tips">需填 {{ ticket.touristInformation == 2 ? 1 : peopleNums() }} 位</view>
      </view>
      <view class="m-two-first-row">
        <view class="user-list-box">
          <view class="m-user-list m-user-list-left" :class="item.selected ? 'active' : ''" v-for="item in navUserList"
            @click="selectUser(item)">
            {{ item.name }}
          </view>
        </view>

        <view class="m-user-list m-more-user" @click="openAddress">
          <span class="m-span">
            新增
            <br />
            更改
          </span>
          <uni-icons type="right" size="18"></uni-icons>
        </view>
      </view>
      <view class="m-two-second-row">
        <view class="m-user-list" v-if="ticket && ticket.qmxId == null">
          <view class="m-user-list-item" v-for="(item, index) in selectUserList">
            <view class="m-list-left">
              <img class="m-img" src="../static/img/predetermine_tourist.svg" alt="" />
              <span class="m-span">游客{{ index + 1 }}</span>
            </view>
            <view class="m-list-middle">
              <view class="m-middle-user-name">
                {{ item.name || '暂无' }}
              </view>
              <view v-if="ticket.ischeckedIdcard == 1" class="m-middle-user-idCode m-gray m-m-font">身份证 {{
                item.idCardNumber || '暂无' }}</view>
              <view v-if="ticket.ischeckedMobile == 1" class="m-middle-user-tel m-gray m-m-font">手机号 {{
                item.phoneNumber || '暂无'
              }}
              </view>
            </view>
            <view class="m-list-right">
              <uni-icons @click="edit(item)" type="compose" size="24"></uni-icons>
              <uni-icons @click="selectUser(item)" type="trash" size="24"></uni-icons>
            </view>
          </view>
        </view>
        <view class="m-user-list" v-else>
          <view class="m-user-list-item" v-for="(item, index) in selectUserList">
            <view class="m-list-left">
              <img class="m-img" src="../static/img/predetermine_tourist.svg" alt="" />
              <span class="m-span">游客{{ index + 1 }}</span>
            </view>
            <view class="m-list-middle">
              <view class="m-middle-user-name">
                {{ item.name || '暂无' }}
              </view>
              <!-- <view v-if="item.idtype && item.idtype == ticketIdType" class="m-middle-user-idCode m-gray m-m-font">{{ -->
              <view class="m-middle-user-idCode m-gray m-m-font">{{ labelName(item.idtype) }}:{{ item.idCardNumber ||
                '暂无' }}
              </view>
              <view v-if="item.phoneNumber" class="m-middle-user-tel m-gray m-m-font">手机号 {{ item.phoneNumber || '暂无'
                }}
              </view>
            </view>
            <view class="m-list-right">
              <uni-icons @click="edit(item)" type="compose" size="24"></uni-icons>
              <uni-icons @click="selectUser(item)" type="trash" size="24"></uni-icons>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view class="m-feet-box" v-if="overSituation">
      <view class="m-feet-left">
        <view class="m-price">
          总价
          <span class="m-red">
            ¥
            <span class="m-red m-xxl-font">{{ sumPrice ? sumPrice : 0 }}</span>
          </span>
        </view>
        <view class="m-nums">
          共
          <span class="m-red">{{ ticket.num ? ticket.num : 0 }}</span>
          张门票
        </view>
      </view>
      <view class="m-feet-right">
        <!-- <button class="m-prime-red" @click.stop="isPayPopup = true">支付</button> -->
        <button :hover-class="!ticket.num || ticket.num == 0 ? 'btn-hover' : ''"
          :class="['m-prime-red', cantClick ? 'disabled-btn' : '']"
          :disabled="cantClick" @click.stop="checkOrder('first')">
          支付
        </button>
      </view>
    </view>
    <view class="no-ticket-tips" v-if="!overSituation">
      今日门票已售罄
    </view>
    <!-- 人员 -->
    <liu-select :multiple="fasle" ref="scroll" :list="dataList" @change="chooseSuccess" @del="del" @edit="edit"
      @add="addPerson"></liu-select>
    <!-- 日历 -->
    <wu-calendar :date="choseDate" ref="calendar" :useToday="false" @monthSwitch="changeMonth" :startDate="startDate"
      :selected="selected" :confirmFullDate="true" @confirm="calendarConfirm" :insert="false"></wu-calendar>
    <!-- 重复订单提醒 -->
    <uni-popup ref="warningPop" type="center" border-radius="20rpx" :is-mask-click="false">
      <view class="m-pop-bg">


        <view class="m-green-bg"></view>
        <view class="m-red-bg"></view>
        <view class="m-notice-popuo">
          <view class="m-notice-ico">
            <img class="m-img" src="" alt="" />
          </view>
          <view class="m-notice-text">您有一笔待支付订单，请优先处理！</view>
          <view class="m-pop-feet">
            <button class="m-prime-line-unset m-size-middle" @click="checkOrder('continue')" size="mini">
              继续下单
            </button>
            <button class="m-prime m-size-middle" size="mini" @click="goOrderList">
              前往处理
            </button>
          </view>
        </view>
      </view>
    </uni-popup>
    <!-- 支付 -->
    <u-popup :show="isPayPopup" mode="bottom" @close="closePay" round="10">
      <f-pay :show-title="false" :show="isPayPopup" :payMoney="orderInfo.orderInfo.orderAmount"
        :tradeNo="orderInfo.orderInfo.orderNumber" :order="orderInfo" @payResult="payResult"></f-pay>
    </u-popup>
    <!-- 须知 -->
    <uni-popup :maskShow="true" ref="mPurchaseNotice" border-radius="10px 10px 0 0" :safe-area="false"
      @change="mPurchaseNoticeChange" @maskClick="maskClick">
      <view class="m-purchase-notice m-pop-bg">
        <view class="m-green-bg"></view>
        <view class="m-red-bg"></view>
        <view class="m-pop-title">购买须知</view>
        <view class="m-contents">
          <view class="m-title">购买须知</view>
          <view class="m-notice-box">
            <view class="m-notice-row">
              <view class="m-tag m-tag-blue">退票规则</view>
              <view class="m-notice-row-content">{{ ticketInfos.refundRules }}</view>
            </view>
            <view class="m-notice-row">
              <view class="m-tag m-tag-blue">使用次数</view>
              <view class="m-notice-row-content">{{ ticketInfos.ticketchecksNum }}</view>
            </view>
            <view class="m-notice-row">
              <view class="m-tag m-tag-red">购票限制</view>
              <view class="m-notice-row-content">{{
                ticketInfos.buyticketlimit == 1
                ? "不限"
                : "每人限购" + ticketInfos.ticketlimitnum + "张"
                }}</view>
            </view>
            <view class="m-notice-row">
              <view class="m-tag m-tag-blue">使用时段</view>
              <view class="m-notice-row-content">{{
                ticketInfos.usertimeslotStart == ticketInfos.usertimeslotEnd
                ? "全天"
                : ticketInfos.usertimeslotStart + "至" + ticketInfos.usertimeslotEnd
                }}</view>
            </view>
          </view>
          <view class="m-driver"></view>
          <view class="m-title">费用说明</view>
          <view class="m-notice-table">
            <view class="m-table-head">费用包含</view>
            <view class="m-table-th">
              <view class="m-table-td">门票</view>
              <view class="m-table-td">{{ ticket.ticketname || "-" }}</view>
            </view>
          </view>
          <view class="m-driver"></view>
          <view class="m-title">使用说明</view>
          <view class="m-notice-table no-border">
            <view class="m-table-th">
              <view class="m-table-td">
                <img class="m-table-inside-ico" src="../static/img/notice_time.svg" alt="" />
                开放时间
              </view>
              <view class="m-table-td">
                <view class="m-ul">
                  <view class="m-li">{{ ticketInfos.openTime }}</view>
                </view>
              </view>
            </view>
            <view class="m-table-th">
              <view class="m-table-td">
                <img class="m-table-inside-ico" src="../static/img/notice_notice.svg" alt="" />
                购票须知
              </view>
              <view class="m-table-td">
                <view class="m-ul">
                  <view class="m-li">{{ ticketInfos.ticketInfo }}</view>
                </view>
              </view>
            </view>
            <view class="m-table-th">
              <view class="m-table-td">
                <img class="m-table-inside-ico" src="../static/img/notice_address.svg" alt="" />
                景区地址
              </view>
              <view class="m-table-td">
                <view class="m-ul">
                  <view class="m-li">{{ ticketInfos.addressInfo }}</view>
                </view>
              </view>
            </view>
          </view>
          <!-- <view class="m-driver"></view>
					<view class="m-title">其他说明</view>
					<view class="m-notice-table no-border">
						<view class="m-table-th">
							<view class="m-table-td m-no-bg">发票说明</view>
							<view class="m-table-td m-no-bg">如需发票、请在付款完成后，在已核订 单中，申请电子发票。</view>
						</view>
					</view> -->
        </view>
      </view>
    </uni-popup>
    <!-- 新增 -->
    <uni-popup ref="mAddPerson" type="bottom" border-radius="10px 10px 0 0" :safe-area="false">
      <view class="m-purchase-notice m-pop-bg">
        <view class="m-green-bg"></view>
        <view class="m-red-bg"></view>
        <view class="m-pop-title">{{ titleName }}游客</view>
        <view class="m-form-box" v-if="ticket && ticket.qmxId == null">
          <uni-forms class="m-form" ref="peopleForm" :modelValue="baseFormData">
            <uni-row class="m-row">
              <!-- <uni-col class="m-col" :span="ticket.ischeckedIdcard == 1 ? 18 : 24"> -->
              <uni-col class="m-col" :span="24">
                <uni-forms-item class="m-form-item" label="姓   名" required name="name">
                  <uni-easyinput :inputBorder="false" v-model="baseFormData.name" placeholder="请输入姓名" />
                </uni-forms-item>
                <uni-forms-item v-if="ticket.ischeckedIdcard == 1" class="m-form-item" label="身份证" required
                  name="idCardNumber">
                  <uni-easyinput :inputBorder="false" v-model="baseFormData.idCardNumber" placeholder="请输入身份证号" />
                </uni-forms-item>
              </uni-col>
              <!-- <uni-col v-if="ticket.ischeckedIdcard == 1" class="m-col1" span="5" offset="1">
                <view class="m-col1">
                  <lzcOCR :dataObj="dataObj" @start="start" @end="end" />
                </view>
              </uni-col> -->
            </uni-row>
            <uni-forms-item v-if="ticket.ischeckedMobile == 1" class="m-form-item" label="手机号" required
              name="phoneNumber">
              <uni-easyinput :inputBorder="false" v-model="baseFormData.phoneNumber" placeholder="请输入手机号" />
            </uni-forms-item>
          </uni-forms>
          <button class="m-prime m-size-middle m-custom-margin" @click="finishPeople">
            完成
          </button>
        </view>
        <view class="m-form-box" v-else>
          <uni-forms class="m-form" ref="peopleForm" :modelValue="baseFormData">
            <uni-row class="m-row">
              <uni-col class="m-col" :span="24">
                <uni-forms-item v-if="ticket.qmxTicketInfoVO.needVisitorName == true" class="m-form-item" label="姓   名"
                  required name="name">
                  <uni-easyinput :inputBorder="false" v-model="baseFormData.name" placeholder="请输入姓名" />
                </uni-forms-item>
                <view v-if="picks && picks.length > 0" class="picks-box">

                  <uni-forms-item v-if="ticketIdType != null" class="m-form-item" label="证   件" required
                    name="idCardNumber">
                    <uni-data-select class="m-select" :clear="false" v-model="baseFormData.idtype" :localdata="picks"
                      @change="pickChange"></uni-data-select>
                    <uni-easyinput :inputBorder="false" v-model="baseFormData.idCardNumber" placeholder="请输入证件号" />
                  </uni-forms-item>
                </view>
              </uni-col>
              <!-- <uni-col v-if="baseFormData.idtype == 1" class="m-col1" span="5" offset="1">
                <view class="m-col1">
                  <lzcOCR :dataObj="dataObj" @start="start" @end="end" />
                </view>
              </uni-col> -->
            </uni-row>
            <uni-forms-item v-if="ticket.qmxTicketInfoVO.needVisitorPhone == true" class="m-form-item" label="手机号"
              required name="phoneNumber">
              <uni-easyinput :inputBorder="false" v-model="baseFormData.phoneNumber" placeholder="请输入手机号" />
            </uni-forms-item>
          </uni-forms>
          <button class="m-prime m-size-middle m-custom-margin" @click="finishPeople">
            完成
          </button>
        </view>
      </view>
    </uni-popup>
  </view>
</template>

<script>
import fPay from "../components/f-pay/f-pay";
import lzcOCR from "../components/lzc-OCR/lzc-OCR.vue";
import { parseTime } from "@/common/util";
import uniPopup from "../components/uni-popup/components/uni-popup/uni-popup.vue";
import uPopup from "../components/uview-ui/components/u-popup/u-popup.vue";
import uniRow from "../components/uni-row/components/uni-row/uni-row.vue"
import liuSelect from "../components/liu-select/components/liu-select/liu-select.vue"
import uniDataSelect from "../components/uni-data-select/components/uni-data-select/uni-data-select.vue"

const validateID = (idType, value) => {
  let regex;

  switch (idType) {
    case 1: // 身份证
      regex = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
      break;
    case '1': // 身份证
      regex = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
      break;
    case '2': // 护照
      regex = /^[A-Za-z0-9]{5,20}$/;
      break;
    case '3': // 台胞证
      regex = /^[0-9]{8}$/;
      break;
    case '4': // 港澳通行证
      regex = /^[H|M][0-9]{10}$/;
      break;
    case '5': // 回乡证
      regex = /^[H|M][0-9]{10}$/; // 回乡证与港澳通行证格式相似
      break;
    case '6': // 台湾通行证
      regex = /^[0-9]{8}$/;
      break;
    case '7': // 港澳居民居住证
      regex = /^[0-9]{18}$/;
      break;
    case '8': // 外国人永久居留证
      regex = /^[A-Za-z0-9]{15}$/;
      break;
    case '9': // 国际海员证
      regex = /^[A-Za-z0-9]{9}$/;
      break;
    case '10': // 军官证
      regex = /^[A-Za-z0-9]{8}$/;
      break;
    case '11': // 学生证
      regex = /^[A-Za-z0-9]{10,20}$/;
      break;
    default:
      return false;
  }
  console.log(idType, value, regex.test(value))
  return regex.test(value);
};
export default {
  components: {
    fPay,
    lzcOCR,
    uniPopup,
    uPopup,
    uniRow,
    liuSelect,
    uniDataSelect
  },
  data() {
    return {
      maxNum: -1,
      maxBuyNums: 100,
      overSituation: true,//启明芯全局判断是否可选
      cantClick:true,
      tentId: null,
      selected: null, //门票日历
      startDate: parseTime(new Date()),
      choseDate: null,
      show: false,
      //门票须知
      ticketInfos: null,
      //生成订单信息
      orderInfo: null,
      //总价
      sumPrice: 0,
      ticket: null,
      ticketInfo: null,
      nowIndex: null,
      titleName: "新增",
      isPayPopup: false,
      dates: [],
      numberValue: 1,
      tradeNo: "16fw61cqew6464wdc", //支付单号
      dataObj: {
        client_id: "qs5EQSE0neZZDh5sA7FmHnUL",
        client_secret: "w92jiLCNSVecfRdyBbjhcOGEQoezaC1B",
      },
      baseFormData: {
        name: null,
        idCardNumber: null,
        phoneNumber: null,
        id: null,
        selected: false,
        idtype: null
      },
      idCardName: null,
      ticketIdType: null,
      //联系人信息
      bookerusername: null,
      bookerphone: null,
      bookeridcard: null,
      picks: [],
      picksValue: null,
      dataList: [], //数据源
      sessionDataList: [],
      navUserList: [],
      selectUserList: [],
      rules: {
        name: {
          rules: [
            {
              required: true,
              errorMessage: "请输入姓名",
            },
          ],
        },
        idCardNumber: {
          rules: [
            {
              required: true,
              errorMessage: "请输入证件号",
            },
            {
              validateFunction: (rule, value, data, callback) => {
                const reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
                let that = this

                if (!value) {
                  callback("证件号不能为空");
                }
                // else if (that.baseFormData.idtype == 1 && !reg.test(value)) {
                //   callback("请输入正确的身份证号码");
                // }
                else {
                  callback();
                }
              },
            },
          ],
        },
        phoneNumber: {
          rules: [
            {
              required: true,
              errorMessage: "请输入手机号",
            },
            {
              validateFunction: function (rule, value, data, callback) {
                const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
                if (!value) {
                  callback("手机号码不能为空");
                }
                else if (!reg.test(value)) {
                  callback("请输入正确的手机号码");
                }
                else {
                  callback();
                }
              },
            },
          ],
        },
      },
    };
  },
  watch: {
    'ticket': {
      handler(val) {
        console.log(val, "-----");
        // if (!val.num) {
        //   val.num = 1;
        // }
        // if (val.qmxId == null) {
        const priceInCents = Math.round(Number(val.settlementPrice) * 100);
        const quantity = Number(val.num);
        this.$nextTick(() => {
          this.sumPrice = (priceInCents * quantity) / 100;
        });
        // }
      },
      deep: true,
    },
    'dataList': {
      handler(val) {
        console.log(val);
        this.navUserList = val
      },
      deep: true
    },
    'nowIndex':{
      handler(val) {
        if (val!=7) {
          this.dates=this.dates.slice(0, 7);
        }
      },
      deep: true,
      immediate: true
    },
  },
  onReady() {
    this.$refs.peopleForm.setRules(this.rules);
  },
  onLoad(options) {
    for (let i = 0; i < 7; i++) {
      this.dates.push({
        label: this.getLabel(i),
        date: this.getFormattedDate(i),
        fullDate: this.getFullDate(i),
        isAvailable: true,
        price: "0元",
        inventory: 0,
      });
    }
    console.log(options);
    const ticket = JSON.parse(decodeURIComponent(options.ticket));
    this.getTicketInfo(ticket.id, ticket);
    if (options.maxNum) {
      this.maxNum = options.maxNum;
    } else {
      this.maxNum = -1;
    }
    // if (ticket.datesettings == 1 && ticket.inventorySettings == 2 && this.maxNum == -1) {
    //   this.maxNum = Number(ticket.currentinventory);
    // }
    this.tentId = options.tentId;
    this.getScencAndTicketInfo(ticket.id, options.tentId);
    const users = uni.getStorageSync('users')
    if (users && users.length > 0) {
      users.forEach(item => { item.selected = false })
      this.dataList = users
      this.sessionDataList = users
    }
  },
  mounted() { },
  methods: {
    labelName(val) {

      switch (val) {
        case 1:
          return '身份证'
          break;
        case '1':
          return '身份证'
          break;
        case '2':
          return '护照'
          break;
        case '3':
          return '台胞证'
          break;
        case '4':
          return '港澳通行证'
          break;
        case '5':
          return '回乡证'
          break;
        case '6':
          return '台湾通行证'
          break;
        case '7':
          return '港澳居住证'
          break;
        case '8':
          return '永久居留证'
          break;
        case '9':
          return '国际海员证'
          break;
        case '10':
          return '军官证'
          break;
        case '11':
          return '学生证'
          break;
        case '12':
          return '其他证件'
          break;
      }
    },
    //查询门票须知信息
    getTicketInfo(val, tick) {
      this.$Request
        .get(this.$config.getTicketInfo, { ticketId: val }, null, null, false, false)
        .then(res => {
          if (res.data.qmxId == null) {
            this.ticket = tick;
          } else {
            this.ticket = res.data;
            //开始判断启明星门票信息是否需要绑定游客信息

            switch (this.ticket.qmxTicketInfoVO.visitorInfoType) {
              case 'ALL':
                this.ticket.touristInformation = 3
                break;
              case 'MORE':
                this.ticket.touristInformation = 3
                break;
              case 'ONE':
                this.ticket.touristInformation = 2
                break;
              case 'NONE':
                this.ticket.touristInformation = 1
                break;
            }
            this.getQmxTicketDoc()
          }
          this.getdateTicket();
        })
        .catch(err => {
          console.log(err);
        });
    },
    //启明星票种证件限制
    getQmxTicketDoc() {
      this.$Request
        .get(this.$config.getQmxTicketDoc, { qmxId: this.ticket.qmxId }, null, null, false, false).then(res => {

          if (res.data.length > 0) {
            this.ticketIdType = res.data[0].key,
              this.idCardName = res.data[0].value

            this.picks = res.data.map(item => {
              return {
                value: item.key,
                text: item.value
              }
            })
          } else {
            this.ticketIdType = null
            this.idCardName = null
          }
          console.log(res)
        }).catch(err => {
          console.log
        })
    },
    //新增编辑时启明星证件类型选择
    pickChange(val) {
      console.log(val, this.baseFormData, 'ssssss')
    },
    //查日历库存
    getdateTicket() {
      let that = this;

      if (this.ticket && this.ticket.qmxId == null) {
        if (this.ticket.datesettings == 1) {
          // 不限库存
          this.ticket.date = that.parseTime(new Date())
          if (this.ticket.inventorySettings == 2) {
            this.maxBuyNums = Number(this.ticket.currentinventory)
          }
          if (this.ticket.inventorySettings == 1) {
            this.maxBuyNums = 100
          }
        }
        if (this.ticket.datesettings == 2 || this.ticket.datesettings == 3) {
          //使用日期和使用小时模式：单日,这里使用日期设置不论星期还是多日都不影响返回的日期了
          //不限库存/总库存
          if (this.ticket.inventorySettings == 1 || this.ticket.inventorySettings == 2) {

            const params = {
              ticketId: that.ticket.id,
              date: that.parseTime(new Date()),
            };
            that.$Request
              .get(that.$config.getTicketDateInventory, params, null, null, false, true)
              .then(res => {
                that.selected = [];
                res.data.forEach(items => {
                  const obj = {
                    date: items.date,
                    info: items.isAvailable && items.inventory != -1 ? "库存:" + items.inventory : "",
                    infoColor: "#666",
                    topInfo: items.isAvailable ? items.settlementPrice + '元' : '',
                    topInfoColor: "",
                    badgeColor: "",
                    disable: !items.isAvailable, // 禁用
                  };
                  that.selected.push(obj);
                });
                const selectedDates = that.selected.slice(0, 7); // 取出前七条数据
                console.log(selectedDates, "selectedDates", that.dates);
                selectedDates.forEach((item, index) => {
                  that.dates[index].isAvailable = item.disable;
                  that.dates[index].price = item.topInfo;
                  that.dates[index].inventory = item.info == "" ? -1 : item.info.match(/\d+/)[0];
                });

                console.log(this.dates);
              })
              .catch(err => {
                console.log(err);
              });
          }
          //日库存
          if (that.ticket.inventorySettings == 3) {


            const params = {
              ticketId: that.ticket.id,
              date: that.parseTime(new Date()),
            };
            that.$Request
              .get(that.$config.getTicketDateInventory, params, null, null, false, true)
              .then(res => {
                that.selected = [];
                res.data.forEach(items => {
                  const obj = {
                    date: items.date,
                    info: items.isAvailable ? "库存:" + items.inventory : "",
                    infoColor: "#666",
                    topInfo: items.isAvailable ? items.settlementPrice + '元' : '',
                    topInfoColor: "",
                    badgeColor: "",
                    disable: !items.isAvailable || items.inventory == 0, // 禁用
                  };
                  that.selected.push(obj);
                });
                const selectedDates = that.selected.slice(0, 7); // 取出前七条数据
                selectedDates.forEach((item, index) => {
                  that.dates[index].isAvailable = item.disable;
                  that.dates[index].price = item.topInfo;
                  that.dates[index].inventory = item.info == "" ? -1 : item.info.match(/\d+/)[0];
                });

                console.log(this.dates);
              })
              .catch(err => {
                console.log(err);
              });
          }
        }
      } else {
        if (this.ticket.datesettings == 1){
          this.ticket.date = that.parseTime(new Date())
        }else{
          this.ticket.date = null
        }
        const params = {
          ticketId: that.ticket.id,
          date: that.parseTime(new Date()),
        };
        that.$Request
          .get(that.$config.getTicketDateInventory, params, null, null, false, true)
          .then(res => {
            that.selected = [];
            that.ticket.settlementPrice = res.data[0].settlementPrice

            const nowDate = that.parseTime(new Date())
            console.log(nowDate)
            const index = res.data.findIndex(item => item.date == nowDate)
            if (index != -1) {
              if (res.data[index].isAvailable == true) {
                that.maxBuyNums = res.data[index].inventory==-1? 100: res.data[index].inventory
                that.overSituation = true
              } else {
                that.overSituation = false
              }
            } else {
              that.overSituation = false
            }

            console.log(that.ticket, 'thatthatthat')
            res.data.forEach(items => {
              const obj = {
                date: items.date,
                info: !items.isAvailable || items.inventory == -1 ? "" : "库存:" + items.inventory,
                infoColor: "#666",
                topInfo: !items.isAvailable ? "" : items.settlementPrice + '元',
                topInfoColor: "",
                badgeColor: "",
                disable: !items.isAvailable, // 禁用
              };
              that.selected.push(obj);
            });
            const selectedDates = that.selected.slice(0, 7); // 取出前七条数据
            selectedDates.forEach((item, index) => {
              that.dates[index].isAvailable = item.disable;
              that.dates[index].price = item.topInfo;
              that.dates[index].inventory = item.info == "" ? -1 : item.info.match(/\d+/)[0];
            });
            console.log(this.dates);

          })
          .catch(err => {
            console.log(err);
          });
      }
    },
    //点击遮罩
    maskClick() {
      this.$refs.mPurchaseNotice.close();
    },
    //切换月份
    changeMonth(e) {
      console.log(e);
      let that = this;

      let fullDate = e.fullDate + "-01";
      if (fullDate < that.parseTime(new Date())) {
        fullDate = that.parseTime(new Date());
      }
      if (that.ticket && that.ticket.qmxId == null) {
        if (that.ticket.inventorySettings == 1 || that.ticket.inventorySettings == 2) {
          const params = {
            ticketId: that.ticket.id,
            date: fullDate,
          };
          that.$Request
            .get(that.$config.getTicketDateInventory, params, null, null, false, true)
            .then(res => {
              that.selected = [];
              res.data.forEach(items => {
                const obj = {
                  date: items.date,
                  info: items.isAvailable && items.inventory != -1 ? "库存:" + items.inventory : "",
                  infoColor: "#666",
                  topInfo: items.isAvailable ? items.settlementPrice + '元' : '',
                  topInfoColor: "",
                  badgeColor: "",
                  disable: !items.isAvailable, // 禁用
                };
                that.selected.push(obj);
              });
              that.$forceUpdate();
              console.log(that.selected);
            })
            .catch(err => {
              console.log(err);
            });
        }
        //日库存
        if (that.ticket.inventorySettings == 3) {
          const params = {
            ticketId: that.ticket.id,
            date: fullDate,
          };
          that.$Request
            .get(that.$config.getTicketDateInventory, params, null, null, false, true)
            .then(res => {
              that.selected = [];
              res.data.forEach(items => {
                const obj = {
                  date: items.date,
                  info: items.isAvailable ? "库存:" + items.inventory : '',
                  infoColor: "#666",
                  topInfo: items.isAvailable ? items.settlementPrice + '元' : '',
                  topInfoColor: "",
                  badgeColor: "",
                  disable: !items.isAvailable || items.inventory == 0, // 禁用
                };
                that.selected.push(obj);
              });
              that.$forceUpdate();
              console.log(that.selected);
            })
            .catch(err => {
              console.log(err);
            });
        }
      } else {
        const params = {
          ticketId: that.ticket.id,
          date: fullDate,
        };
        that.$Request
          .get(that.$config.getTicketDateInventory, params, null, null, false, true)
          .then(res => {
            that.selected = [];
            res.data.forEach(items => {
              const obj = {
                date: items.date,
                info: items.isAvailable && items.inventory != -1 ? "库存:" + items.inventory : "",
                infoColor: "#666",
                topInfo: items.isAvailable ? items.settlementPrice + '元' : '',
                topInfoColor: "",
                badgeColor: "",
                disable: !items.isAvailable, // 禁用
              };
              that.selected.push(obj);
            });
          })
          .catch(err => {
            console.log(err);
          });
      }

    },
    //计算需要填写的人员信息数量
    peopleNums() {
      if (this.ticket.touristInformation == 3) {
        return Number(this.ticket.usersNumber ? this.ticket.usersNumber : 0) * Number(this.ticket.num ? this.ticket.num : 0);
      }
      if (this.ticket.touristInformation == 2) {
        return 1;
      }
    },
    //支付结果
    payResult(data) {
      console.log(data);
      if (data.payStatus == 1) {
        uni.showToast({ title: "支付成功", icon: "none" });
        this.isPayPopup = false;
        setTimeout(() => {
          uni.redirectTo({ url: "/subPageC/order/order" });
        }, 1000);
      } else {
        uni.showToast({ title: "支付失败", icon: "none" });
        this.isPayPopup = false;
        setTimeout(() => {
          uni.redirectTo({ url: "/subPageC/order/order" });
        }, 1000);
      }
      //uni.showToast({title: data.detail.errMsg,icon:'none'});
    },
    //重复订单跳订单页面
    goOrderList() {
      uni.redirectTo({ url: "/subPageC/order/order" });
    },
    //门票信息
    getScencAndTicketInfo(id, tentId) {
      this.$Request
        .get(
          this.$config.getScencAndTicketInfo,
          { ticketId: id, tenantId: tentId },
          null,
          null,
          false,
          true
        )
        .then(res => {
          console.log(res);
          this.ticketInfos = res.data;
        })
        .catch(err => {
          console.log(err);
        });
    },
    //格式化数组时间
    parseArrTime(val) {
      return val.join("-");
    },
    //格式化时间
    parseTime(val) {
      return parseTime(val, "{y}-{m}-{d}");
    },
    //滑动日历选中
    chooseDate(index, date) {
      console.log(date);
      if (index != 7 && this.dates.length>7){
        this.dates = this.dates.slice(0,7)
      }
      if (date.isAvailable == false) {

        this.nowIndex = index;
        this.ticket.date = date.fullDate;
        this.choseDate = date.fullDate;
        console.log(date.price.replace("元", ""))
        this.ticket.settlementPrice = parseFloat(date.price.replace("元", "").trim());
        this.ticket.num = 1
        this.cantClick=false
        this.sumPrice = this.ticket.settlementPrice;
        this.maxBuyNums = date.inventory == -1 ? 100 : date.inventory
        this.$forceUpdate();
        console.log(this.ticket, "this.ticket");

      } else {
        this.ticket.date = null;
      }
    },
    //修改编辑游客信息
    finishPeople(form) {
      ;
      let that = this;
      this.$refs.peopleForm
        .validate()
        .then(res => {
          ;
          if (this.baseFormData.id == null) {
            this.baseFormData.id = new Date().getTime();
            this.dataList.push(this.baseFormData);
          } else {
            // 找到要替换项的索引
            const index = this.dataList.findIndex(item => item.id === this.baseFormData.id);
            const index1 = this.selectUserList.findIndex(item => item.id === this.baseFormData.id);
            this.$set(this.dataList, index, { ...this.dataList[index], ...this.baseFormData });
            this.$set(this.selectUserList, index1, { ...this.selectUserList[index1], ...this.baseFormData });
          }
          console.log("表单数据信息：", that.dataList, that.navUserList, that.selectUserList);
          const sessionDataList = [...this.dataList];
          uni.setStorageSync('users', sessionDataList)
          this.$refs.mAddPerson.close();

          this.baseFormData = {
            name: null,
            idCardNumber: null,
            phoneNumber: null,
            id: null,
            selected: false,
            idtype: this.ticket && this.ticket.qmxId == null ? '1' : this.ticketIdType
          }

        })
        .catch(err => {
          console.log("表单错误信息：", err);
        });
    },
    //ocr开始
    start(e) {
      console.log(e);
    },
    end(e) {
      console.log(e);
    },
    //ocr结束
    //新增
    addPerson() {
      this.baseFormData = {
        name: null,
        idCardNumber: null,
        phoneNumber: null,
        id: null,
        selected: false,
        idtype: this.ticket && this.ticket.qmxId == null ? '1' : this.ticketIdType
      }
      this.$refs.mAddPerson.open();
      this.$refs.scroll.close();

      this.titleName = "新增";
    },
    //编辑游客信息
    edit(val) {
      console.log(val);
      this.$refs.scroll.close();
      this.$refs.mAddPerson.open();
      this.titleName = "编辑";
      this.baseFormData = JSON.parse(JSON.stringify(val));
    },
    //删除游客信息
    del(val) {
      this.$nextTick(() => {

        console.log(this.dataList, this.sessionDataList, this.navUserList);

        this.dataList = this.dataList.filter(item => item.id != val.id);
        this.sessionDataList = this.sessionDataList.filter(item => item.id != val.id);
        this.navUserList = this.navUserList.filter(item => item.id != val.id);
        this.selectUserList = this.selectUserList.filter(item => item.id != val.id);

        uni.setStorageSync('users', this.sessionDataList);

        console.log(this.dataList, this.sessionDataList, this.navUserList);
      });
    },
    //打开选择器
    openAddress() {
      this.$refs.scroll.open();
      this.$refs.scroll.dataList = this.dataList
    },
    //选择成功
    chooseSuccess(e) {
      console.log("所选择的信息:", e);
      this.selectUser(e[0], true)
    },
    //检查重复证件
    hasDuplicateIdcard(users) {
      const idcardCounts = users.reduce((acc, user) => {
        if (acc[user.idCardNumber]) {
          acc[user.idCardNumber] += 1;
        } else {
          acc[user.idCardNumber] = 1;
        }
        return acc;
      }, {});

      return Object.values(idcardCounts).some(count => count > 1);
    },
    //查看是否有重复订单
    checkOrder(val) {
        this.cantClick = true
      
      // if (this.ticket.qmxId == null) {
      let that = this;
      if (this.ticket.touristInformation == 2) {
        if (!this.selectUserList || this.selectUserList.length < 1) {
          this.cantClick = false
          uni.showToast({ title: "暂无游客信息", icon: "none" });
          return;
        } else {
          this.cantClick = false
          this.ticket.visitorInfoList = [...this.selectUserList]
        }
      }
      if (this.ticket.touristInformation == 3) {
        if (
          !this.selectUserList ||
          this.selectUserList.length <
          Number(this.ticket.usersNumber) * Number(this.ticket.num)
        ) {
          this.cantClick = false
          uni.showToast({ title: "请填写全部游客信息", icon: "none" });
          return;
        } else if (this.selectUserList.length >
          Number(this.ticket.usersNumber) * Number(this.ticket.num)) {
          this.cantClick = false
          uni.showToast({ title: "请删除超出的游客信息", icon: "none" });
          return;
        } else {
          this.cantClick = false
          this.ticket.visitorInfoList = [...this.selectUserList]
        }
      }
      // }
      const userInfo = uni.getStorageSync("userInfo");
      const extConfig = uni.getAccountInfoSync().miniProgram;
      let appId = extConfig.appId
      const params = {
        openid: userInfo.openid,
        appid: appId,
        tenantId: this.tentId,
      };
      this.$Request
        .get(this.$config.isHaveOrder, params, null, null, false, true)
        .then(res => {


          console.log(res);
          if (res.data != 0 && val != 'continue') {
            this.$refs.warningPop.open();
          }
          else {
            this.$refs.warningPop.close();



            if (that.ticket && that.ticket.qmxId == null) {

              if (that.ticket.touristInformation == 1) {
                const httpData = {
                  openid: userInfo.openid,
                  appid: appId,
                  mobile: userInfo.phone,
                  tenantId: this.tentId,
                  settlementAmount: that.sumPrice,
                  orderPrice: that.sumPrice,
                  ticketInfo: {
                    ticketId: that.ticket.id,
                    ticketName: that.ticket.ticketname,
                    num: that.ticket.num,
                    ticketPrice: that.ticket.settlementPrice,
                    date: that.ticket.date,
                    visitorInfoList: [],
                  },
                };
                this.setOrder(httpData)
              } else {

                let allValid = true;
                let allValids = true;
                let allValidtel = true;
                for (let i = 0; i < that.ticket.visitorInfoList.length; i++) {
                  // let isValid = validateID(that.ticket.visitorInfoList[i].idtype, that.ticket.visitorInfoList[i].idCardNumber);

                  let isValid = validateID(that.ticket.visitorInfoList[i].idtype, that.ticket.visitorInfoList[i].idCardNumber);
                  if (!isValid && this.ticket.ischeckedIdcard == 1) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客${this.labelName(that.ticket.visitorInfoList[i].idtype)}格式错误，请检查！`,
                      icon: "none"
                    });
                    allValid = false;
                    break;
                  }
                  if (this.ticket.ischeckedIdcard == 1 && !that.ticket.visitorInfoList[i].idCardNumber) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客${this.labelName(that.ticket.visitorInfoList[i].idtype)}未输入，请检查！`,
                      icon: "none"
                    });
                    allValid = false;
                    break;
                  }
                  if (this.ticket.ischeckedMobile == 1 && !that.ticket.visitorInfoList[i].phoneNumber) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客手机号未输入，请检查！`,
                      icon: "none"
                    });
                    allValidtel = false;
                    break;
                  }
                  const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
                  if (this.ticket.ischeckedMobile == 1 && !reg.test(that.ticket.visitorInfoList[i].phoneNumber)) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客手机号错误，请检查！`,
                      icon: "none"
                    });
                    allValidtel = false;
                    break;
                  }
                }
                if (this.hasDuplicateIdcard(that.ticket.visitorInfoList)) {
                  this.cantClick = false
                  allValids = false;
                  uni.showToast({
                    title: `游客证件号重复，请核对！`,
                    icon: "none"
                  });
                } else {
                  allValids = true;
                  this.cantClick = false
                }
                let arr = [...that.ticket.visitorInfoList]
                arr.forEach(item => {
                  if (that.ticket.ischeckedMobile == 0) {
                    item.phoneNumber = "";
                  }
                  if (that.ticket.ischeckedIdcard == 0) {
                    item.idCardNumber = "";
                  }
                  console.log(item, '当前访客信息');
                })
                console.log(arr, 'arrarrarr', that.ticket.ischeckedMobile, that.ticket.ischeckedIdcard)
                if (allValid && allValids && allValidtel) {
                  const httpData = {
                    openid: userInfo.openid,
                    appid: appId,
                    mobile: userInfo.phone,
                    tenantId: this.tentId,
                    settlementAmount: that.sumPrice,
                    orderPrice: that.sumPrice,
                    ticketInfo: {
                      ticketId: that.ticket.id,
                      ticketName: that.ticket.ticketname,
                      num: that.ticket.num,
                      ticketPrice: that.ticket.settlementPrice,
                      date: that.ticket.date,
                      visitorInfoList: arr,
                    },
                  };
                  console.log(httpData.ticketInfo.visitorInfoList)

                  this.setOrder(httpData);
                }
              }
            } else {


              if (that.ticket.qmxTicketInfoVO.needContactName == true) {

                if (!that.bookerusername) {
                  this.cantClick = false
                  uni.showToast({
                    title: '请输入联系人姓名',
                    icon: 'none'
                  })
                  return;
                }
              }
              if (that.ticket.qmxTicketInfoVO.needContactPhone == true) {

                if (!that.bookerphone) {
                  this.cantClick = false
                  uni.showToast({
                    title: '请输入联系人手机号',
                    icon: 'none'
                  })
                  return;
                }
                const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
                if (reg.test(that.bookerphone) == false) {
                  this.cantClick = false
                  uni.showToast({
                    title: '请输入正确的手机号',
                    icon: 'none'
                  })
                  return;
                }
              }
              if (that.ticket.qmxTicketInfoVO.needContactIdCard == true) {

                if (!that.bookeridcard) {
                  this.cantClick = false
                  uni.showToast({
                    title: '请输入联系人身份证号',
                    icon: 'none'
                  })
                  return;
                }
                const reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
                if (reg.test(that.bookeridcard) == false) {
                  this.cantClick = false
                  uni.showToast({
                    title: '请输入正确的身份证号',
                    icon: 'none'
                  })
                  return;
                }
              }
              if (that.ticket.visitorInfoList && that.ticket.visitorInfoList.length > 0) {

                let allValid = true;
                let allValids = true;
                let allValidtel = true;
                for (let i = 0; i < that.ticket.visitorInfoList.length; i++) {
                  // let isValid = validateID(that.ticket.visitorInfoList[i].idtype, that.ticket.visitorInfoList[i].idCardNumber);

                  let isValid = validateID(that.ticket.visitorInfoList[i].idtype, that.ticket.visitorInfoList[i].idCardNumber);
                  if (!isValid && this.ticketIdType != null) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客${this.labelName(that.ticket.visitorInfoList[i].idtype)}格式错误，请检查！`,
                      icon: "none"
                    });
                    allValid = false;
                    break;
                  }
                  if (this.ticketIdType != null && !that.ticket.visitorInfoList[i].idCardNumber) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客${this.labelName(that.ticket.visitorInfoList[i].idtype)}未输入，请检查！`,
                      icon: "none"
                    });
                    allValid = false;
                    break;
                  }
                  if (this.ticket.qmxTicketInfoVO.needVisitorPhone == true && !that.ticket.visitorInfoList[i].phoneNumber) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客手机号未输入，请检查！`,
                      icon: "none"
                    });
                    allValidtel = false;
                    break;
                  }
                  const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
                  if (this.ticket.qmxTicketInfoVO.needVisitorPhone == true && !reg.test(that.ticket.visitorInfoList[i].phoneNumber)) {
                    this.cantClick = false
                    uni.showToast({
                      title: `第${i + 1}位游客手机号错误，请检查！`,
                      icon: "none"
                    });
                    allValidtel = false;
                    break;
                  }
                }
                if (this.hasDuplicateIdcard(that.ticket.visitorInfoList)) {
                  allValids = false;
                  this.cantClick = false
                  uni.showToast({
                    title: `游客证件号重复，请核对！`,
                    icon: "none"
                  });
                } else {
                  allValids = true;
                  this.cantClick = false
                }
                let arr = [...that.ticket.visitorInfoList]
                arr.forEach(item => {
                  if (that.ticket.qmxTicketInfoVO.needVisitorPhone != true) {
                    item.phoneNumber = "";
                  }
                  if (that.ticketIdType == null) {
                    item.idCardNumber = "";
                  }
                })
                if (allValid && allValids && allValidtel) {
                  const httpData = {
                    openid: userInfo.openid,
                    appid: appId,
                    mobile: userInfo.phone,
                    tenantId: this.tentId,
                    settlementAmount: that.sumPrice,
                    orderPrice: that.sumPrice,
                    bookerusername: that.bookerusername ? that.bookerusername : "",
                    bookerphone: that.bookerphone ? that.bookerphone : "",
                    bookeridcard: that.bookeridcard ? that.bookeridcard : "",
                    ticketInfo: {
                      ticketId: that.ticket.id,
                      ticketName: that.ticket.ticketname,
                      num: that.ticket.num,
                      ticketPrice: that.ticket.settlementPrice,
                      date: that.ticket.date,
                      visitorInfoList: arr,
                    },
                  }
                  console.log(httpData.ticketInfo.visitorInfoList)
                  this.setOrder(httpData);
                }
              } else {
                const httpData = {
                  openid: userInfo.openid,
                  appid: appId,
                  mobile: userInfo.phone,
                  tenantId: this.tentId,
                  settlementAmount: that.sumPrice,
                  orderPrice: that.sumPrice,
                  bookerusername: that.bookerusername ? that.bookerusername : "",
                  bookerphone: that.bookerphone ? that.bookerphone : "",
                  bookeridcard: that.bookeridcard ? that.bookeridcard : "",
                  ticketInfo: {
                    ticketId: that.ticket.id,
                    ticketName: that.ticket.ticketname,
                    num: that.ticket.num,
                    ticketPrice: that.ticket.settlementPrice,
                    date: that.ticket.date,
                    visitorInfoList: [],
                  },
                };
                this.setOrder(httpData);
              }
            }
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //下单接口
    setOrder(val) {
      this.$Request
        .post(
          this.$config.verifyAndCreateOrder,
          val,
          "json",
          null,
          false,
          true
        )
        .then(res => {
          if (res.code == 0 && res.data != null) {
            this.orderInfo = res.data;
            this.isPayPopup = true;
          }
          else {
            this.cantClick = false
            uni.showToast({
              title: res.msg,
              icon: 'none'
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 打开日历
    openCalendar() {
      this.getdateTicket()
      this.$refs.calendar.open();
    },
    //选择日历
    calendarConfirm(e) {
      let that = this
      console.log(e);
      this.dates.forEach((item, index) => {
        if (item.fullDate == e.fulldate) {
          this.$nextTick(() => {
            that.nowIndex = index
          })
        } else {
          // that.nowIndex = -1
          that.nowIndex = 7
        }
      })
      if(that.nowIndex == 7){
        this.dates = this.dates.slice(0, 7)
        this.dates.push({
          label: e.lunar.ncWeek,
          date: e.lunar.cMonth + '-' + e.lunar.cDay,
          fullDate: e.fulldate,
          isAvailable: false,
          price: e.extraInfo.topInfo.replace("元", "").trim(),
          inventory: e.extraInfo.info == "" ? -1 : e.extraInfo.info.match(/\d+/)[0]
        })
      }else{
        this.$set(that.dates, 0, that.dates.slice(0, 7));
      }
      this.maxBuyNums = e.extraInfo.info == "" ? 100 : e.extraInfo.info.match(/\d+/)[0]
      this.ticket.date = e.fulldate;
      this.choseDate = e.fulldate;
      this.ticket.settlementPrice = parseFloat(
        e.extraInfo.topInfo.replace("元", "").trim()
      );
      this.ticket.num = 1
      this.cantClick=false
      this.sumPrice = this.ticket.settlementPrice;
      this.$forceUpdate();
      console.log(this.ticket, "this.ticket");

    },
    //须知
    openPop(val) {
      switch (val) {
        case 1:
          this.$refs.mPurchaseNotice.open("bottom");
          break;
        default:
          break;
      }
    },
    //购票数量
    changeCount(val, ticket) {
      console.log(val, ticket);
      if(val == 0){
        this.cantClick = true
      }else{
        this.cantClick = false
      }
      this.ticket.num = val;
      const priceInCents = Math.round(Number(ticket.settlementPrice) * 100);
      const quantity = Number(val);
      this.sumPrice = (priceInCents * quantity) / 100;
    },
    //选择游客
    selectUser(val, boo) {

      let this_ = this;
      if (val) {

        if (val.selected == false) {
          if (this.selectUserList.length == this.peopleNums()) {
            uni.showToast({
              title: "无需添加更多游客",
              icon: "none"
            });
            return;
          } else {
            val.selected = true;
            this.dataList.forEach(item => {
              if (item.id == val.id) {
                item.selected = true
              }
            })
            this_.selectUserList.push(val);

          }
        } else {
          val.selected = false;
          this.dataList.forEach(item => {
            if (item.id == val.id) {
              item.selected = false
            }
          })
          this_.$nextTick(() => {
            this_.selectUserList = this_.selectUserList.filter(user => user.id != val.id);
          })
        }
      }
    },
    change(value) {
      this.numberValue = value;
    },
    // 日历
    getFormattedDate(offset) {
      const date = new Date();
      date.setDate(date.getDate() + offset);
      const month = (date.getMonth() + 1).toString().padStart(2, "0");
      const day = date.getDate().toString().padStart(2, "0");
      return `${month}-${day}`;
    },
    getFullDate(offset) {
      const date = new Date();
      date.setDate(date.getDate() + offset);
      const year = date.getFullYear();
      const month = (date.getMonth() + 1).toString().padStart(2, "0");
      const day = date.getDate().toString().padStart(2, "0");
      return `${year}-${month}-${day}`;
    },
    getLabel(offset) {
      const dayIndex = (new Date().getDay() + offset) % 7;
      switch (offset) {
        case 0:
          return "今天";
        case 1:
          return "明天";
        case 2:
          return "后天";
        default:
          return `周${"日一二三四五六"[dayIndex]}`;
      }
    },
    //须知禁止页面滚动
    mPurchaseNoticeChange(e) {
      this.show = e.show
    },
    closePay() {
      let that = this
      uni.showModal({
        title: '提示',
        content: '确定取消支付？',
        cancelText: '再想想',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            that.isPayPopup = false
            setTimeout(() => {
              uni.redirectTo({ url: "/subPageC/order/order" });
            }, 500)
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        }
      })
    }
  },
};
</script>

<style lang="scss" scoped>
.m-content {
  background: linear-gradient(180deg,
      rgba(9, 131, 255, 0.8) 0%,
      rgba(9, 131, 255, 0) 100%);
  overflow: scroll;
  padding-bottom: 200rpx;

  .m-card {
    background: #ffffff;
    border-radius: 20rpx;
    margin: 25rpx;
    overflow: hidden;
    padding: 25rpx;
  }

  .m-card-one {
    .m-one-first-row {
      padding-bottom: 20rpx;
      border-bottom: solid 1rpx #ddd;

      .m-ticket-name {
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 32rpx;
        color: #1b1b1b;
        margin-top: 10rpx;
        margin-bottom: 15rpx;
      }

      .m-ticket-use-time {
        display: flex;
        justify-content: start;

        .m-ticket-use-time-label {
          display: flex;
          align-items: center;
          color: #666666;

          .m-img {
            width: 25rpx;
            height: 25rpx;
            margin-right: 10rpx;
          }
        }
      }
    }

    .m-one-second-row {
      padding: 20rpx 0;
      border-bottom: solid 1rpx #ddd;

      .m-row-title {
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 32rpx;
        color: #1b1b1b;
        margin-bottom: 20rpx;
      }

      .m-date-pick-box {
        display: flex;
        justify-content: center;
        align-items: center;

        .scroll-view1 {
          display: flex;
          flex-direction: row;
          width: 100%;
          height: 200rpx;
          overflow-x: scroll;

          .date-item {
            flex-shrink: 0;
            width: 160rpx;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0 10rpx;

            .date-box {
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
              width: 100%;
              height: 100%;
              background-color: #f5f5f5;
              border-radius: 12rpx;
              // padding: 20rpx;
              position: relative;
            }

            .date-box.active {
              background: #ebf5ff;
            }

            .date-box.active::after {
              content: "";
              width: 22rpx;
              height: 22rpx;
              position: absolute;
              right: 0;
              bottom: 0;
              background-color: #0983ff;
              background-image: url("../static/img/duigou.png");
              background-repeat: no-repeat;
              background-size: 70%;
              background-position: center;
              border-radius: 12rpx 0rpx 12rpx 0rpx;
            }
          }

          .available {
            .date-box {
              background-color: #dedede;
              color: #949494;
            }
          }
        }
      }

      .m-more-date {
        display: flex;
        margin-left: 20rpx;
        align-items: center;
        box-shadow: -6px 0px 8px 0px #e8e8e8;
        padding: 8rpx 0 8rpx 14rpx;
        border-radius: 10rpx;
      }
    }

    .m-one-third-row {
      .m-ticket-count {
        display: flex;
        width: 100%;
        justify-content: space-between;
        border-bottom: solid 1rpx #ddd;
        padding: 20rpx 0;

        .m-ticket-count-label {
          font-family: PingFang SC;
          font-weight: bold;
          font-size: 32rpx;
          color: #1b1b1b;
        }

        ::v-deep .m-ticket-count-value {
          .uni-numbox-btns {
            border-radius: 50%;

            .uni-numbox--text {
              background: #ebf5ff;
              color: #0983ff !important;
            }

            .uni-numbox--disabled {
              color: #333 !important;
            }
          }

          .uni-numbox__value {
            background-color: #fff !important;
            font-size: 32rpx !important;
          }
        }
      }
    }

    .m-one-fourth-row {
      .m-ticket-count {
        display: flex;
        justify-content: space-between;
        padding: 20rpx 0;

        ::v-deep .m-ticket-count-value {
          color: #0983ff;

          .uni-icons {
            color: #0983ff !important;
          }
        }
      }
    }
  }

  .m-card-two {
    .m-card-title {
      display: flex;
      padding: 10rpx 0 10rpx;
      align-items: baseline;

      .m-title {
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 32rpx;
        color: #1b1b1b;
      }

      .m-title-tips {
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 24rpx;
        color: #0983ff;
        margin-left: 20rpx;
      }
    }

    .m-two-first-row {
      display: flex;
      align-items: center;
      justify-content: space-around;
      margin: 20rpx 0;

      .m-user-list {
        padding: 20rpx 40rpx;
        border-radius: 12rpx;
        border: solid 1rpx #ddd;
        position: relative;
        margin-left: 10rpx;
      }

      .user-list-box {
        width: 75%;
        display: flex;
        align-items: center;
        overflow-x: scroll;

        .m-user-list-left {
          width: fit-content;
          flex: none;
        }
      }


      .m-user-list.active {
        background: #ebf5ff;
        border-radius: 12rpx;
        border: 1px solid #0983ff;
      }

      .m-user-list.active::after {
        content: "";
        width: 22rpx;
        height: 22rpx;
        position: absolute;
        right: 0;
        bottom: 0;
        background-color: #0983ff;
        background-image: url("../static/img/duigou.png");
        background-repeat: no-repeat;
        background-size: 70%;
        background-position: center;
        border-radius: 12rpx 0rpx 12rpx 0rpx;
      }

      .m-more-user {
        padding: 20rpx 10rpx 20rpx 20rpx;
        display: flex;
        align-items: center;
        margin-left: auto;

        .m-span {
          margin-right: 10rpx;
        }
      }
    }

    .m-two-second-row {
      .m-user-list {
        .m-user-list-item {
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-bottom: 20rpx;

          .m-list-left {
            width: 100rpx;
            display: flex;
            flex-direction: column;
            align-items: center;

            .m-img {
              width: 50rpx;
              height: 50rpx;
              margin-bottom: 5rpx;
            }

            .m-span {
              font-family: PingFang SC;
              font-weight: 500;
              font-size: 28rpx;
              color: #333333;
            }
          }

          .m-list-middle {
            flex: 1;
            margin: 0 25rpx;

            .m-middle-user-name {
              font-size: 32rpx;
              font-weight: 500;
            }

            .m-m-font {
              font-size: 22rpx;
              color: #666;
            }
          }

          .m-list-right {
            width: 100rpx;
            display: flex;
            justify-content: space-around;
          }
        }
      }
    }
  }

  .m-feet-box {
    position: fixed;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 20rpx 0 60rpx;
    background: #fff;
    bottom: 0;
    align-items: center;

    .m-feet-left {
      margin-left: 40rpx;
    }

    .m-feet-right {
      width: 200rpx;
      border-radius: 20rpx;
      height: fit-content;
      margin-right: 40rpx;

      .m-prime-red {
        background-color: #fe2b54;
        color: #fff;
      }

      .disabled-btn {
        background-color: #fe2b5531;
        color: #fff;
      }

      .btn-hover {
        opacity: 0.9;
      }
    }
  }
}

.date-label,
.date-date,
.date-price {
  // margin: 5px 0;
}

.m-pop-bg {
  position: relative;
  background-color: #fff;
  overflow: auto;
  border-radius: 20rpx;

  .m-green-bg,
  .m-red-bg {
    position: absolute;
    width: 50%;
    height: 200rpx;
  }

  .m-green-bg {
    left: 0;
    top: 0;
    background: radial-gradient(circle, #00ffa4 0%, rgba(0, 255, 164, 0) 100%);
    border-radius: 20rpx 20rpx 0rpx 0rpx;
    opacity: 0.1;
  }

  .m-red-bg {
    right: 0;
    top: 0;
    background: radial-gradient(circle, #ff5500 0%, rgba(255, 85, 0, 0) 100%);
    border-radius: 20rpx 20rpx 0rpx 0rpx;
    opacity: 0.1;
  }
}

.m-purchase-notice {
  width: 100vw;
  height: 90vh;
  margin-top: 10vh;
  background-color: #f5f6f8;
  border-radius: 20rpx 20rpx 0 0;
  position: relative;
  overflow: scroll;

  .m-green-bg,
  .m-red-bg {
    position: absolute;
    width: 50%;
    height: 200rpx;
  }

  .m-green-bg {
    left: 0;
    top: 0;
    background: radial-gradient(circle, #00ffa4 0%, rgba(0, 255, 164, 0) 100%);
    border-radius: 20rpx 20rpx 0rpx 0rpx;
    opacity: 0.1;
  }

  .m-red-bg {
    right: 0;
    top: 0;
    background: radial-gradient(circle, #ff5500 0%, rgba(255, 85, 0, 0) 100%);
    border-radius: 20rpx 20rpx 0rpx 0rpx;
    opacity: 0.1;
  }

  .m-pop-title {
    font-family: PingFang SC;
    font-weight: 500;
    font-size: 34rpx;
    color: #000000;
    text-align: center;
    position: relative;
    margin: 35rpx 0;
  }

  .m-pop-title::after {
    content: "";
    width: 20%;
    height: 16rpx;
    background: linear-gradient(90deg, #0983ff 0%, rgba(9, 131, 255, 0) 100%);
    border-radius: 8rpx;
    opacity: 0.3;
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
  }

  .m-contents {
    background-color: #fff;
    margin: 0 24rpx;
    border-radius: 20rpx;
    height: fit-content;
    position: relative;
    padding: 25rpx;
    z-index: 9;

    .m-notice-box {
      background: linear-gradient(-90deg,
          rgba(9, 131, 255, 0.07) 0%,
          rgba(9, 131, 255, 0.04) 100%);
      border-radius: 12rpx;
      padding: 20rpx;

      .m-notice-row {
        display: flex;
        align-items: center;

        &:not(:last-child) {
          margin-bottom: 20rpx;
        }

        .m-tag {
          margin-right: 20rpx;
        }

        .m-notice-row-content {
          font-family: PingFang SC;
          font-weight: 400;
          font-size: 28rpx;
          color: #1b1b1b;
        }
      }
    }

    .m-notice-table {
      margin: 25rpx 0;

      .m-table-head {
        background: #f7f8fc;
        border-radius: 12rpx 12rpx 0rpx 0rpx;
        border: 1px solid #e0e5eb;
        line-height: 84rpx;
        padding: 0 25rpx;
      }

      .m-table-th {
        display: flex;
        border-bottom: 1px solid #e0e5eb;
        border-left: 1px solid #e0e5eb;
        border-right: 1px solid #e0e5eb;

        &:last-child {
          border-radius: 0 0 12rpx 12rpx;
        }

        .m-table-td {
          padding: 0 40rpx;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;

          &:last-child {
            flex: 1;
            border-left: 1px solid #e0e5eb;
            // white-space: nowrap;
            // overflow: hidden;
            // text-overflow: ellipsis;
            align-items: flex-start;
          }

          font-family: PingFang SC;
          font-weight: 400;
          font-size: 28rpx;
          color: #1b1b1b;
          line-height: 84rpx;

          .m-table-inside-ico {
            width: 32rpx;
            height: 32rpx;
            margin-top: 20rpx;
          }

          .m-ul {
            .m-li {
              line-height: 35rpx;
            }
          }
        }
      }
    }

    .no-border {
      .m-table-th {
        border: none !important;

        .m-table-td {
          background: #f7f8fc;
          border: none !important;
          margin-bottom: 6rpx;

          &:last-child {
            margin-left: 6rpx;
          }
        }
      }
    }
  }
}

.m-notice-popuo {
  position: relative;

  .m-notice-ico {
    width: 247rpx;
    height: 181rpx;
    margin: 0 auto;
    // background-color: #00ffa4;
    background-color: transparent;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: -30%;

    .m-img {
      width: 100%;
      height: auto;
    }
  }

  .m-notice-text {
    margin-top: 90rpx;
    font-family: PingFang SC;
    font-weight: 500;
    font-size: 26rpx;
    color: #1b1b1b;
    line-height: 39rpx;
    padding: 0 20rpx;
  }

  .m-pop-feet {
    display: flex;
    width: 100%;
    justify-content: space-around;
    margin: 40rpx 0;
  }
}

.m-form-box {
  position: relative;
  padding: 25rpx;
  z-index: 9;
  background-color: #f1f1f1;

  .m-prime {
    background-color: #0983ff;
    color: #fff;
    width: 90%;
    margin: 0 5%;


  }

  .m-col1 {
    background: #fff;
    border-radius: 20rpx;
  }
}

.picks-input {
  position: relative;

  .label-pick {
    position: absolute;
  }
}

::v-deep .picks-box {
  display: flex;
  position: relative;

  .m-select {
    margin-bottom: 10rpx;

    .uni-select {
      border: none;
    }
  }

  .uni-forms-item {
    flex: 1;
    align-items: center;
  }
}

.contact-user-box {
  width: 100%;

  .content-box {
    width: 100%;

    .content-box-row {
      display: flex;
      align-items: center;

      .content-box-label {
        text-align: right;
        color: #666666;
      }
    }

  }
}

.no-ticket-tips {
  text-align: center;
  background-color: #ffffff61;
  color: #333;
  padding: 200rpx 0;
  margin: 0 50rpx;
  font-size: 44rpx;
  border-radius: 20rpx;
  margin-top: 200rpx;
}
</style>
