// pages/user/companyMine/focusedProject/focusedProject.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists: [],
    page: 1,
    has_more: true
  },
  onShow() {
    this.getList();
  },

  // 获取活动列表
  getList() {
    wx.$api.companyModule.getCrowdfundsLike(this.data.page).then(res => {
      setTimeout(() => {
        wx.hideLoading({})
      }, 1000);
      var lists = this.data.lists.concat(res.data)
      if (res.page.has_more) {
        this.setData({
          has_more: res.page.has_more,
          page: this.data.page + 1,
          lists: lists
        })
      } else {
        this.setData({
          has_more: res.page.has_more,
          lists: lists
        })
      }
    })
  },
  // 触底加载更多
  onReachBottom() {
    if (this.data.has_more) {
      this.getList();
    } else {
      wx.showToast({
        icon: 'none',
        title: '没有更多',
      })
    }
  },
  //跳转到详情页 
  goUrl(e) {
    wx.navigateTo({
      url: '/pages/home/activeDetail/activeDetail?id=' + e.currentTarget.dataset.id,
    })
  },
  // 取消项目
  crowdfundsUnLike(e) {
    var id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    var arr = this.data.lists
    var temp = []
    for (var i = 0; i < arr.length; i++) {
      if (i != index) {
        temp.push(arr[i]);
      }
    }
    console.log(temp)
    wx.showModal({
      title: '提示',
      content: '是否确认取消关注',
      success: res => {
        if (res.confirm) {
          wx.showLoading({
            title: '取消中',
          })
          wx.$api.companyModule.crowdfundsUnLike(id).then(res => {
            this.setData({
              lists: temp
            })
            wx.showToast({
              title: '取消成功',
              icon: 'none'
            })
            wx.hideLoading({})
          });
        }
      }
    })
  }
})