<template>
  <view class="container container-hot-list">
    <view class="top-content">
      <view class="global_one_tabs">
        <view v-for="item in tabList" :key="item.Source" :class="['item', tabsActive == item.Source && 'tabs-active']" @click="tabsHandler(item)">
          {{ item.Name }}
        </view>
      </view>
    </view>
    <view class="content">
      <view class="content-ul" v-if="hotList.length && tabsActive == 1">
        <view class="global_card_content hot-li" v-for="(item, index) in hotList" :key="item.IndustrialManagementId">
          <view class="li-item hot-item">
            <view style="display: flex" class="text_oneLine hot-new" @click="themeDetails(item)">
              <text class="li-serial serial-number" :style="{ background: serialBackground(index) }">
                {{ index + 1 }}
              </text>
              <text class="global_title text_oneLine" style="display: inline">{{ item.IndustryName }} </text>
              <view class="industry-color" :style="[classifyColor(item.PermissionName)]">{{ item.PermissionName }}</view>
              <image class="new-img" v-if="item.IsNew" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/new_icon.png"></image>
            </view>
            <view :class="['follw', 'global_content_center', item.IsFollow && 'cancel-follw']" @click="isAttention(item, '主题')">
              {{ item.IsFollow ? "取消关注" : "+ 关注" }}
            </view>
          </view>
          <view class="li-item read-more">
            <view class="industry-video-item" @click.stop="handelVideoPlay(item)" :style="{ 'background-image': 'url(' + item.IndustryVideo.BackgroundImg + ')' }" v-if="item.IndustryVideo">
              5min
              <br />
              逻辑解析
              <view class="industry-video-icon">
                <image src="https://hzstatic.hzinsights.com/cygx/video-right-top-icon.svg"></image>
              </view>
            </view>
            <block v-if="item.IndustrialSubjectList">
              <view v-if="item.IndustryVideo" style="display: flex; flex-wrap: wrap; width: 502rpx">
                <view v-for="val in item.IndustrialSubjectList.slice(0, 6)" :key="val.IndustrialSubjectId" class="text-box text_oneLine">{{ val.SubjectName }}</view>
              </view>
              <block v-if="item.IndustryVideo && item.IndustrialSubjectList.length > 6">
                <view v-for="val in item.IndustrialSubjectList.slice(6)" :key="val.IndustrialSubjectId" class="text-box">{{ val.SubjectName }}</view>
              </block>
              <block v-if="!item.IndustryVideo">
                <view v-for="val in item.IndustrialSubjectList" :key="val.IndustrialSubjectId" class="text-box text_oneLine">{{ val.SubjectName }}</view>
              </block>
            </block>
          </view>
        </view>
      </view>
      <view class="content-ul" v-if="kolList.length && tabsActive != 1">
        <view class="global_card_content user-li" v-for="(item, index) in kolList" :key="item.ArticleId">
          <view class="li-item">
            <text class="li-serial" :style="{ background: serialBackground(index) }">
              {{ index + 1 }}
            </text>
            <view>
              <text @click="goDetail(item)" class="global_title" style="display: inline; margin-right: 20rpx">{{ item.Title }}</text>
              <text class="li-industry" @click="themeDetails(key)" v-for="key in item.List" :key="key.IndustrialManagementId"> # {{ key.IndustryName }} </text>
            </view>
          </view>
          <view class="li-item li-bottom" style="color: #999999">
            <view class="li-user text_oneLine">
              {{ item.PublishDate }}
              <view class="industry-color" :style="[classifyColor(item.PermissionName)]">{{ item.PermissionName }}</view>
            </view>
          </view>
        </view>
      </view> 
    </view>
    <view class="content-bottom">最新榜单您已掌握，明天再刷刷看~</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>
    <videoModule :showVideoPop.sync="showVideoPop" :videoPopList="videoPopList" />
    <modalDialog :isShowhasPermission="isShowhasPermission" :applyForIsShow="applyForIsShow" :jurisdictionList="jurisdictionList" :hasPermission="hasPermission" />
    <Loading />
  </view>
</template>

