footprint.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. },
  8. getFootprintList() {
  9. let that = this;
  10. util.request(api.FootprintList).then(function (res) {
  11. if (res.errno === 0) {
  12. if (res.data.data) {
  13. that.setData({
  14. footprintList: res.data.data
  15. });
  16. }
  17. }
  18. });
  19. },
  20. deleteItem (event){
  21. let that = this;
  22. let footprint = event.currentTarget.dataset.footprint;
  23. var touchTime = that.data.touch_end - that.data.touch_start;
  24. //如果按下时间大于350为长按
  25. if (touchTime > 350) {
  26. wx.showModal({
  27. title: '',
  28. content: '要删除所选足迹?',
  29. success: function (res) {
  30. if (res.confirm) {
  31. util.request(api.FootprintDelete, { footprintId: footprint.id }, 'POST').then(function (res) {
  32. if (res.errno === 0) {
  33. wx.showToast({
  34. title: '删除成功',
  35. icon: 'success',
  36. duration: 2000
  37. });
  38. that.getFootprintList();
  39. }
  40. });
  41. console.log('用户点击确定')
  42. }
  43. }
  44. });
  45. } else {
  46. wx.navigateTo({
  47. url: '/pages/goods/goods?id=' + footprint.goods_id + '&&storeId=' + footprint.storeId,
  48. });
  49. }
  50. },
  51. onLoad: function (options) {
  52. this.getFootprintList();
  53. },
  54. onReady: function () {
  55. },
  56. onShow: function () {
  57. let that = this;
  58. // 页面显示
  59. if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
  60. if (wx.getStorageSync('storeId')) {
  61. util.request(api.ChooseStoreId, {
  62. storeId: wx.getStorageSync('storeId'),
  63. merchSn: wx.getStorageSync('merchSn')
  64. }, 'POST').then(function (res) {
  65. if (res.errno === 0) {
  66. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  67. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  68. }
  69. });
  70. }
  71. }
  72. },
  73. onHide: function () {
  74. // 页面隐藏
  75. },
  76. onUnload: function () {
  77. // 页面关闭
  78. },
  79. //按下事件开始
  80. touchStart: function (e) {
  81. let that = this;
  82. that.setData({
  83. touch_start: e.timeStamp
  84. })
  85. console.log(e.timeStamp + '- touch-start')
  86. },
  87. //按下事件结束
  88. touchEnd: function (e) {
  89. let that = this;
  90. that.setData({
  91. touch_end: e.timeStamp
  92. })
  93. console.log(e.timeStamp + '- touch-end')
  94. },
  95. })