img-box.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var app = getApp();
  2. Component({
  3. properties: {
  4. item: {
  5. type: Object
  6. }
  7. },
  8. methods: {
  9. agree: function() {
  10. let that = this;
  11. let item = this.data.item;
  12. let token = wx.getStorageSync('token');
  13. app.util.request({
  14. 'url': 'entry/wxapp/index',
  15. 'data': {
  16. controller: 'recipe.fav_recipe_do',
  17. token: token,
  18. id: item.id
  19. },
  20. dataType: 'json',
  21. success: function (res) {
  22. if(res.data.code == 0) {
  23. //成功
  24. wx.showToast({
  25. title: '已喜欢~',
  26. icon: 'none'
  27. })
  28. item.fav_count = res.data.fav_count;
  29. item.has_fav = 1;
  30. that.setData({ item })
  31. } else if (res.data.code == 1) {
  32. //未登录
  33. that.triggerEvent('needAuth');
  34. } else if (res.data.code == 2) {
  35. //取消收藏
  36. item.fav_count = res.data.fav_count;
  37. item.has_fav = 0;
  38. that.setData({ item })
  39. wx.showToast({
  40. title: '取消喜欢~',
  41. icon: 'none'
  42. })
  43. }
  44. }
  45. })
  46. },
  47. goDetails: function(e){
  48. let id = e.currentTarget.dataset.id || '';
  49. let url = `/lionfish_comshop/moduleA/menu/details?id=${id}`
  50. var pages_all = getCurrentPages();
  51. if (pages_all.length > 3) {
  52. id && wx.redirectTo({ url })
  53. } else {
  54. id && wx.navigateTo({ url })
  55. }
  56. }
  57. }
  58. })