collect.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. typeId: 0,
  7. loadding: true,
  8. collectList: []
  9. },
  10. getCollectList() {
  11. let that = this;
  12. that.setData({loadding: true})
  13. util.request(api.CollectList, { typeId: that.data.typeId}).then(function (res) {
  14. if (res.code === 0) {
  15. that.setData({
  16. collectList: res.data,
  17. loadding: false
  18. });
  19. }
  20. });
  21. },
  22. onLoad: function (options) {
  23. getApp().checkNetStatu();
  24. },
  25. onReady: function () {
  26. },
  27. onShow: function () {
  28. this.getCollectList();
  29. },
  30. onHide: function () {
  31. // 页面隐藏
  32. },
  33. onUnload: function () {
  34. // 页面关闭
  35. },
  36. openGoods(event) {
  37. let that = this;
  38. let goodsId = this.data.collectList[event.currentTarget.dataset.index].value_id;
  39. //触摸时间距离页面打开的毫秒数
  40. var touchTime = that.data.touch_end - that.data.touch_start;
  41. //如果按下时间大于350为长按
  42. if (touchTime > 350) {
  43. wx.showModal({
  44. title: '',
  45. content: '确定删除收藏吗?',
  46. success: function (res) {
  47. if (res.confirm) {
  48. util.request(api.CollectAddOrDelete, { typeId: that.data.typeId, valueId: goodsId}).then(function (res) {
  49. if (res.code === 0) {
  50. wx.showToast({
  51. title: '删除成功',
  52. icon: 'success',
  53. duration: 2000
  54. });
  55. that.getCollectList();
  56. }
  57. });
  58. }
  59. }
  60. })
  61. } else {
  62. wx.navigateTo({
  63. url: '/pages/goods/goods?id=' + goodsId,
  64. });
  65. }
  66. },
  67. //按下事件开始
  68. touchStart: function (e) {
  69. let that = this;
  70. that.setData({
  71. touch_start: e.timeStamp
  72. })
  73. },
  74. //按下事件结束
  75. touchEnd: function (e) {
  76. let that = this;
  77. that.setData({
  78. touch_end: e.timeStamp
  79. })
  80. },
  81. })