<template>
  <view class="container Index-container">    
    <view class="index-fixed">
      <view class="index-header">
        <input type="text" placeholder="搜索您想要的纪要" placeholder-class="sea_ipt_placeholder" class="sea_ipt" v-model="searchTxt" disabled @click="goSearch" />
        <icon type="search" size="15" class="search_ico" />
      </view>
      <!-- 导航条 -->
      <view class="tab-cont">
        <scroll-view scroll-x="true" scroll-with-animation class="scroll-tab" @scroll="scrollMove" :scroll-left="scrollLeft" :scroll-into-view="'_' + tabIndex">
          <block v-for="(item, index) in tabBars" :key="item.ChartPermissionId">
            <view :id="'_' + index" class="scroll-tab-item" :class="{ active: tabAct_id == item.ChartPermissionId }" @click.stop="toggleTab(item, index)">
              {{ item.PermissionName }}
              <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/border_act.png" mode="" class="border_act" v-if="tabAct_id == item.ChartPermissionId"></image>
            </view>
          </block>
          <view class="limit-box" v-if="limitIsShow">
            <image class="limit-img" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/limit_icon.png" mode=""></image>
          </view>
        </scroll-view>
      </view>
    </view>  
    <block v-if="haveData">
      <view class="data-cont">
        <view class="report-ul">
          <view class="report-item" v-for="(report, index) in dataList" :key="index" v-if="index % 2 === 0" @click="goDetail(report)">
            <view class="item-content-img" v-if="report.BodyHtml">
              <!-- <mp-html :content="report.BodyHtml" /> -->
              <image :src="report.BodyHtml" mode=""></image>
            </view>
            <view class="item-content" v-else>{{ report.Body }}</view>
            <view class="line"></view>
            <text class="item-title">{{ report.Title }}</text>
            <view class="item-abstract text_twoLine" v-if="report.ExpertBackground">
              <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/fenxi_ico.png" class="report_ico"></image>
              {{ report.ExpertBackground }}
            </view>
            <view class="item-createtime">
              <text>{{ report.PublishDate }}</text>
              <view class="item-examine" v-if="report.IsResearch">
                <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/examine_icon.png"></image>
                <text>{{ report.Pv }}</text>
              </view>
            </view>
          </view>
        </view>
        <view class="report-ul">
          <view class="report-item" v-for="(report, index) in dataList" :key="index" v-if="index % 2 !== 0" @click="goDetail(report)">
            <view class="item-content-img" v-if="report.BodyHtml">
              <!-- <mp-html :content="report.BodyHtml" /> -->
              <image :src="report.BodyHtml"></image>
            </view>
            <view class="item-content" v-else>{{ report.Body }}</view>
            <view class="line"></view>
            <text class="item-title">{{ report.Title }}</text>
            <view class="item-abstract text_twoLine" v-if="report.ExpertBackground">
              <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/fenxi_ico.png" class="report_ico"></image>
              {{ report.ExpertBackground }}
            </view>
            <view class="item-createtime">
              <text>{{ report.PublishDate }}</text>
              <view class="item-examine" v-if="report.IsResearch">
                <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/examine_icon.png"></image>
                <text>{{ report.Pv }}</text>
              </view>
            </view>
          </view>
        </view>
      </view>
      <u-loadmore :status="status" icon-type="flower" :load-text="loadText" margin-top="20" />
    </block>
    <view class="nodata" v-else-if="haveData === false" style="padding-top: 400rpx">
      <image src="@/static/img/nodata.png" mode="" class="nodata_ico"></image>
      <text>暂时没有行业数据</text>
    </view>
    <view class="content-intimate" v-if="reportShow">
      <van-transition :show="showTransition" name="fade-right">
        <view class="content">
          <view @click="goSecretDetail('1')">
            <text>报告</text>
            <text>精选</text>
          </view>
          <view class="cont-border" @click="goSecretDetail('2')">
            <text>本周研</text>
            <text>究汇总</text>
          </view>
          <view @click="goSecretDetail('3')">
            <text>上周纪</text>
            <text>要汇总</text>
          </view>
        </view>
      </van-transition>
      <image @click="showTransition = !showTransition" src="https://hzstatic.hzinsights.com/cygx/czbk/intimate-icon.png" mode=""></image>
    </view>
  </view>
</template>

