/*
 * @Descripttion: HJ
 * @Company: 思宏科技
 * @version: v1.0
 * @Author: HJ
 * @Date: 2021-07-01 20:08:37
 * @LastEditors: HJ
 * @LastEditTime: 2021-07-01 21:29:28
 */
import { formatRichText } from "../../utils/tool";
import { fhGetArticle } from "../../api/hospital/index";

const pageOptions = {
  // 页面数据
  data: {
    isFirstOnShow: true, // 是否为首次执行onShow
    article: {},
    loading: false
  },
  // 页面载入时
  onLoad(e) {
    this.init(e);
  },
  // 页面初始化
  init(e) {
    const { id } = e;
    this.articleId = id;
    wx.nextTick(() => {
      this.getArticle();
    });
  },
  // 页面显示时
  onShow() {
    const { isFirstOnShow } = this.data;

    if (isFirstOnShow) {
      // 首次执行时
      this.setData({
        isFirstOnShow: false,
      });
      return;
    }
  },
  // 下拉页面时
  onPullDownRefresh() {
    this.getArticle()
  },
  // 分享时，注：onShareAppMessage不能为async异步函数，会导致不能及时取得返回值，使得分享设置无效
  onShareAppMessage() {
    /* const title = ''
    const path = ''
    const imageUrl = ``

    return {
      title,
      path,
      imageUrl,
    } */
  },
  // 获取文章详情
  async getArticle() {
    this.setData({loading: true})
    try {
      let { results } = await fhGetArticle(this.articleId);
      results.content = formatRichText(results.content);
      this.setData({
        article: results,
      });
      wx.stopPullDownRefresh()
    } catch (e) {
      console.log("debug axios", e);
    }
    this.setData({loading: false})
  },
};

Page(pageOptions);
