1
0

collect.js 2.6 KB

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