orders.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const WXAPI = require('apifm-wxapi')
  2. const APP = getApp()
  3. // fixed首次打开不显示标题的bug
  4. APP.configLoadOK = () => {
  5. }
  6. var timer
  7. Page({
  8. data: {
  9. },
  10. onLoad: function (options) {
  11. this.data.status = options.status
  12. if (this.data.status == -1) {
  13. timer =setInterval(() => {
  14. this.peisongOrdersGrabbing()
  15. }, 1000)
  16. }
  17. },
  18. onShow: function () {
  19. if (this.data.status != -1) {
  20. this.orders()
  21. }
  22. },
  23. onUnload() {
  24. if (timer) {
  25. clearTimeout(timer)
  26. }
  27. },
  28. async orders() {
  29. wx.showLoading({
  30. title: '',
  31. })
  32. const _data = {
  33. token: wx.getStorageSync('token'),
  34. }
  35. if(this.data.status) {
  36. _data.statusBatch = this.data.status
  37. _data.refundStatusBatch = '0,2'
  38. } else {
  39. _data.uid = wx.getStorageSync('uid')
  40. }
  41. const res = await WXAPI.peisongOrders(_data)
  42. wx.hideLoading({
  43. complete: (res) => {},
  44. })
  45. if (res.code != 0) {
  46. wx.showToast({
  47. title: res.msg,
  48. icon: 'none'
  49. })
  50. this.setData({
  51. orderList: null
  52. })
  53. } else {
  54. res.data.result.forEach(ele => {
  55. if (ele.status == 2) {
  56. ele.statusStr = '已接单'
  57. }
  58. if (ele.status == 3) {
  59. ele.statusStr = '配送中'
  60. }
  61. })
  62. this.setData({
  63. orderList: res.data.result
  64. })
  65. }
  66. },
  67. async peisongOrdersGrabbing() {
  68. // wx.showLoading({
  69. // title: '',
  70. // })
  71. const res = await WXAPI.peisongOrdersGrabbing(wx.getStorageSync('token'))
  72. // wx.hideLoading({
  73. // complete: (res) => {},
  74. // })
  75. if (res.code != 0) {
  76. // wx.showToast({
  77. // title: res.msg,
  78. // icon: 'none'
  79. // })
  80. this.setData({
  81. orderList: null
  82. })
  83. } else {
  84. res.data.forEach(ele => {
  85. if (ele.status == 2) {
  86. ele.statusStr = '已接单'
  87. }
  88. if (ele.status == 3) {
  89. ele.statusStr = '服务中'
  90. }
  91. })
  92. this.setData({
  93. orderList: res.data
  94. })
  95. }
  96. },
  97. })