// components/production/production.js

var http = require('../../utils/http.js');

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item:Object,
    sts:Number,
    showCancelCollect: Boolean, // 是否展示取消收藏按钮
  },


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

  },

  /**
   * 组件的方法列表
   */
  methods: {
    toProdPage: function (e) {
      var prodid = e.currentTarget.dataset.prodid;
      wx.navigateTo({
        url: '/pages/prod/prod?prodid=' + prodid,
      })
    },
    handleCancelCollection(e) {
      var prodid = e.currentTarget.dataset.prodid;
      wx.showLoading()
      var params = {
        url: "/p/user/collection/addOrCancel",
        method: "POST",
        data: prodid,
        callBack: (res) => {
          wx.hideLoading()
          wx.showToast({
            title: res? '已添加收藏' : '已取消收藏',
            duration: 1200,
            icon: 'none',
            complete: com =>{
              setTimeout(()=>{
                this.triggerEvent('getCollectionProd')
              },500)
            }
          })
        }
      };
      http.request(params);
    }
  }
})
