<template>
  <block>
    <block>
      <view id="keyconmpany" class="container content-conmpany" v-if="haveData">
        <block v-if="Object.keys(reportDetail).length > 0">
          <view class="report-content-title global_title">{{ reportDetail.Title }}</view>
          <view class="author-time">
            <text>{{ reportDetail.Department }}</text>
            <text>{{ reportDetail.PublishDate }}</text>
          </view>
          <view class="content-statement">
            <view style="display: flex"> <text>注:请务必阅读</text> <text class="statement" @click="isShowStatement = true">免责声明 </text>   </view>
            <text class="statement" @click="goSecret">往期汇总>> </text>
          </view>
          <view class="content-abstract">
            <text>产品说明:</text>
            <text>{{ reportDetail.ProductDescription }} </text>
          </view>
          <view class="macro-strategy">
            <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/macro-strategy.png"></image>
            宏观策略
          </view>
          <view class="description">
            <mp-html :content="strFontSize(reportDetail.MarketStrategy)" />
            <view class="detailed">
              <text>详细策略报告请</text>
              <text @click="reportDetailLink">点击查看</text>
            </view>
          </view>
          <block v-if="isUserBindingPhoneNumber">
            <view class="industry-ul">
              <view class="industry-li" v-for="(item, index) in dataListSubject" :key="index">
                <view class="industry-name">{{ item.PermissionName }}</view>
                <view :class="['industry-subject', item.ListSubject.length < 3 && 'industry-top-border']">
                  <view
                    :class="['subject-item', 'text_oneLine', item.ListSubject.length < 3 && 'subject-item-top-border']"
                    @click="positionSubject(key)"
                    v-for="key in item.ListSubject"
                    :key="key.IndustrialSubjectId"
                  >
                    {{ key.SubjectName }}
                    <image v-if="key.IsNew" class="icon_subject" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/new_subject.png"></image>
                  </view>
                </view>
              </view>
            </view>
            <view class="content-ul">
              <view class="content-li" v-for="item in dataList" :key="item.PermissionName">
                <view class="content-title">
                  <image :src="item.IcoLink"></image>
                  {{ item.PermissionName }}
                </view>
                <mp-html :content="strFontSize(item.BodyChartSummary)" />
                <view class="li-list">
                  <view class="li-item" v-for="key in item.List" :key="key.IndustrialSubjectId">
                    <view :id="'subject' + key.IndustrialSubjectId" class="li-subject">
                      <view class="item-name">
                        <text style="display: inline-block; vertical-align: middle; font-weight: 600">{{ key.SubjectName }}</text>
                        <image v-if="key.IsNew" src="https://hzstatic.hzinsights.com/cygx/icon/new_report.png"></image>
                      </view>
                      <text class="itel-label" v-for="val in key.CompanyLabel" :key="val"># {{ val }}</text>
                    </view>
                    <mp-html :content="strFontSize(key.Body)" />
                    <view :style="{ 'margin-bottom': key.IsShowApplyButton ? '50rpx' : '120rpx' }" v-if="key.OverviewArticleId > 0 || key.List">
                      <view class="subject-detali" v-if="key.OverviewArticleId > 0">
                        <text style="display: inline-block">公司综述报告请</text>
                        <text style="color: #376cbb; margin-left: 10rpx; display: inline-block" @click="goArticle(key.OverviewArticleId)">点击查看</text>
                      </view>
                      <view class="subject-detali" v-if="key.List">
                        <text style="display: inline-block">相关调研纪要、深度报告请</text>
                        <text style="color: #376cbb; margin-left: 10rpx; display: inline-block" @click="industry(key.List)">点击查看</text>
                      </view>
                    </view>
                    <view v-if="key.IsShowApplyButton" class="item-application" @click="applicationHandel(key)"> 申请路演</view>
                  </view>
                </view>
              </view>
            </view>
            <view class="back-top" v-if="isShowBackTop" @click="goBackTop">
              <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/back_top.png"></image>
            </view>
            <statement :show="isShowStatement" />
            <view class="select-box">
              <u-popup v-model="areacodeShow" mode="bottom" @close="cancel">
                <view class="box" style="color: #2c83ff" v-for="item in list" :key="item.IndustrialManagementId" @click="industryDetitle(item)"> {{ item.IndustryName }}</view>
                <view class="box box-bottom" style="color: #a9afb8" @click="cancel">取消</view>
              </u-popup>
            </view>
          </block>
          <view class="content-bottom" v-else>
            <view class="make-outbound" @click="pleaseGoLogin"> 请登录后报名 </view>
          </view>
        </block>
      </view>
      <view class="nodata" v-else>
        <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/report_loading_icon.png" class="nodata_img"></image>
        <view class="nodata-tip">正在努力编辑中,请耐心等待...</view>
      </view>
    </block>
    <!-- <not-have-login v-else /> -->
    <Loading />
  </block>
