|
@@ -1,8 +1,16 @@
|
|
|
|
|
+import UIButton from '@/components/ui/ui-button';
|
|
|
|
|
+import { Colors } from '@/constants/theme';
|
|
|
|
|
+import api from '@/utils/api';
|
|
|
|
|
+import { openSystemSettings } from '@/utils/os';
|
|
|
import { ActionSheet, ActivityIndicator, Icon, Modal, Toast } from '@ant-design/react-native';
|
|
import { ActionSheet, ActivityIndicator, Icon, Modal, Toast } from '@ant-design/react-native';
|
|
|
import { Ionicons } from '@expo/vector-icons';
|
|
import { Ionicons } from '@expo/vector-icons';
|
|
|
import clsx from 'clsx';
|
|
import clsx from 'clsx';
|
|
|
|
|
+import type { DocumentPickerAsset } from 'expo-document-picker';
|
|
|
import { getDocumentAsync } from 'expo-document-picker';
|
|
import { getDocumentAsync } from 'expo-document-picker';
|
|
|
import { File } from 'expo-file-system';
|
|
import { File } from 'expo-file-system';
|
|
|
|
|
+import type {
|
|
|
|
|
+ ImagePickerAsset
|
|
|
|
|
+} from 'expo-image-picker';
|
|
|
import {
|
|
import {
|
|
|
launchCameraAsync,
|
|
launchCameraAsync,
|
|
|
launchImageLibraryAsync,
|
|
launchImageLibraryAsync,
|
|
@@ -12,14 +20,6 @@ import {
|
|
|
import { Link } from 'expo-router';
|
|
import { Link } from 'expo-router';
|
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
|
import { Platform, Pressable, Text, View } from 'react-native';
|
|
import { Platform, Pressable, Text, View } from 'react-native';
|
|
|
-import UIButton from '@/components/ui/ui-button';
|
|
|
|
|
-import { Colors } from '@/constants/theme';
|
|
|
|
|
-import api from '@/utils/api';
|
|
|
|
|
-import { openSystemSettings } from '@/utils/os';
|
|
|
|
|
-import type { DocumentPickerAsset } from 'expo-document-picker';
|
|
|
|
|
-import type {
|
|
|
|
|
- ImagePickerAsset
|
|
|
|
|
-} from 'expo-image-picker';
|
|
|
|
|
|
|
|
|
|
type Asset = ImagePickerAsset | DocumentPickerAsset;
|
|
type Asset = ImagePickerAsset | DocumentPickerAsset;
|
|
|
type UploadHandler = (assets: Asset[], customerId?: string) => void;
|
|
type UploadHandler = (assets: Asset[], customerId?: string) => void;
|
|
@@ -53,7 +53,7 @@ function alertPermissionDenied() {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const takePhoto = async (upload: UploadHandler) => {
|
|
|
|
|
|
|
+const takePhoto = async (upload: UploadHandler, ...args: any[]) => {
|
|
|
const permission = await requestCameraPermissionsAsync();
|
|
const permission = await requestCameraPermissionsAsync();
|
|
|
if (!permission.granted) {
|
|
if (!permission.granted) {
|
|
|
alertPermissionDenied();
|
|
alertPermissionDenied();
|
|
@@ -62,7 +62,7 @@ const takePhoto = async (upload: UploadHandler) => {
|
|
|
const toastKey = Toast.loading('正在打开相机...');
|
|
const toastKey = Toast.loading('正在打开相机...');
|
|
|
try {
|
|
try {
|
|
|
const result = await launchCameraAsync({ allowsEditing: false, quality: 0.9 });
|
|
const result = await launchCameraAsync({ allowsEditing: false, quality: 0.9 });
|
|
|
- if (!result.canceled) upload(result.assets);
|
|
|
|
|
|
|
+ if (!result.canceled) upload(result.assets, ...args);
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.warn(err);
|
|
console.warn(err);
|
|
|
Toast.fail('打开相机失败,请重试');
|
|
Toast.fail('打开相机失败,请重试');
|
|
@@ -71,7 +71,7 @@ const takePhoto = async (upload: UploadHandler) => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const pickImage = async (upload: UploadHandler) => {
|
|
|
|
|
|
|
+const pickImage = async (upload: UploadHandler, ...args: any[]) => {
|
|
|
const permission = await requestMediaLibraryPermissionsAsync();
|
|
const permission = await requestMediaLibraryPermissionsAsync();
|
|
|
if (!permission.granted) {
|
|
if (!permission.granted) {
|
|
|
alertPermissionDenied();
|
|
alertPermissionDenied();
|
|
@@ -84,7 +84,7 @@ const pickImage = async (upload: UploadHandler) => {
|
|
|
allowsEditing: false,
|
|
allowsEditing: false,
|
|
|
quality: 0.9,
|
|
quality: 0.9,
|
|
|
});
|
|
});
|
|
|
- if (!result.canceled) upload(result.assets);
|
|
|
|
|
|
|
+ if (!result.canceled) upload(result.assets, ...args);
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.warn(err);
|
|
console.warn(err);
|
|
|
Toast.fail('打开相册失败,请重试');
|
|
Toast.fail('打开相册失败,请重试');
|
|
@@ -93,14 +93,14 @@ const pickImage = async (upload: UploadHandler) => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const pickDocument = async (upload: UploadHandler) => {
|
|
|
|
|
|
|
+const pickDocument = async (upload: UploadHandler, ...args: any[]) => {
|
|
|
const toastKey = Toast.loading('正在打开文件选择器...');
|
|
const toastKey = Toast.loading('正在打开文件选择器...');
|
|
|
try {
|
|
try {
|
|
|
const result = await getDocumentAsync({
|
|
const result = await getDocumentAsync({
|
|
|
type: DOCUMENT_MIME_TYPES,
|
|
type: DOCUMENT_MIME_TYPES,
|
|
|
copyToCacheDirectory: true,
|
|
copyToCacheDirectory: true,
|
|
|
});
|
|
});
|
|
|
- if (!result.canceled) upload(result.assets);
|
|
|
|
|
|
|
+ if (!result.canceled) upload(result.assets, ...args);
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.warn(err);
|
|
console.warn(err);
|
|
|
Toast.fail('打开文件失败,请重试');
|
|
Toast.fail('打开文件失败,请重试');
|
|
@@ -114,14 +114,16 @@ async function uploadAndCreateCredit(assets: Asset[], customerId?: string) {
|
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
|
formData.append('file', file);
|
|
formData.append('file', file);
|
|
|
const attachment = await api.uploadFile<Attachment>('common/upload', { body: formData });
|
|
const attachment = await api.uploadFile<Attachment>('common/upload', { body: formData });
|
|
|
- await api.post('/credit/create', { att: JSON.stringify(attachment) });
|
|
|
|
|
|
|
+ await api.post('credit/create', { customer_id: customerId, att: JSON.stringify(attachment) });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function UploadScreen({
|
|
export function UploadScreen({
|
|
|
visible,
|
|
visible,
|
|
|
onClose,
|
|
onClose,
|
|
|
|
|
+ customerId
|
|
|
}: {
|
|
}: {
|
|
|
visible: boolean;
|
|
visible: boolean;
|
|
|
|
|
+ customerId?: string;
|
|
|
onClose: (isCancel: boolean) => void;
|
|
onClose: (isCancel: boolean) => void;
|
|
|
}) {
|
|
}) {
|
|
|
const [state, setState] = useState<UploadState>(0);
|
|
const [state, setState] = useState<UploadState>(0);
|
|
@@ -133,7 +135,7 @@ export function UploadScreen({
|
|
|
const upload = useCallback<UploadHandler>(async (assets) => {
|
|
const upload = useCallback<UploadHandler>(async (assets) => {
|
|
|
setState(1);
|
|
setState(1);
|
|
|
try {
|
|
try {
|
|
|
- await uploadAndCreateCredit(assets);
|
|
|
|
|
|
|
+ await uploadAndCreateCredit(assets, customerId);
|
|
|
setState(2);
|
|
setState(2);
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.warn(err);
|
|
console.warn(err);
|
|
@@ -170,7 +172,7 @@ export function UploadScreen({
|
|
|
<Text className="mt-4 ml-4 text-2xl">AI 正在分析</Text>
|
|
<Text className="mt-4 ml-4 text-2xl">AI 正在分析</Text>
|
|
|
</View>
|
|
</View>
|
|
|
<Text className="mt-4 ml-4 text-2xl">
|
|
<Text className="mt-4 ml-4 text-2xl">
|
|
|
- <Link asChild href="/(tabs)/analytics" onPress={() => onClose(false)}>
|
|
|
|
|
|
|
+ <Link asChild href="/(tabs)/credit" onPress={() => onClose(false)}>
|
|
|
<Text className="text-primary">分析页</Text>
|
|
<Text className="text-primary">分析页</Text>
|
|
|
</Link>
|
|
</Link>
|
|
|
查看状态和结果
|
|
查看状态和结果
|
|
@@ -207,21 +209,21 @@ export function UploadComponent({ askCustomer, onComplete, customerId }: { askCu
|
|
|
Toast.fail('上传失败,请重试');
|
|
Toast.fail('上传失败,请重试');
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
- [onComplete, customerId]
|
|
|
|
|
|
|
+ [onComplete]
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const handleSelect = useCallback(
|
|
const handleSelect = useCallback(
|
|
|
(index: number) => {
|
|
(index: number) => {
|
|
|
if (Platform.OS === 'ios') {
|
|
if (Platform.OS === 'ios') {
|
|
|
- if (index === 0) pickDocument(upload);
|
|
|
|
|
|
|
+ if (index === 0) pickDocument(upload, customerId);
|
|
|
else if (index === 1) pickImage(upload);
|
|
else if (index === 1) pickImage(upload);
|
|
|
else if (index === 2) takePhoto(upload);
|
|
else if (index === 2) takePhoto(upload);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (index === 0) pickDocument(upload);
|
|
|
|
|
- else if (index === 1) takePhoto(upload);
|
|
|
|
|
|
|
+ if (index === 0) pickDocument(upload, customerId);
|
|
|
|
|
+ else if (index === 1) takePhoto(upload, customerId);
|
|
|
},
|
|
},
|
|
|
- [upload]
|
|
|
|
|
|
|
+ [upload, customerId]
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
const selectFile = useCallback(async () => {
|
|
const selectFile = useCallback(async () => {
|
|
@@ -229,12 +231,12 @@ export function UploadComponent({ askCustomer, onComplete, customerId }: { askCu
|
|
|
const ask = await new Promise<boolean>((resolve) => {
|
|
const ask = await new Promise<boolean>((resolve) => {
|
|
|
Modal.alert("注意", "您没有选择客户,是否在分析完征信信息后匹配或新增客户?", [{
|
|
Modal.alert("注意", "您没有选择客户,是否在分析完征信信息后匹配或新增客户?", [{
|
|
|
text: "否,先选客户",
|
|
text: "否,先选客户",
|
|
|
- onPress: ()=> resolve(false),
|
|
|
|
|
|
|
+ onPress: () => resolve(false),
|
|
|
}, {
|
|
}, {
|
|
|
text: "是,先分析",
|
|
text: "是,先分析",
|
|
|
- style: {color: Colors.error.DEFAULT},
|
|
|
|
|
- onPress: ()=> resolve(true),
|
|
|
|
|
- }], ()=> {
|
|
|
|
|
|
|
+ style: { color: Colors.error.DEFAULT },
|
|
|
|
|
+ onPress: () => resolve(true),
|
|
|
|
|
+ }], () => {
|
|
|
resolve(false);
|
|
resolve(false);
|
|
|
return true
|
|
return true
|
|
|
});
|
|
});
|