Explorar el Código

feat: 确认发货对接完成

xyh hace 2 años
padre
commit
2524448aeb

+ 6 - 0
src/apis/client.js

@@ -0,0 +1,6 @@
+import {get} from './request';
+
+/** 查询发货天数 */
+export function getDays(code) {
+  return get({url: '/client/getClient', data: {code}});
+}

+ 23 - 0
src/apis/deliver.js

@@ -0,0 +1,23 @@
+import {post} from './request';
+
+const BASE_URL = '/dispatch';
+
+/**
+ * 上传发货单 
+ * 
+ * [
+    {
+      "dataList": [
+        {
+          "qty": "sed est",
+          "partNumber": "84"
+        }
+      ],
+      "customer": "tempor quis anim",
+      "truckNo": "anim commodo velit est consequat"
+    }
+  ]
+ * */
+export function addDeliver(data) {
+  return post({url: `${BASE_URL}/addDispatch`, data});
+}

+ 1 - 0
src/apis/index.js

@@ -1,2 +1,3 @@
 export * from './user';
 export * from './client';
+export * from './deliver';

+ 2 - 0
src/apis/request.js

@@ -11,6 +11,7 @@ function request({url, data, method, skipError}) {
       url: `${NETWORK_URL}${url}`,
       data,
       method,
+      timeout: 5000,
       header: {
         'Content-Type': 'application/json',
         'Cache-Control': 'no-cache',
@@ -72,6 +73,7 @@ export function uploadFile(url, skipError) {
       url: 'https://www.tuyatrip.com/api/upload/uploadFile',
       filePath: url,
       name: 'file',
+      timeout: 5000,
       header: {
         'Cache-Control': 'no-cache',
       },

+ 1 - 0
src/hooks/index.js

@@ -1 +1,2 @@
 export * from './use-scan-order';
+export * from './use-navigate';

+ 59 - 5
src/pages/deliver/hooks.js

@@ -1,16 +1,32 @@
+import {getDays, addDeliver} from '@apis';
+import {useMutation, useQuery} from '@tanstack/react-query';
 import dayjs from 'dayjs';
-import {useEffect, useState} from 'react';
+import {useEffect, useState, useMemo} from 'react';
+import {showLoading, hideLoading, showToast, showModal} from '@tarojs/taro';
+import {useNavigate} from '@hooks';
 
 export function useDate(customerNo) {
   const [date, setDate] = useState('');
+  const {data} = useQuery({
+    queryKey: [getDays.name, customerNo],
+    async queryFn() {
+      showLoading({title: '获取发货时长', mask: true});
+      const data = await getDays(customerNo);
+      hideLoading({noConflict: true});
+
+      if (data.code === '200') return Number(data.data.days);
+
+      return 0;
+    },
+    enabled: customerNo.length > 0,
+    initialData: 0,
+  });
 
   useEffect(
     function () {
-      if (customerNo) {
-        setDate(dayjs().format('YYYY-MM-DD'));
-      }
+      setDate(dayjs().add(data, 'day').format('YYYY-MM-DD'));
     },
-    [customerNo],
+    [data],
   );
 
   function onDateChagne(e) {
@@ -19,3 +35,41 @@ export function useDate(customerNo) {
 
   return [date, onDateChagne];
 }
+
+export function useSubmit({goodsList, customerNo, truckNo, date}) {
+  const dataList = useMemo(
+    function () {
+      return goodsList.map(function ({no, num}) {
+        return {partNumber: no, qty: num};
+      });
+    },
+    [goodsList],
+  );
+
+  const {pop} = useNavigate();
+  const {isLoading, mutate} = useMutation({
+    mutationFn: addDeliver,
+    onSuccess({code}) {
+      if (code === '200') {
+        pop();
+        showToast({title: '上传成功', icon: 'success'});
+      }
+    },
+  });
+
+  function onSubmit() {
+    if (!customerNo || !truckNo) {
+      return showToast({title: '请先扫码', icon: 'error'});
+    }
+
+    showModal({
+      title: '提交发货',
+      content: `你确定要提交${truckNo}${customerNo}发货单吗?`,
+      complete() {
+        mutate({dataList, customer: customerNo, truckNo, arrivalTime: date});
+      },
+    });
+  }
+
+  return [isLoading, onSubmit];
+}

+ 18 - 3
src/pages/deliver/index.jsx

@@ -2,13 +2,20 @@ import {Image, Text, View, Picker} from '@tarojs/components';
 import icon from '@assets/goods/sending.svg';
 import {Button} from '@antmjs/vantui';
 import {TextGroup as Item} from '@components';
-import {useDate} from './hooks';
+import {useDate, useSubmit} from './hooks';
 import dayjs from 'dayjs';
 import {useScanOrder} from '@hooks';
+import {BTN_LOADING_SIZE} from '@utils';
 
 export default function DeliverGoods() {
   const [{goodsList, customerNo, truckNo}, onScan] = useScanOrder();
   const [date, onDateChagne] = useDate(customerNo);
+  const [isLoading, onSubmit] = useSubmit({
+    goodsList,
+    customerNo,
+    truckNo,
+    date,
+  });
 
   return (
     <View className='h-screen overflow-auto bg-gray-100 flex flex-col'>
@@ -54,10 +61,18 @@ export default function DeliverGoods() {
       ) : null}
 
       <View className='flex mt-auto justify-around pb-12'>
-        <Button className='w-36' onClick={onScan} round>
+        <Button className='w-36' onClick={onScan} round disabled={isLoading}>
           扫码
         </Button>
-        <Button type='primary' className='w-36' color='#58C6EA' round>
+        <Button
+          onClick={onSubmit}
+          loading={isLoading}
+          type='primary'
+          className='w-36'
+          color='#58C6EA'
+          round
+          loadingSize={BTN_LOADING_SIZE}
+        >
           发货
         </Button>
       </View>

+ 2 - 0
src/pages/index/login/index.jsx

@@ -2,6 +2,7 @@ import {Popup, Button} from '@antmjs/vantui';
 import {View} from '@tarojs/components';
 import Field from './field';
 import {useFields, useLogin} from './hooks';
+import {BTN_LOADING_SIZE} from '@utils';
 
 export default function Login({visible, onClose}) {
   const [{userName, password}, onChange] = useFields(visible);
@@ -39,6 +40,7 @@ export default function Login({visible, onClose}) {
             color='#58C6EA'
             round
             onClick={onClick}
+            loadingSize={BTN_LOADING_SIZE}
           >
             登录
           </Button>

+ 2 - 0
src/utils/constants.js

@@ -2,3 +2,5 @@
 export const NETWORK_URL = 'https://3f0974b6.r8.vip.cpolar.cn';
 /** token存储 */
 export const USER_TOKEN_STORAGE = 'userToken';
+/** 按钮loading大小 */
+export const BTN_LOADING_SIZE = 16;