</template>

<script>
import { Reports, Mine } from "@/config/api.js";
import statement from "@/reportPages/components/statement.vue";
import { Throttle } from "@/config/util.js";
import NotHaveLogin from "../../components/notHaveLogin.vue";

export default {
  data() {
    return {
      list: [],
      dataList: [],
      dataListSubject: [],
      reportDetail: {},
      isShowBackTop: false,
      isShowStatement: false,
      areacodeShow: false,
      haveData: true,
      hasPermission: "",
      readTiem: 0,
      setIntervalTiem: null,
    };
  },
  components: { statement, NotHaveLogin },
  methods: {
    // 返回top
    goBackTop() {
      wx.pageScrollTo({
        selector: ".industry-ul",
        duration: 300,
      });
    },
    async reportSelectionDetail(option) {
      const res = await Reports.reportSelectionDetail({
        IsBestNew: option.id ? "" : true,
        ActivityId: Number(option.id) || 0,
      });
      if (res.Ret === 200) {
        this.hasPermission = res.Data.HasPermission;
        this.reportDetail = res.Data.Detail;
        this.haveData = this.reportDetail ? true : false;
        this.dataList = res.Data.List;
        this.dataListSubject = res.Data.ListPermissionSubject;
      } else {
        this.haveData = false;
      }
    },
    // 详细策略报告请
    reportDetailLink() {
      if (this.reportDetail.CeLueArticleId > 0) {
        uni.navigateTo({ url: "/pageMy/reportDetail/reportDetail?id=" + this.reportDetail.CeLueArticleId });
      } else {
        uni.showToast({
          title: "文章ID有误",
          icon: "error",
          duration: 2000,
        });
      }
    },
    // 锚点
    positionSubject: Throttle(function (item) {
      let className = `#subject${item.IndustrialSubjectId}`;
      uni
        .createSelectorQuery()
        .select(className)
        .boundingClientRect((con) => {
          uni
            .createSelectorQuery()
            .select("#keyconmpany")
            .boundingClientRect((res) => {
              // 获取根元素要滑动的元素
              uni.pageScrollTo({
                selector: "#keyconmpany", // 滑动的元素
                duration: 300,
                scrollTop: con.top - res.top, //到达距离顶部的top值
              });
            })
            .exec();
        })
        .exec();
      const res = Reports.reportClickHistory({
        ArticleId: this.reportDetail.ArticleId,
        IndustrialSubjectId: item.IndustrialSubjectId,
      });
    }),
    // 公司综述报告请
    goArticle(id) {
      uni.navigateTo({ url: "/pageMy/reportDetail/reportDetail?id=" + id });
    },
    // 判断一个还是多个
    industry(item) {
      if (item.length > 1) {
        this.list = item;
        this.areacodeShow = true;
      } else if (item.length > 0 || item.length == 1) {
        uni.navigateTo({
          url: "/reportPages/IndustryReport/IndustryReport?id=" + item[0].IndustrialManagementId,
        });
      }
    },

    // 选择后的事件
    industryDetitle(item) {
      uni.navigateTo({
        url: "/reportPages/IndustryReport/IndustryReport?id=" + item.IndustrialManagementId,
      });

      this.areacodeShow = false;
    },

    // 选择的取消
    cancel() {
      this.areacodeShow = false;
    },

    /* 无权限申请开通权限 */
    applyAuth() {
      this.hasPermission === 4
        ? uni.navigateTo({
            url: "/pageMy/applyTrial/applyTrial?tryType=ReportSelection&detailId=" + this.id,
          })
        : uni.showModal({
            title: "",
            content: "您已经提交过申请了,请耐心等待",
            showCancel: false,
            confirmColor: "#365595",
            success: function (res) {
              uni.navigateBack({
                fail() {
                  uni.switchTab({
                    url: "/pages/index/index",
                  });
                },
              });
            },
          });
    },
    // 上传阅读时长的记录
    async postStopTime(type) {
      const res = await Mine.report_selectionAddStopTime({
        ArticleId: this.reportDetail.ArticleId,
        StopTime: this.readTiem,
        OutType: type,
        Source: 1,
      });
    },
    // 跳转往期汇总
    goSecret() {
      uni.navigateTo({
        url: "/reportPages/companyTabulation/companyTabulation",
      });
    },
    applicationHandel(item) {
      uni.showModal({
        content: "路演申请会提交至您的对口销售,确定要申请吗?",
        confirmColor: "#376cbb",
        cancelColor: "#606266",
        success: async (res) => {
          if (res.confirm) {
            const res = await Reports.report_selection_logApply({ ArticleId: this.reportDetail.ArticleId, SubjectName: item.SubjectName });
            if (res.Ret === 200) {
              uni.showToast({
                title: "申请成功",
                duration: 2000,
              });
            }
          } else {
            uni.showToast({
              title: "取消申请",
              icon: "none",
              duration: 2000,
            });
          }
        },
      });
    },
  },
  onLoad(option) {
    this.reportSelectionDetail(option);
  },
  onShow() {
    this.readTiem = 0;
    this.setIntervalTiem = setInterval(() => {
      this.readTiem++;
    }, 1000);
    this.$store.commit("setRouterReport", "重点公司");
  },
  onPageScroll(e) {
    this.isShowBackTop = e.scrollTop > 180 ? true : false;
  },
  onShareAppMessage() {
    return {
      title: "重点公司",
      path: "/reportPages/keyCompany/keyCompany",
    };
  },
  // 页面隐藏/切入后台时触发
  async onHide() {
    clearInterval(this.setIntervalTiem);
    this.postStopTime(2);
  },
  // 页面卸载时触发
  async onUnload() {
    clearInterval(this.setIntervalTiem);
    this.postStopTime(1);
  },
};
</script>