<script>
import { Reports } from "@/config/api.js";
import { color_word_bg } from "@/utils/styleClassify";
import videoModule from "@/components/videoModule/index";
import modalDialog from "@/components/modalDialog.vue";
export default {
  data() {
    return {
      tabList: [], //tab
      tabsActive: 1,
      hotList: [],
      kolList: [],
      confirmText: "知道了",
      accounts: "",
      isCancelBtn: false,
      goFollowShow: false,
      showVideoPop: false, //视频弹窗显示控制
      videoPopList: {}, // 视频信息
      isShowhasPermission: false, //  联系销售的提交申请
      applyForIsShow: false, // 提交申请
      jurisdictionList: {},
      hasPermission: "", //权限
      labelListData: [],
    };
  },
  components: { modalDialog, videoModule },
  methods: {
    /* 获取tab*/
    async getTabList() {
      const res = await Reports.getHotTableList();
      if (res.Ret === 200) {
        this.tabList = res.Data.List || [];
        this.tabsActive = this.tabList.length ? this.tabList[0].Source : 1;
        this.researchHotList();
      }
    },
    /* 点击一级的tabs*/
    tabsHandler(item) {
      this.tabsActive = item.Source;
      this.$store.commit("setRouterReport", item.Name);
      this.listInit();
      this.researchHotList();
    },
    //产业关注 阅读、报告收藏
    async researchHotList() {
      const res = this.tabsActive == 1 ? await Reports.getIndustryFllowList() : await Reports.getIndustryReadList({ Source: this.tabsActive });
      if (res.Ret === 200) {
        if (this.tabsActive == 1) {
          this.hotList = res.Data.List || [];
        } else {
          this.kolList = res.Data.List || [];
        }
      }
    },
    listInit() {
      if (this.tabsActive == 1) {
        this.hotList = [];
      } else {
        this.kolList = [];
      }
    },
    //去往作者详情
    authorDetails(item) {
      uni.navigateTo({
        url: "/reportPages/authorPages/authorPages?id=" + item.DepartmentId,
      });
    },
    //去往主题详情
    themeDetails(item) {
      uni.navigateTo({ url: "/reportPages/IndustryReport/IndustryReport?id=" + item.IndustrialManagementId });
    },
    //计算遍历的颜色
    serialBackground(index) {
      index += 1;
      return index == 1 ? "#D7584F" : index == 2 ? "#E98033" : index == 3 ? "#FDD367" : "#D3D3D3";
    },
    //关注
    async isAttention(item, val) {
      await this.$store.dispatch("showLoginModal");
      const res =
        val === "主题"
          ? await Reports.reportFllow({ IndustrialManagementId: item.IndustrialManagementId, PageRouter: "榜单产业关注榜" })
          : await Reports.reportFllowDepartment({ DepartmentId: item.DepartmentId });
      if (res.Ret === 200) {
        item.IsFollow = !item.IsFollow;
        if (res.Data.Status == 1) {
          this.goFollowShow = true;
          this.confirmText = res.Data.GoFollow ? "去关注" : "知道了";
          if (res.Data.GoFollow) {
            this.accounts = `${val == "主题" ? "产业" : "作者"}关注成功 <br> 想要及时获取该${val === "主题" ? "产业内容的更新推送" : "作者的报告更新提示"}，请关注【查研观向小助手】公众号`;
            this.isCancelBtn = true;
          } else {
            this.accounts = `${val == "主题" ? "产业" : "作者"}` + `关注成功<br>请关注【查研观向小助手】公众号，及时获取${val === "主题" ? "产业" : "作者"}报告更新提醒`;
          }
        } else {
          uni.showToast({
            title: "已取消关注",
            icon: "none",
            duration: 2000,
          });
        }
      }
    },
    //去关注
    goFollowShowBtn() {
      if (this.confirmText == "去关注") {
        uni.navigateTo({
          url: "/activityPages/accountsOfficial/accountsOfficial",
        });
      }
      this.goFollowShow = false;
    },
    goDetail(item) {
      uni.navigateTo({
        url: "/pageMy/reportDetail/reportDetail?id=" + item.ArticleId,
      });
    },
    // 视频播放权限判断
    async handelVideoPlay(item) {
      await this.$store.dispatch("showLoginModal");
      if (item.AuthInfo.HasPermission == 1) {
        this.playVideo(item);
      } else {
        this.hasPermission = item.AuthInfo.HasPermission;
        this.jurisdictionList.ActivityId = item.IndustryVideo.Id;
        this.jurisdictionList.isAudioVideo = 3;
        if (this.hasPermission == 2) {
          this.jurisdictionList.SellerMobile = item.AuthInfo.SellerMobile;
          this.jurisdictionList.SellerName = item.AuthInfo.SellerName;
          this.jurisdictionList.PopupMsg = item.AuthInfo.PopupMsg;
          this.isShowhasPermission = true;
        } else if (this.hasPermission == 3 || this.hasPermission == 4 || this.hasPermission == 5) {
          this.jurisdictionList.PopupMsg = item.AuthInfo.PopupMsg;
          this.applyForIsShow = true;
        }
      }
    },
    playVideo(item) {
      let params = {
        Id: item.IndustryVideo.Id,
        ResourceUrl: item.IndustryVideo.ResourceUrl,
        BackgroundImg: item.IndustryVideo.BackgroundImg,
        Title: `5min【${item.IndustryName}】逻辑解析`,
      };
      if (this.$store.state.videoPlay.playVideoId != item.Id) {
        this.$store.commit("videoPlay/palyTimeUpdate", 0);
        this.$store.commit("videoPlay/playVideo", item.Id);
      }
      this.globalBgAudioManager.stop();
      this.videoPopList = params;
      this.showVideoPop = true;
    },
    classifyColor(item) {
      let text_color = color_word_bg.color_word.find((key) => key.name == item).color;
      let back_ground = color_word_bg.color_bg.find((key) => key.name == item).color;
      let _isColor = { color: text_color, "background-color": back_ground };
      return _isColor;
    },
  },
  onLoad() {
    this.$store.commit("setRouterReport", "产业关注榜");
    this.getTabList();
  },
};
</script>

