<template>
  <!-- 顶部 banner 区域 -->
  <!-- banner start -->
  <view class="all">
    <text class="top_menu_text">海外资讯</text>
    <view class="banner">

      <img :src="bannerImg" class="banner_bk" />
      <view class="r_banner_title">
        <img :src="bannerTitle2" class="banner_title" />
      </view>
    </view>
    <!-- banner end -->

    <view class="list_content">
      <!-- 搜索 start -->
      <view class="r_sreach">
        <view class="sreach">
          <view class="sreach_icon">
            <image :src="icon_search"></image>
          </view>
          <view class="sreach_text">
            <text>搜索资讯</text>
          </view>
        </view>
      </view>
      <!-- 搜索 end -->

      <view class="r_list">
        <view v-for="item in listData" :key="item.day">
          <!-- 时间轴顶部日期 start -->
          <view class="item_top">
            <view class="r_line">
              <view class="item_point"></view>
              <view class="item_line"></view>
            </view>
            <text class="item_day">{{ dayjs(item.day).format("YYYY年MM月DD日") }}</text>
          </view>
          <!-- 时间轴顶部日期 end -->
          <view class="list_card">
            <view class="card_left">
              <img :src="time_icon" />
              <view class="left_line"></view>
            </view>
            <view class="card_right">
              <view v-for="item in item.list" :key="item.time">
                <view class="item_time">
                  <text>{{ item.time }}</text>
                  <text class="item_source_title">来自<text class="item_source">中国证券报</text></text>
                </view>
                <view class="item_title">
                  <text>{{ item.title }}</text>
                </view>
                <view class="item_summary">
                  <text>{{ item.summary }}</text>
                </view>
                <view class="item_etf">


                  <view v-for="etf in item.etfs" :key="etf.code" class="item_etf_item">
                    <text>{{ etf.name }}</text>
                    <div class="btn-play">
                    </div>
                  </view>
                </view>
              </view>
            </view>
          </view>

        </view>
      </view>


    </view>

    <view class="logout" @click="loginOut" v-if="Session.get('token')">退出登录</view>

    <LoginPopup :show="LoginShow" @handlePopupClose="handlePopupClose"
      @handlePopupSuccessCallback="handlePopupSuccessCallback" @handlePopupErrorCallback="handlePopupErrorCallback" />
  </view>
</template>

<script setup>
import { ref, onMounted, onUnmounted, reactive } from "vue";
import Line from "@/components/charts/Line.vue";
import bannerImg from "@/assets/zixun/banner_pic1.png";
import bannerTitle from "@/assets/zixun/banner_title.png";
import bannerTitle2 from "@/assets/zixun/banner_title3.png";
import icon_search from "@/assets/zixun/icon_search.png";
import time_icon from "@/assets/zixun/time_icon.png";
import LoginPopup from "@/components/loginPopup/index.vue";
import { Session } from "@/utils/storage";
import dayjs from "dayjs/esm/index";

import {
  getEtfIndexList,
} from "@/api/index";


const listData = ref(
  [
    {
      "day": "2026-10-26",
      "list": [
        {
          "time": "11:30:56",
          "title": "刚果延长禁令后，中国钴价和库存飙升",
          "summary": "刚果民主共和国将钴出口禁令延长至9月，导致全球约四分之三的钴供应受到影响。这一消息引…",
          "etfs": [
            {
              "name": "医药 ETF",
              "code": "string"
            }
          ]
        }
      ]
    }
  ]
)

async function getData() {
  let { code, data } = await getEtfIndexList({
    "date": "2026-10-26",
  })
  if (code == 200) {
    listData.value = data
  }
}

const LoginShow = ref(false);
const isLoginStatus = ref();
// 关闭弹框
const handlePopupClose = () => {
  LoginShow.value = false;
};

// 登录成功之后的回调
const handlePopupSuccessCallback = () => {
  isLoginStatus.value = true;
};

// 登录失败之后的回调
const handlePopupErrorCallback = () => {
  console.log("登录失败");
};
import { doLogout } from "@/api";
function loginOut() {
  doLogout({
    financialAccount: Session.get("userPhone"),
  });
  Session.clear();
  window.location.reload();
}

function goSreach() {
  if (Session.get("token")) {
    uni.navigateTo({
      url: "/pages/sreachReq/index",
    });
  } else {
    LoginShow.value = true;
  }
}

onMounted(async () => {
  if (!Session.get("token")) {
    LoginShow.value = true;
  }
  getData()
});
</script>

<style scoped lang="scss">
.all {
  display: flex;
  flex-direction: column;

}

.banner {
  position: relative;
  // background: red;

  .top_menu_text {
    position: absolute;
    top: 30rpx;
    left: 50%;
    transform: translateX(-50%);

    font-family: PingFangSC, PingFang SC;
    font-weight: 500;
    font-size: 34rpx;
    color: #FFFFFF;
    line-height: 36rpx;
    text-align: center;
    font-style: normal;
  }
}

.banner_bk {
  width: 100vw;
}

.r_banner_title {
  position: absolute;
  top: 160rpx;
  left: 50rpx;
  display: flex;
  flex-direction: column;

  .banner_title {
    width: 461rpx;
    height: 110rpx;
  }

  text {
    font-family: AlibabaPuHuiTiM;
    font-size: 32rpx;
    color: #FFFFFF;
    line-height: 44rpx;
    text-align: left;
    font-style: normal;
  }
}



