<template>
  <view class="container theme-content">
    <view class="global_card_content box-content-top">
      <view class="content-top">
        <text class="text_oneLine"> {{ themeList.IndustryName }}</text>
        <view :class="['follw', 'global_content_center', isFollw && 'cancel-follw']" @click="isAttention">
          {{ isFollw ? "取消关注" : "+ 关注" }}
        </view>
      </view>
      <view class="read-more">
        <text class="text-box text_oneLine" @click="scrollGo(item.IndustrialSubjectId)" v-for="item in themeList.ListSubject" :key="item.IndustrialSubjectId">
          {{ item.SubjectName }}
        </text>
      </view>
    </view>
    <view class="all-theme" @click="goThemeAll"> 全部主题>> </view>
    <view class="global_card_content content-item" :id="'tabItem-' + item.IndustrialSubjectId" v-for="item in themeList.List" :key="item.ArticleId">
      <view class="item-user" v-if="item.NickName" @click="authorDetails(item)">
        <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/user_report.png"></image>
        <text> {{ item.NickName }}</text>
      </view>
      <view class="item-title">
        <text class="global_title" style="display: inline" @click="goDetail(item)">
          {{ item.Title }}
        </text>
        <text class="item-industry" v-if="item.SubjectName">&nbsp;&nbsp;&nbsp;#{{ item.SubjectName }}</text>
      </view>
      <view class="item-more">
        <text>{{ item.PublishDate }}</text>
        <view class="global_pv-ollect">
          <view>
            <image class="pv" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/examine_icon.png"></image>
            {{ item.Pv }}
          </view>
          <view @click="collectClick(item)">
            <image v-if="item.IsCollect" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/collect_act.png"></image>
            <image v-else src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/collect_ico.png"></image>
            {{ item.CollectNum }}
          </view>
        </view>
      </view>
    </view>
    <u-modal
      v-model="goFollowShow"
      :content-style="{ fontSize: '32rpx' }"
      @confirm="goFollowShowBtn"
      :show-cancel-button="isCancelBtn"
      :confirm-text="confirmText"
      @cancel="isCancelBtn = false"
      :show-title="false"
      :cancel-style="{ borderRight: '1rpx solid #EBEBEB' }"
      :confirm-style="{ fontWeight: '700' }"
    >
      <view class="slot-content">
        <rich-text :nodes="accounts"></rich-text>
      </view>
    </u-modal>
    <Loading />
  </view>
</template>

