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