fav.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. res.data.forEach(ele => {
  32. if (ele.type == 1 && ele.json) {
  33. ele.json = JSON.parse(ele.json)
  34. }
  35. })
  36. this.setData({
  37. goods: res.data,
  38. })
  39. } else {
  40. this.setData({
  41. goods: null
  42. })
  43. }
  44. },
  45. async removeFav(e){
  46. const idx = e.currentTarget.dataset.idx
  47. const fav = this.data.goods[idx]
  48. const res = await WXAPI.goodsFavDeleteV2({
  49. token: wx.getStorageSync('token'),
  50. goodsId: fav.goodsId,
  51. type: fav.type
  52. })
  53. if (res.code == 0) {
  54. wx.showToast({
  55. title: '取消收藏',
  56. icon: 'success'
  57. })
  58. this.goodsFavList()
  59. } else {
  60. wx.showToast({
  61. title: res.msg,
  62. icon: 'none'
  63. })
  64. }
  65. },
  66. })