<script>
import { Reports, Research, Report } from "@/config/api.js";
export default {
  data() {
    return {
      themeList: [],
      isFollw: false,
      goFollowShow: false,
      confirmText: "知道了",
      isCancelBtn: false,
      accounts: "",
      themeId: 0,
      sourceShare: "",
      pageRouterShare: "",
    };
  },
  methods: {
    // 跳转主题
    goThemeAll() {
      uni.navigateTo({ url: "/pages-purchaser/researchTheme/researchTheme" });
    },
    async researchThemeDetail(id, source, PageRouter) {
      const res = await Research.researchThemeDetail({ IndustrialManagementId: id, Source: source ? 2 : 1, PageRouter });
      if (res.Ret === 200) {
        this.themeList = res.Data || {};
        this.isFollw = res.Data.IsFollw;
      }
    },
    //关注
    async isAttention(item) {
      await this.$store.dispatch("showLoginModal");
      const res = await Reports.reportFllow({ IndustrialManagementId: this.themeList.IndustrialManagementId, PageRouter: "主题详情" });
      if (res.Ret === 200) {
        this.isFollw = !this.isFollw;
        if (res.Data.Status == 1) {
          this.goFollowShow = true;
          this.confirmText = res.Data.GoFollow ? "去关注" : "知道了";
          if (res.Data.GoFollow) {
            this.accounts = `主题关注成功 <br> 想要及时获取该主题内容的更新推送，请关注【查研观向小助手】公众号`;
            this.isCancelBtn = true;
          } else {
            this.accounts = "主题关注成功<br>请关注【查研观向小助手】公众号，及时获取产业报告更新提醒";
          }
        } else {
          uni.showToast({
            title: "已取消关注",
            icon: "none",
            duration: 2000,
          });
        }
        uni.$emit("updateFllowTheme", { isFollw: this.isFollw, id: this.themeList.IndustrialManagementId });
      }
    },
    //点击了去关注
    goFollowShowBtn() {
      if (this.confirmText == "去关注") {
        uni.navigateTo({
          url: "/activityPages/accountsOfficial/accountsOfficial",
        });
      }
      this.goFollowShow = false;
    },
    //收藏
    async collectClick(item) {
      await this.$store.dispatch("showLoginModal");
      const res = await Report.collectRpt({ ArticleId: item.ArticleId, PageRouter: this.$store.state.pageRouterReport });
      if (res.Ret === 200) {
        item.IsCollect = !item.IsCollect;
        item.IsCollect
          ? (item.CollectNum += 1) &&
            uni.showToast({
              title: "收藏成功",
              icon: "none",
              duration: 2000,
            })
          : (item.CollectNum -= 1);
        !item.IsCollect &&
          uni.showToast({
            title: "已取消收藏",
            icon: "none",
            duration: 2000,
          });
      }
    },
    //去往文章详情页面
    goDetail(item) {
      uni.navigateTo({ url: "/pageMy/reportDetail/reportDetail?id=" + item.ArticleId });
    },
    //去往作者详情
    authorDetails(item) {
      uni.navigateTo({
        url: "/reportPages/authorPages/authorPages?id=" + item.DepartmentId,
      });
    },
    //点击后滚动
    scrollGo(item) {
      uni.pageScrollTo({
        duration: 300,
        selector: "#" + "tabItem-" + item,
      });
    },
  },
  onLoad(options) {
    let source = options.source || "";
    let pageRouter = options.pageRouter || "";
    this.themeId = options.id;
    this.pageRouterShare = pageRouter;
    this.sourceShare = source;
    this.researchThemeDetail(options.id, source, pageRouter);
  },
  onShow() {
    this.$store.commit("setRouterReport", "主题详情");
  },
  /** 用户点击分享 */
  onShareAppMessage: function (res) {
    return {
      title: "研选主题",
      path: "/reportPages/researchTheme/researchTheme?id=" + this.themeId + "&source=" + this.sourceShare + "&pageRouter=" + this.pageRouterShare,
    };
  },
};
</script>

<style lang="scss" scoped>
.theme-content {
  padding: 30rpx;
  background-color: $uni-bg-color;
  .box-content-top {
    position: relative;
    background-color: #fff;
    padding: 30rpx;
    border-radius: 8rpx;
  }
  .content-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 28rpx;
    color: #333;
    font-weight: 600;
    .follw {
      color: #fff;
      border-radius: 4rpx;
      font-size: 24rpx;
      width: 110rpx;
      height: 42rpx;
      background-color: $uni-color-new;
    }
    .cancel-follw {
      background-color: #e5efff;
      color: $uni-color-new;
    }
  }
  .read-more {
    display: flex;
    flex-wrap: wrap;
    .text-box {
      margin-top: 30rpx;
      margin-right: 10rpx;
      width: 150rpx;
      height: 48rpx;
      background-color: #f8f8fa;
      color: $uni-color-new;
      line-height: 48rpx;
      border-radius: 200rpx;
      font-weight: 600;
      font-size: 24rpx;
      text-align: center !important;
      text-indent: 0em;
    }
  }
  .all-theme {
    width: 186rpx;
    height: 52rpx;
    font-weight: 600;
    font-size: 24rpx;
    color: $uni-color-new;
    line-height: 52rpx;
    text-align: center;
    padding-bottom: 20rpx;
    margin: 20rpx auto;
    background-color: #e5efff;
  }
  .content-item {
    background-color: #fff;
    border-top: 4rpx solid #376cbb;
    margin-bottom: 20rpx;
    padding: 20rpx 30rpx;
    .item-title {
      .item-industry {
        font-size: 32rpx;
        font-weight: 600;
        margin-left: 10rpx;
        color: $uni-color-new;
        display: inline-block;
      }
    }
    .item-user {
      display: flex;
      align-items: center;
      color: #999999;
      font-size: 28rpx;
      margin-bottom: 20rpx;
      image {
        width: 24rpx;
        height: 24rpx;
        margin-right: 20rpx;
      }
    }
    .item-more {
      display: flex;
      justify-content: space-between;
      color: #cecece;
      margin: 20rpx 0 0;
    }
  }
}
</style>
