<template>
  <div>
    <q-card
      class="light-shadow q-pa-md bg-white rounded-borders q-mb-md"
      flat
      :class="$q.platform.is.desktop ? 'row' : ''"
      v-for="(x, index) in orders"
    >
      <div class="col-2">

        <div class="mb-title">
          <i class="iconfont icon-biaoti1"></i><span>包机信息</span>
        </div>
        {{ x.GTeamName }}
        <div class="mb">
          <span>{{ x.Title }}</span>
        </div>
        <div>
          出发日期：<span>{{ x.StartDate }}</span>
        </div>
        <div>
          团队信息：<span>{{ x.TCNUM }}({{ x.TCID }})</span>
        </div>
      </div>
      <div class="col-4">
                <div class="mb-title"><i class="iconfont icon-hangban1"></i><span>航班信息</span></div>
        <div
          class="mb"
          v-for="(subItem, subIndex) in x.TravelTeamFlightList"
          :key="subIndex + 1000"
        >
          <div>
            {{ subItem.Flight_number }} {{ subItem.DepartureAirPortName }}
            {{ subItem.Departure_time }} {{ subItem.ArrivalAirPortName }}
            {{ subItem.Arrival_time }}
          </div>
        </div>
      </div>
      <div class="col-2">
        <div>
          <div class="mb-title">
            <i class="iconfont icon-jiage"></i><span>团位信息</span>
          </div>
          <div class="mb bold"><span class="item-title">经济舱:</span><span>{{x.YSeat}} <span class="item-title">剩余:</span>{{x.SurplusYSeatNum}}</span></div>
                  <div class="mb bold"><span class="item-title">商务舱:</span><span> {{x.CSeat}} <span class="item-title">剩余:</span>{{x.SurplusCSeatNum}}</span></div>
                  <div class="mb bold"><span class="item-title">头等舱:</span><span> {{x.FSeat}} <span class="item-title">剩余:</span>{{x.SurplusFSeatNum}}</span></div>
                  
        </div>
      </div>
      <div class="col-3">
        <div class="mb-title">
          <i class="iconfont icon-jiage"></i><span>价格信息</span>
        </div>
        <div class="mb">
          <span>中心价: {{ x.B2BMemberPrice }}</span>
        </div>
        <div class="mb">
          <span
            >小孩占床: {{ x.ChildNeedPrice }}&nbsp;不占床:
            {{ x.ChildNoNeedPrice }}</span
          >
        </div>
        <div class="mb">
          <span
            >婴儿: {{ x.BabyPrice }}&nbsp; 婴儿附加费: {{ x.BabyChargePrice }}</span
          >
        </div>
        <div class="mb">
          <span
            >老人附加费: {{ x.OldManChargePrice }} &nbsp;签证:
            {{ x.VisaPrice }}</span
          >
        </div>
      </div>
      <div class="col-1">
        <q-btn color="primary" unelevated @click="ViewPayment(x)">下单</q-btn>
        <q-btn :class="$q.platform.is.desktop ? 'q-mt-md' : 'q-ml-md'" color="primary" unelevated @click="gotoUrl(x)">包机结算</q-btn>
      </div>
    </q-card>
    <q-card
      class="light-shadow q-pa-md bg-white rounded-borders q-mb-md"
      v-if="pages.pageCount > 0"
      flat
    >
      <q-pagination
        class="full-width justify-end"
        v-model="pages.pageIndex"
        color="primary"
        :max="pages.pageCount"
        :input="true"
        @update:model-value="changePageHandler"
      />
    </q-card>
    <q-inner-loading
      :showing="loading"
      :label="$t('loading')"
      label-class="text-grey-6 f12"
    />
  </div>
  <div class="text-center q-mt-xl" v-if="(!orders || orders.length == 0) && !loading">
    <svg-icon :size="50" color="nav" icon="General/Clipboard.svg"></svg-icon>
    <div class="q-mt-md f12 text-grey-6">{{ $t("noneData") }}</div>
  </div>
  <q-dialog v-model="showOrderdDetail">
    <!-- <OrderdDetail :OrderID="OrderID"></OrderdDetail> -->
  </q-dialog>

  <q-dialog v-model="showAddOrder">
    <AddOrder :info="info" @close="showAddOrder = false"></AddOrder>
  </q-dialog>
</template>

<script lang="ts">
import { DirtionmaryHelper } from "../../../config/dictionary";
import { defineComponent, inject, reactive, toRefs, watch, toRaw } from "vue";
import travelService from "../../../api/travel";
import { ApiResult } from "../../../@types/enumHelper";
import message from "../../../utils/message";
import { RoomType, StandardStatus } from "../../../@types";
import { getHotelOrderStatus, getHotelRoomType, moneyFormat } from "../../../utils/tools";
import { useI18n } from "vue-i18n";
import svgIcon from "../../../global/svg-icon.vue";
import { copyToClipboard, useQuasar } from "quasar";
import { currentRouter } from "../../../router";
// import OrderdDetail from './OrderdDetail.vue'
// import BankAccount from '../../BankAccount.vue'
import AddOrder from "./addOrder.vue";
import {useRouter} from 'vue-router'

