var Api = require("../../../utils/util.js");
Page({
  data: {
    detail:{}
  },
  onLoad: function(options) {
    if(options.id){
      this.setData({
        id: options.id,
      })
    }
    var that = this,    
    data = {
      id: options.id,
      readId: wx.getStorageSync('userId'),
    }
    wx.showLoading({
      title: '加载中...',
    })   
    Api.req('sf/platformAnnouncement/detail', data, 'get')
      .then(res => {
        wx.hideLoading()
        if(res.code == 200){
          var html = res.data.html
          html = html.replace('<img','<img style="max-width:100%;height:auto;margin:0 auto;display:block"')
          that.setData({
            detail: res.data,
            html
          })
          if(!res.data.bid){
            this.readFun()
          }
        }else{
          wx.showToast({
            title: res.msg,
            icon: 'none'
          })
        }  
      })    
  },
  //已读
  readFun(){
  Api.req('sf/announcementReadinfo/save', {
    platformAnnouncementId: this.data.id,
    readId: wx.getStorageSync('userId'),
    reader: wx.getStorageSync('name'),
  }, 'post','','1')
    .then(res => {
      if(res.code == 200){
        
      }else{
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }  
    })
  }
})