<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>
        <div>
          订单编号：<span>{{ x.orderId }}</span>
        </div>
        <div>
          团号：<span>{{ x.tcnum }}</span>
        </div>
        <!-- <div>
          ：<span>{{ x.tcid }}</span>
        </div> -->
        <!-- <div>
          状态id：<span>{{ x.status }}</span>
        </div>
        <div>
          订单状态：<span>{{ x.orderState }}</span>
        </div> -->
        <div>
          订单状态：<span>{{ x.statsstr }}</span>
        </div>
        <!-- <div>
          ：<span>{{ x.isEnd }}</span>
        </div> -->
        <div>
          是否入定金单 1是 2否：<span>{{ x.isHaveFinance }}</span>
        </div>
        <!-- <div>
          ：<span>{{ x.zaiTuMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.discountMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.redEnvelopeMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.couponAllotIds }}</span>
        </div>
        <div>
          ：<span>{{ x.couponAllotList }}</span>
        </div>
        <div>
          ：<span>{{ x.dueInMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.compensationMoney }}</span>
        </div> -->
        <!-- <div>
          ：<span>{{ x.airConfirm }}</span>
        </div>
        <div>
          ：<span>{{ x.createByName }}</span>
        </div> -->
        <div>
          下单时间：<span>{{ x.createDate }}</span>
        </div>
        <div>
          订单来源：<span>{{ x.orderSource }}</span>
        </div>
        <!-- <div>
          ：<span>{{ x.leaveStr }}</span>
        </div>
        <div>
          ：<span>{{ x.lureEmpName }}</span>
        </div> -->
        <!-- <div>
          ：<span>{{ x.orderTypeName }}</span>
        </div>
        <div>
          ：<span>{{ x.receivableMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.guestList }}</span>
        </div>
        <div>
          ：<span>{{ x.cancelGuestList }}</span>
        </div>
        <div>
          ：<span>{{ x.photoNum }}</span>
        </div>
        <div>
          ：<span>{{ x.remarksName }}</span>
        </div>
        <div>
          ：<span>{{ x.rematksTime }}</span>
        </div>
        <div>
          ：<span>{{ x.remarksList }}</span>
        </div>
        <div>
          ：<span>{{ x.ySeatNum }}</span>
        </div>
        <div>
          ：<span>{{ x.eSeatNum }}</span>
        </div>
        <div>
          ：<span>{{ x.fSeatNum }}</span>
        </div>
        <div>
          ：<span>{{ x.waitingESeatNum }}</span>
        </div>
        <div>
          ：<span>{{ x.waitingFSeatNum }}</span>
        </div>
        <div>
          ：<span>{{ x.waitingYSeatNum }}</span>
        </div>
        <div>
          ：<span>{{ x.waitENum }}</span>
        </div>
        <div>
          ：<span>{{ x.waitFNum }}</span>
        </div>
        <div>
          ：<span>{{ x.waitYNum }}</span>
        </div>
        <div>
          ：<span>{{ x.confirmFileList }}</span>
        </div>
        <div>
          ：<span>{{ x.oP_Remarks }}</span>
        </div>
        <div>
          ：<span>{{ x.opSetLossPeople }}</span>
        </div>
        <div>
          ：<span>{{ x.opSetLossMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.isChargeLossOrders }}</span>
        </div>
        <div>
          ：<span>{{ x.tipMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.opTipMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.latestCommissionMoney }}</span>
        </div>
        <div>
          ：<span>{{ x.tsId }}</span>
        </div>
        <div>
          ：<span>{{ x.tsIdList }}</span>
        </div>
        <div>
          ：<span>{{ x.platformAccount }}</span>
        </div>
        <div>
          ：<span>{{ x.platformAccountTypeId }}</span>
        </div>
        <div>
          ：<span>{{ x.teamType }}</span>
        </div>
        <div>
          ：<span>{{ x.orderForm }}</span>
        </div>
        <div>
          ：<span>{{ x.isCanClear }}</span>
        </div>
        <div>
          ：<span>{{ x.orderGuestHouseStr }}</span>
        </div>
        <div>
          ：<span>{{ x.refuseVisaNum }}</span>
        </div> -->
        <!-- <div>
          ：<span>{{ x.orderSourceName }}</span>
        </div>
        <div>
          ：<span>{{ x.operationState }}</span>
        </div>
        <div>
          ：<span>{{ x.scoreNum }}</span>
        </div>
        <div>
          ：<span>{{ x.oneSex }}</span>
        </div>
        <div>
          ：<span>{{ x.contractNum }}</span>
        </div>
        <div>
          ：<span>{{ x.isFormB2B }}</span>
        </div>
        <div>
          ：<span>{{ x.quotationUrl }}</span>
        </div>
        <div>
          ：<span>{{ x.standardCurrencyName }}</span>
        </div> -->
      </div>
      <div class="col-4">
                <div class="mb-title"><i class="iconfont icon-hangban1"></i><span>包团信息</span></div>
        <div>
          出团公司id：<span>{{ x.outBranchId }}</span>
        </div>
        <!-- <div>
          ：<span>{{ x.clientSource }}</span>
        </div> -->
        <div>
          发团日期：<span>{{ x.startDate }}</span>
        </div>
        <div>
          团返程日期：<span>{{ x.backDate }}</span>
        </div>
        <div>
          备注：<span>{{ x.remarks }}</span>
        </div>
      </div>
      <div class="col-2">
        <div>
          <div class="mb-title">
            <i class="iconfont icon-jiage"></i><span>旅客信息</span>
          </div>
        <div>
          客人名称：<span>{{ x.contactName }}</span>
        </div>
        <div>
          客人联系电话：<span>{{ x.contactMobile }}</span>
        </div>
        <div>
          旅客录入人数：<span>{{ x.entGuestNum }}</span>
        </div>
        <div>
          <!-- 1录入完毕 2录入部门 3没有录入 -->
          人数状态：<span>{{ ['','录入完毕','录入部分','没有录入',][x.guestNumStatus] }}</span>
        </div>
        <div>
          老人：<span>{{ x.oldPeopleNum }}</span>
        </div>
        <div>
          成年人：<span>{{ x.manNum }}</span>
        </div>
        <div>
          婴儿：<span>{{ x.babyNum }}</span>
        </div>
        <div>
          儿童：<span>{{ x.chirdNum }}</span>
        </div>
        <div>
          机票：<span>{{ x.airticketNum }}</span>
        </div>
        <div>
          顾客数量：<span>{{ x.guestNum }}</span>
        </div>
        </div>
      </div>
      <div class="col-3">
        <div class="mb-title">
          <i class="iconfont icon-jiage"></i><span>价格信息</span>
        </div>
        <div>
          成交单价：<span>{{ x.unit_Price }}</span>
        </div>
        <div>
          本团单价：<span>{{ x.tC_Price }}</span>
        </div>
        <div>
          支付方式：<span>{{ ['','线上','-线下'][x.tradeWay] }}</span>
        </div>
        <!-- <div>
          平台单号：<span>{{ x.platformOrder }}</span>
        </div> -->
        <!-- <div>
          ：<span>{{ x.brandName }}</span>
        </div> -->
        <div>
          应收总额：<span>{{ x.preferPrice }}</span>
        </div>
        <!-- <div>
          ：<span>{{ x.configId }}</span>
        </div>
        <div>
          ：<span>{{ x.refund }}</span>
        </div>
        <div>
          ：<span>{{ x.platformTax }}</span>
        </div> -->
        <div>
          已收金额：<span>{{ x.income }}</span>
        </div>
      </div>
      <!-- <div class="col-1">
        <q-btn color="primary" unelevated @click="ViewPayment(x)">下单</q-btn>
        <q-btn 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
          .getOrderList(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>