<template>
  <!-- 认购 -->
  <div class="subscription">
    <div class="subscription-content" v-if="subscriptionData > 0">
      <div class="subscription-head pf400 fs12 fc666666">
        <div class="head-name">名称</div>
        <div class="head-price">单价</div>
        <div class="head-operate">操作</div>
      </div>
      <div class="subscription-body">
        <div class="subscription-item" v-for="(item, index) in icoData" :key="index">
          <div class="item-name pf400 fs14 fc2C3131">{{ item.asset_name }}</div>
          <div class="item-price pf400 fs14 fc2C3131">
            {{ Number(item.issue_price).toFixed(2) }}
          </div>
          <div class="item-operate">
            <div class="text pf500 fs12 fcFFFFFF" @click="subscriptionOrderFlag = true">
              认购
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="subscription-null" v-else>
      <img
        src="../../../assets/icon/index/subscription-null.svg"
        class="img-null"
        alt="" />
    </div>
    <SubscriptionOrder
      v-show="subscriptionOrderFlag"
      @subscriptionOrderClose="subscriptionOrderClose"></SubscriptionOrder>
  </div>
</template>
<script setup>
  import { ref, onMounted } from "vue";
  import { GetIcoIco } from "@/api/index";
  import SubscriptionOrder from "../dialog/SubscriptionOrder.vue";

  const icoData = ref();
  const subscriptionData = ref();

  const subscriptionOrderFlag = ref(false);
  const subscriptionOrderClose = () => {
    subscriptionOrderFlag.value = false;
  };

  const GetIcoIcoData = async () => {
    // 1，认购 2，配售
    const params = {
      asset_type: "1",
    };
    const data = await GetIcoIco(params);
    if (data) {
      icoData.value = data.list;
      subscriptionData.value = data.total;
    }
  };

  onMounted(() => {
    GetIcoIcoData();
  });
</script>
<style lang="less" scoped>
  .subscription {
    width: 349px;

    .subscription-content {
      margin-top: 15px;
      width: 100%;

      .subscription-head {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        width: 100%;
        height: 24px;

        .head-name {
          width: 116px;
          height: 24px;
          line-height: 24px;
          text-align: left;
          letter-spacing: 0.17px;
        }

        .head-price {
          width: 117px;
          height: 24px;
          line-height: 24px;
          text-align: center;
          letter-spacing: 0.17px;
        }

        .head-operate {
          width: 116px;
          height: 24px;
          line-height: 24px;
          text-align: right;
          letter-spacing: 0.17px;
        }
      }

      .subscription-body {
        width: 100%;

        .subscription-item {
          display: flex;
          flex-direction: row;
          justify-content: flex-start;
          margin-top: 8px;
          padding-bottom: 8px;
          width: 100%;
          border-bottom: 1px solid #f5f5f5;

          .item-name {
            width: 116px;
            height: 24px;
            line-height: 24px;
            text-align: left;
            letter-spacing: 0.17px;
          }

          .item-price {
            width: 117px;
            height: 24px;
            line-height: 24px;
            text-align: center;
            letter-spacing: 0.17px;
          }

          .item-operate {
            display: flex;
            flex-direction: row;
            justify-content: flex-end;
            width: 116px;
            height: 24px;

            .text {
              width: 61px;
              height: 24px;
              line-height: 24px;
              text-align: center;
              border-radius: 5px;
              background: #45b26b;
            }
          }
        }
      }
    }

    .subscription-null {
      .img-null {
        margin-top: 117px;
        width: 343px;
        height: 267px;
      }
    }
  }
</style>
