collect.js 2.0 KB

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