footprint.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. Page({
  5. data: {
  6. footprintList: [],
  7. page: 1,
  8. limit: 10,
  9. totalPages: 1
  10. },
  11. getFootprintList() {
  12. wx.showLoading({
  13. title: '加载中...',
  14. });
  15. let that = this;
  16. util.request(api.FootprintList, {
  17. page: that.data.page,
  18. limit: that.data.limit
  19. }).then(function(res) {
  20. if (res.errno === 0) {
  21. let f1 = that.data.footprintList;
  22. let f2 = res.data.list;
  23. for (let i = 0; i < f2.length; i++) {
  24. f2[i].addDate = f2[i].addTime.substring(0, 10)
  25. let last = f1.length - 1;
  26. if (last >= 0 && f1[last][0].addDate === f2[i].addDate) {
  27. f1[last].push(f2[i]);
  28. } else {
  29. let tmp = [];
  30. tmp.push(f2[i])
  31. f1.push(tmp);
  32. }
  33. }
  34. that.setData({
  35. footprintList: f1,
  36. totalPages: res.data.pages
  37. });
  38. }
  39. wx.hideLoading();
  40. });
  41. },
  42. deleteItem(event) {
  43. let that = this;
  44. let index = event.currentTarget.dataset.index;
  45. let iindex = event.currentTarget.dataset.iindex;
  46. let footprintId = this.data.footprintList[index][iindex].id;
  47. let goodsId = this.data.footprintList[index][iindex].goodsId;
  48. var touchTime = that.data.touchEnd - that.data.touchStart;
  49. console.log(touchTime);
  50. //如果按下时间大于350为长按
  51. if (touchTime > 350) {
  52. wx.showModal({
  53. title: '',
  54. content: '要删除所选足迹?',
  55. success: function(res) {
  56. if (res.confirm) {
  57. util.request(api.FootprintDelete, {
  58. id: footprintId
  59. }, 'POST').then(function(res) {
  60. if (res.errno === 0) {
  61. wx.showToast({
  62. title: '删除成功',
  63. icon: 'success',
  64. duration: 2000
  65. });
  66. that.data.footprintList[index].splice(iindex, 1)
  67. if (that.data.footprintList[index].length == 0) {
  68. that.data.footprintList.splice(index, 1)
  69. }
  70. that.setData({
  71. footprintList: that.data.footprintList
  72. });
  73. }
  74. });
  75. }
  76. }
  77. });
  78. } else {
  79. wx.navigateTo({
  80. url: '/pages/goods/goods?id=' + goodsId,
  81. });
  82. }
  83. },
  84. onLoad: function(options) {
  85. this.getFootprintList();
  86. },
  87. onReachBottom() {
  88. if (this.data.totalPages > this.data.page) {
  89. this.setData({
  90. page: this.data.page + 1
  91. });
  92. this.getFootprintList();
  93. } else {
  94. wx.showToast({
  95. title: '没有更多用户足迹了',
  96. icon: 'none',
  97. duration: 2000
  98. });
  99. return false;
  100. }
  101. },
  102. onReady: function() {
  103. },
  104. onShow: function() {
  105. },
  106. onHide: function() {
  107. // 页面隐藏
  108. },
  109. onUnload: function() {
  110. // 页面关闭
  111. },
  112. //按下事件开始
  113. touchStart: function(e) {
  114. let that = this;
  115. that.setData({
  116. touchStart: e.timeStamp
  117. })
  118. console.log(e.timeStamp + '- touchStart')
  119. },
  120. //按下事件结束
  121. touchEnd: function(e) {
  122. let that = this;
  123. that.setData({
  124. touchEnd: e.timeStamp
  125. })
  126. console.log(e.timeStamp + '- touchEnd')
  127. },
  128. })