feat(doctor): 添加订单诊断和治疗方案表单功能
- 引入 TextArea 组件用于多行文本输入- 新增诊断结果、治疗方案和煎药说明表单项 - 实现表单数据状态管理和字段变更处理- 更新消息内容拼接逻辑,包含诊断和治疗信息- 支持从本地存储恢复选中的患者和处方数据 - 移除调试日志并优化表单提交流程 - 调整界面布局,增强药方信息展示效果- 修改组件名称从 AddMessage 为 AddOrder
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {useEffect, useState, useRef} from "react";
|
||||
import {useRouter} from '@tarojs/taro'
|
||||
import {Loading, CellGroup, Input, Form, Cell, Avatar, Tag} from '@nutui/nutui-react-taro'
|
||||
import {Loading, CellGroup, Input, Form, Cell, Avatar, Tag, TextArea} from '@nutui/nutui-react-taro'
|
||||
import {ArrowRight} from '@nutui/icons-react-taro'
|
||||
import {View, Text} from '@tarojs/components'
|
||||
import Taro from '@tarojs/taro'
|
||||
@@ -12,17 +12,24 @@ import {User} from "@/api/system/user/model";
|
||||
import {ClinicPatientUser} from "@/api/clinic/clinicPatientUser/model";
|
||||
import {ClinicPrescription} from "@/api/clinic/clinicPrescription/model";
|
||||
|
||||
const AddMessage = () => {
|
||||
const AddOrder = () => {
|
||||
const {params} = useRouter();
|
||||
const [toUser, setToUser] = useState<User>()
|
||||
const [loading, setLoading] = useState<boolean>(true)
|
||||
const [FormData, _] = useState<ClinicPrescription>()
|
||||
const formRef = useRef<any>(null)
|
||||
|
||||
// 患者和处方状态
|
||||
const [selectedPatient, setSelectedPatient] = useState<ClinicPatientUser | null>(null)
|
||||
const [selectedPrescription, setSelectedPrescription] = useState<ClinicPrescription | null>(null)
|
||||
|
||||
// 表单数据
|
||||
const [formData, setFormData] = useState({
|
||||
diagnosis: '',
|
||||
treatmentPlan: '',
|
||||
decoctionInstructions: '',
|
||||
content: ''
|
||||
})
|
||||
|
||||
// 判断是编辑还是新增模式
|
||||
const isEditMode = !!params.id
|
||||
const toUserId = params.id ? Number(params.id) : undefined
|
||||
@@ -38,9 +45,7 @@ const AddMessage = () => {
|
||||
// 设置选中的患者(供其他页面调用)
|
||||
// @ts-ignore
|
||||
const setSelectedPatientFunc = (patient: ClinicPatientUser) => {
|
||||
console.log('患者:', patient)
|
||||
setSelectedPatient(patient)
|
||||
console.log(selectedPatient,'selectedPatient')
|
||||
}
|
||||
|
||||
// 设置选中的处方(供其他页面调用)
|
||||
@@ -49,15 +54,18 @@ const AddMessage = () => {
|
||||
setSelectedPrescription(prescription)
|
||||
}
|
||||
|
||||
// 处理表单字段变化
|
||||
const handleFormChange = (field: string, value: string) => {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
[field]: value
|
||||
}))
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitSucceed = async (values: any) => {
|
||||
try {
|
||||
// 准备提交的数据
|
||||
const submitData = {
|
||||
...values
|
||||
};
|
||||
|
||||
console.log('提交数据:', submitData)
|
||||
console.log('提交数据:', values)
|
||||
|
||||
// 参数校验
|
||||
if(!toUser && !selectedPatient){
|
||||
@@ -71,14 +79,13 @@ const AddMessage = () => {
|
||||
// 判断内容是否为空
|
||||
if (!values.content) {
|
||||
Taro.showToast({
|
||||
title: `请输入内容`,
|
||||
title: `请输入消息内容`,
|
||||
icon: 'error'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果选择了患者,在消息内容中添加患者信息
|
||||
console.log(values,'vals.s..s.s.s.s.s')
|
||||
let content = values.content;
|
||||
if (selectedPatient) {
|
||||
content = `[患者: ${selectedPatient.realName || '未知'}] ${content}`;
|
||||
@@ -89,6 +96,19 @@ const AddMessage = () => {
|
||||
content = `[处方: ${selectedPrescription.orderNo || '未知'}] ${content}`;
|
||||
}
|
||||
|
||||
// 添加诊断结果和治疗方案到消息内容
|
||||
if (values.diagnosis) {
|
||||
content = `诊断结果: ${values.diagnosis}\n` + content;
|
||||
}
|
||||
|
||||
if (values.treatmentPlan) {
|
||||
content = `治疗方案: ${values.treatmentPlan}\n` + content;
|
||||
}
|
||||
|
||||
if (values.decoctionInstructions) {
|
||||
content = `煎药说明: ${values.decoctionInstructions}\n` + content;
|
||||
}
|
||||
|
||||
// 执行新增或更新操作
|
||||
await addShopChatMessage({
|
||||
toUserId: toUserId || selectedPatient?.userId,
|
||||
@@ -129,6 +149,19 @@ const AddMessage = () => {
|
||||
Taro.getCurrentInstance().page.setSelectedPatient = setSelectedPatientFunc;
|
||||
// @ts-ignore
|
||||
Taro.getCurrentInstance().page.setSelectedPrescription = setSelectedPrescriptionFunc;
|
||||
|
||||
// 从本地存储获取之前选择的患者和处方
|
||||
const storedPatient = Taro.getStorageSync('selectedPatient');
|
||||
if (storedPatient) {
|
||||
setSelectedPatient(JSON.parse(storedPatient));
|
||||
Taro.removeStorageSync('selectedPatient');
|
||||
}
|
||||
|
||||
const storedPrescription = Taro.getStorageSync('selectedPrescription');
|
||||
if (storedPrescription) {
|
||||
setSelectedPrescription(JSON.parse(storedPrescription));
|
||||
Taro.removeStorageSync('selectedPrescription');
|
||||
}
|
||||
}, [isEditMode]);
|
||||
|
||||
if (loading) {
|
||||
@@ -153,7 +186,6 @@ const AddMessage = () => {
|
||||
)}
|
||||
|
||||
{/* 选择患者 */}
|
||||
{JSON.stringify(selectedPatient)}
|
||||
<Cell
|
||||
title="选择患者"
|
||||
extra={selectedPatient ? (
|
||||
@@ -162,22 +194,36 @@ const AddMessage = () => {
|
||||
<ArrowRight color="#cccccc" size={18}/>
|
||||
</View>
|
||||
) : (
|
||||
<ArrowRight color="#cccccc" size={18}/>
|
||||
<Text className={'text-gray-400'}>请选择患者</Text>
|
||||
)}
|
||||
onClick={() => navTo(`/doctor/orders/selectPatient`, true)}
|
||||
/>
|
||||
|
||||
<Cell
|
||||
title="诊断结果"
|
||||
extra={selectedPatient ? (
|
||||
<Form.Item name="content" initialValue={FormData?.diagnosis} required>
|
||||
<Input placeholder="填写诊断结果" maxLength={300}/>
|
||||
</Form.Item>
|
||||
) : (
|
||||
<ArrowRight color="#cccccc" size={18}/>
|
||||
)}
|
||||
onClick={() => navTo(`/doctor/orders/selectPatient`, true)}
|
||||
{/* 诊断结果 */}
|
||||
<CellGroup>
|
||||
<Cell title="诊断结果">
|
||||
<TextArea
|
||||
value={formData.diagnosis}
|
||||
onChange={(value) => handleFormChange('diagnosis', value)}
|
||||
placeholder="请填写诊断结果"
|
||||
rows={2}
|
||||
maxLength={200}
|
||||
/>
|
||||
</Cell>
|
||||
</CellGroup>
|
||||
|
||||
{/* 治疗方案 */}
|
||||
<CellGroup>
|
||||
<Cell title="治疗方案">
|
||||
<TextArea
|
||||
value={formData.treatmentPlan}
|
||||
onChange={(value) => handleFormChange('treatmentPlan', value)}
|
||||
placeholder="请填写治疗方案"
|
||||
rows={2}
|
||||
maxLength={200}
|
||||
/>
|
||||
</Cell>
|
||||
</CellGroup>
|
||||
|
||||
{/* 选择处方 */}
|
||||
<Cell
|
||||
@@ -188,46 +234,76 @@ const AddMessage = () => {
|
||||
<ArrowRight color="#cccccc" size={18}/>
|
||||
</View>
|
||||
) : (
|
||||
<ArrowRight color="#cccccc" size={18}/>
|
||||
<Text className={'text-gray-400'}>请选择处方</Text>
|
||||
)}
|
||||
onClick={() => navTo(`/doctor/orders/selectPrescription`, true)}
|
||||
/>
|
||||
|
||||
<Cell
|
||||
title="药方信息"
|
||||
extra={selectedPrescription ? (
|
||||
<View className={'flex items-center'}>
|
||||
{/* 药方信息 */}
|
||||
{selectedPrescription && (
|
||||
<CellGroup>
|
||||
<Cell title="药方信息">
|
||||
<View className={'flex flex-wrap'}>
|
||||
{selectedPrescription.items?.map(item => (
|
||||
<Tag key={item.id} className={'mr-2'}>{item.medicineName}</Tag>
|
||||
<Tag key={item.id} className={'mr-2 mb-2'}>{item.medicineName}</Tag>
|
||||
))}
|
||||
</View>
|
||||
) : (
|
||||
<ArrowRight color="#cccccc" size={18}/>
|
||||
)}
|
||||
onClick={() => navTo(`/doctor/orders/selectPrescription`, true)}
|
||||
</Cell>
|
||||
|
||||
{/* 煎药说明 */}
|
||||
<Cell title="煎药说明">
|
||||
<TextArea
|
||||
value={formData.decoctionInstructions}
|
||||
onChange={(value) => handleFormChange('decoctionInstructions', value)}
|
||||
placeholder="请填写煎药说明"
|
||||
rows={2}
|
||||
maxLength={200}
|
||||
/>
|
||||
</Cell>
|
||||
</CellGroup>
|
||||
)}
|
||||
|
||||
|
||||
{/* 消息内容 */}
|
||||
<CellGroup>
|
||||
<Cell title="消息内容">
|
||||
<TextArea
|
||||
value={formData.content}
|
||||
onChange={(value) => handleFormChange('content', value)}
|
||||
placeholder="请填写要发送的消息内容"
|
||||
rows={3}
|
||||
maxLength={300}
|
||||
/>
|
||||
</Cell>
|
||||
</CellGroup>
|
||||
|
||||
<Form
|
||||
ref={formRef}
|
||||
divider
|
||||
initialValues={FormData}
|
||||
initialValues={formData}
|
||||
labelPosition="left"
|
||||
onFinish={(values) => submitSucceed(values)}
|
||||
onFinishFailed={(errors) => submitFailed(errors)}
|
||||
>
|
||||
<CellGroup style={{padding: '4px 0'}}>
|
||||
<Form.Item name="content" initialValue={FormData?.decoctionInstructions} required>
|
||||
<Input placeholder="填写消息内容" maxLength={300}/>
|
||||
<Form.Item name="diagnosis" initialValue={formData.diagnosis}>
|
||||
<Input type="hidden" />
|
||||
</Form.Item>
|
||||
<Form.Item name="treatmentPlan" initialValue={formData.treatmentPlan}>
|
||||
<Input type="hidden" />
|
||||
</Form.Item>
|
||||
<Form.Item name="decoctionInstructions" initialValue={formData.decoctionInstructions}>
|
||||
<Input type="hidden" />
|
||||
</Form.Item>
|
||||
<Form.Item name="content" initialValue={formData.content} required>
|
||||
<Input type="hidden" />
|
||||
</Form.Item>
|
||||
</CellGroup>
|
||||
</Form>
|
||||
|
||||
{/* 底部浮动按钮 */}
|
||||
<FixedButton text={isEditMode ? '立即发送' : '立即发送'} onClick={() => formRef.current?.submit()}/>
|
||||
<FixedButton text={'立即发送'} onClick={() => formRef.current?.submit()}/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AddMessage;
|
||||
export default AddOrder;
|
||||
@@ -130,10 +130,12 @@ 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')
|
||||
}
|
||||
}
|
||||
Taro.navigateBack();
|
||||
|
||||
Reference in New Issue
Block a user