panhui 5 years ago
parent
commit
5579e57828
10 changed files with 184 additions and 19 deletions
  1. 6 6
      components/SmsInput.tsx
  2. 1 1
      i18n.ts
  3. 18 1
      login/LoginScreen.tsx
  4. 29 0
      login/model.ts
  5. 14 3
      order/OrderCom.tsx
  6. 37 4
      order/OrderScreen.tsx
  7. 72 0
      stores/User.ts
  8. 1 0
      utils/MapUtils.ts
  9. 5 3
      utils/SmsUtil.ts
  10. 1 1
      utils/SystemUtils.ts

+ 6 - 6
components/SmsInput.tsx

@@ -5,7 +5,7 @@ import { Div, Image, Text, Avatar, Input, Button } from 'react-native-magnus';
 import { TextInputMask } from 'react-native-masked-text';
 import { TextInputMask } from 'react-native-masked-text';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 import { useInterval } from 'ahooks';
 import { useInterval } from 'ahooks';
-import { sendSms } from '../Utils/SmsUtil';
+import { sendSms } from '../utils/SmsUtil';
 import { toastInfo } from '../utils/SystemUtils';
 import { toastInfo } from '../utils/SystemUtils';
 
 
 export default function SmsInput({ phone, onCodeChange, type }) {
 export default function SmsInput({ phone, onCodeChange, type }) {
@@ -27,8 +27,8 @@ export default function SmsInput({ phone, onCodeChange, type }) {
 
 
   return (
   return (
     <Div row alignItems="center" py={10}>
     <Div row alignItems="center" py={10}>
-      <Text textAlign="right" w={labelWidth || 80}>
-        {label}
+      <Text textAlign="right" w={90}>
+        验证码
       </Text>
       </Text>
       <Div
       <Div
         flex={1}
         flex={1}
@@ -47,8 +47,8 @@ export default function SmsInput({ phone, onCodeChange, type }) {
             mask: '9999',
             mask: '9999',
           }}
           }}
           onChangeText={(text) => {
           onChangeText={(text) => {
-            setCode(value);
-            onCodeChange(value);
+            setCode(text);
+            onCodeChange(text);
           }}
           }}
           placeholderTextColor="#a6a6a6"
           placeholderTextColor="#a6a6a6"
           style={{ flex: 1, fontSize: 14 }}
           style={{ flex: 1, fontSize: 14 }}
@@ -64,7 +64,7 @@ export default function SmsInput({ phone, onCodeChange, type }) {
             })
             })
             .catch((e) => {
             .catch((e) => {
               console.log(e);
               console.log(e);
-              toastInfo(e.response.data.error);
+              toastInfo(e.error);
             });
             });
         }}
         }}
         bg="transparent"
         bg="transparent"

+ 1 - 1
i18n.ts

@@ -1,7 +1,7 @@
 import i18n from 'i18next';
 import i18n from 'i18next';
 import * as Localization from 'expo-localization';
 import * as Localization from 'expo-localization';
 import { initReactI18next } from 'react-i18next';
 import { initReactI18next } from 'react-i18next';
-import en from './locales/enc';
+import en from './locales/en.json';
 import zh from './locales/zh-CN.json';
 import zh from './locales/zh-CN.json';
 import th from './locales/th.json';
 import th from './locales/th.json';
 
 

+ 18 - 1
login/LoginScreen.tsx