.logout {
  // width: 100%;
  height: 80rpx;
  background-color: red;
  display: flex;
  text-align: center;
  justify-content: center;
  align-items: center;
  color: white;
  margin-top: 50rpx;
  border-radius: 20rpx;
  margin-left: 20rpx;
  margin-right: 20rpx;
  margin-bottom: 20rpx;
}


.logo_text {
  width: 88rpx;
  height: 40rpx;
}

.top_bk {
  width: 100vw;
  height: 60px;
}

.list_content {
  position: relative;
  z-index: 9999;

  background: linear-gradient(180deg, #FFFFFF 0%, #F3F5F8 100%);
  border-radius: 24rpx 24rpx 0rpx 0rpx;
  margin-top: -50px;
  padding: 10rpx 30rpx;

  background: linear-gradient(180deg, #FFFFFF 0%, #F3F5F8 100%);
  // min-height: 80vh;

  .r_sreach {
    width: 100%;
    height: 72rpx;
    display: flex;
    align-items: center;
    margin-top: 30rpx;
  }

  .sreach {
    display: flex;
    align-items: center;
    padding: 0rpx 30rpx;
    background-color: #fff;
    border-radius: 100rpx;
    width: 100%;
    height: 100%;
    background: #F3F5F8;
    border-radius: 36rpx;
    // box-shadow: 0 0 10rpx rgba(97, 97, 97, 0.1);
  }

  .sreach_icon {
    margin-right: 10rpx;
    display: flex;
    align-items: center;

    image {
      width: 35rpx;
      height: 35rpx;
      margin-top: 5rpx;
    }
  }

  .sreach_text {
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 28rpx;
    color: #999999;
    line-height: 40rpx;
    text-align: left;
    font-style: normal;
  }
}



.item_day {
  font-family: PingFangSC, PingFang SC;
  font-weight: bold;
  font-size: 24rpx;
  color: #222222;
  text-align: left;
  font-style: normal;
  margin-top: -10rpx;
  margin-left: 10rpx;

}

.item_top {
  display: flex;
  margin-top: 30rpx;
  padding: 0 30rpx;

  .r_line {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .item_point {
    width: 12rpx;
    height: 12rpx;
    background: #EB5D46;
    border-radius: 100rpx;
  }

  .item_line {
    width: 1rpx;
    height: 35rpx;
    border-left: 2px dashed #D9D7D7;
  }
}

.list_card {
  display: flex;
  height: 334rpx;
  background: #FFFFFF;
  border-radius: 24rpx;
  padding: 20rpx 30rpx;


  .card_left {
    display: flex;
    flex-direction: column;
    align-items: center;

    img {
      width: 8rpx;
      height: 33rpx;
    }

    .left_line {
      width: 1rpx;
      height: 100%;
      border-left: 2px dashed #D9D7D7;
      margin-top: 10rpx;
    }
  }

  .card_right {
    display: flex;
    flex-direction: column;
    margin-left: 20rpx;

    .item_time {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 32rpx;
      color: #222222;
      line-height: 44rpx;
      text-align: left;
      font-style: normal;
      display: flex;
      justify-content: space-between;
      margin-top: -8rpx;
    }

    .item_title {
      font-family: PingFangSC, PingFang SC;
      font-weight: bold;
      font-size: 28rpx;
      color: #222222;
      line-height: 40rpx;
      text-align: left;
      font-style: normal;
      margin-top: 30rpx;
    }

    .item_summary {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 28rpx;
      color: #666666;
      line-height: 44rpx;
      text-align: left;
      font-style: normal;
      margin-top: 10rpx;

      /* 1. 必须将元素设置为块级或弹性盒 */
      display: -webkit-box;
      /* 2. 定义盒模型的排列方向为垂直 */
      -webkit-box-orient: vertical;
      /* 3. 限制显示的行数 */
      -webkit-line-clamp: 2;
      /* 4. 隐藏超出的内容 */
      overflow: hidden;
      /* 5. (可选) 当文本溢出时显示省略号 */
      text-overflow: ellipsis;
    }

    .item_source_title {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 24rpx;
      color: #B3B3B3;
      line-height: 33rpx;
      text-align: left;
      font-style: normal;
    }

    .item_source {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 24rpx;
      color: #5978B2;
      line-height: 33rpx;
      text-align: left;
      font-style: normal;
    }

    .item_etf {
      display: flex;
      flex-wrap: wrap;
      margin-top: 10rpx;
      gap: 20rpx;
      margin-top: 30rpx;

      .item_etf_item {
        // width: 168rpx;
        height: 48rpx;
        background: #EDF1F5;
        border-radius: 125rpx;
        padding: 5rpx 25rpx;
        display: flex;
        align-items: center;

        text {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 24rpx;
          color: #666666;
          line-height: 44rpx;
          text-align: left;
          font-style: normal;
        }
      }

      /* 容器样式（模拟红框） */
      .btn-play {
        display: inline-flex;
        align-items: center;
        border-radius: 10rpx;
      }

      /* 三角形伪元素 */
      .btn-play::before {
        content: "";
        width: 0;
        height: 0;
        border-top: 5px solid transparent;
        border-bottom: 5px solid transparent;
        border-left: 8px solid #999;
        /* 注意：这里是border-left，因为三角形朝右时，左边框是实心 */
        margin-left: 4px;
        /* 与文字的间距（从右边移到左边） */
      }

      /* 文字部分 */
      .btn-play span {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 24rpx;
        color: #666666;
        line-height: 44rpx;
        text-align: left;
        font-style: normal;
      }
    }
  }
}
</style>
