fix(doctor):优化患者和订单相关功能
- 移除患者添加页面中冗余的日期选择器相关代码和逻辑 - 修复订单页面图片上传接口的Content-Type配置 - 增强订单页面上传响应数据校验和错误提示 - 完善订单页面患者和处方数据传递及本地存储逻辑 - 优化选择患者和处方页面的数据加载和滚动列表实现 - 改进页面间数据通信的稳定性和容错处理
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import {useEffect, useState, useRef} from "react";
|
||||
import {Loading, CellGroup, Input, Form, Calendar} from '@nutui/nutui-react-taro'
|
||||
import {Edit, Calendar as CalendarIcon} from '@nutui/icons-react-taro'
|
||||
import {Loading, CellGroup, Input, Form} from '@nutui/nutui-react-taro'
|
||||
import {Edit} from '@nutui/icons-react-taro'
|
||||
import Taro from '@tarojs/taro'
|
||||
import {useRouter} from '@tarojs/taro'
|
||||
import {View, Text} from '@tarojs/components'
|
||||
import {View} from '@tarojs/components'
|
||||
import FixedButton from "@/components/FixedButton";
|
||||
import {useUser} from "@/hooks/useUser";
|
||||
import {ClinicPatientUser} from "@/api/clinic/clinicPatientUser/model";
|
||||
@@ -12,10 +12,6 @@ import {
|
||||
getClinicPatientUser,
|
||||
updateClinicPatientUser
|
||||
} from "@/api/clinic/clinicPatientUser";
|
||||
import {
|
||||
formatDateForDatabase,
|
||||
extractDateForCalendar, formatDateForDisplay
|
||||
} from "@/utils/dateUtils";
|
||||
|
||||
const AddPatient = () => {
|
||||
const {user} = useUser()
|
||||
@@ -25,27 +21,8 @@ const AddPatient = () => {
|
||||
const formRef = useRef<any>(null)
|
||||
const [isEditMode, setIsEditMode] = useState<boolean>(false)
|
||||
|
||||
// 日期选择器状态
|
||||
const [showCreateTimePicker, setShowCreateTimePicker] = useState<boolean>(false)
|
||||
const [createTime, setCreateTime] = useState<string>('')
|
||||
|
||||
console.log('AddPatient Component Rendered');
|
||||
|
||||
// 处理创建时间选择
|
||||
const handleCreateTimeConfirm = (param: string) => {
|
||||
const selectedDate = param[3] // 选中的日期字符串 (YYYY-M-D)
|
||||
const formattedDate = formatDateForDatabase(selectedDate) // 转换为数据库格式
|
||||
setCreateTime(selectedDate) // 保存原始格式用于显示
|
||||
setShowCreateTimePicker(false)
|
||||
|
||||
// 更新表单数据(使用数据库格式)
|
||||
if (formRef.current) {
|
||||
formRef.current.setFieldsValue({
|
||||
createTime: formattedDate
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const reload = async () => {
|
||||
if (!params.id) {
|
||||
return false;
|
||||
@@ -57,11 +34,6 @@ const AddPatient = () => {
|
||||
setFormData(patient)
|
||||
setIsEditMode(true);
|
||||
|
||||
// 初始化日期数据(从数据库格式转换为Calendar组件格式)
|
||||
if (patient.createTime) {
|
||||
setCreateTime(extractDateForCalendar(patient.createTime))
|
||||
}
|
||||
|
||||
Taro.setNavigationBarTitle({title: '编辑患者'})
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -98,8 +70,6 @@ const AddPatient = () => {
|
||||
...values,
|
||||
realName: values.realName || user?.nickname,
|
||||
phone: values.phone,
|
||||
// 确保日期数据正确提交(使用数据库格式)
|
||||
createTime: values.createTime || (createTime ? formatDateForDatabase(createTime) : new Date().toISOString().slice(0, 19).replace('T', ' '))
|
||||
};
|
||||
|
||||
// 调试信息
|
||||
@@ -179,30 +149,9 @@ const AddPatient = () => {
|
||||
<Form.Item name="comments" label="备注" initialValue={formData?.comments}>
|
||||
<Input placeholder="请填写备注信息" />
|
||||
</Form.Item>
|
||||
<Form.Item name="createTime" label="创建时间" initialValue={formData?.createTime}>
|
||||
<View
|
||||
className="flex items-center justify-between py-2"
|
||||
onClick={() => setShowCreateTimePicker(true)}
|
||||
>
|
||||
<View className="flex items-center">
|
||||
<CalendarIcon size={16} color="#999" className="mr-2"/>
|
||||
<Text style={{color: createTime ? '#333' : '#999'}}>
|
||||
{createTime ? formatDateForDisplay(createTime) : '请选择创建时间'}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</Form.Item>
|
||||
</CellGroup>
|
||||
</Form>
|
||||
|
||||
{/* 创建时间选择器 */}
|
||||
<Calendar
|
||||
visible={showCreateTimePicker}
|
||||
defaultValue={createTime}
|
||||
onClose={() => setShowCreateTimePicker(false)}
|
||||
onConfirm={handleCreateTimeConfirm}
|
||||
/>
|
||||
|
||||
{/* 底部浮动按钮 */}
|
||||
<FixedButton
|
||||
icon={<Edit/>}
|
||||
|
||||
@@ -57,8 +57,6 @@ const AddOrder = () => {
|
||||
}
|
||||
}
|
||||
|
||||
setDisabled(true);
|
||||
|
||||
// 设置选中的患者(供其他页面调用)
|
||||
// @ts-ignore
|
||||
const setSelectedPatientFunc = (patient: ClinicPatientUser) => {
|
||||
@@ -140,20 +138,19 @@ const AddOrder = () => {
|
||||
|
||||
// 上传单张图片
|
||||
const uploadSingleImage = (filePath: any, index: number) => {
|
||||
|
||||
Taro.uploadFile({
|
||||
url: 'https://server.websoft.top/api/oss/upload',
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
'content-type': 'application/json',
|
||||
'content-type': 'multipart/form-data',
|
||||
TenantId
|
||||
},
|
||||
success: (res) => {
|
||||
try {
|
||||
const data = JSON.parse(res.data);
|
||||
console.log('上传成功', data)
|
||||
if (data.code === 0) {
|
||||
if (data.code === 0 && data.data && data.data.url) {
|
||||
// 更新文件列表
|
||||
const newFile = {
|
||||
name: `图片${Date.now()}_${index}`,
|
||||
@@ -192,7 +189,7 @@ const AddOrder = () => {
|
||||
} catch (error) {
|
||||
console.error('解析响应失败:', error)
|
||||
Taro.showToast({
|
||||
title: '上传失败',
|
||||
title: '上传失败: 数据格式错误',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
@@ -200,7 +197,7 @@ const AddOrder = () => {
|
||||
fail: (err) => {
|
||||
console.log('上传请求失败', err);
|
||||
Taro.showToast({
|
||||
title: '上传失败',
|
||||
title: '上传失败: 网络错误',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
@@ -256,8 +253,8 @@ const AddOrder = () => {
|
||||
|
||||
// 执行新增或更新操作
|
||||
await addShopChatMessage({
|
||||
toUserId: toUserId || selectedPatient?.userId,
|
||||
formUserId: Taro.getStorageSync('UserId'),
|
||||
toUserId: toUserId || (selectedPatient?.userId ?? 0),
|
||||
formUserId: Taro.getStorageSync('UserId') || 0,
|
||||
type: 'text',
|
||||
content: content
|
||||
});
|
||||
@@ -271,10 +268,10 @@ const AddOrder = () => {
|
||||
Taro.navigateBack();
|
||||
}, 1000);
|
||||
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error('发送失败:', error);
|
||||
Taro.showToast({
|
||||
title: `发送失败`,
|
||||
title: `发送失败: ${error.message || error || '未知错误'}`,
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
@@ -290,21 +287,40 @@ const AddOrder = () => {
|
||||
})
|
||||
|
||||
// 设置页面实例的方法,供其他页面调用
|
||||
// @ts-ignore
|
||||
Taro.getCurrentInstance().page.setSelectedPatient = setSelectedPatientFunc;
|
||||
// @ts-ignore
|
||||
Taro.getCurrentInstance().page.setSelectedPrescription = setSelectedPrescriptionFunc;
|
||||
try {
|
||||
// @ts-ignore
|
||||
if (Taro.getCurrentInstance() && Taro.getCurrentInstance().page) {
|
||||
// @ts-ignore
|
||||
Taro.getCurrentInstance().page.setSelectedPatient = setSelectedPatientFunc;
|
||||
// @ts-ignore
|
||||
Taro.getCurrentInstance().page.setSelectedPrescription = setSelectedPrescriptionFunc;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('设置页面实例方法失败:', error);
|
||||
}
|
||||
|
||||
// 从本地存储获取之前选择的患者和处方
|
||||
const storedPatient = Taro.getStorageSync('selectedPatient');
|
||||
if (storedPatient) {
|
||||
setSelectedPatient(JSON.parse(storedPatient));
|
||||
try {
|
||||
const storedPatient = Taro.getStorageSync('selectedPatient');
|
||||
if (storedPatient) {
|
||||
const parsedPatient = JSON.parse(storedPatient);
|
||||
setSelectedPatient(parsedPatient);
|
||||
Taro.removeStorageSync('selectedPatient');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析存储的患者数据失败:', error);
|
||||
Taro.removeStorageSync('selectedPatient');
|
||||
}
|
||||
|
||||
const storedPrescription = Taro.getStorageSync('selectedPrescription');
|
||||
if (storedPrescription) {
|
||||
setSelectedPrescription(JSON.parse(storedPrescription));
|
||||
try {
|
||||
const storedPrescription = Taro.getStorageSync('selectedPrescription');
|
||||
if (storedPrescription) {
|
||||
const parsedPrescription = JSON.parse(storedPrescription);
|
||||
setSelectedPrescription(parsedPrescription);
|
||||
Taro.removeStorageSync('selectedPrescription');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('解析存储的处方数据失败:', error);
|
||||
Taro.removeStorageSync('selectedPrescription');
|
||||
}
|
||||
}, [isEditMode]);
|
||||
@@ -539,8 +555,7 @@ const AddOrder = () => {
|
||||
|
||||
<ImagePreview
|
||||
autoPlay
|
||||
// @ts-ignore
|
||||
images={fileList2}
|
||||
images={fileList2.filter(file => file.src).map(file => ({ src: file.src! }))}
|
||||
visible={showBdImgPreview}
|
||||
onClose={() => setShowBdImgPreview(false)}
|
||||
/>
|
||||
@@ -548,4 +563,4 @@ const AddOrder = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default AddOrder;
|
||||
export default AddOrder;
|
||||
@@ -70,7 +70,7 @@ const SelectPatient = () => {
|
||||
if (resetPage || currentPage === 1) {
|
||||
setList(res.list);
|
||||
} else {
|
||||
setList(prevList => prevList.concat(res.list));
|
||||
setList(prevList => [...prevList, ...res.list]);
|
||||
}
|
||||
|
||||
// 正确判断是否还有更多数据
|
||||
@@ -130,14 +130,20 @@ const SelectPatient = () => {
|
||||
const pages = Taro.getCurrentPages();
|
||||
if (pages.length > 1) {
|
||||
const prevPage = pages[pages.length - 2];
|
||||
console.log('11111')
|
||||
// @ts-ignore
|
||||
if (prevPage && typeof prevPage.setSelectedPatient === 'function') {
|
||||
// @ts-ignore
|
||||
prevPage.setSelectedPatient(patient);
|
||||
console.log('22222')
|
||||
}
|
||||
}
|
||||
|
||||
// 同时存储到本地存储,作为备选方案
|
||||
try {
|
||||
Taro.setStorageSync('selectedPatient', JSON.stringify(patient));
|
||||
} catch (e) {
|
||||
console.error('存储患者信息失败:', e);
|
||||
}
|
||||
|
||||
Taro.navigateBack();
|
||||
};
|
||||
|
||||
@@ -226,17 +232,7 @@ const SelectPatient = () => {
|
||||
target="scroll"
|
||||
hasMore={hasMore}
|
||||
onLoadMore={reloadMore}
|
||||
onScroll={() => {
|
||||
// 滚动事件处理
|
||||
}}
|
||||
onScrollToUpper={() => {
|
||||
// 滚动到顶部事件处理
|
||||
}}
|
||||
loadingText={
|
||||
<>
|
||||
加载中...
|
||||
</>
|
||||
}
|
||||
loadingText="加载中..."
|
||||
loadMoreText={
|
||||
list.length === 0 ? (
|
||||
<Empty
|
||||
@@ -286,4 +282,4 @@ const SelectPatient = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default SelectPatient;
|
||||
export default SelectPatient;
|
||||
@@ -38,7 +38,7 @@ const SelectPrescription = () => {
|
||||
if (resetPage || currentPage === 1) {
|
||||
setList(res.list);
|
||||
} else {
|
||||
setList(prevList => prevList.concat(res.list));
|
||||
setList(prevList => [...prevList, ...res.list]);
|
||||
}
|
||||
|
||||
// 正确判断是否还有更多数据
|
||||
@@ -104,6 +104,14 @@ const SelectPrescription = () => {
|
||||
prevPage.setSelectedPrescription(prescription);
|
||||
}
|
||||
}
|
||||
|
||||
// 同时存储到处方存储,作为备选方案
|
||||
try {
|
||||
Taro.setStorageSync('selectedPrescription', JSON.stringify(prescription));
|
||||
} catch (e) {
|
||||
console.error('存储处方信息失败:', e);
|
||||
}
|
||||
|
||||
Taro.navigateBack();
|
||||
};
|
||||
|
||||
@@ -173,17 +181,7 @@ const SelectPrescription = () => {
|
||||
target="scroll"
|
||||
hasMore={hasMore}
|
||||
onLoadMore={reloadMore}
|
||||
onScroll={() => {
|
||||
// 滚动事件处理
|
||||
}}
|
||||
onScrollToUpper={() => {
|
||||
// 滚动到顶部事件处理
|
||||
}}
|
||||
loadingText={
|
||||
<>
|
||||
加载中...
|
||||
</>
|
||||
}
|
||||
loadingText="加载中..."
|
||||
loadMoreText={
|
||||
list.length === 0 ? (
|
||||
<Empty
|
||||
|
||||
Reference in New Issue
Block a user