// packageI/newMedia/components/contentStatisticsBar/contentStatisticsBar.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true
  },
  properties: {
    path: {
      value: "adDetails",
      type: String
    },
    details: {
      value: {},
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    sendLike() {
      let details = this.data.details;
      let id = details.id;
      let urlStr = app.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.like");
      app._getNetWork({
        url: urlStr,
        data: {
          advertisingt_id: id
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result != 1) return app.tips(res.msg);
          let is_like = details.is_like;
          let like_count = is_like ? details.like_count - 1 : details.like_count + 1;
          this.setData({
            'details.is_like': is_like ? false : true,
            'details.like_count': like_count
          });
          this.triggerEvent("like",{is_like,like_count});
          if(res.data.is_reward==1){
            this.triggerEvent("reward",res.data);
          }
        }
      });
    },
    sendFavorites() {
      let details = this.data.details;
      let id = details.id;
      let urlStr = app.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.favorites");
      app._getNetWork({
        url: urlStr,
        data: {
          advertisingt_id: id
        },
        success: (resdata) => {
          var res = resdata.data;
          if (res.result != 1) return app.tips(res.msg);
          let is_favorites = details.is_favorites;
          let favorites_count = is_favorites ? details.favorites_count - 1 : details.favorites_count + 1;
          this.setData({
            'details.is_favorites': is_favorites ? false : true,
            'details.favorites_count': favorites_count
          });
          this.triggerEvent("favorites",{is_favorites,favorites_count});
          if(res.data.is_reward==1){
            this.triggerEvent("reward",res.data);
          }
        }
      });
    },
    //添加转发记录
    addShareRecord() {
      let urlStr = app.getNetAddresss("plugin.new-media-advertising.frontend.media-advertisingt.forward");
      app._getNetWork({
        url: urlStr,
        data: {
          advertisingt_id: this.data.details.id
        },
        success: (resdata) => {}
      });
    },
    handCommentClick(){
      this.triggerEvent('commentClick');
    }
  }
});