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