var app = getApp();
var $ = require('../../../js/util.js');
Page({
  data: {
    data: [],
    catname:'',
    param: {
      id: 0
    },
    hasMore: false,//无更多数据提示
    dataNull: true//未获取到数据提示
  },
  onLoad: function (options) {//接收上个页面传的参数
    if (options.invite_key) {
      app.globalData.invite_key = options.invite_key;
    }
    if (options.id) {
      this.setData({
        param: {
          id: options.id
        },
        id: options.id
      });
    }
  },
  onReady: function () {
    //初始化数据
    var self = this;
    self.getIndex();
  },
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      param: {},
      hasMore: false,
      dataNull: true
    });
    this.getIndex();
  },
  getIndex: function () {
    var self = this;
    var action = 'c=Article&a=article_cont';
    app.showLoading('加载中...');
    app.ajaxRequest(action, 'GET', $.ObjectToStr(self.data.param), function (ret) {
      if (ret.status == 1) {
        if (ret.data.content.content){
          ret.data.content.content = ret.data.content.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ')
        }
        self.setData({
          data: ret.data.content
        });
        
        if (ret.data.catname != '') {
          app.HCsetNavigationBarTitle(ret.data.catname);
        }
      } else {
        app.HCerror(ret.msg);
      }
    });
  },
    //分享
  onshare:function(){
    wx.showShareMenu({
      widthShareTicket:true
    })
  },
  onShareAppMessage:function(){
    var self = this;
    return {
      title: self.data.catename,
      desc: self.data.data.addtime,
      path: '/' + $.getCurrentPageUrl() + '?invite_key=' + app.globalData.init_invite_key + '&id=' + this.data.param.id+'&lshop_id='+app.globalData.lshop_id
    }
  },
})