export default defineComponent({
  components: { AddOrder },
  setup(props) {
    const $router = useRouter()
    const search = inject(DirtionmaryHelper.TRAVEL_ORDER_OBJ) as any;
    const { t } = useI18n();
    const $q = useQuasar();

    watch(search, (n, o) => {
      if (data.loading) return;
      data.pages.pageIndex = 1;
      data.orders = [];
      methods.initOrders();
    });

    const data = reactive({
      info: {},
      copyId: 0,
      showAddOrder: false,
      OrderID: "",
      showOrderdDetail: false,
      orders: [] as Array<any>,
      status: [] as Array<StandardStatus>,
      rooms: [] as Array<RoomType>,
      pages: {
        pageIndex: 1,
        pageSize: 10,
        pageCount: 0,
      },
      loadingCel: false,
      loading: false,
    });

    const methods = {
      changePageHandler(n: any) {
        console.log(n);
        data.pages.pageIndex = n;
        methods.initOrders();
      },
      ViewPayment(info: any) {
        data.info = toRaw(info);
        console.log("ViewPayment", toRaw(info));
        data.showAddOrder = true;
      },
      gotoUrl(x) {
        console.log('`/travel/payList?id=${x.TCID}`')
        $router.push({ path:`/travel/payList`, query: {id: x.TCID}})
      },
      canCelHotel(ThirdOrderNo) {
        $q.dialog({
          title: t("dialog.titles.horder"),
          message: t("dialog.contents.horder"),
          cancel: true,
          persistent: true,
        }).onOk(() => {
          methods.cancellations(ThirdOrderNo);
        });
      },
      cancellations(ThirdOrderNo) {
        if (data.loadingCel) return;
        let msg = {
          bookingNumber: ThirdOrderNo,
          CancelBy: search.CustomerId,
          CancelType: 2,
        };
        let param = Object.assign(msg);
        data.loadingCel = true;
        travelService
          .getTravelList(param)
          .then((r) => {
            if (r.data.resultCode == ApiResult.SUCCESS) {
              message.successMsg(`${t("success")}`);
              methods.initOrders();
            } else {
              message.errorMsg(r.data.message);
            }
            data.loadingCel = false;
          })
          .catch((e) => {
            message.errorMsg(e.message);
            data.loadingCel = false;
          });
      },
      getDetail(OrderID) {
        data.showOrderdDetail = true;
        data.OrderID = OrderID;
      },

      initOrders() {
        data.loading = true;
        let param = Object.assign(data.pages, search);
        travelService
          .getTravelList(param)
          .then((r) => {
            data.loading = false;
            if (r.data.resultCode == ApiResult.SUCCESS) {
              // r.data.data.pageData.forEach((x: any) => {
              //   x.typeInfo = data.status.find(y => y.StatusId == x.OrderStatus) ?? data.status[1]
              //   x.SendType = data.sends.find(y => y.Id == x.MailingState) ?? data.sends[0]
              //   x.Money = 0
              //   let Money = 0
              //   x.DetailList.forEach((y:any)=>{
              //     Money+=y.Money
              //   })
              //   x.Money= Number(Money+x.MailingMoney)
              // })
              data.orders = r.data.data.pageData;
              data.pages.pageCount = r.data.data.pageCount;
            } else {
              message.errorMsg(r.data.message);
            }
          })
          .catch((e) => {
            message.errorMsg(e.message);
            data.loading = false;
          });
      },
      init() {
        data.status = getHotelOrderStatus();
        data.rooms = getHotelRoomType();
        methods.initOrders();
      },
      setCopyHandler(order: any, ctx?: string) {
        if (ctx) {
          data.copyId = -1;
          copyToClipboard(ctx);
        } else {
          data.copyId = order.OrderID;
          copyToClipboard(order.ThirdOrderNo);
        }

        setTimeout(() => {
          data.copyId = 0;
        }, 2000);
      },
    };

    methods.init();
    return {
      ...toRefs(data),
      ...methods,
      moneyFormat,
    };
  },
});
</script>

<style>
.light-border table,
.light-border table td,
.light-border .q-table__middle,
.light-border.borders,
.light-border table th {
  border-color: #eee !important;
  white-space: wrap;
}
.light-border .room-item {
  height: 28px;
  line-height: 28px;
  border-bottom: 1px solid #eee;
}
.light-border .room-item:last-child {
  border-bottom: none;
}
.light-border .max-hotelname {
  width: 140px;
  height: 28px;
  line-height: 28px;
}
.orderListDialog-title {
  position: relative;
}
.orderListDialog-title span {
  font-size: 20px;
}
.orderListDialog-close {
  position: absolute;
  right: 0;
  top: -10px;
  font-size: 26px;
}
.orderListDialog-bg {
  background: #5098ff;
  border-radius: 10px;
}
.orderListDialog-img {
  background: url("../../../assets/images/wallet.png") no-repeat right #5098ff;
  background-size: 97px 100%;
}
</style>
<style scoped>
.mb-title {
  font-weight: bold;
  margin-bottom: 10px;
}
.mb {
  margin-bottom: 10px;
}
</style>