<template>
  <div class="fix-height-subpage column no-wrap" v-if="detailsObj && parameters.TCID">
    <div
      class="row q-pa-md"
      style="min-width: 375px; margin: 0 auto"
      :style="{ width: $q.screen.lt.xl ? '100%' : '1320px' }"
      :class="{
        row: $q.screen.width >= 1200 && $q.platform.is.desktop,
        column: $q.screen.width < 1200 || $q.platform.is.mobile,
      }"
    >
      <div class="col">
        <q-card class="q-pa-md" flat>
          <div>
            <div class="text-h6 q-mb-md">
              {{ $t("v103.scheduledTrip.ascendingorder") }}
            </div>
            <div class="bg-light-blue-1 q-pa-md fz14 rounded-borders q-mt-md">
              <!-- <div class="text-weight-bold">{{$t('v103.scheduledTrip.ascendingorder')}}</div> -->
              <div class="text-grey-900 q-mt-sm f12">
                <div class="row wrap">
                  <div class="col-6 q-py-xs" v-if="detailsObj.startCityName">
                    {{ $t("v103.scheduledTrip.setout") }}： {{ detailsObj.startCityName }}
                  </div>
                  <div class="col-6 q-py-xs" v-if="priceFlight.gatherAddres">
                    {{ $t("v103.scheduledTrip.address") }}：
                    {{ priceFlight.gatherAddress }}
                  </div>
                  <div
                    class="col-6 q-py-xs"
                    v-if="priceFlight.startDate || priceFlight.gatherTime"
                  >
                    {{ $t("v103.scheduledTrip.time") }}： {{ priceFlight.startDate }}
                    {{ priceFlight.gatherTime }}
                  </div>
                  <div class="col-6 q-py-xs" v-if="detailsObj.returnArriveCityName">
                    {{ $t("v103.scheduledTrip.arrive") }}：
                    {{ detailsObj.returnArriveCityName }}
                  </div>
                  <div class="col-6 q-py-xs" v-if="detailsObj.currentPriceInfo">
                    {{ $t("v103.scheduledTrip.surplus") }}：
                    {{
                      detailsObj.currentPriceInfo.surplusCSeat +
                      detailsObj.currentPriceInfo.surplusFSeat +
                      detailsObj.currentPriceInfo.surplusYSeat
                    }}
                  </div>
                  <div class="col-6 q-py-xs text-red">
                    {{ $t("v103.scheduledTrip.nosupport") }}
                  </div>
                </div>
              </div>
            </div>
            <div>
              <!-- <div class="row items-center q-mt-md text-grey-600 q-mb-md" v-if="$q.platform.is.desktop">
                <div class="col q-mr-md">姓名:<span class="text-dark q-pl-md">{{parameters.ContactName}}</span></div>
                <div class="col q-mr-md">{{ $t('v102.ticket.sjc.c4') }}:<span class="text-dark q-pl-md">{{parameters.ContactMobile}}</span></div>
              </div> -->
              <!-- <div style="border-top: 1px dashed #eee" :class="{'row items-center':$q.platform.is.desktop,'column':$q.platform.is.mobile}">
                <q-input dense standout v-model="parameters.ContactName" class="col q-mt-md" :class="{'q-mr-md':$q.platform.is.desktop}" :placeholder="$t('v102.ticket.sjcp.c1')"  :rules="[ val => val && val.length > 0 || ' ']" ref="guestName" readonly/>
                <q-input dense standout v-model="parameters.ContactMobile" class="col q-mt-md" :class="{'q-mr-md':$q.platform.is.desktop}"  :placeholder="$t('v102.ticket.sjcp.c4')" :rules="[ val => val && val.length == 11 || ' ']" ref="guestMobile" readonly/>
            </div> -->
            </div>
          </div>
        </q-card>
        <q-card class="q-pa-md q-mt-lg" flat>
          <div>
            <div class="text-h6 q-mb-md">{{ $t("v103.scheduledTrip.passenger") }}</div>
            <div class="row">
              <q-img
                :src="
                  detailsObj && detailsObj.imgCover && detailsObj.imgCover[0].Url
                    ? detailsObj.imgCover[0].Url
                    : 'http://imgfile.oytour.com/Upload/DMC/yEiRE8pRWE5ZF8cPNRnAiQST8WbyaGQc.jpg'
                "
                class="rounded-borders"
                spinner-color="grey-3"
                style="width: 80px"
              />
              <div class="q-ml-md col">
                <div class="text-subtitle1 ellipsis">
                  {{ detailsObj.title }}
                </div>
                <div class="text-caption text-grey-6 ellipsis q-mt-sm">
                  {{ detailsObj.ltName }}
                </div>
              </div>
            </div>
            <div class="q-mt-md row">
              <div class="text-grey-9">
                <q-icon name="iconfont iconrili" size="20px" class="q-mr-sm" />
                <span>{{ chosenObj.startDate }}</span>
              </div>
              <div class="text-grey-9 q-ml-md">
                <q-icon name="person" size="20px" class="q-mr-sm" />
                <span class="q-mr-sm" v-if="chosenObj.crCount > 0"
                  >{{ $t("v103.scheduledTripDetails.cr") }} x
                  {{ chosenObj.crCount }}</span
                >
                <span class="q-mr-sm" v-if="chosenObj.etzcCount"
                  >{{ $t("v103.scheduledTripDetails.et")
                  }}{{ $t("v103.scheduledTripDetails.room") }} x
                  {{ chosenObj.etzcCount }}</span
                >
                <span class="q-mr-sm" v-if="chosenObj.etbzcCount"
                  >{{ $t("v103.scheduledTripDetails.et")
                  }}{{ $t("v103.scheduledTripDetails.noroom") }} x
                  {{ chosenObj.etbzcCount }}</span
                >
                <span class="q-mr-sm" v-if="chosenObj.yeCount"
                  >{{ $t("v103.scheduledTripDetails.ye") }} x
                  {{ chosenObj.yeCount }}</span
                >
                <span class="q-mr-sm" v-if="chosenObj.df"
                  >{{ $t("v103.scheduledTripDetails.singleroom1") }} x
                  {{ chosenObj.df }}</span
                >
              </div>
            </div>
            <div class="q-mt-md">
              <q-input
                v-model="parameters.Remarks"
                standout
                autogrow
                :label="$t('v102.ticket.or')"
              />
            </div>
          </div>
        </q-card>

        <div class="q-mt-lg" v-if="!($q.screen.width < 1200 || $q.platform.is.mobile)">
          <div
            class="bg-orange-1 q-pa-md rounded-borders fz14"
            style="border: 1px dashed orange"
          >
            <div class="text-weight-bold">{{ $t("v102.ticket.d5") }}</div>
            <div class="text-grey-700 q-mt-sm">
              {{ detailsObj.BookingInfo }}
            </div>
          </div>
        </div>
      </div>

      <div
        class=""
        :class="{
          'q-ml-lg': !($q.screen.width < 1200 || $q.platform.is.mobile),
          'q-mt-lg': $q.screen.width < 1200 || $q.platform.is.mobile,
        }"
      >
        <div
          class="rounded-borders bg-white q-pa-md"
          style="width: 300px"
          :style="{
            width: $q.screen.width < 1200 || $q.platform.is.mobile ? '100%' : '300px',
          }"
        >
          <div class="text-h6 text-grey-900">{{ $t("v102.ticket.st") }}</div>
          <div class="q-mb-lg" :class="{ 'q-mt-md': $q.platform.is.desktop }">
            <div class="row q-mt-md" v-if="$q.platform.is.desktop">
              <q-img
                :src="
                  detailsObj && detailsObj.imgCover && detailsObj.imgCover[0].Url
                    ? detailsObj.imgCover[0].Url
                    : 'http://imgfile.oytour.com/Upload/DMC/yEiRE8pRWE5ZF8cPNRnAiQST8WbyaGQc.jpg'
                "
                class="rounded-borders"
                spinner-color="grey-3"
                style="width: 80px"
              />
              <div class="q-ml-md col">
                <div class="text-subtitle1 ellipsis">
                  {{ detailsObj.title }}
                </div>
                <div class="text-caption text-grey-6 ellipsis q-mt-sm">
                  {{ detailsObj.ltName }}
                </div>
              </div>
            </div>
            <div class="q-pt-md text-grey-6">
              {{ $t("v103.scheduledTrip.startdate") }}: {{ chosenObj.startDate }}
            </div>
          </div>
          <div class="q-pt-md q-mb-lg" style="border-top: 1px dashed #eee">
            <div class="text-grey-900 text-subtitle2 text-weight-bold">
              {{ $t("v102.ticket.ms") }}
            </div>
            <div class="row q-my-sm" v-if="chosenObj.crCount > 0">
              <div class="col">
                <q-badge
                  color="grey-3"
                  style="padding: 5px 8px"
                  text-color="info"
                  :label="
                    $t('v103.scheduledTripDetails.cr') +
                    $t('v103.scheduledTripDetails.room')
                  "
                />
                x {{ chosenObj.crCount }}
              </div>
              <div>
                {{ domain == `id.oytour` ? "IDR" : "CNY" }} {{ price.originalB2BPrice }}
              </div>
            </div>
            <div class="row q-my-sm" v-if="chosenObj.etzcCount > 0">
              <div class="col">
                <q-badge
                  color="grey-3"
                  style="padding: 5px 8px"
                  text-color="info"
                  :label="
                    $t('v103.scheduledTripDetails.et') +
                    $t('v103.scheduledTripDetails.room')
                  "
                />
                x {{ chosenObj.etzcCount }}
              </div>
              <div>
                {{ domain == `id.oytour` ? "IDR" : "CNY" }}
                {{ price.originalB2BPrice + price.childNeedPrice }}
              </div>
            </div>
            <div class="row q-my-sm" v-if="chosenObj.etbzcCount > 0">
              <div class="col">
                <q-badge
                  color="grey-3"
                  style="padding: 5px 8px"
                  text-color="info"
                  :label="
                    $t('v103.scheduledTripDetails.et') +
                    $t('v103.scheduledTripDetails.noroom')
                  "
                />
                x {{ chosenObj.etbzcCount }}
              </div>
              <div>
                {{ domain == `id.oytour` ? "IDR" : "CNY" }}
                {{ price.originalB2BPrice - price.childNoNeedPrice }}
              </div>
            </div>
            <div class="row q-my-sm" v-if="chosenObj.yeCount > 0">
              <div class="col">
                <q-badge
                  color="grey-3"
                  style="padding: 5px 8px"
                  text-color="info"
                  :label="
                    $t('v103.scheduledTripDetails.ye') +
                    $t('v103.scheduledTripDetails.noroom')
                  "
                />
                x {{ chosenObj.yeCount }}
              </div>
              <div>{{ domain == `id.oytour` ? "IDR" : "CNY" }} {{ price.babyPrice }}</div>
            </div>

            <div v-if="price.safeMoney > 0">
              <hr
                style="border: none; border-top: 1px dashed #eee !important"
                class="bg-transparent q-mb-sm"
              />
              <div class="row q-mb-sm" v-if="price.safeMoney > 0">
                <div class="col">
                  {{ $t("v103.scheduledTripDetails.insurance1") }} x
                  {{ price.safeMoney }}/{{ $t("v103.scheduledTripDetails.people") }}
                </div>
                <div>
                  {{ domain == `id.oytour` ? "IDR" : "CNY" }}
                  {{
                    moneyFormat(
                      price.safeMoney *
                        (chosenObj.crCount + chosenObj.etCount + chosenObj.yeCount),
                      2
                    )
                  }}
                </div>
              </div>
            </div>
            <div v-if="price.visaPrice > 0 || price.otherPrice > 0">
              <hr
                style="border: none; border-top: 1px dashed #eee !important"
                class="bg-transparent q-mb-sm"
              />
              <div class="row q-mb-sm" v-if="price.visaPrice > 0">
                <div class="col">
                  {{ $t("v103.scheduledTripDetails.visafee") }} x {{ price.visaPrice }}/{{
                    $t("v103.scheduledTripDetails.people")
                  }}
                </div>
                <div>
                  {{ domain == `id.oytour` ? "IDR" : "CNY" }}
                  {{
                    moneyFormat(
                      price.visaPrice *
                        (chosenObj.crCount + chosenObj.etCount + chosenObj.yeCount),
                      2
                    )
                  }}
                </div>
              </div>
              <div class="row q-mb-sm" v-if="price.otherPrice > 0">
                <div class="col">
                  {{ $t("v103.scheduledTripDetails.miscellaneous") }} x
                  {{ price.otherPrice }}/{{ $t("v103.scheduledTripDetails.people") }}
                </div>
                <div>
                  {{ domain == `id.oytour` ? "IDR" : "CNY" }}
                  {{
                    price.otherPrice *
                    (chosenObj.crCount + chosenObj.etCount + chosenObj.yeCount)
                  }}
                </div>
              </div>
            </div>
            <hr
              v-if="chosenObj.etCount > 0 || chosenObj.df > 0"
              style="border: none; border-top: 1px dashed #eee !important"
              class="bg-transparent q-mb-sm"
            />
            <div class="row q-mb-sm" v-if="chosenObj.etCount > 0">
              <div class="col">
                {{ $t("v103.scheduledTripDetails.surcharge") }} x {{ chosenObj.etCount }}
              </div>
              <div>
                {{ domain == `id.oytour` ? "IDR" : "CNY" }} {{ price.babyChargePrice }}
              </div>
            </div>
            <div class="row q-mb-sm" v-if="chosenObj.df > 0">
              <div class="col">
                {{ $t("v103.scheduledTripDetails.pricedifference") }} x {{ chosenObj.df }}
              </div>
              <div>
                {{ domain == `id.oytour` ? "IDR" : "CNY" }} {{ price.singleRoomPrice }}
              </div>
            </div>
          </div>
          <div class="q-pt-md q-mb-lg text-right" style="border-top: 1px dashed #eee">
            <span class="f12 text-dark q-mr-md"> {{ $t("v102.ticket.ds") }}： </span>
            <span class="text-h6 text-negative">
              {{ sumPrice }}
              <span class="fz14" v-if="types && types.length > 0">{{
                types[0].CurrencyName
              }}</span>
            </span>
          </div>
          <div class="text-right">
            <q-btn
              color="primary"
              unelevated
              class="q-px-lg"
              :loading="loading"
              :disable="!isCheck"
              :label="$t('v102.ticket.sb')"
              @click="submit"
            />
          </div>
        </div>
      </div>

      <div class="q-mt-lg" v-if="$q.screen.width < 1200 || $q.platform.is.mobile">
        <div
          class="bg-orange-1 q-pa-md rounded-borders fz14"
          style="border: 1px dashed orange"
        >
          <div class="text-weight-bold">{{ $t("v102.ticket.d5") }}</div>
          <div class="text-grey-700 q-mt-sm">
            {{ detailsObj.BookingInfo }}
          </div>
        </div>
      </div>
    </div>
  </div>
  <q-dialog v-model="showDetails">
    <ticket-card :ticket="detailsObj"></ticket-card>
  </q-dialog>
