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