<style lang="scss" scoped>
.container-hot-list {
  background-color: $uni-bg-color;
  padding: 100rpx 30rpx 30rpx;
  .top-content {
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 99;
    background-color: #fff;
    padding-bottom: 10rpx;
    .item {
      flex: 1 !important;
    }
  }
  .content-ul {
    margin: 20rpx 0 0;
    border-top: 1px solid #f6f6f6;
    .user-li,
    .hot-li {
      margin-bottom: 20rpx;
      background-color: #fff;
    }
    .li-serial {
      width: 26rpx;
      height: 26rpx;
      line-height: 26rpx;
      color: #fff;
      font-size: 20rpx;
      text-align: center;
      border-radius: 4rpx 4rpx 4rpx 4rpx;
      margin: 7rpx 10rpx 0 20rpx;
      flex-shrink: 0;
    }
    .serial-number {
      margin-top: 0 !important;
    }
    .li-item {
      display: flex;
      .li-industry {
        color: $uni-color-new;
        margin-right: 20rpx;
        display: inline-block;
      }
      .li-user {
        margin-left: 46rpx;
        display: flex;
        align-items: center;
      }
      .li-title {
        display: flex;
      }
    }
    .li-bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 30rpx;
      width: 100%;
      image {
        width: 23rpx;
        height: 26rpx;
        margin-right: 10rpx;
      }
    }
    .read-more {
      margin-top: 10rpx;
      display: flex;
      flex-wrap: wrap;
      .industry-video-item {
        height: 106rpx;
        width: 150rpx;
        margin: 0 10rpx 10rpx 0;
        border-radius: 8rpx;
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        font-weight: 500;
        font-size: 32rpx;
        color: white;
        line-height: 45rpx;
        padding: 20rpx;
        position: relative;
        overflow: hidden;

        .industry-video-icon {
          height: 0rpx;
          width: 0rpx;
          border-style: solid;
          border-color: #3385ff #3385ff transparent transparent;
          border-width: 28rpx;
          position: absolute;
          right: 0;
          top: 0;
          image {
            position: absolute;
            right: -24rpx;
            bottom: 0;
            height: 20rpx;
            width: 20rpx;
          }
        }
      }
      .text-box {
        padding: 0;
        margin: 0 10rpx 10rpx 0;
        font-size: 24rpx;
        color: $uni-color-new;
        width: 150rpx;
        height: 48rpx;
        text-indent: 0em;
        line-height: 48rpx;
        text-align: center;
        background-color: #f8f8fa;
        border-radius: 200rpx;
      }
    }
    .hot-item {
      justify-content: space-between;
      align-items: center;
      .hot-new {
        align-items: center;
        flex: 1;
        padding-right: 20rpx;
      }
      .new-img {
        width: 26rpx;
        height: 28rpx;
        margin-left: 15rpx;
        flex-shrink: 0;
      }
    }
  }
  .content-bottom {
    background-color: $uni-bg-color;
    text-align: center;
    line-height: 100rpx;
    color: #c4c4c4;
    font-size: 20rpx;
  }
  .industry-color {
    font-size: 26rpx;
    padding: 0rpx 20rpx;
    border-radius: 4rpx;
    margin-left: 20rpx;
  }
  .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;
  }
}
</style>
