1
0

collect.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. let that = this;
  27. // 页面显示
  28. if (wx.getStorageSync('userInfo') && wx.getStorageSync('token')) {
  29. if (wx.getStorageSync('storeId')) {
  30. util.request(api.ChooseStoreId, {
  31. storeId: wx.getStorageSync('storeId'),
  32. merchSn: wx.getStorageSync('merchSn'),
  33. isRefusedLogin: wx.getStorageSync('isRefusedLogin')
  34. }, 'POST').then(function (res) {
  35. if (res.errno === 0) {
  36. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  37. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  38. }
  39. });
  40. this.getCollectList();
  41. }
  42. } else {
  43. wx.navigateTo({
  44. url: '/pages/ucenter/userLogin/userLogin'
  45. })
  46. }
  47. },
  48. onHide: function () {
  49. // 页面隐藏
  50. },
  51. onUnload: function () {
  52. // 页面关闭
  53. },
  54. openGoods(event) {
  55. let that = this;
  56. let goodsId = this.data.collectList[event.currentTarget.dataset.index].value_id;
  57. //触摸时间距离页面打开的毫秒数
  58. var touchTime = that.data.touch_end - that.data.touch_start;
  59. //如果按下时间大于350为长按
  60. if (touchTime > 350) {
  61. wx.showModal({
  62. title: '',
  63. content: '确定删除吗?',
  64. success: function (res) {
  65. if (res.confirm) {
  66. util.request(api.CollectAddOrDelete, { typeId: that.data.typeId, valueId: goodsId}, 'POST').then(function (res) {
  67. if (res.errno === 0) {
  68. console.log(res.data);
  69. wx.showToast({
  70. title: '删除成功',
  71. icon: 'success',
  72. duration: 2000
  73. });
  74. that.getCollectList();
  75. }
  76. });
  77. }
  78. }
  79. })
  80. } else {
  81. wx.navigateTo({
  82. url: '/pages/goods/goods?id=' + goodsId,
  83. });
  84. }
  85. },
  86. //按下事件开始
  87. touchStart: function (e) {
  88. let that = this;
  89. that.setData({
  90. touch_start: e.timeStamp
  91. })
  92. console.log(e.timeStamp + '- touch-start')
  93. },
  94. //按下事件结束
  95. touchEnd: function (e) {
  96. let that = this;
  97. that.setData({
  98. touch_end: e.timeStamp
  99. })
  100. console.log(e.timeStamp + '- touch-end')
  101. },
  102. })