model.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import request from '../utils/RequestUtils';
  2. import {
  3. toastShow,
  4. toastHide,
  5. toastInfo,
  6. toastSuccess,
  7. } from '../utils/SystemUtils';
  8. import {
  9. addAsyncStorage,
  10. removeAsyncStorage,
  11. } from '../utils/AsyncStorageUtils';
  12. import User from '../stores/User';
  13. import { submitPhone } from '../utils/SmsUtil';
  14. const MapModel = (now) => ({
  15. applyInfo: {},
  16. loginByPsd(username, password) {
  17. toastShow();
  18. return request
  19. .post('/auth/loginByRegister', {
  20. data: {
  21. phone: submitPhone(username),
  22. password,
  23. identity: 'RIDER',
  24. },
  25. requestType: 'form',
  26. })
  27. .then((res) => {
  28. return addAsyncStorage('token', res);
  29. })
  30. .then(() => {
  31. const { getInit } = now(User);
  32. return getInit();
  33. })
  34. .then(() => {
  35. toastHide();
  36. toastSuccess('登录成功');
  37. })
  38. .catch((e) => {
  39. toastHide();
  40. toastInfo(e.error);
  41. });
  42. },
  43. loginByCode(phone, code) {
  44. toastShow();
  45. return request
  46. .post('/auth/phoneLogin', {
  47. data: {
  48. phone: '+86' + submitPhone(phone),
  49. code,
  50. identity: 'RIDER',
  51. },
  52. requestType: 'form',
  53. })
  54. .then((res) => {
  55. return addAsyncStorage('token', res);
  56. })
  57. .then(() => {
  58. const { getInit } = now(User);
  59. return getInit();
  60. })
  61. .then(() => {
  62. toastHide();
  63. toastSuccess('登录成功');
  64. })
  65. .catch((e) => {
  66. toastHide();
  67. toastInfo(e.error);
  68. });
  69. },
  70. loginByRegister(phone, password) {
  71. toastShow();
  72. return request
  73. .post('/auth/loginByRegister', {
  74. data: {
  75. phone: phone,
  76. password,
  77. identity: 'RIDER',
  78. },
  79. requestType: 'form',
  80. })
  81. .then((res) => {
  82. return addAsyncStorage('token', res);
  83. })
  84. .then(() => {
  85. const { getInit } = now(User);
  86. return getInit();
  87. })
  88. .then(() => {
  89. toastHide();
  90. toastSuccess('注册成功');
  91. })
  92. .catch((e) => {
  93. toastHide();
  94. toastInfo(e.error);
  95. });
  96. },
  97. verifiedSave(realName, idNo, idNoImg, handheldIdNo, verifiedId) {
  98. const { id, getInit, riderInfo } = now(User);
  99. console.log(id);
  100. toastShow();
  101. if (riderInfo.status === 'DENY') {
  102. addAsyncStorage('seApply', 'Certification');
  103. }
  104. return request
  105. .post('/verified/save', {
  106. data: {
  107. userId: id,
  108. realName,
  109. idNo,
  110. idNoImg,
  111. handheldIdNo,
  112. id: verifiedId,
  113. },
  114. })
  115. .then(() => {
  116. if (riderInfo.status === 'DENY') {
  117. addAsyncStorage('seApply', 'Transportation');
  118. }
  119. return getInit();
  120. })
  121. .then(() => {
  122. toastHide();
  123. return Promise.resolve();
  124. })
  125. .catch((e) => {
  126. toastHide();
  127. toastInfo(e.error);
  128. });
  129. },
  130. riderApplyPre(transportation, transportationImg, driverLicenseImg) {
  131. const { riderInfo } = now(User);
  132. const data = { ...riderInfo };
  133. delete data.user;
  134. delete data.enabled;
  135. delete data.status;
  136. now({
  137. applyInfo: {
  138. ...data,
  139. transportation,
  140. transportationImg,
  141. driverLicenseImg,
  142. },
  143. });
  144. },
  145. setLocation(area, lat, lng) {
  146. const { applyInfo } = now();
  147. now({
  148. applyInfo: {
  149. ...applyInfo,
  150. area,
  151. latitude: lat,
  152. longitude: lng,
  153. },
  154. });
  155. },
  156. saveEvent() {
  157. const { applyInfo } = now();
  158. const { id } = now(User);
  159. if (applyInfo.id) {
  160. return request.post('/rider/save', {
  161. data: {
  162. ...applyInfo,
  163. userId: id,
  164. },
  165. });
  166. } else {
  167. return request.get('/rider/apply', {
  168. params: {
  169. ...applyInfo,
  170. userId: id,
  171. },
  172. });
  173. }
  174. },
  175. saveRiderApply() {
  176. const { saveEvent } = now();
  177. const { id, getInit } = now(User);
  178. toastShow();
  179. return saveEvent()
  180. .then(() => {
  181. return getInit();
  182. })
  183. .then(() => {
  184. toastHide();
  185. return Promise.resolve();
  186. })
  187. .catch((e) => {
  188. toastHide();
  189. toastInfo(e.error);
  190. });
  191. },
  192. });
  193. export default MapModel;