<script>
import { Home, Reports } from "@/config/api.js";
import { Throttle } from "@/config/util.js";
let app = getApp();
export default {
  data() {
    return {
      refresh: false,
      pageSize: 10, //条数
      pageNum: 1, //页码
      haveMore: true, //是否有更多数据
      haveData: null, //是否有数据
      tabAct_id: 0,
      //数据列表
      dataList: [],
      // tab
      tabBars: [],
      status: "loadmore",
      loadText: {
        loadmore: "上拉加载更多",
        loading: "加载中",
        nomore: "已经到底了",
      },
      totalPage: "",
      limitIsShow: false, //限免的隐现
      scrollLeft: 0,
      showTransition: false, //点击绝密后的隐现
      reportShow: false, //绝密标签的隐现
    };
  },
  watch: {
    tabAct_id: {
      handler() {
        this.getReportList();
      },
      immediate: true,
    },
  },
  onLoad(optios) {
    uni.getSystemInfo({
      success: function (res) {
        if (res.windowWidth > 700) {
          uni.reLaunch({
            url: "/pages/pcWebViev/pcWebViev",
          });
        }
      },
    });
    if (optios.tabid) {
      this.tabAct_id = optios.tabid;
    }
    this.getTabs();
    this.reportIsShow();
  },
  onShow() {
    this.$store.dispatch("statistics", { PageType: "Summary", ChartPermissionId: Number(this.tabAct_id) });
    // #ifdef MP-WEIXIN
    uni.hideHomeButton();
    // #endif
  },
  methods: {
      gopc(){
            uni.reLaunch({
              url: "/pages/pcWebViev/pcWebViev",
            });
      },
    goSecretDetail(type) {
      uni.navigateTo({
        url: "/reportPages/secretDetails/secretDetails?type=" + type,
      });
    },
    async reportIsShow() {
      const res = await Reports.reportIsShow();
      if (res.Ret === 200) {
        this.reportShow = res.Data.IsShow;
      }
    },
    /* 切换分类 */
    toggleTab(item, index) {
      if (this.tabAct_id !== item.ChartPermissionId) {
        this.tabAct_id = item.ChartPermissionId;
        this.pageNum = 1;
        uni.pageScrollTo({
          scrollTop: 0,
          duration: 0,
        });
        this.$store.dispatch("statistics", { PageType: "Summary", ChartPermissionId: Number(this.tabAct_id) });
      }
    },
    scrollMove(e) {
      this.scrollLeft = e.detail.scrollLeft;
    },
    /* 获取列表 */
    getReportList() {
      Home.getList({
        PageSize: this.pageSize,
        CurrentIndex: this.pageNum,
        ChartPermissionId: Number(this.tabAct_id) || 0,
      }).then((res) => {
        if (res.Ret === 200) {
          if (!res.Data.HaveResearch) {
            this.$util.modalShow("", "您暂无查看研选权限", "", () => {
              uni.reLaunch({
                url: "/pages/index/index",
              });
            });
          }
          this.status = this.pageNum < res.Data.Paging.Pages ? "loadmore" : "nomore";
          // this.totalPage = res.Data.Paging.Pages;//总页数
          if (res.Data.List && res.Data.List.length > 0) {
            res.Data.List.forEach((item) => {
              if (item.BodyHtml) {
                item.BodyHtml = item.BodyHtml.replace(/'\'/g, "");
              }
            });
          }
          if (this.pageNum === 1) {
            this.dataList = res.Data.List || [];
            this.haveData = this.dataList.length ? true : false;
          } else {
            this.dataList = this.dataList.concat(res.Data.List);
          }
          if (this.refresh) {
            uni.stopPullDownRefresh();
            this.refresh = false;
          }
        }
      });
    },
    /* 获取tab分类 */
    getTabs() {
      Home.Tab().then((res) => {
        if (res.Ret === 200) {
          let arr = res.Data.List;
          arr.unshift({
            ChartPermissionId: 0,
            PermissionName: "最新",
          });
          this.tabBars = arr;
          this.limitIsShow = this.tabBars.some((item) => item.IsShowSustainable);
          if (this.tabAct_id == 0) {
            this.getReportList();
          }
        }
      });
    },
    /* 进入详情 校验是否有该品种权限 */
    goDetail(item) {
      /* 无需授权且已绑定 检验是或否有权限 */
      this.$store.dispatch("checkHandle", "/pageMy/reportDetail/reportDetail?id=" + item.ArticleId);
    },
    /* 搜索 */
    goSearch() {
      this.$store.dispatch("checkHandle", "/pageMy/search/search");
    },
    adviceHandle() {
      this.$store.dispatch("checkHandle", "/pageMy/advice/advice");
    },
  },
  onShow() {
    this.$store.dispatch("statistics", { PageType: "Activit" });
  },
  /* 下拉刷新 */
  onPullDownRefresh: Throttle(function () {
    this.pageNum = 1;
    this.refresh = true;
    this.getReportList();
  }),
  // 上拉加载
  onReachBottom: Throttle(function () {
    if (this.status === "nomore") return;
    this.status = "loading";
    this.pageNum++;
    this.getReportList();
  }),
  /**
   * 用户点击分享
   */
  onShareAppMessage: function (res) {
    return {
      title: "您手边的弘则研究素材检索库",
      path: "/pages/index/index?tabid=" + this.tabAct_id,
      imageUrl: this.tabAct_id == 0 ? "https://hzstatic.hzinsights.com/cygx/czbk/home_share.png" : "",
      success: (res) => {},
      fail: (err) => {},
    };
  },
  onHide() {
    if (this.showTransition) {
      this.showTransition = false;
    }
  },
};
</script>

<style lang="scss">
.Index-container {
  background-color: #f7f7f7;
  font-size: 30rpx;
  .index-fixed {
    width: 750rpx;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 999;
    .index-header {
      background-color: #fff;
      padding: 32rpx 34rpx;
      position: relative;
      .sea_ipt_placeholder {
        color: #8d8d8d;
        opacity: 0.7;
      }
      .sea_ipt {
        width: 100%;
        height: 70rpx;
        font-size: 30rpx;
        color: #707070;
        background-color: #f6f6f6;
        padding: 0 34rpx 0 70rpx;
        border-radius: 70rpx;
        border: 1rpx solid #e5e5e5;
      }
      .search_ico {
        display: block;
        position: absolute;
        color: #8d8d8d;
        left: 60rpx;
        top: 50%;
        z-index: 100;
        transform: translateY(-50%);
      }
    }
    .tab-cont {
      padding: 0 26rpx;
      background-color: #fff;
      font-size: 32rpx;
      box-shadow: 0 3rpx 6rpx rgba(187, 216, 255, 0.2);
      .scroll-tab {
        position: relative;
        width: 100%;
        white-space: nowrap;
      }
      .limit-box {
        position: absolute;
        text-align: center;
        display: inline-block;
        padding-right: 50rpx;
        top: -9rpx;
        margin-left: -38rpx;
        image {
          width: 46rpx;
          height: 26rpx;
        }
      }
      .scroll-tab-item {
        // flex-grow: 1;
        text-align: center;
        display: inline-block;
        padding: 10rpx 8rpx 20rpx 8rpx;
        margin-right: 35rpx;
        border-bottom: 8rpx solid transparent;
        position: relative;
        &:last-child {
          margin-right: 0;
        }
        &.active {
          border-bottom: none;
          color: #2c83ff;
          font-weight: 700;
        }
        .border_act {
          width: 100%;
          height: 8rpx;
          position: absolute;
          bottom: 0;
          left: 0;
        }
      }
    }
  }
  .data-cont {
    padding: 228rpx 20rpx 10rpx;
    display: flex;
    .report-ul {
      width: 50%;
      &:first-child {
        margin-right: 10rpx;
      }
      .report-item {
        padding: 20rpx 20rpx 24rpx 20rpx;
        margin-bottom: 20rpx;
        border-radius: 8rpx;
        box-shadow: 0 3rpx 6rpx rgba($color: #000000, $alpha: 0.16);
        background: #fff;
        .item-content-img {
          display: flex;
          align-items: center;
          image {
            width: 100%;
            height: 232rpx;
            vertical-align: middle;
          }
        }
        .item-content {
          height: 273rpx;
          font-size: 24rpx;
          line-height: 40rpx;
          color: #7f7f7f;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 7;
          -webkit-box-orient: vertical;
          image {
            width: 100% !important;
          }
        }
        .line {
          margin: 18rpx 0;
          content: "";
          width: 100%;
          height: 1px;
          padding: 0 32rpx;
          box-sizing: border-box;
          background-color: #e5e5e5;
          -webkit-transform: scale(1, 0.5);
          transform: scale(1, 0.5);
          -webkit-transform-origin: center bottom;
          transform-origin: center bottom;
        }
        .item-title {
          font-size: 28rpx;
          color: #4a4a4a;
          margin-bottom: 10rpx;
        }
        .item-abstract {
          font-size: 26rpx;
          color: #6a6a6a;
          margin-bottom: 10rpx;
          .report_ico {
            width: 32rpx;
            height: 26rpx;
            margin-right: 20rpx;
            display: inline-block;
          }
        }
        .item-createtime {
          display: flex;
          align-items: center;
          justify-content: space-between;
          color: #acacac;
          font-size: 24rpx;
          .item-examine {
            display: flex;
            align-items: center;
            image {
              width: 30rpx;
              height: 24rpx;
              margin: 0 10rpx 0 15rpx;
            }
          }
        }
      }
    }
  }
  .advice_ico {
    width: 81rpx;
    height: 81rpx;
    position: fixed;
    right: 30rpx;
    bottom: 214rpx;
  }
  .content-intimate {
    position: fixed;
    display: flex;
    align-items: center;
    bottom: 96rpx;
    right: 41rpx;
    height: 156rpx;
    .content {
      width: 432rpx;
      height: 112rpx;
      background-color: #fff;
      display: flex;
      border-radius: 56rpx;
      overflow: hidden;
      .cont-border {
        margin: 0 2rpx;
      }
      view {
        flex: 1;
        background-color: #3385ff;
        font-size: 30rpx;
        color: #fff;
        padding-top: 15rpx;
        text-align: center;
      }
    }

    image {
      width: 156rpx;
      height: 100%;
      z-index: 99;
    }
  }
  // .rich-text {
  //     width: 315rpx;
  //     height: 272rpx;
  //     image {
  //         width: 315rpx;
  //         height: 272rpx;
  //     }
  //     img {
  //       width: 315rpx;
  //       height: 272rpx;
  //     }
  // }
}
</style>
