1
0

collect.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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
  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. //如果按下时间大于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, { typeId: that.data.typeId, valueId: goodsId}, '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. })