collect.js 2.3 KB

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