import request from '../utils/RequestUtils'; import { toastShow, toastInfo, toastSuccess } from '../utils/SystemUtils'; import MapModel from '../map/model'; const OrderMap = (now) => ({ receiverOrder(orderId, successEvent) { toastShow(); request .get('/rider/receiver', { params: { orderId, pass: true, }, }) .then((res) => { if (successEvent) { successEvent(res); } }) .catch((e) => { toastInfo(e.error); }); }, changeStatus(orderId, status, successEvent, errorEvent, pickImg) { toastShow(); const { pickupPhotos } = now(); if (status === 'TAKE_MEAL') { pickupPhotos(orderId, status, successEvent, errorEvent, pickImg); return; } const { getNowLocation } = now(MapModel); getNowLocation() .then((res) => { const { location } = res; return request.post('/orderInfo/riderStatus', { data: { orderId, status, longitude: location.lng, latitude: location.lat, }, requestType: 'form', }); }) .then((res) => { if (successEvent) { successEvent(res); } }) .catch((e) => { if (e.error && errorEvent) { errorEvent(); } else { toastInfo(e.error); } }); }, pickupPhotos(orderId, status, successEvent, errorEvent, pickImg) { request .get('/orderInfo/pickupPhotos', { params: { orderId, status, img: pickImg, }, }) .then((res) => { if (successEvent) { successEvent(res); } }) .catch((e) => { toastInfo(e.error); }); }, changeStatusAll(orderId, status, successEvent) { toastShow(); request .get('/orderInfo/mandatory', { params: { orderId, status, }, }) .then((res) => { if (successEvent) { successEvent(res); } }) .catch((e) => { toastInfo(e.error); }); }, }); export default OrderMap;