model.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import request from '../utils/RequestUtils';
  2. import { toastShow, toastInfo, toastSuccess } from '../utils/SystemUtils';
  3. import MapModel from '../map/model';
  4. const OrderMap = (now) => ({
  5. receiverOrder(orderId, successEvent) {
  6. toastShow();
  7. request
  8. .get('/rider/receiver', {
  9. params: {
  10. orderId,
  11. pass: true,
  12. },
  13. })
  14. .then((res) => {
  15. if (successEvent) {
  16. successEvent(res);
  17. }
  18. })
  19. .catch((e) => {
  20. toastInfo(e.error);
  21. });
  22. },
  23. changeStatus(orderId, status, successEvent, errorEvent, pickImg) {
  24. toastShow();
  25. const { pickupPhotos } = now();
  26. if (status === 'TAKE_MEAL') {
  27. pickupPhotos(orderId, status, successEvent, errorEvent, pickImg);
  28. return;
  29. }
  30. const { getNowLocation } = now(MapModel);
  31. getNowLocation()
  32. .then((res) => {
  33. const { location } = res;
  34. return request.post('/orderInfo/riderStatus', {
  35. data: {
  36. orderId,
  37. status,
  38. longitude: location.lng,
  39. latitude: location.lat,
  40. },
  41. requestType: 'form',
  42. });
  43. })
  44. .then((res) => {
  45. if (successEvent) {
  46. successEvent(res);
  47. }
  48. })
  49. .catch((e) => {
  50. if (e.error && errorEvent) {
  51. errorEvent();
  52. } else {
  53. toastInfo(e.error);
  54. }
  55. });
  56. },
  57. pickupPhotos(orderId, status, successEvent, errorEvent, pickImg) {
  58. request
  59. .get('/orderInfo/pickupPhotos', {
  60. params: {
  61. orderId,
  62. status,
  63. img: pickImg,
  64. },
  65. })
  66. .then((res) => {
  67. if (successEvent) {
  68. successEvent(res);
  69. }
  70. })
  71. .catch((e) => {
  72. toastInfo(e.error);
  73. });
  74. },
  75. changeStatusAll(orderId, status, successEvent) {
  76. toastShow();
  77. request
  78. .get('/orderInfo/mandatory', {
  79. params: {
  80. orderId,
  81. status,
  82. },
  83. })
  84. .then((res) => {
  85. if (successEvent) {
  86. successEvent(res);
  87. }
  88. })
  89. .catch((e) => {
  90. toastInfo(e.error);
  91. });
  92. },
  93. });
  94. export default OrderMap;