model.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. changePsd(phone, code, password, back) {
  71. toastShow();
  72. return request
  73. .post('/user/changePassword', {
  74. params: {
  75. password,
  76. key: '+86' + submitPhone(phone),
  77. code,
  78. identity: 'RIDER',
  79. },
  80. })
  81. .then(() => {
  82. toastSuccess('修改成功');
  83. if (back) {
  84. back();
  85. }
  86. })
  87. .catch((e) => {
  88. toastInfo(e.error);
  89. });
  90. },
  91. loginByRegister(phone, password) {
  92. toastShow();
  93. return request
  94. .post('/auth/loginByRegister', {
  95. data: {
  96. phone: submitPhone(phone),
  97. password,
  98. identity: 'RIDER',
  99. },
  100. requestType: 'form',
  101. })
  102. .then((res) => {
  103. return addAsyncStorage('token', res);
  104. })
  105. .then(() => {
  106. const { getInit } = now(User);
  107. return getInit();
  108. })
  109. .then(() => {
  110. toastHide();
  111. toastSuccess('注册成功');
  112. })
  113. .catch((e) => {
  114. toastHide();
  115. toastInfo(e.error);
  116. });
  117. },
  118. verifiedSave(realName, idNo, idNoImg, handheldIdNo, verifiedId) {
  119. const { id, getInit, riderInfo } = now(User);
  120. console.log(id);
  121. toastShow();
  122. if (riderInfo.status === 'DENY') {
  123. addAsyncStorage('seApply', 'Certification');
  124. }
  125. return request
  126. .post('/verified/save', {
  127. data: {
  128. userId: id,
  129. realName,
  130. idNo,
  131. idNoImg,
  132. handheldIdNo,
  133. id: verifiedId,
  134. },
  135. })
  136. .then(() => {
  137. if (riderInfo.status === 'DENY') {
  138. addAsyncStorage('seApply', 'Transportation');
  139. }
  140. return getInit();
  141. })
  142. .then(() => {
  143. toastHide();
  144. return Promise.resolve();
  145. })
  146. .catch((e) => {
  147. toastHide();
  148. toastInfo(e.error);
  149. });
  150. },
  151. riderApplyPre(transportation, transportationImg, driverLicenseImg) {
  152. const { riderInfo } = now(User);
  153. const data = { ...riderInfo };
  154. delete data.user;
  155. delete data.enabled;
  156. delete data.status;
  157. now({
  158. applyInfo: {
  159. ...data,
  160. transportation,
  161. transportationImg,
  162. driverLicenseImg,
  163. },
  164. });
  165. },
  166. setLocation(area, lat, lng) {
  167. const { applyInfo } = now();
  168. now({
  169. applyInfo: {
  170. ...applyInfo,
  171. area,
  172. latitude: lat,
  173. longitude: lng,
  174. },
  175. });
  176. },
  177. saveEvent() {
  178. const { applyInfo } = now();
  179. const { id } = now(User);
  180. if (applyInfo.id) {
  181. return request.post('/rider/save', {
  182. data: {
  183. ...applyInfo,
  184. userId: id,
  185. },
  186. });
  187. } else {
  188. return request.get('/rider/apply', {
  189. params: {
  190. ...applyInfo,
  191. userId: id,
  192. },
  193. });
  194. }
  195. },
  196. saveRiderApply() {
  197. const { saveEvent } = now();
  198. const { id, getInit } = now(User);
  199. toastShow();
  200. return saveEvent()
  201. .then(() => {
  202. return getInit();
  203. })
  204. .then(() => {
  205. toastHide();
  206. return Promise.resolve();
  207. })
  208. .catch((e) => {
  209. toastHide();
  210. toastInfo(e.error);
  211. });
  212. },
  213. });
  214. export default MapModel;