</template>

<script lang="ts">
import Store from "../../store";
import { useRouter } from "vue-router";
import { ApiResult } from "src/@types/enumHelper";
import scheduledTripService from "../../api/scheduledTrip";
import message from "../../utils/message";
import { currentRouter } from "src/router";
import { ref, inject, provide, reactive, toRefs, defineComponent, watch } from "vue";
import useMetaModule from "../../module/meta/metaModule";
import { useI18n } from "vue-i18n";
import { DirtionmaryHelper } from "../../config/dictionary";
import TicketCard from "../../components/ticket/TicketCard.vue";
import { date, useQuasar } from "quasar";
import { moneyFormat } from "src/utils/tools";
export default defineComponent({
  components: { TicketCard },
  setup(props) {
    const $router = useRouter();
    const $q = useQuasar();
    let { setTitle } = useMetaModule();
    const { t } = useI18n();
    const pageTitle = inject(DirtionmaryHelper.PAGE_TITLE_KEY) as any;
    pageTitle.value = t("v102.ticket.preview.pageTitle");
    setTitle(pageTitle.value);
    const domain = inject(DirtionmaryHelper.DOMAIN_NAME);

    const data = reactive({
      loading: false,
      SelffetchAddress: "",
      msg: {
        configId: "",
        cityId: 0,
        preview: 0,
        tcid: 0,
        teamType: 0,
        isGetPriceFlight: true,
      },
      customer: {} as any,
      parameters: {
        OrderId: 0,
        TCID: null, //产品tcid
        CustomerType: null, //客户等级
        GroupType: 1,
        ContactName: null, //客户昵称
        ContactMobile: null, //客户电话
        CustomerId: null, //客户id
        DepartureCityId: null, //出发城市
        IsIntermodal: null,
        Unit_Price: null, //单价
        TC_Price: null, //价格、单价
        ManNum: null, //成人数
        ChirdNum: null, //儿童数不占床
        ChirdNeedBedNum: null, //儿童数占床
        BabyNum: null, //婴儿数
        OldPeopleNum: null, //老人数
        SingleRoomNum: null, //单人房数
        PreferPrice: null, //实付价格
        DiscountMoney: 0, //优惠价格
        CouponAllotIds: "", //优惠券id
        YSeatNum: null, //盈收
        ESeatNum: null,
        FSeatNum: null,
        Commission: 0, //todo 提成
        ClientSource: 2,
        BrandId: 0,
        TradeWay: 0,
        PlatformOrder: "",
        GuestNum: 0, //客人总数
        IsChildrenTour: null, //是否儿童
        IsBirdDiscount: 2, //是否早鸟折扣
        PredictRoomNum: null, //预计房间数
        BigRoomNum: null, //大床房数
        TripleRoomNum: null, //三床房数
        TradeDate: null, //交易日期
        CostType: 0, //成本类型
        MinOrderPrice: 0, //最低订单价格
        Remarks: "", //备注
        VisaNum: "", //签证数
        SafeNum: "", //保险数
        AirticketNum: 0,
        ReturnArriveCityId: "", //回程城市id
        IsReturnIntermodal: "", //回程联运
        GoCityTime: "", //去程时间
        BackCityTime: "", //返程时间
        ScenicRefundArr: [], //景点退款办事处
        CommissionSharePeople: 0,
        CommissionShareMoney: 0,
        OrderSource: 2,
        RedEnvelopeMoney: 0, //使用红包
      },
      types: [],
      isCheck: false,
      OpenTime: "",
      detailsObj: {} as any,
      order: null,
      orderKey: null,
      chosenObj: null,
      price: {},
      sumPrice: 0,
      priceFlight: {},
    });
    const guestName = ref(null) as any;
    const guestEName = ref(null) as any;
    const guestMobile = ref(null) as any;
    const guestAddress = ref(null) as any;
    data.msg.UseDate = date.formatDate(
      date.addToDate(new Date(), { days: 0 }),
      "YYYY/MM/DD"
    );

    const menu = inject(DirtionmaryHelper.MENU_KEYS) as any;
    menu.value = 17;
    const methods = {
      // 获取团期信息
      changeStartDate() {
        if (data.chosenObj.startDate && data.chosenObj.startDate != "") {
          data.detailsObj.priceList.forEach((x, i) => {
            if (x.startDate == data.chosenObj.startDate) {
              data.priceFlight = x;
            }
          });
        }
      },
      // 获取用户信息
      getB2BSellByCustomerId() {
        let CustomerId;
        if (Store.state && Store.state.user?.userDetail) {
          CustomerId = Store.state.user?.userDetail?.customerId;
        }
        scheduledTripService
          .GetCustomerSummary({})
          .then((r) => {
            if (r.data.resultCode == ApiResult.SUCCESS) {
              data.customer = r.data.data;
              methods.initia();
            } else {
              message.errorMsg(r.data.message);
            }
          })
          .catch((e) => {
            message.errorMsg(e.message);
          });
      },
      checkParamsHandler() {
        try {
          if (
            currentRouter.currentRoute.value.params &&
            currentRouter.currentRoute.value.params.tripId
          ) {
            let key = currentRouter.currentRoute.value.params.tripId;
            let lineTrip = localStorage.getItem("lineTrip");
            lineTrip = lineTrip ? JSON.parse(lineTrip) : [];
            if (lineTrip.length > 0) {
              data.order = lineTrip.find((x) => x.key == key);
              if (data.order) {
                data.chosenObj = data.order.order.orderInfo;
                data.orderKey = key;
                data.msg.configId = data.order.order.configId;
                data.msg.tcid = data.order.order.tcid;
              }
            }
          }
        } catch (error) {}
        if (data.orderKey == "") {
          setTimeout(() => {
            location.href = location.origin;
          }, 3000);
        }
        return data.orderKey != "";
      },
      // 计算总金额
      calcMoney() {
        data.price.discountPrice = data.price.discountPrice
          ? data.price.discountPrice
          : 0;
        //成人价格
        let crMoney = data.price.originalB2BPrice * data.chosenObj.crCount;
        //儿童不占床价格
        let etbzcMoney =
          (data.price.originalB2BPrice - data.price.childNoNeedPrice) *
          data.chosenObj.etbzcCount;
        //儿童占床价格
        let etzcMoney =
          (data.price.originalB2BPrice + data.price.childNeedPrice) *
          data.chosenObj.etzcCount;
        //婴儿价格
        let babyMoney = data.price.babyPrice * data.chosenObj.yeCount;
        //单房差
        let singleRoomMoney = data.price.singleRoomPrice * data.chosenObj.df;
        let sumCount =
          data.chosenObj.crCount +
          data.chosenObj.etbzcCount +
          data.chosenObj.etzcCount +
          data.chosenObj.yeCount;
        //签证费
        let visaMoney = data.price.visaPrice * sumCount;
        let safeMoney = data.price.safeMoney * sumCount;
        let otherMoney = data.price.otherPrice * sumCount;
        // console.log("totalPersion", sumCount);
        // console.log("crMoney", crMoney);
        // console.log("etbzcMoney", etbzcMoney);
        // console.log("etzcMoney", etzcMoney);
        // console.log("babyMoney", babyMoney);
        // console.log("singleRoomMoney", singleRoomMoney);
        // console.log("visaMoney", visaMoney);
        // console.log("safeMoney", safeMoney);
        // console.log("otherMoney", otherMoney);
        let money =
          crMoney +
          etbzcMoney +
          etzcMoney +
          babyMoney +
          singleRoomMoney +
          visaMoney +
          safeMoney +
          otherMoney;
        //console.log("money",money);
        data.sumPrice = money;
        if (data.sumPrice > 0) {
          data.isCheck = true;
        }
      },
      initia() {
        let sumSeat =
          data.chosenObj.crCount + data.chosenObj.etCount + data.chosenObj.lrCount;
        let youhuiMoney = 0;
        data.detailsObj.lineTeamDiscountList.forEach((x) => {
          if (x.startNum <= sumSeat && sumSeat <= x.endNum) {
            youhuiMoney = x.discountAmount;
            return false;
          }
        });
        let y = 0,
          f = 0,
          c = 0,
          fcnt = 0;
        if (sumSeat > data.detailsObj.currentPriceInfo.surplusYSeat) {
          y = data.detailsObj.currentPriceInfo.surplusYSeat;
          sumSeat = data.detailsObj.currentPriceInfo.surplusYSeat - sumSeat;
        } else {
          y = sumSeat;
          sumSeat = 0;
        }
        if (sumSeat > 0) {
          if (sumSeat > data.detailsObj.currentPriceInfo.surplusFSeat) {
            f = data.detailsObj.currentPriceInfo.surplusFSeat;
            sumSeat = data.detailsObj.currentPriceInfo.surplusFSeat - sumSeat;
          } else {
            f = sumSeat;
            sumSeat = 0;
          }
        }
        if (sumSeat > 0) {
          if (sumSeat > data.detailsObj.currentPriceInfo.surplusYSeat) {
            c = data.detailsObj.currentPriceInfo.surplusYSeat;
            sumSeat = data.detailsObj.currentPriceInfo.surplusYSeat - sumSeat;
          } else {
            c = sumSeat;
            sumSeat = 0;
          }
        }
        let sumFang =
          data.chosenObj.crCount + data.chosenObj.etzc + data.chosenObj.lrCount;
        sumFang =
          sumFang - data.chosenObj.df - data.chosenObj.dcf * 2 - data.chosenObj.srf * 3;
        if (sumFang > 0) {
          fcnt =
            parseFloat(sumFang) / 2.0 +
            data.chosenObj.dcf +
            data.chosenObj.df +
            data.chosenObj.srf;
        }
        fcnt += data.chosenObj.dcf + data.chosenObj.df + data.chosenObj.srf;
        let childNum = data.chosenObj.etCount + data.chosenObj.etzc;
        data.parameters = {
          OrderId: 0,
          TCID: data.msg.tcid, //产品tcid
          CustomerType: 2, //客户等级 data.customer.gradeLevel
          GroupType: 1,
          ContactName: data.customer.customerName, //客户昵称
          ContactMobile: data.customer.contactNumber, //客户电话
          CustomerId: data.customer.customerId, //客户id
          DepartureCityId:
            data.chosenObj.unicoDep.city && data.chosenObj.unicoDep.city.length > 0
              ? data.chosenObj.unicoDep.city[data.chosenObj.unicoDep.city.length - 1]
              : data.detailsObj.startCityId, //出发城市
          IsIntermodal:
            data.chosenObj.unicoDep.city &&
            data.chosenObj.unicoDep.city.length > 0 &&
            data.chosenObj.unicoDep.date
              ? 1
              : 2,
          Unit_Price: data.detailsObj.currentPriceInfo.b2BPrice, //成交单价
          TC_Price: data.detailsObj.currentPriceInfo.b2BMemberPrice, //团本来的价格、单价
          ManNum: data.chosenObj.crCount, //成人数
          ChirdNum: childNum, //儿童数不占床+儿童不占床
          ChirdNeedBedNum: data.chosenObj.etzcCount, //儿童数占床
          BabyNum: data.chosenObj.yeCount, //婴儿数
          OldPeopleNum: data.chosenObj.lrCount, //老人数
          SingleRoomNum: data.chosenObj.df, //单人房数
          PreferPrice: data.sumPrice, //实付价格
          DiscountMoney: 0, //优惠价格
          CouponAllotIds: "", //优惠券id
          YSeatNum: y, //盈收
          ESeatNum: f,
          FSeatNum: c,
          Commission: (
            parseFloat(youhuiMoney) / 2.0 +
            parseFloat(data.sumPrice) * 0.01
          ).toFixed(2), //todo 提成
          ClientSource: 2,
          BrandId: 0,
          TradeWay: 0,
          PlatformOrder: "",
          GuestNum:
            data.chosenObj.crCount +
            data.chosenObj.etCount +
            data.chosenObj.yeCount +
            data.chosenObj.lrCount, //客人总数
          IsChildrenTour: data.detailsObj.currentPriceInfo.isSupportChildren, //是否儿童
          IsBirdDiscount: 2, //是否早鸟折扣
          PredictRoomNum: fcnt, //预计房间数
          BigRoomNum: data.chosenObj.dcf, //大床房数
          TripleRoomNum: data.chosenObj.srf, //三床房数
          TradeDate: date.formatDate(new Date(), "YYYY/MM/DD"), //交易日期
          CostType: 0, //成本类型
          MinOrderPrice: 0, //最低订单价格
          Remarks: data.parameters.Remarks, //备注
          VisaNum:
            data.chosenObj.crCount + data.chosenObj.etCount + data.chosenObj.lrCount, //签证数
          SafeNum:
            data.chosenObj.crCount + data.chosenObj.etCount + data.chosenObj.lrCount, //保险数
          AirticketNum: 0,
          ReturnArriveCityId:
            data.chosenObj.unicoArr.city && data.chosenObj.unicoArr.city.length > 0
              ? data.chosenObj.unicoArr.city[data.chosenObj.unicoArr.city.length - 1]
              : data.detailsObj.returnArriveCityId, //回程城市id
          IsReturnIntermodal:
            data.chosenObj.unicoArr.city &&
            data.chosenObj.unicoArr.city.length > 0 &&
            data.chosenObj.unicoArr.date
              ? 1
              : 2, //回程联运
          GoCityTime:
            data.chosenObj.unicoDep.city &&
            data.chosenObj.unicoDep.city.length > 0 &&
            data.chosenObj.unicoDep.date
              ? data.chosenObj.unicoDep.date
              : "", //去程时间
          BackCityTime:
            data.chosenObj.unicoArr.city &&
            data.chosenObj.unicoArr.city.length > 0 &&
            data.chosenObj.unicoArr.date
              ? data.chosenObj.unicoArr.date
              : "", //返程时间
          ScenicRefundArr: [], //景点退款办事处
          CommissionSharePeople: 0,
          CommissionShareMoney: 0,
          OrderSource: 2,
          RedEnvelopeMoney: 0, //使用红包
        };
      },
      getInfo() {
        $q.loading.show();
        let param = Object.assign(data.msg);
        scheduledTripService
          .GetB2BTravelInfoV1(param)
          .then((r) => {
            if (r.data.resultCode == ApiResult.SUCCESS) {
              data.detailsObj = r.data.data;
              data.detailsObj.imgCover = JSON.parse(data.detailsObj.imgCover);
              data.price = data.detailsObj.currentPriceInfo;

              methods.calcMoney();
              methods.changeStartDate();
              methods.getB2BSellByCustomerId();
            } else {
              message.errorMsg(r.data.message);
            }
            setTimeout(() => {
              $q.loading.hide();
            }, 500);
          })
          .catch((e) => {
            message.errorMsg(e.message);
            data.isCheck = false;
          });
      },
      submit() {
        if (!data.isCheck) return;
        if (data.loading) return;
        data.loading = true;
        let param = Object.assign(data.parameters);
        scheduledTripService
          .SetOrderInfoForB2B(param)
          .then((r) => {
            if (r.data.resultCode == ApiResult.SUCCESS) {
              data.loading = false;
              message.successMsg(`${t("success")}`);
              $router.push({ path: "/scheduledTrip/order" });
            } else {
              data.loading = false;
              message.errorMsg(r.data.message);
            }
          })
          .catch((e) => {
            data.loading = false;
            message.errorMsg(e.message);
          });
      },
    };
    if (methods.checkParamsHandler()) {
      methods.getInfo();
    }
    return {
      ...toRefs(data),
      ...methods,
      guestName,
      guestEName,
      guestMobile,
      guestAddress,
      domain,
      moneyFormat,
    };
  },
});
</script>

<style></style>
