<template>
  <view class="container note-and-viewpoint" v-if="detailDataForm.HasPermission == 1">
    <view class="content-item">
      <view class="author-name">
        <view class="img-box">
          <image :src="detailDataForm.HeadImg" @click="goDetailPages"></image>
        </view>
        <text style="margin-left: 10rpx">{{ detailDataForm.NickName }}</text>
      </view>
      <view class="type-time">
        <view class="type"> {{ detailDataForm.Type == 1 ? "笔 记" : "观 点" }} </view>

        <view class="time">{{ detailDataForm.PublishTime }}</view>
      </view>
      <view class="title-item global_title"> {{ detailDataForm.Title }}</view>
      <view class="text-conten">
        <mp-html :content="isUserBindingPhoneNumber ? detailDataForm.Content : detailDataForm.Content.slice(0, 80)" />
      </view>
      <block v-if="isUserBindingPhoneNumber">
        <block v-if="detailDataForm.Docs && detailDataForm.Docs.length > 0">
          <view @click="goFilePages(item)" class="file-item text_oneLine" v-for="(item, index) in detailDataForm.Docs" :key="index">
            <image :src="item.DocIcon"></image>
            {{ item.DocName }}
          </view>
        </block>
        <view class="image-conten">
          <image v-for="key in dataProcessing(detailDataForm.ImgUrl)" :key="key" :src="key" @click="previewImageMediahandler(key)"></image>
        </view>
        <view class="lable-conten">
          <view class="item" v-for="key in dataProcessing(detailDataForm.Tags)" :key="key">{{ key }}</view>
        </view>
      </block>
    </view>
    <block v-if="isUserBindingPhoneNumber">
      <view class="statement-content" v-if="detailDataForm.Status == 3">
        <text>郑重声明：</text>
        本文为用户投稿，用户在平台中发表的所有资料、言论等仅代表个人或嘉宾观点，与本网站、任何公司与任何机构立场无关。本平台对文中陈述、观点判断保持中立，不对所包含内容及数据的真实性、准确性、可靠性或完整性提供任何明示或暗示的保证。
        股市波动与很多因素有关，任何用户或嘉宾的发言，都有其特定立场，投资决策是个人基于自己的研究分析所做的决定，本文章或会议目的在于事实、观点分享，不构成任何的投资建议。投资者应当自主进行投资决策，对投资者因依赖上述信息进行投资决策而导致的财产损失，本平台不承担法律责任。
        本文章或会议未经本平台和作者的书面许可，任何机构和个人不得以任何形式转发、转载、翻版、复制、刊登、发表、修改、仿制或引用文章或会议的全部或部分内容。本平台对任何第三方的未经授权行为所产生的的影响不承担任何责任，同时保持实施法律行动的权利。
      </view>
      <view class="collect-conten">
        <image @click="collectHandler(2)" v-if="detailDataForm.IsCollect == 1" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/collected_icon.png"></image>
        <image @click="collectHandler(1)" v-else src="https://hzchart.oss-cn-shanghai.aliyuncs.com/new_cygx/collect_ico.png"></image>
        {{ detailDataForm.IsCollect == 1 ? "已收藏" : "收藏" }}
      </view>
    </block>
    <view v-else class="please-login" @click="pleaseGoLogin">请登录后查看更多内容</view>
    <Loading />
  </view>
  <view class="noauth-cont" v-else>
    <block v-if="isSpecialArticle_report">
      <image src="https://hzstatic.hzinsights.com/cygx/czbk/noauth.png" class="noauth-ico"></image>
      <view class="tip" v-if="detailDataForm.HasPermission === 3">
        需要升级行业套餐权限才可查看此报告，请联系对口销售
        <view class="btn-cont back-btn" @click="backIndex"> 返回 </view>
      </view>
    </block>
    <block v-else>
      <image src="https://hzstatic.hzinsights.com/cygx/czbk/noauth.png" class="noauth-ico"></image>
      <block v-if="detailDataForm.HasPermission !== 3">
        <view class="research-noauth">
          暂无 <text class="strong-text">买方研选</text> 权限
          <text style="margin-bottom: 30rpx"> 您可申请开通试用 </text>
        </view>
        <view class="btn-cont" @click="applyAuth">{{ "立即申请" }} </view>
      </block>
      <view class="tip" v-if="detailDataForm.HasPermission === 3">
        <view class="research-noauth">
          暂无 <text class="strong-text">买方研选</text> 权限
          <text> 点击提交申请，提醒对口销售为你开通试用 </text>
        </view>
      </view>
      <view v-if="detailDataForm.HasPermission === 3" class="btn-cont" @click="sellerApplyAuth"> {{ isShowText ? "提交申请" : "立即申请" }}</view>
      <view class="btn-cont back-btn" @click="backIndex"> 返回 </view>
      <view class="product-introduction-box">
        <view class="product-introduction">
          <view class="introduction-header">
            <view class="introduction-header-left"></view>
            <view class="introduction-header-right">
              <view class="introduction-title-CN"> 产品介绍 </view>
              <view class="introduction-title-US"> Product Introduction </view>
            </view>
          </view>
          <view class="introduction-body">
            <view class="introduction-body-box">
              <view class="body-box-title"> 独家亮点 </view>
              <view class="introduction-body-row"><span class="highHight-text">低至1000元</span>起访谈优质专家</view>
              <view class="introduction-body-row">重点公司小范围交流<span class="highHight-text">破圈</span>参加</view>
              <view class="introduction-body-row"><span class="highHight-text">海量</span>调研过程及纪要共享</view>
            </view>
            <view class="introduction-body-box">
              <view class="body-box-title"> 优质资源 </view>
              <view class="introduction-body-row"><span class="highHight-text">500+</span>篇/年调研纪要更新，</view>
              <view class="introduction-body-row"><span class="highHight-text">300+</span>场/年海内外重点公司小范围交流，</view>
              <view class="introduction-body-row"><span class="highHight-text">100+</span>场/年热点线下调研，</view>
              <view class="introduction-body-row"><span class="highHight-text">30000+</span>名优质行业专家长期合作，</view>
              <view class="introduction-body-row"><span class="highHight-text">1000+</span>名优秀买方汇集，</view>
            </view>
            <view class="introduction-body-box">
              <view class="body-box-title" style="margin-bottom: 18rpx"> 服务报价 </view>
              <view class="body-row-content">
                <view class="body-row-title"> 3万/年 </view>
                <view class="introduction-body-row">含无限量调研纪要查阅</view>
                <view class="introduction-body-row"><span class="highHight-text">以及3次</span>公开专家访谈；</view>
              </view>
              <view class="body-row-content">
                <view class="body-row-title"> 5万/年 </view>
                <view class="introduction-body-row">含无限量调研纪要查阅</view>
                <view class="introduction-body-row"> <span class="highHight-text">以及15次</span>公开专家访谈<span class="highHight-text">或30次</span>重点公司、专家小范围交流； </view>
              </view>
              <view class="body-row-content" style="margin-bottom: 0">
                <view class="body-row-title"> 10万/年 </view>
                <view class="introduction-body-row">含无限量调研纪要查阅</view>
                <view class="introduction-body-row">
                  <span class="highHight-text">以及40次</span>公开专家访谈 <span class="highHight-text">或80次</span>重点公司、专家小范围交流 <span class="highHight-text">或20次</span>私享专家一对一。
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </block>
  </view>
