fav.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. Page({
  4. data: {
  5. },
  6. onLoad: function (options) {
  7. },
  8. onShow: function () {
  9. AUTH.checkHasLogined().then(isLogined => {
  10. this.setData({
  11. wxlogin: isLogined
  12. })
  13. if (isLogined) {
  14. this.goodsFavList()
  15. }
  16. })
  17. },
  18. async goodsFavList() {
  19. // 搜索商品
  20. wx.showLoading({
  21. title: '加载中',
  22. })
  23. const _data = {
  24. token: wx.getStorageSync('token'),
  25. page: 1,
  26. pageSize: 10000,
  27. }
  28. const res = await WXAPI.goodsFavList(_data)
  29. wx.hideLoading()
  30. if (res.code == 0) {
  31. this.setData({
  32. goods: res.data,
  33. })
  34. } else {
  35. this.setData({
  36. goods: null
  37. })
  38. }
  39. },
  40. async removeFav(e){
  41. const id = e.currentTarget.dataset.id
  42. const res = await WXAPI.goodsFavDelete(wx.getStorageSync('token'), '', id)
  43. if (res.code == 0) {
  44. wx.showToast({
  45. title: '取消收藏',
  46. icon: 'success'
  47. })
  48. this.goodsFavList()
  49. } else {
  50. wx.showToast({
  51. title: res.msg,
  52. icon: 'none'
  53. })
  54. }
  55. },
  56. })