<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="detailDataForm.Content" />
      </view>
      <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>
    </view>
    <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>
    <Loading />
  </view>
  <view class="nodata" v-else>
    <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
    <text>报告加急审核中，请耐心等待～</text>
  </view>
</template>

<script>
import { purchaserApi } from "@/config/api";
export default {
  data() {
    return {
      detailDataForm: "",
      detailId: 0,
    };
  },
  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,
            success: function (res) {
              console.log("打开文档成功");
            },
          });
        },
      });
    },
    goDetailPages() {
      uni.navigateTo({ url: "/pages-purchaser/columnDetail/columnDetail?id=" + this.detailDataForm.UserId });
    },
  },
  onLoad(options) {
    this.detailId = Number(options.id) || 0;
    this.detailId > 0 && this.getDetaliData();
  },
  /** 用户点击分享 */
  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;
    }
  }
}
</style>