</template>

<script>
import { purchaserApi, User } from "@/config/api";
export default {
  data() {
    return {
      detailDataForm: "",
      detailId: 0,
      readTiem: 0,
      setIntervalTiem: null,
    };
  },
  methods: {
    previewImageMediahandler(key) {
      uni.previewImage({
        urls: [key], //查看图片的数组
      });
    },
    // 获取专栏详情
    async getDetaliData() {
      const res = await purchaserApi.yanxuanSpecialDetail({
        Id: this.detailId,
      });
      if (res.Ret === 200) {
        this.detailDataForm = res.Data;
        let str = this.detailDataForm.Type == 1 ? "笔记" : "观点";
        wx.setNavigationBarTitle({
          title: `${str}详情`,
        });
      }
    },
    // 数据处理
    dataProcessing(item) {
      return item ? item.split(",") : [];
    },
    // 收藏
    async collectHandler(type) {
      await this.$store.dispatch("checkHandle");
      if (!this.$store.state.isAuth && !this.$store.state.isBind) {
        const res = await purchaserApi.yanxuanSpecialCollect({
          Id: this.detailDataForm.Id,
          Status: type,
        });
        if (res.Ret === 200) {
          this.$util.toast(res.Msg);
          this.getDetaliData();
        }
      }
    },
    // 去往预览文件
    goFilePages(item) {
      wx.downloadFile({
        // 示例 url，并非真实存在
        url: item.DocUrl,
        success: function (res) {
          const filePath = res.tempFilePath;
          wx.openDocument({
            filePath: filePath,
          });
        },
      });
    },
    goDetailPages() {
      uni.navigateTo({ url: "/pages-purchaser/columnDetail/columnDetail?id=" + this.detailDataForm.UserId });
    },
    /* 无权限申请开通权限 */
    applyAuth() {
      /* 区分是否是潜在用户 */
      this.detailDataForm.HasPermission === 2
        ? User.applyTry({
            ApplyMethod: 3,
            TryType: "Article",
            DetailId: this.detailId,
          }).then((res) => {
            if (res.Ret === 200) {
              uni.navigateTo({
                url: "/pageMy/applyResult/applyResult",
              });
            }
          })
        : this.detailDataForm.HasPermission === 4
        ? uni.navigateTo({
            url: "/pageMy/applyTrial/applyTrial?tryType=Article&detailId=" + this.detailId,
          })
        : uni.showModal({
            title: "",
            content: "您已经提交过申请了，请耐心等待",
            showCancel: false,
            confirmColor: "#365595",
            success: function (res) {},
          });
    },

    // 销售的立即申请
    sellerApplyAuth() {
      User.applyTry({
        TryType: "Article",
        DetailId: this.id,
      }).then((res) => {
        if (res.Ret === 200) {
          uni.showModal({
            title: "",
            content: "提交申请成功，请耐心等待",
            showCancel: false,
            confirmColor: "#365595",
            success: function (res) {
              this.backIndex();
            },
          });
        }
      });
    },

    // 返回首頁
    backIndex() {
      uni.navigateBack({
        fail() {
          uni.switchTab({
            url: "/pages/index/index",
          });
        },
      });
    },
  },
  onLoad(options) {
    this.detailId = Number(options.id) || 0;
    this.detailId > 0 && this.getDetaliData();
  },
  onShow() {
    this.readTiem = 0;
    this.setIntervalTiem = setInterval(() => {
      this.readTiem++;
    }, 1000);
  },
  onHide() {
    //页面退出
    if (this.detailId && this.detailId > 0) {
      clearInterval(this.setIntervalTiem);
      purchaserApi
        .YanxuanSpecialRecord({
          SpecialId: this.detailId,
          StopTime: this.readTiem,
        })
        .then((res) => {});
    }
  },
  onUnload() {
    if (this.detailId && this.detailId > 0) {
      //页面返回
      clearInterval(this.setIntervalTiem);
      purchaserApi
        .YanxuanSpecialRecord({
          SpecialId: this.detailId,
          StopTime: this.readTiem,
        })
        .then((res) => {});
    }
  },
  /** 用户点击分享 */
  onShareAppMessage: function (res) {
    return {
      title: this.detailDataForm.Title,
      path: "/pages-purchaser/noteAndViewpoint/noteAndViewpoint?id=" + this.detailId,
    };
  },
};
</script>

