collect.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. that.setData({
  14. collectList: res.data
  15. });
  16. }
  17. });
  18. },
  19. onLoad: function (options) {
  20. },
  21. onReady: function () {
  22. },
  23. onShow: function () {
  24. this.getCollectList();
  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].value_id;
  35. //触摸时间距离页面打开的毫秒数
  36. var touchTime = that.data.touch_end - that.data.touch_start;
  37. //如果按下时间大于350为长按
  38. if (touchTime > 350) {
  39. wx.showModal({
  40. title: '',
  41. content: '确定删除收藏吗?',
  42. success: function (res) {
  43. if (res.confirm) {
  44. util.request(api.CollectAddOrDelete, { typeId: that.data.typeId, valueId: goodsId}).then(function (res) {
  45. if (res.errno === 0) {
  46. wx.showToast({
  47. title: '删除成功',
  48. icon: 'success',
  49. duration: 2000
  50. });
  51. that.getCollectList();
  52. }
  53. });
  54. }
  55. }
  56. })
  57. } else {
  58. wx.navigateTo({
  59. url: '/pages/goods/goods?id=' + goodsId,
  60. });
  61. }
  62. },
  63. //按下事件开始
  64. touchStart: function (e) {
  65. let that = this;
  66. that.setData({
  67. touch_start: e.timeStamp
  68. })
  69. },
  70. //按下事件结束
  71. touchEnd: function (e) {
  72. let that = this;
  73. that.setData({
  74. touch_end: e.timeStamp
  75. })
  76. },
  77. })