|
|
@@ -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];
|
|
|
+}
|