<style lang="scss" scope>
.note-and-viewpoint {
  padding: 30rpx;
  background: $uni-bg-color;
  .content-item {
    padding: 40rpx;
    background-color: #fff;
    .type-time {
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: #666666;
      .type {
        width: 110rpx;
        height: 42rpx;
        line-height: 42rpx;
        text-align: center;
        border-radius: 38rpx;
        color: #928563;
        background-color: #fff6de;
        font-weight: 500;
      }
    }
    .title-item {
      margin: 10rpx 0 20rpx;
      line-height: 46rpx;
    }
    .file-item {
      width: 100%;
      height: 42rpx;
      margin: 20rpx 0;
      display: flex;
      align-items: center;
      background-color: #f8f8fa;
      color: #376cbb;
      image {
        margin-right: 15rpx;
        width: 27rpx;
        height: 27rpx;
      }
    }
    .text-conten {
      font-size: 32rpx;
      line-height: 44rpx;
    }
    .image-conten {
      display: flex;
      flex-wrap: wrap;
      image {
        width: 144rpx;
        height: 144rpx;
        margin-right: 20rpx;
      }
    }
    .lable-conten {
      display: flex;
      flex-wrap: wrap;
      margin: 20rpx 0;
      font-size: 24rpx;
      .item {
        display: flex;
        align-items: center;
        height: 34rpx;
        border-radius: 44rpx;
        padding: 0 35rpx;
        background-color: #f0f1f3;
        margin: 0 20rpx 20rpx 0;
      }
    }

    .author-name {
      display: flex;
      align-items: center;
      margin-bottom: 50rpx;
      .img-box {
        width: 48rpx;
        height: 48rpx;
        overflow: hidden;
        font-size: 28rpx;
        color: #333;
        image {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  .collect-conten {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20rpx 0 10rpx;
    background-color: #fff;
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #666666;
    font-size: 24rpx;
    line-height: 28rpx;
    image {
      display: inline-block;
      flex-shrink: 0;
      width: 44rpx;
      height: 44rpx;
    }
  }
  .statement-content {
    margin-top: 20rpx;
    padding-bottom: 200rpx;
    font-size: 28rpx;
    line-height: 48rpx;
    color: #666;
    text {
      font-weight: 500;
      font-size: 34rpx;
      line-height: 48rpx;
    }
  }
  .please-login {
    margin: 50rpx auto 150rpx;
    width: 556rpx;
    height: 64rpx;
    color: #fff;
    font-size: 24rpx;
    font-weight: 600;
    background-color: #376cbb;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9rpx;
  }
}
</style>
