<template>
  <div class="sell-and-buy">
    <div class="apply-mask" @click="emits('sellAndBuyClose')"></div>
    <div class="apply-content">
      <div class="slide-line"></div>
      <div class="apply-text pf600 fs18 fc121212">购买</div>
      <div class="goods-info">
        <div class="info-left">
          <div class="shangjia">
            <img src="@/assets/img/index/user/default-head.png" alt="" />
            <div class="left-name pf500 fs14 fc2C3131">商家昵称</div>
            <div class="vip-flag pf500 fs10 fcDF384C">V2</div>
          </div>
          <div class="chengjiao pf400 fs10 fc999999">成交量 12550 · 98.95% 成交率</div>
        </div>
        <div class="info-right">
          <div class="text pf400 fs10 fc999999">单价</div>
          <div class="price-number pf400 fs10 fc999999">
            ￥
            <span class="pf500 fs16 fc333333">6.58</span>
            /USDT
          </div>
        </div>
      </div>
      <div class="required-quantity pf500 fs14 fc999999">
        <div>需求数量</div>
        <div>150200.00 USDT</div>
      </div>
      <div class="required-quantity pf500 fs14 fc999999">
        <div>单笔限额</div>
        <div>100.00 - 252020.00 USDT</div>
      </div>
      <div class="number-input">
        <input
          type="text"
          v-model="buyCount"
          class="input pf400 fs14 fc333333"
          placeholder="请输入购买数量" />
        <div class="all pf400 fs14 fc333333">USDT <span class="fcDF384C">全部</span></div>
      </div>
      <div class="use-number pf400 fs12 fc333333">可买&nbsp; 215.0508 USDT</div>
      <div class="account pf500 fs14 fc999999">
        <div>付款方式</div>
        <div class="account-right">
          <div class="color"></div>
          <span v-if="payList.type == 1">银行卡</span>
          <span v-if="payList.type == 2">支付宝</span>
          <span v-if="payList.type == 3">微信</span>
        </div>
      </div>
      <div class="account pf500 fs14 fc999999">
        <div>付款账号</div>
        <div class="account-right fcDF384C" @click="goAddBankAccount">
          {{ payList.card_no }}
          <img src="@/assets/icon/asset/right-arrow-black.svg" alt="" />
        </div>
      </div>
      <div class="sure-btn pf600 fs14 fcFFFFFF" @click="sureBuy">确定购买</div>
    </div>
  </div>
</template>
<script setup>
  import { useRoute, useRouter } from "vue-router";
  import { GetPayList, BuyCoin } from "@/api/otc";
  import { watch, ref } from "vue";

  const router = useRouter();
  const props = defineProps(["otcId", "chatId", "orderId"]);
  const emits = defineEmits(["sellAndBuyClose"]);

  const payList = ref({});
  const otcId = ref();
  const chatId = ref();
  const orderId = ref();
  const buyCount = ref(0);

  watch(
    () => props.otcId,
    async (newVal, oldVal) => {
      otcId.value = newVal;
      console.log(otcId.value);
    }
  );

  watch(
    () => props.orderId,
    async (newVal, oldVal) => {
      orderId.value = newVal;
    }
  );

  watch(
    () => props.chatId,
    async (newVal, oldVal) => {
      chatId.value = newVal;
      console.log(chatId.value);
    }
  );

  const sureBuy = async () => {
    const params = {
      pid: orderId.value,
      count: buyCount.value,
    };
    const data = await BuyCoin(params);
    if (data == "success") {
      router.push({
        name: "OTCCustomService",
        params: { chatId: chatId.value, otcId: otcId.value },
      });
    }
  };

  const goAddBankAccount = () => {
    router.push("/addBankAccount");
  };
</script>
<style lang="less" scoped>
  .sell-and-buy {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: 100%;
    min-height: 100vh;

    .apply-mask {
      position: fixed;
      left: 0;
      top: 0;
      z-index: -1;
      width: 100%;
      min-height: 100vh;
      background: rgba(0, 0, 0, 0.5);
    }

    .apply-content {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      align-items: center;
      width: 375px;
      background: #ffffff;
      border-radius: 24px 24px 0px 0px;

      .slide-line {
        margin-top: 12px;
        width: 32px;
        height: 4px;
        border-radius: 2px;
        opacity: 0.4;
        background: rgba(0, 0, 0, 0.5);
      }

      .apply-text {
        margin-top: 20px;
        height: 24px;
        line-height: 24px;
        letter-spacing: 0.2px;
      }

      .goods-info {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin-top: 11px;
        width: 345px;

        .info-left {
          .shangjia {
            display: flex;
            flex-direction: row;
            justify-content: flex-start;
            align-items: center;
            height: 24px;

            img {
              width: 24px;
              height: 24px;
            }

            .left-name {
              margin-left: 4px;
            }

            .vip-flag {
              margin-left: 4px;
              width: 18px;
              height: 15px;
              line-height: 15px;
              text-align: center;
              border-radius: 3px;
              background: #df384c1a;
            }
          }

          .chengjiao {
            margin-top: 3px;
          }
        }

        .info-right {
          display: flex;
          flex-direction: column;
          justify-content: flex-start;
          align-items: flex-end;

          .text {
            height: 24px;
            line-height: 24px;
          }

          .price-number {
            margin-top: -6px;
          }
        }
      }

      .required-quantity {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-top: 10px;
        width: 345px;
        height: 18px;
      }

      .number-input {
        position: relative;
        margin-top: 18px;
        width: 345px;
        height: 45px;

        .input {
          padding-left: 11px;
          width: 100%;
          height: 100%;
          box-sizing: border-box;
          border-radius: 6px;
          border: none;
          outline: none;
          background: #f5f5f5;
        }

        .all {
          position: absolute;
          top: 13px;
          right: 11px;
        }
      }

      .use-number {
        margin-top: 7px;
        width: 345px;
        height: 18px;
        line-height: 18px;
      }

      .account {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-top: 8px;
        width: 345px;
        height: 18px;

        .account-right {
          display: flex;
          flex-direction: row;
          justify-content: flex-start;
          align-items: center;
          margin-top: 5px;
          height: 12px;

          .color {
            margin-right: 3px;
            width: 3px;
            height: 10px;
            border-radius: 2px;
            background: #df384c;
          }

          img {
            margin-left: 5px;
          }
        }
      }

      .sure-btn {
        margin-top: 47px;
        margin-bottom: 40px;
        width: 311px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        border-radius: 100px;
        background: #45b26b;
      }
    }
  }
</style>
