<script setup>
import { reactive, onMounted, toRefs, ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import { Icon, Dialog, Toast } from "vant";
import { RaiApiPc } from "@/api/cygxPc/api.js";

import dlg from "../cygx/dlg.vue";

const router = useRouter();
const route = useRoute();
const state = reactive({
  reportInfo: {},
  reportResearch: [],
});
const rerportId = ref(null);
const from_type = ref(null);
const haveData = ref(true);
const showTips = ref(false);
const mobile = ref("");
/* 获取报告详情 */
const getReport = (id) => {
  RaiApiPc.lookReport({
    ArticleIdMd5: id,
  }).then((res) => {
    if (res.Ret === 200) {
      haveData.value = res.Data.HasPermission === 1 ? true : false;
      mobile.value = res.Data.Mobile;
      if (res.Data.HasPermission === 1) {
        //有访问权限
        state.reportInfo = res.Data.Detail;
        $(document).on("click", "#report-content img", function (event) {
          let imgArray = [];
          let src_tag = $(this).attr("src");
          let parent_tag = $(this).parent();
          if (src_tag && !parent_tag.attr("href")) {
            $("#report-content img").each(function (index, el) {
              let itemSrc = $(this).attr("src");
              imgArray.push(itemSrc);
            });
            wx.previewImage({ current: src_tag, urls: imgArray });
          }
        });
      }
    }
  });
};
const lookDeeperReport = () => {
  router.push({
    path: "/strategyReport",
    query: {
      url: state.reportInfo.ReportLink,
      pc: "true",
    },
  });
};
const scrolltop = () => {
  document.body.scrollTop = document.documentElement.scrollTop = 0;
};
onMounted(() => {
  if (localStorage.getItem("cygx_token")) {
    rerportId.value = route.query.id;
    getReport(rerportId.value);
  } else {
    router.push("/cygx/login");
  }
});
const { reportInfo, reportResearch } = toRefs(state);
</script>

<template>
  <div class="container-cygx-pc" v-if="haveData" :class="reportInfo.IsResearch ? 'no-cv' : ''">
    <div class="z-index-content" v-if="reportInfo.ArticleId">
      <div class="content-top">
        <div class="report-title">{{ reportInfo.Title }}</div>
        <div class="report-text">
          <template v-if="!reportInfo.IsResearch">
            <!-- <div class="report_desc">
              <span class="author">{{ reportInfo.Department }}</span>
              <span>{{ reportInfo.PublishDate }}</span>
            </div> -->
            <!-- <div class="seller-list"> -->
            <!-- <span>联系人:</span>
              <span v-for="(item, index) in reportInfo.SellerList" :key="index"> {{ item.SellerName }}({{ item.SellerMobile }})&nbsp;&nbsp; </span> -->
            <!-- </div> -->
            <div class="report-research">
              <div style="display: flex">
                <img :src="reportInfo.DepartmentImgUrl" v-if="reportInfo.DepartmentImgUrl" />
                <div class="research-author">
                  <p>{{ reportInfo.NickName }}</p>
                  <p class="time">{{ reportInfo.PublishDate }}</p>
                </div>
              </div>
            </div>
          </template>
          <template v-else>
            <div class="report-research">
              <div style="display: flex">
                <img :src="reportInfo.DepartmentImgUrl" @click="goAuthorPages" />
                <div class="research-author">
                  <p @click="goAuthorPages">{{ reportInfo.SellerAndMobile }}</p>
                  <p class="time">{{ reportInfo.PublishDate }}</p>
                </div>
              </div>
              <div @click="attentionBtn" class="is-follow" :class="reportInfo.IsFollow ? 'follow-cancel' : ''">
                {{ reportInfo.IsFollow ? "取消关注" : "+ 关注" }}
              </div>
            </div>
          </template>
          <div>注：请务必阅读<span class="tip" @click="showTips = true"> &nbsp;免责声明</span></div>
          <div class="container-abstract">&nbsp;&nbsp;摘要:&nbsp;{{ reportInfo.Abstract }}</div>
        </div>
      </div>
      <div class="detail-report" :class="reportInfo.IsResearch ? '' : 'detail-bottom'">
        <div id="report-content" v-html="reportInfo.Body"></div>
      </div>
      <div class="deeperReport" @click="lookDeeperReport" v-if="reportInfo.ReportLink">查看报告链接</div>
    </div>
    <div class="btn-returntop" v-if="reportInfo.ArticleId">
      <img src="~@/assets/cygx/returntop.png" @click="scrolltop" style="width: 40px" />
    </div>
    <dlg :showTips="showTips" :reportInfo="reportInfo" @hideDlg="showTips = false" />
  </div>
  <div v-else class="nodata-cygx-pc">
    <div>
      <img src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" alt="" />
      <div>
        <span>{{ mobile }}</span>
        <p>您暂无权限查看【买方研选】的报告内容</p>
      </div>
    </div>
  </div>
</template>

<style lang="scss">
.container-cygx-pc {
  @media screen and (min-width: 790px) {
    width: 1200px;
    margin: 0 auto;
  }
  padding: 20px;
  position: relative;
  z-index: 5;
  .z-index-content {
    position: relative;
    z-index: 5;
  }
  .host-collect {
    margin-top: 10px;
    padding-bottom: 50px;
    padding-bottom: calc(50px + constant(safe-area-inset-bottom));
    padding-bottom: calc(50px + env(safe-area-inset-bottom));
    h4 {
      font-size: 14px;
    }

    background-color: #fff;
    .host-content {
      border-top: 1px solid #ececec;
      .host-title {
        margin: 15px 0;
        color: #333;
        font-size: 14px;
        font-weight: 500;
      }
      .item-more {
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #cecece;
        font-size: 12px;
        margin-bottom: 15px;
      }
      .pv-ollect {
        display: flex;
        align-items: center;
        justify-content: space-between;
        img {
          width: 10px;
          height: 10px;
          margin-left: 5px;
        }
        .pv {
          height: 8px;
        }
      }
    }
  }
  .search {
    width: 100%;
    padding: 10;
    line-height: 35px;
    position: fixed;
    top: 0;
    left: 0;
    background: #fff;
    z-index: 9;

    .search-box {
      display: flex;
      align-items: center;
      padding-left: 10px;
      width: 100%;
      height: 35px;
      border-radius: 18px;
      background: #f6f6f6;
      color: #8d8d8d;
      font-size: 12px;
    }
  }
  .content-top {
    .report-research {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      font-weight: 500;
      color: #333;
      margin-bottom: 10px;

      img {
        width: 41px;
        height: 41px;
        overflow: hidden;
        margin-right: 15px;
      }
      .time {
        font-size: 12px;
        color: #999999;
        font-weight: 300;
      }
      .is-follow {
        padding: 3px 14px;
        background-color: #3385ff;
        border-radius: 39px;
        color: #fff;
      }
      .follow-cancel {
        background: #f0f0f0;
        color: #999999;
      }
    }

    .report-title {
      font-size: 17px;
      font-weight: bold;
      color: #4a4a4a;
      margin: 0px 0 10px;
    }
    .report-text {
      color: #999999;
      font-size: 14px;

      .seller-list {
        margin: 10px 0;
      }
      .report_desc {
        display: flex;
        justify-content: space-between;
      }
      .tip {
        color: #3385ff;
        cursor: pointer;
      }
      .container-abstract {
        margin: 20px 0 10px;
        padding-bottom: 20px;
        border-bottom: 1px dashed #999;
        position: relative;
        line-height: 22px;
        color: #333;
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 0;
          width: 4px;
          height: 22px;
          background: #2a65f5;
        }
      }
    }
  }
  .deeperReport {
    width: 128px;
    height: 40px;
    background: #1890ff;
    box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.04);
    border-radius: 2px 2px 2px 2px;
    font-size: 16px;
    font-weight: 400;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 80px auto 0 auto;
    cursor: pointer;
  }
  .report-link {
    font-size: 14px;
    line-height: 40px;
  }
  .detail-report {
    font-size: 14px !important;
    // p,
    // span,
    // li {
    //   font-size: 14px !important;
    // }
    img {
      width: 100% !important;
    }
    a {
      color: #333;
    }
    table {
      border-collapse: collapse;
      width: 100% !important;
      margin-left: 0 !important;
    }
    tr td,
    th {
      border: 1px solid #333;
    }
  }
  pre {
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    outline: none;
    border: 0;
    white-space: pre-wrap;
    word-break: normal;
  }
  .btn-returntop {
    position: fixed;
    right: 20px;
    bottom: 150px;
    width: 44px;
    height: 44px;
    z-index: 10;
  }
  .fixed_cont {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    border-top: 1px solid #ddd;
    padding-bottom: calc(5px + constant(safe-area-inset-bottom));
    padding-bottom: calc(5px + env(safe-area-inset-bottom));
    background-color: #fff;
    z-index: 9;
    box-sizing: border-box;
    .handle-item {
      padding-top: 7px;
      text-align: center;
      line-height: 17px;
      font-size: 12px;
      color: #888888;

      img {
        width: 22px;
        height: 22px;
        padding: 0;
        margin: 0;
      }
      div {
        padding: 0;
        margin: 0;
      }
    }
  }
  .btn-freecharge {
    position: fixed;
    right: 10px;
    bottom: 190px;
    z-index: 10;
    .image {
      width: 78px;
      height: 78px;
    }
    .remove-icon {
      width: 16px;
      height: 16px;
      position: absolute;
      right: 0;
      top: 0;
    }
  }
}
.nodata-cygx-pc {
  width: 100%;
  height: 100vh;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  img {
    width: 260px;
    height: 200px;
  }
  span {
    color: #3385ff;
  }
  p {
    margin-top: 20px;
    color: #666666;
  }
  @media screen and (min-width: 790px) {
    width: 1200px;
    margin: 0 auto;
    font-size: 24px;
  }
}
</style>
