| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- import request from '../utils/RequestUtils';
- import {
- toastShow,
- toastHide,
- toastInfo,
- toastSuccess,
- } from '../utils/SystemUtils';
- import {
- addAsyncStorage,
- removeAsyncStorage,
- } from '../utils/AsyncStorageUtils';
- import User from '../stores/User';
- import { submitPhone } from '../utils/SmsUtil';
- const MapModel = (now) => ({
- applyInfo: {},
- loginByPsd(username, password) {
- toastShow();
- return request
- .post('/auth/loginByRegister', {
- data: {
- phone: submitPhone(username),
- password,
- identity: 'RIDER',
- },
- requestType: 'form',
- })
- .then((res) => {
- return addAsyncStorage('token', res);
- })
- .then(() => {
- const { getInit } = now(User);
- return getInit();
- })
- .then(() => {
- toastHide();
- toastSuccess('登录成功');
- })
- .catch((e) => {
- toastHide();
- toastInfo(e.error);
- });
- },
- loginByCode(phone, code) {
- toastShow();
- return request
- .post('/auth/phoneLogin', {
- data: {
- phone: '+86' + submitPhone(phone),
- code,
- identity: 'RIDER',
- },
- requestType: 'form',
- })
- .then((res) => {
- return addAsyncStorage('token', res);
- })
- .then(() => {
- const { getInit } = now(User);
- return getInit();
- })
- .then(() => {
- toastHide();
- toastSuccess('登录成功');
- })
- .catch((e) => {
- toastHide();
- toastInfo(e.error);
- });
- },
- changePsd(phone, code, password, back) {
- toastShow();
- return request
- .post('/user/changePassword', {
- params: {
- password,
- key: '+86' + submitPhone(phone),
- code,
- identity: 'RIDER',
- },
- })
- .then(() => {
- toastSuccess('修改成功');
- if (back) {
- back();
- }
- })
- .catch((e) => {
- toastInfo(e.error);
- });
- },
- loginByRegister(phone, password) {
- toastShow();
- return request
- .post('/auth/loginByRegister', {
- data: {
- phone: submitPhone(phone),
- password,
- identity: 'RIDER',
- },
- requestType: 'form',
- })
- .then((res) => {
- return addAsyncStorage('token', res);
- })
- .then(() => {
- const { getInit } = now(User);
- return getInit();
- })
- .then(() => {
- toastHide();
- toastSuccess('注册成功');
- })
- .catch((e) => {
- toastHide();
- toastInfo(e.error);
- });
- },
- verifiedSave(realName, idNo, idNoImg, handheldIdNo, verifiedId) {
- const { id, getInit, riderInfo } = now(User);
- console.log(id);
- toastShow();
- if (riderInfo.status === 'DENY') {
- addAsyncStorage('seApply', 'Certification');
- }
- return request
- .post('/verified/save', {
- data: {
- userId: id,
- realName,
- idNo,
- idNoImg,
- handheldIdNo,
- id: verifiedId,
- },
- })
- .then(() => {
- if (riderInfo.status === 'DENY') {
- addAsyncStorage('seApply', 'Transportation');
- }
- return getInit();
- })
- .then(() => {
- toastHide();
- return Promise.resolve();
- })
- .catch((e) => {
- toastHide();
- toastInfo(e.error);
- });
- },
- riderApplyPre(transportation, transportationImg, driverLicenseImg) {
- const { riderInfo } = now(User);
- const data = { ...riderInfo };
- delete data.user;
- delete data.enabled;
- delete data.status;
- now({
- applyInfo: {
- ...data,
- transportation,
- transportationImg,
- driverLicenseImg,
- },
- });
- },
- setLocation(area, lat, lng) {
- const { applyInfo } = now();
- now({
- applyInfo: {
- ...applyInfo,
- area,
- latitude: lat,
- longitude: lng,
- },
- });
- },
- saveEvent() {
- const { applyInfo } = now();
- const { id } = now(User);
- if (applyInfo.id) {
- return request.post('/rider/save', {
- data: {
- ...applyInfo,
- userId: id,
- },
- });
- } else {
- return request.get('/rider/apply', {
- params: {
- ...applyInfo,
- userId: id,
- },
- });
- }
- },
- saveRiderApply() {
- const { saveEvent } = now();
- const { id, getInit } = now(User);
- toastShow();
- return saveEvent()
- .then(() => {
- return getInit();
- })
- .then(() => {
- toastHide();
- return Promise.resolve();
- })
- .catch((e) => {
- toastHide();
- toastInfo(e.error);
- });
- },
- });
- export default MapModel;
|