@@ -201,6 +201,7 @@ function LoginByCode() {
   const { t } = useTranslation();
   const { t } = useTranslation();
   const [phone, setphone] = React.useState<string>('');
   const [phone, setphone] = React.useState<string>('');
   const [code, setCode] = React.useState<string>('');
   const [code, setCode] = React.useState<string>('');
+  const loginModel = useModel(Login, []);
   return (
   return (
     <Div bg="white">
     <Div bg="white">
       <Div row alignItems="center" py={10}>
       <Div row alignItems="center" py={10}>
@@ -231,6 +232,14 @@ function LoginByCode() {
             style={{ flex: 1, fontSize: 14 }}
             style={{ flex: 1, fontSize: 14 }}
             placeholder={t('shu-ru-shou-ji-hao')}
             placeholder={t('shu-ru-shou-ji-hao')}
           />
           />
+          {__DEV__ && (
+            <Input
+              onChangeText={(text) => {
+                console.log(text);
+                setphone(text);
+              }}
+            />
+          )}
         </Div>
         </Div>
       </Div>
       </Div>
       <SmsInput phone={phone} onCodeChange={setCode} type="login" />
       <SmsInput phone={phone} onCodeChange={setCode} type="login" />
@@ -244,7 +253,15 @@ function LoginByCode() {
         </Button>
         </Button>
       </Div>
       </Div>
 
 
-      <Button block bg="yellow500" w={112} fontSize="sm" ml={96} mt={10}>
+      <Button
+        onPress={() => loginModel.loginByCode(phone, code)}
+        block
+        bg="yellow500"
+        w={112}
+        fontSize="sm"
+        ml={96}
+        mt={10}
+      >
         {t('deng-lu')}
         {t('deng-lu')}
       </Button>
       </Button>
     </Div>
     </Div>

+ 29 - 0
login/model.ts

@@ -11,6 +11,8 @@ import {
 } from '../utils/AsyncStorageUtils';
 } from '../utils/AsyncStorageUtils';
 import User from '../stores/User';
 import User from '../stores/User';
 
 
+import { submitPhone } from '../utils/SmsUtil';
+
 const MapModel = (now) => ({
 const MapModel = (now) => ({
   applyInfo: {},
   applyInfo: {},
   loginByPsd(username, password) {
   loginByPsd(username, password) {
@@ -40,6 +42,33 @@ const MapModel = (now) => ({
         toastInfo(e.error);
         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);
+      });
+  },
   loginByRegister(phone, password) {
   loginByRegister(phone, password) {
     toastShow();
     toastShow();
     return request
     return request

+ 14 - 3
order/OrderCom.tsx

@@ -1,5 +1,6 @@
 import * as React from 'react';
 import * as React from 'react';
 import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
 import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
+import { useTranslation } from 'react-i18next';
 
 
 export default function OrderCom({
 export default function OrderCom({
   info,
   info,
@@ -8,6 +9,7 @@ export default function OrderCom({
   receiverOrder,
   receiverOrder,
   goMap,
   goMap,
   changeStatus,
   changeStatus,
+  sign,
 }) {
 }) {
   const {
   const {
     user,
     user,
@@ -20,6 +22,8 @@ export default function OrderCom({
     merAddress,
     merAddress,
   } = info;
   } = info;
 
 
+  const { t } = useTranslation();
+
   return (
   return (
     <Button bg="white" p={0} block mb={15} onPress={goDetail}>
     <Button bg="white" p={0} block mb={15} onPress={goDetail}>
       <Div flex={1}>
       <Div flex={1}>
@@ -45,9 +49,9 @@ export default function OrderCom({
             </Text>
             </Text>
             <Div flex={1} ml={12}>
             <Div flex={1} ml={12}>
               <Text fontSize="sm" pb={3}>
               <Text fontSize="sm" pb={3}>
-                {merShowName || merchant.showName}
+                {merShowName}
               </Text>
               </Text>
-              <Text fontSize="xs">{merAddress || merchant.address}</Text>
+              <Text fontSize="xs">{merAddress}</Text>
             </Div>
             </Div>
           </Div>
           </Div>
           <Div row mt={10}>
           <Div row mt={10}>
@@ -66,7 +70,14 @@ export default function OrderCom({
           </Div>
           </Div>
         </Div>
         </Div>
         {riderStatus === 'NOT_RECEIVED' && (
         {riderStatus === 'NOT_RECEIVED' && (
-          <Button block mx={15} mb={20} bg="yellow500" onPress={receiverOrder}>
+          <Button
+            block
+            mx={15}
+            mb={20}
+            bg={sign ? 'yellow500' : 'gray500'}
+            disabled={!sign}
+            onPress={receiverOrder}
+          >
             {t('jie-dan')}
             {t('jie-dan')}
           </Button>
           </Button>
         )}
         )}

+ 37 - 4
order/OrderScreen.tsx

@@ -2,7 +2,7 @@ import { StackScreenProps } from '@react-navigation/stack';
 import * as React from 'react';
 import * as React from 'react';
 import { RefreshControl } from 'react-native';
 import { RefreshControl } from 'react-native';
 import { useFocusEffect } from '@react-navigation/native';
 import { useFocusEffect } from '@react-navigation/native';
-import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
+import { Div, Button, Image, Text, Avatar, Icon } from 'react-native-magnus';
 import { FlatList } from 'react-native-gesture-handler';
 import { FlatList } from 'react-native-gesture-handler';
 import Constants from 'expo-constants';
 import Constants from 'expo-constants';
 import TimScreen from '../notice/TimScreen';
 import TimScreen from '../notice/TimScreen';
@@ -10,6 +10,7 @@ import TimScreen from '../notice/TimScreen';
 import useModel from 'flooks';
 import useModel from 'flooks';
 import Map from '../map/model';
 import Map from '../map/model';
 import OrderModel from './model';
 import OrderModel from './model';
+import User from '../stores/User';
 import { useMount, useRequest, useCreation } from 'ahooks';
 import { useMount, useRequest, useCreation } from 'ahooks';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
 
 
@@ -31,14 +32,18 @@ export default function OrderScreen({ navigation }: StackScreenProps) {
     []
     []
   );
   );
 
 
+  const { getSignInfo, sign, riderOrder } = useModel(User, [
+    'getSignInfo',
+    'sign',
+  ]);
+
   const [chooseStatus, setChooseStatus] = React.useState<string>(
   const [chooseStatus, setChooseStatus] = React.useState<string>(
     'NOT_RECEIVED'
     'NOT_RECEIVED'
   );
   );
   useMount(() => {
   useMount(() => {
     getNowLocation();
     getNowLocation();
+    getSignInfo();
   });
   });
-  const { addressName } = locationInfo;
-
   const chooseStatusInfo = useCreation(() => {
   const chooseStatusInfo = useCreation(() => {
     return orderRiderStatus.get(chooseStatus);
     return orderRiderStatus.get(chooseStatus);
   }, [chooseStatus]);
   }, [chooseStatus]);
@@ -85,7 +90,33 @@ export default function OrderScreen({ navigation }: StackScreenProps) {
         px={14}
         px={14}
         px={15}
         px={15}
       >
       >
-        <Image w={50} h={50} source={require('../assets/images/logo.png')} />
+        {/* <Image w={50} h={50} source={require('../assets/images/logo.png')} /> */}
+        <Button
+          bg="transparent"
+          onPress={() => {
+            if (sign) {
+              alert(navigation, {
+                msg: '确定要休息吗?',
+                submitEvent: riderOrder,
+                hasCancel: true,
+              });
+            } else {
+              riderOrder();
+            }
+          }}
+        >
+          <Div alignItems="center">
+            <Icon
+              fontSize="6xl"
+              color="white"
+              fontFamily="MaterialCommunityIcons"
+              name={sign ? 'coffee' : 'motorbike'}
+            />
+            <Text fontSize="sm" color="white" fontWeight="bold">
+              {sign ? '休息' : '开工'}
+            </Text>
+          </Div>
+        </Button>
         <Text fontSize="xl" color="white" mr={50} textAlign="center" flex={1}>
         <Text fontSize="xl" color="white" mr={50} textAlign="center" flex={1}>
           骑手客户端
           骑手客户端
         </Text>
         </Text>
@@ -116,6 +147,7 @@ export default function OrderScreen({ navigation }: StackScreenProps) {
         renderItem={({ item }) => {
         renderItem={({ item }) => {
           return (
           return (
             <OrderCom
             <OrderCom
+              sign={sign}
               info={item}
               info={item}
               type={chooseStatusInfo.type}
               type={chooseStatusInfo.type}
               goDetail={() =>
               goDetail={() =>
@@ -197,6 +229,7 @@ export default function OrderScreen({ navigation }: StackScreenProps) {
             return <></>;
             return <></>;
           }
           }
         }}
         }}
+        extraData={sign}
       />
       />
 
 
       <Div position="absolute" w={0} h={0} bottom={0} left={0} zIndex={0}>
       <Div position="absolute" w={0} h={0} bottom={0} left={0} zIndex={0}>

+ 72 - 0
stores/User.ts

@@ -10,6 +10,7 @@ import {
   toastInfo,
   toastInfo,
   toastSuccess,
   toastSuccess,
 } from '../utils/SystemUtils';
 } from '../utils/SystemUtils';
+import Map from '../map/model';
 
 
 import i18n from '../i18n';
 import i18n from '../i18n';
 
 
@@ -19,6 +20,8 @@ const user = (now) => ({
   initialRouteName: '',
   initialRouteName: '',
   verifiedInfo: {},
   verifiedInfo: {},
   riderInfo: {},
   riderInfo: {},
+  sign: false,
+  noSign: false,
   getUser() {
   getUser() {
     let userInfo = {
     let userInfo = {
       id: 0,
       id: 0,
@@ -145,6 +148,75 @@ const user = (now) => ({
       })
       })
       .catch(() => {});
       .catch(() => {});
   },
   },
+  getSignInfo() {
+    const { id } = now();
+    if (!id) {
+      now({
+        sign: false,
+      });
+      return Promise.resolve(false);
+    }
+    return request
+      .get('/riderSign/all', {
+        params: {
+          query: {
+            userId: id,
+          },
+        },
+      })
+      .then((res) => {
+        if (res.content.length > 0) {
+          now({
+            sign: res.content[0].takingOrders,
+            noSign: false,
+          });
+          return Promise.resolve(res.content[0].takingOrders);
+        } else {
+          now({
+            sign: false,
+            noSign: true,
+          });
+          return Promise.resolve(false);
+        }
+      });
+  },
+  riderOrder() {
+    toastShow();
+    const { sign, noSign, riderInfo } = now();
+    const { getNowLocation } = now(Map);
+    return getNowLocation()
+      .then((res) => {
+        const { location } = res;
+        if (noSign) {
+          return request.post('/riderSign/save', {
+            data: {
+              takingOrders: true,
+              longitude: location.lng,
+              latitude: location.lat,
+              riderId: riderInfo.id,
+            },
+          });
+        } else {
+          return request.get('/riderSign/riderOrder', {
+            params: {
+              isStart: !sign,
+              longitude: location.lng,
+              latitude: location.lat,
+            },
+          });
+        }
+      })
+      .then((res) => {
+        now({
+          sign: !sign,
+          noSign: false,
+        });
+        toastSuccess((sign ? '休息' : '开工') + '成功');
+      })
+      .catch((e) => {
+        toastInfo(e.error);
+      });
+  },
 });
 });
 
 
 export default user;
 export default user;

+ 1 - 0
utils/MapUtils.ts

@@ -16,6 +16,7 @@ async function getLocation() {
       if (res.status === 'granted') {
       if (res.status === 'granted') {
         return Location.getCurrentPositionAsync({
         return Location.getCurrentPositionAsync({
           enableHighAccuracy: true,
           enableHighAccuracy: true,
+          timeout: 5000,
         });
         });
       } else {
       } else {
         return Promise.reject();
         return Promise.reject();

+ 5 - 3
utils/SmsUtil.js → utils/SmsUtil.ts

@@ -1,5 +1,4 @@
 import request from './RequestUtils';
 import request from './RequestUtils';
-import submitPhone from './FormUtils';
 
 
 const templateMap = new Map([
 const templateMap = new Map([
   [
   [
@@ -32,6 +31,10 @@ const templateMap = new Map([
   ],
   ],
 ]);
 ]);
 
 
+function submitPhone(params) {
+  return params.replace(/ /g, '');
+}
+
 function sendSms(phone, type) {
 function sendSms(phone, type) {
   return request.get('/sms/tencentSend', {
   return request.get('/sms/tencentSend', {
     params: {
     params: {
@@ -41,5 +44,4 @@ function sendSms(phone, type) {
   });
   });
 }
 }
 
 
-// eslint-disable-next-line import/prefer-default-export
-export { sendSms };
+export { sendSms, submitPhone };

+ 1 - 1
utils/SystemUtils.ts

@@ -1,7 +1,7 @@
 import i18n from '../i18n';
 import i18n from '../i18n';
 import * as Linking from 'expo-linking';
 import * as Linking from 'expo-linking';
 
 
-import { Toast, ModalIndicator } from 'teaset';
+// import { Toast, ModalIndicator } from 'teaset';
 import { Platform } from 'react-native';
 import { Platform } from 'react-native';
 
 
 function connect(navigation) {
 function connect(navigation) {