<template>
  <view class="container-report-page">
    <view class="content-list">
      <view class="list-ui" v-for="(item, index) in reportPageData.ListHzResource" :key="item.IndustrialManagementId" @click.stop="themeDetails(item)">
        <view v-if="index % 2 == 0">
          <Industrialsource :list="item" />
        </view>
        <view v-if="index % 2 !== 0">
          <Industrialsource :list="item" />
        </view>
      </view>
    </view>
    <view class="content-report">
      <block v-if="reportPageData.ListHzReport.length">
        <text style="height: 1rpx; background: #ececec"></text>
        <view class="global_card_content content-item" v-for="item in reportPageData.ListHzReport" :key="item.ArticleId">
          <view class="item-title global_title">
            <text :class="['tag', item.ResourceObj == 'articlevmp' && 'tag-hz']" v-if="['articleyx', 'articlevmp'].includes(item.ResourceObj)">{{
              item.ResourceObj == "articleyx" ? "买方研选" : item.ResourceObj == "articlevmp" ? "弘则报告" : ""
            }}</text>
            <text style="display: inline; margin-right: 10rpx" @click="goDetailReport(item)"> {{ item.Title }} </text>
            <text class="item-industry" v-for="key in item.List" :key="key.IndustrialManagementId" @click="themeDetails(key)">#{{ key.IndustryName }}&nbsp;&nbsp;&nbsp;</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, 'ListHzReport')">
                <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>
      </block>
    </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" class="industry-video-module" />
    <!-- 权限弹窗 -->
    <modalDialog :isShowhasPermission="isShowhasPermission" :applyForIsShow="applyForIsShow" :jurisdictionList="jurisdictionList" :hasPermission="hasPermission" />
  </view>
</template>

<script>
import { Report, Reports, purchaserApi } from "@/config/api";
import videoModule from "@/components/videoModule/index";
import modalDialog from "@/components/modalDialog.vue";
import Industrialsource from "./industrialsource.vue";

