<template>
  <view id="keyconmpany" class="container content-conmpany" v-if="haveData">
    <view class="title">{{ reportDetail.Title }}</view>
    <view class="author-time">
      <text>{{ reportDetail.Department }}</text>
      <text>{{ reportDetail.PublishDate }}</text>
    </view>
    <view class="content-statement">
      <text>注:请务必阅读</text>
      <text class="statement" @click="isShowStatement = true">免责声明 </text>
    </view>
    <view class="content-abstract">
      <text>产品说明:</text>
      <text>{{ reportDetail.ProductDescription }} </text>
    </view>
    <view class="description">
      <mp-html :content="reportDetail.MarketStrategy" />
      <view class="detailed">
        <text>详细策略报告请</text>
        <text @click="reportDetailLink">点击查看</text>
      </view>
    </view>
    <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']"
            class=""
            @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="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">{{ key.SubjectName }}</text>
                <image v-if="key.IsNew" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/new_report.png"></image>
              </view>
              <text class="itel-label" v-for="val in key.CompanyLabel" :key="val"># {{ val }}</text>
            </view>
            <mp-html :content="key.Body" />
            <view class="subject-detali" v-if="key.OverviewArticleId > 0">
              <text style="display: inline-block">公司综述报告请</text>
              <text style="color: #3385ff; 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: #3385ff; margin-left: 10rpx; display: inline-block" @click="industry(key.List)">点击查看</text>
            </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>
  </view>
</template>

<script>
import { Reports } from "@/config/api.js";
import statement from "@/reportPages/components/statement.vue";

export default {
  data() {
    return {
      list: [],
      dataList: [],
      dataListSubject: [],
      reportDetail: {},
      isShowBackTop: false,
      isShowStatement: false,
      areacodeShow: false,
      haveData: false,
    };
  },
  components: { statement },
  methods: {
    // 返回top
    goBackTop() {
      wx.pageScrollTo({
        scrollTop: 0,
        duration: 300,
      });
    },
    async reportSelectionDetail() {
      const res = await Reports.reportSelectionDetail({
        IsBestNew: true,
      });
      if (res.Ret === 200) {
        this.reportDetail = res.Data.Detail;
        this.haveData = true;
        this.dataList = res.Data.List;
        this.dataListSubject = res.Data.ListPermissionSubject;
      }
    },
    // 详细策略报告请
    reportDetailLink() {
      if (this.reportDetail.CeLueArticleId > 0) {
        this.$store.dispatch("checkHandle", "/pageMy/reportDetail/reportDetail?id=" + this.reportDetail.CeLueArticleId);
      } else {
        uni.showToast({
          title: "文章ID有误",
          icon: "error",
          duration: 2000,
        });
      }
    },
    // 锚点
    positionSubject(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();
    },
    // 公司综述报告请
    goArticle(id) {
      this.$store.dispatch("checkHandle", "/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;
    },
  },
  onLoad() {
    this.reportSelectionDetail();
  },
  onShow() {
    this.$store.commit("setRouterReport", "重点公司");
  },
  onPageScroll(e) {
    this.isShowBackTop = e.scrollTop > 180 ? true : false;
  },
};
</script>

<style lang="scss" scoped>
.content-conmpany {
  padding: 30rpx 34rpx;
  color: #333;
  font-size: 28rpx;
  .title {
    font-weight: 500;
    font-size: 34rpx;
    line-height: 48rpx;
  }
  .author-time {
    display: flex;
    justify-content: space-between;
    line-height: 39rpx;
    margin: 25rpx 0 35rpx;
  }
  .content-statement {
    display: flex;
    color: #707070;
    .statement {
      margin-left: 10rpx;
      color: #3385ff;
    }
  }
  .content-abstract {
    margin: 30rpx 0 20rpx;
    :first-child {
      float: left;
      font-weight: 500;
    }
  }
  .description {
    color: #666666;
    .detailed {
      display: flex;
      justify-content: flex-end;
      color: #3385ff;
      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;
        background: #3385ff;
        color: #fff;
        writing-mode: tb-rl;
      }
      .industry-subject {
        border-top: 1px solid #ececec;
        flex: 1;
        display: flex;
        flex-wrap: wrap;
        .subject-item {
          position: relative;
          width: 213rpx;
          height: 63rpx;
          display: flex;
          justify-content: center;
          align-items: center;
          line-height: 39rpx;
          border-bottom: 1px solid #ececec;
          border-right: 1px solid #ececec;
          .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;
      .content-title {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 195rpx;
        padding: 3rpx 0;
        border-radius: 0rpx 50rpx 50rpx 0rpx;
        background-color: #3385ff;
        color: #fff;
        margin-bottom: 20rpx;
        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;
            margin-right: 27rpx;
            line-height: 60rpx;
          }
          .itel-label {
            display: inline-block;
            margin-right: 27rpx;
            color: #3385ff;
            line-height: 60rpx;
            vertical-align: middle;
          }
          image {
            width: 60rpx;
            height: 30rpx;
            vertical-align: middle;
            margin-left: 10rpx;
          }
        }
        .li-item {
          margin-top: 20rpx;
        }
      }
    }
    .subject-detali {
      text-align: right;
      margin-top: 20rpx;
    }
  }
}
</style>