footprint.js 2.3 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. onPullDownRefresh(){
  9. // 增加下拉刷新数据的功能
  10. var self = this;
  11. this.getFootprintList();
  12. },
  13. getFootprintList() {
  14. let that = this;
  15. var tmpFootPrint;
  16. util.request(api.FootprintList).then(function (res) {
  17. if (res.code === 0) {
  18. if (res.data.data != undefined){
  19. tmpFootPrint = res.data.data;
  20. } else {
  21. tmpFootPrint = [];
  22. }
  23. that.setData({
  24. footprintList: tmpFootPrint
  25. });
  26. }
  27. });
  28. getApp().onPullDownRefresh()
  29. },
  30. deleteItem (event){
  31. let that = this;
  32. let footprint = event.currentTarget.dataset.footprint;
  33. var touchTime = that.data.touch_end - that.data.touch_start;
  34. //如果按下时间大于350为长按
  35. if (touchTime > 350) {
  36. wx.showModal({
  37. title: '',
  38. content: '要删除所选足迹?',
  39. success: function (res) {
  40. if (res.confirm) {
  41. util.request(api.FootprintDelete, { footprintId: footprint.id }).then(function (res) {
  42. if (res.code === 0) {
  43. wx.showToast({
  44. title: res.errmsg,
  45. icon: 'success',
  46. duration: 2000,
  47. complete:function(){
  48. that.getFootprintList();
  49. }
  50. });
  51. } else{
  52. util.showErrorToast(res.errmsg);
  53. }
  54. });
  55. }
  56. }
  57. });
  58. } else {
  59. wx.navigateTo({
  60. url: '/pages/goods/goods?id=' + footprint.goods_id,
  61. });
  62. }
  63. },
  64. onLoad: function (options) {
  65. getApp().checkNetStatu();
  66. this.getFootprintList();
  67. },
  68. onReady: function () {
  69. },
  70. onShow: function () {
  71. },
  72. onHide: function () {
  73. // 页面隐藏
  74. },
  75. onUnload: function () {
  76. // 页面关闭
  77. },
  78. //按下事件开始
  79. touchStart: function (e) {
  80. let that = this;
  81. that.setData({
  82. touch_start: e.timeStamp
  83. })
  84. },
  85. //按下事件结束
  86. touchEnd: function (e) {
  87. let that = this;
  88. that.setData({
  89. touch_end: e.timeStamp
  90. })
  91. },
  92. })