<template>
  <view class="column-list-content-detail">
    <block v-if="mySpecialList && mySpecialList.length">
      <view class="content-item" v-for="item in mySpecialList" :key="item.Id">
        <view class="author-box" @click="goDetailPages(item)">
          <image :src="item.HeadImg"></image>
          {{ item.NickName }}
        </view>
        <view class="type-time">
          <view class="type">{{ item.Type == 1 ? "笔 记" : "观 点" }} </view>
          <view class="time"> {{ item.PublishTime }}</view>
        </view>
        <view class="title-item global_title"> {{ item.Title }}</view>
        <view class="text-conten" v-if="item.Content">
          <mp-html :content="richTextSlicing(item.Content)" />
        </view>
        <view class="look-all-box" v-if="item.Content.length > 150 || item.ContentHasImg">
          <view class="look-all" @click="goDetail(item)"> 查看全文 </view>
        </view>
        <block v-if="item.Docs && item.Docs.length > 0">
          <view @click="goFilePages(key)" class="file-item text_oneLine" v-for="(key, index) in item.Docs" :key="index"> <image :src="key.DocIcon"></image>{{ key.DocName }}</view>
        </block>
        <view class="image-conten">
          <image v-for="key in dataProcessing(item.ImgUrl)" :key="key" :src="key" @click="previewImageMediahandler(key)"></image>
        </view>
        <view class="lable-conten">
          <view class="item" v-for="key in dataProcessing(item.Tags)" :key="key">{{ key }}</view>
        </view>
        <view class="collect-conten">
          <image @click="collectHandler(2, item)" v-if="item.IsCollect == 1" src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/collect_act.png"></image>
          <image @click="collectHandler(1, item)" v-else src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/collect_icon.png"></image>
          {{ item.CollectNum }}
        </view>
      </view>
    </block>
    <view class="nodata" v-else>
      <image src="https://hzchart.oss-cn-shanghai.aliyuncs.com/cygx/czbk/act_search.png" mode="" class="nodata_ico"></image>
      <view class="nodata-text">还没有发布过内容</view>
    </view>
    <Loading />
  </view>
</template>

<script>
import { purchaserApi } from "@/config/api";
export default {
  props: {
    authorDetail: {
      type: Object,
      default: {},
    },
    mySpecialList: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {};
  },
  methods: {
    previewImageMediahandler(key) {
      uni.previewImage({
        urls: [key], //查看图片的数组
      });
    },
    // 数据处理
    dataProcessing(item) {
      return item ? item.split(",") : [];
    },
    //
    richTextSlicing(val) {
      let str = val.length >= 150 ? val.slice(0, 150) + " ..." : val;
      return str;
    },
    // 去往详情
    goDetail(item) {
      uni.navigateTo({ url: "/pages-purchaser/noteAndViewpoint/noteAndViewpoint?id=" + item.Id });
    },
    // 收藏取消收藏
    async collectHandler(type, item) {
      await this.$store.dispatch("checkHandle");
      if (!this.$store.state.isAuth && !this.$store.state.isBind) {
        //已授权已绑定
        const res = await purchaserApi.yanxuanSpecialCollect({
          Id: item.Id,
          Status: type,
        });
        if (res.Ret === 200) {
          this.$util.toast(res.Msg);
          // item.CollectNum = item.IsCollect == 1 ? item.CollectNum - 1 : item.CollectNum + 1;
          // item.IsCollect = item.IsCollect == 1 ? 0 : 1;
          this.$emit("upDateCollectHandler", item);
        }
      }
    },
    // 去往预览文件
    goFilePages(item) {
      wx.downloadFile({
        // 示例 url，并非真实存在
        url: item.DocUrl,
        success: function (res) {
          const filePath = res.tempFilePath;
          wx.openDocument({
            filePath: filePath,
          });
        },
      });
    },
    // 去往专栏详情
    goDetailPages(item) {
      uni.navigateTo({ url: "/pages-purchaser/columnDetail/columnDetail?id=" + item.UserId });
    },
  },
};
</script>

<style lang="scss" scope>
.column-list-content-detail {
  position: relative;
  padding: 50rpx 40rpx;
  background: #fff;
  .text-conten {
    width: 100%;
    font-size: 32rpx;
    line-height: 40rpx;
  }

  .introduce-detail {
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: justify;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    position: relative;
    &.expand {
      -webkit-line-clamp: 999;
      height: auto;
    }
    .expan-btn-sl {
      position: absolute;
      bottom: 0;
      right: 0;
      background-color: #fff;
      padding: 2rpx 0 2rpx 8rpx;
      z-index: 9;
    }
  }
  .expan-btn {
    margin-top: 15rpx;
    color: #2c83ff;
    text-align: right;
    position: relative;
    &.pos {
      padding: 0 0 0 40rpx;
      background-color: rgba(255, 255, 255, 0.882);
      position: absolute;
      right: 0;
      bottom: 0;
    }
  }
  .content-item {
    padding: 40rpx 0;
    border-bottom: 1px solid #f0f1f3;
    .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 {
        width: 27rpx;
        height: 27rpx;
        margin-right: 15rpx;
      }
    }
    .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-content: center;
        height: 34rpx;
        border-radius: 44rpx;
        padding: 0 35rpx;
        background-color: #f0f1f3;
        margin: 0 20rpx 20rpx 0;
      }
    }
    .collect-conten {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      color: #666666;
      image {
        width: 27rpx;
        height: 26rpx;
        margin-right: 8rpx;
      }
    }
    .look-all-box {
      display: flex;
      justify-content: flex-end;
    }
    .look-all {
      width: 160rpx;
      height: 52rpx;
      border-radius: 150rpx;
      text-align: center;
      line-height: 52rpx;
      font-size: 28rpx;
      color: #fff;
      background-color: #376cbb;
      margin: 20rpx 0;
    }
  }
  .nodata-text {
    color: #999;
    text-align: center;
    margin-top: -80rpx;
    font-size: 24rpx;
  }
  .author-box {
    display: flex;
    align-items: center;
    margin-bottom: 25rpx;
    font-size: 28rpx;
    color: #333;
    line-height: 40rpx;
    image {
      display: inline-block;
      width: 48rpx;
      height: 48rpx;
      border-radius: 50%;
      margin-right: 10rpx;
      overflow: hidden;
    }
  }
}
</style>