export default {
  components: { videoModule, modalDialog, Industrialsource },
  props: {
    reportPageData: {
      type: Object,
    },
  },
  data() {
    return {
      goFollowShow: false,
      confirmText: "知道了",
      isCancelBtn: false,
      accounts: "",
      showVideoPop: false, //视频弹窗显示控制
      videoPopList: {}, // 视频信息
      isShowhasPermission: false, //  联系销售的提交申请
      applyForIsShow: false, // 提交申请
      jurisdictionList: {},
      hasPermission: "", //权限
    };
  },
  watch: {},
  methods: {
    //去往文章详情页面
    goDetailReport(item) {
      if (item.Resource == 3) {
        uni.navigateTo({ url: "/pages-ficc/reportDetail/reportDetail?id=" + item.ReportId });
        return;
      }
      if (item.SpecialType > 0) {
        uni.navigateTo({ url: "/pages-purchaser/noteAndViewpoint/noteAndViewpoint?id=" + item.ArticleId });
        return;
      }
      uni.navigateTo({ url: "/pageMy/reportDetail/reportDetail?id=" + item.ArticleId });
    },
    /* 进入详情 校验是否有该品种权限 */
    goDetail(item) {
      uni.navigateTo({
        url: "/reportPages/IndustryReport/IndustryReport?id=" + item.IndustrialManagementId,
      });
    },
    //去往主题详情
    themeDetails(item, val) {
      if (item.SpecialType > 0) return;
      let id = item.IndustrialManagementId > 0 ? item.IndustrialManagementId : val.IndustrialManagementId;
      if (item.Source === 1) {
        //非严选
        uni.navigateTo({ url: "/reportPages/IndustryReport/IndustryReport?id=" + id });
      } else {
        //严选
        uni.navigateTo({ url: "/reportPages/researchTheme/researchTheme?id=" + id });
      }
    },
    //收藏
    async collectClick(item, type) {
      //  if () {
      //   uni.navigateTo({ url: "/pages-purchaser/noteAndViewpoint/noteAndViewpoint?id=" + item.ArticleId });
      //   return;
      // }
      const res =
        item.SpecialType > 0
          ? await purchaserApi.yanxuanSpecialCollect({
              Id: item.ArticleId,
              Status: item.IsCollect ? 2 : 1,
            })
          : await Report.collectRpt({ ArticleId: item.ArticleId, PageRouter: this.$store.state.pageRouterReport });
      if (res.Ret === 200) {
        this.$parent.reportPageData[type].forEach((_) => {
          if (item.ArticleId === _.ArticleId) {
            _.IsCollect = !_.IsCollect;
            _.IsCollect
              ? (_.CollectNum += 1) &&
                uni.showToast({
                  title: "收藏成功",
                  icon: "none",
                  duration: 2000,
                })
              : (_.CollectNum -= 1);
            !_.IsCollect &&
              uni.showToast({
                title: "已取消收藏",
                icon: "none",
                duration: 2000,
              });
          }
        });
      }
    },
    //点击关注的图标
    reportFllow(id, type) {
      if (!this.$store.state.isAuth && !this.$store.state.isBind) {
        Reports.reportFllow({
          IndustrialManagementId: id,
          PageRouter: "搜索关注",
        }).then((res) => {
          if (res.Ret === 200) {
            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>请关注【查研观向小助手】公众号，及时获取产业报告更新提醒";
              }
            }
            this.$emit("updateFllow", id, type);
          }
        });
      } else if (this.$store.state.isAuth) {
        //未授权
        uni.navigateTo({
          url: "/pageMy/authGuide/authGuide",
        });
      } else if (!this.$store.state.isAuth && this.$store.state.isBind) {
        //已授权未绑定
        uni.navigateTo({
          url: "/pageMy/login/login",
        });
      }
    },
    //点击了去关注
    goFollowShowBtn() {
      if (this.confirmText == "去关注") {
        uni.navigateTo({
          url: "/activityPages/accountsOfficial/accountsOfficial",
        });
      }
      this.goFollowShow = false;
    },
    // 播放权限判断
    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;
    },
  },
};
</script>
<style scoped lang="scss">
.container-report-page {
  background-color: $uni-bg-color;
  padding: 0 24rpx 50rpx;
  .content-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .list-ui {
      width: 49%;
      &:first-child {
        margin-right: 10rpx;
      }
    }
    .item-title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 100rpx;
      border-bottom: 1px solid #f6f6f6;
      padding: 0 30rpx;
      background-color: #fff;
      image {
        margin-left: 10rpx;
        width: 60rpx;
        height: 30rpx;
      }
    }
    .read-more {
      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: 24rpx;
        color: white;
        line-height: 45rpx;
        padding: 20rpx;
        position: relative;
        overflow: hidden;

        .industry-video-icon {
          height: 0rpx;
          width: 0rpx;
          border-style: solid;
          border-color: #376cbb #376cbb 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;
      }
    }
  }
  .resource {
    display: flex;
    align-items: center;
    height: 66rpx;
    width: 100%;
    image {
      width: 34rpx;
      height: 36rpx;
      margin-right: 10rpx;
    }
  }
  .content-report {
    .content-item {
      background-color: #fff;
      padding: 20rpx;
      margin-bottom: 20rpx;
      border-top: 4rpx solid #376cbb;
      .item-title {
        font-weight: 500;
        position: relative;
        .item-industry {
          text-indent: 0;
          margin-right: 10rpx;
          color: #376cbb;
          display: inline-block;
        }
        .tag {
          display: inline-block !important;
          padding: 0 20rpx;
          color: #928563;
          font-size: 24rpx;
          font-weight: 500;
          border-radius: 38rpx;
          background-color: #f2e8cc;
          margin-right: 10rpx;
        }
        .tag-hz {
          color: #bc372b;
          background-color: #f2dacb;
        }
      }
      .item-user {
        display: flex;
        align-items: center;
        color: #999999;
        font-size: 24rpx;
        margin-bottom: 10rpx;
        margin-top: -10rpx;
        image {
          width: 24rpx;
          height: 24rpx;
          margin-right: 20rpx;
        }
      }
      .item-more {
        display: flex;
        justify-content: space-between;
        color: #cecece;
        margin-top: 20rpx;
      }
    }
  }

  .industry-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15rpx;
    .industry-box-left {
      display: flex;
      align-items: center;
      .follw {
        color: #fff;
        border-radius: 4rpx;
        font-size: 24rpx;
        width: 110rpx;
        height: 42rpx;
        margin-right: 10rpx;
        background-color: $uni-color-new;
      }
    }
    .ndustry-box-tiem {
      font-size: 24rpx;
      color: #999;
      .read {
        width: 14rpx;
        height: 14rpx;
        background-color: #ff0000;
        border-radius: 50%;
        margin-right: 10rpx;
      }
      .ndustry-box-text {
        margin: 0 10rpx;
      }
    }
  }
  .follw-image {
    width: 32rpx;
    height: 32rpx;
    margin-right: 10rpx;
  }
  .title-content-box {
    display: flex;
    .tag {
      width: 126rpx;
      height: 42rpx;
      color: #928563;
      font-size: 24rpx;
      font-weight: 500;
      border-radius: 38rpx;
      background-color: #f2e8cc;
      flex-shrink: 0;
      margin-right: 10rpx;
    }
  }
}
</style>