<style lang="scss" scoped>
.content-conmpany {
  padding: 30rpx 34rpx;
  color: #333;
  font-size: 28rpx;
  .author-time {
    display: flex;
    justify-content: space-between;
    line-height: 39rpx;
    margin: 25rpx 0 35rpx;
  }
  .content-statement {
    display: flex;
    color: #707070;
    justify-content: space-between;
    .statement {
      margin-left: 10rpx;
      color: $uni-color-new;
    }
  }
  .content-abstract {
    margin-top: 30rpx;
    :first-child {
      float: left;
      font-weight: 500;
    }
  }
  .description {
    color: #666666;
    .detailed {
      display: flex;
      justify-content: flex-end;
      color: $uni-color-new;
      margin: 20rpx 0;
      :first-child {
        float: left;
        margin-right: 10rpx;
        color: #333333;
        font-weight: 500;
      }
    }
  }
  .industry-ul {
    margin-bottom: 20rpx;
    .industry-li {
      display: flex;
      margin-bottom: 10rpx;
      .industry-name {
        width: 42rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        background: $uni-color-new;
        color: #fff;
        writing-mode: tb-rl;
      }
      .industry-subject {
        flex: 1;
        display: flex;
        flex-wrap: wrap;
        .subject-item {
          position: relative;
          width: 213rpx;
          height: 80rpx;
          display: flex;
          justify-content: center;
          align-items: center;
          line-height: 39rpx;
          border-bottom: 2rpx solid #ececec;
          border-top: 2rpx solid #ececec;
          border-right: 2rpx solid #ececec;
          text-decoration: underline;
          margin-top: -2rpx;
          .icon_subject {
            position: absolute;
            top: 0;
            left: 0;
            width: 48rpx;
            height: 48rpx;
          }
        }
      }
      .industry-top-border {
        border-top: none !important;
      }
      .subject-item-top-border {
        border-top: 1px solid #ececec;
      }
    }
  }
  .back-top {
    position: fixed;
    z-index: 99;
    bottom: 200rpx;
    right: 50rpx;
    width: 100rpx;
    height: 100rpx;
    image {
      width: 100%;
      height: 100%;
    }
  }
  .content-ul {
    .content-li {
      margin-top: 30rpx;
      padding-bottom: 20rpx;
      border-bottom: 2rpx dashed #e2e2e2;
      font-size: 28rpx;
      .content-title {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 195rpx;
        padding: 3rpx 0;
        border-radius: 0rpx 50rpx 50rpx 0rpx;
        background-color: $uni-color-new;
        color: #fff;
        margin-bottom: 20rpx;
        font-size: 32rpx;
        image {
          width: 32rpx;
          height: 34rpx;
          margin-right: 15rpx;
        }
      }
      .li-list {
        margin-top: 20rpx;
        .li-subject {
          padding: 20rpx;
          margin-bottom: 20rpx;
          background: #f2f2f2;
          .item-name {
            display: inline-block;
            font-size: 34rpx;
            margin-right: 27rpx;
            line-height: 60rpx;
          }
          .itel-label {
            font-size: 30rpx;
            display: inline-block;
            margin-right: 27rpx;
            color: $uni-color-new;
            line-height: 60rpx;
            vertical-align: middle;
            font-weight: 500;
          }
          image {
            width: 60rpx;
            height: 30rpx;
            vertical-align: middle;
            margin-left: 10rpx;
          }
        }
        .li-item {
          margin-top: 20rpx;
          margin-bottom: 80rpx;
        }
      }
    }
    .subject-detali {
      text-align: right;
      margin-top: 20rpx;
    }
  }
  .macro-strategy {
    display: flex;
    align-items: center;
    width: 230rpx;
    height: 50rpx;
    padding-left: 35rpx;
    background-color: $uni-color-new;
    color: #fff;
    border-radius: 0rpx 50rpx 50rpx 0rpx;
    margin: 30rpx 0;
    image {
      width: 36rpx;
      height: 36rpx;
      margin-right: 10rpx;
    }
  }
  .nodata-tip {
    color: #999;
    font-size: 30rpx;
  }
  .content-bottom {
    margin: 50rpx 0 30rpx;

    .make-outbound {
      margin: 0 auto;
      width: 368rpx;
      height: 80rpx;
      background: linear-gradient(268deg, #2ddbff 0%, #1599ff 49%, #005eff 100%);
      opacity: 1;
      border-radius: 4rpx;
      color: #ffffff;
      font-size: 34rpx;
      line-height: 80rpx;
      text-align: center;
    }
    .make-generation {
      padding-top: 0rpx !important;
      line-height: 76rpx;
    }
    .make-conference {
      margin: 30rpx auto;
      width: 368rpx;
      height: 80rpx;
      border: 2px solid #2c83ff;
      opacity: 1;
      border-radius: 4rpx;
      padding-top: 5rpx;
      text-align: center;
      color: #2c83ff;
      font-size: 30rpx;
      text {
        font-size: 16rpx;
      }
    }
  }
}
.noauth-cont {
  padding-top: 150rpx;
  text-align: center;
  font-size: 28rpx;
  .noauth-ico {
    width: 365rpx;
    height: 229rpx;
    margin-bottom: 70rpx;
  }
  .tip {
    width: 532rpx;
    margin: 0 auto 100rpx;
    .contract {
      padding: 40rpx 90rpx 0;
      line-height: 44rpx;
      text {
        display: inline-block;
      }
    }
  }
  .btn-cont {
    width: 500rpx;
    height: 52rpx;
    background: $uni-color-new;
    color: #fff;
    font-size: 24rpx;
    font-weight: 600;
    border-radius: 8rpx;
    margin: 0 auto;
    text-align: center;
    line-height: 52rpx;
    &.back-btn {
      background: #e5efff !important;
      color: $uni-color-new;
      margin-top: 30rpx;
    }
    .btn_bg {
      width: 100%;
      height: 80rpx;
      position: absolute;
      left: 0;
      top: 0;
    }
    .btn-txt {
      width: 100%;
      position: absolute;
      z-index: 1;
    }
  }
}
.item-application {
  margin: 0 auto 120rpx;
  width: 368rpx;
  height: 80rpx;
  font-size: 34rpx;
  line-height: 80rpx;
  text-align: center;
  color: #ffffff;
  background: linear-gradient(268deg, #2ddbff 0%, #1599ff 49%, #005eff 100%);
  opacity: 1;
  border-radius: 4rpx;
}
</style>