refactor(clinic): 重构处方订单相关功能
- 删除废弃的处方订单模型定义文件 - 删除处方订单相关的API接口文件 - 更新处方API返回类型为ClinicPrescription - 移除新增处方订单页面配置文件 - 移除新增处方订单页面组件文件 - 移除处方订单管理页面配置文件 - 移除处方订单管理页面组件文件 - 修改医生确认订单页面逻辑,分离处方与订单创建流程- 更新医生订单列表页面,使用处方数据替代经销商订单数据- 调整订单数据结构,关联处方ID和处方编号 -优化订单创建流程,先创建处方再创建订单 - 移除冗余的经销商订单相关导入和类型定义
This commit is contained in:
@@ -14,7 +14,8 @@ import Taro from '@tarojs/taro'
|
||||
import FixedButton from "@/components/FixedButton";
|
||||
import {ClinicPatientUser} from "@/api/clinic/clinicPatientUser/model";
|
||||
import {ClinicPrescription} from "@/api/clinic/clinicPrescription/model";
|
||||
import {addClinicOrder} from "@/api/clinic/clinicOrder";
|
||||
import {addClinicPrescription} from "@/api/clinic/clinicPrescription";
|
||||
import {addClinicPrescriptionItem} from "@/api/clinic/clinicPrescriptionItem";
|
||||
import './confirm.scss'
|
||||
|
||||
// 订单数据接口
|
||||
@@ -84,32 +85,84 @@ const DoctorOrderConfirm = () => {
|
||||
try {
|
||||
setSubmitLoading(true)
|
||||
|
||||
// 构建诊所订单数据
|
||||
const doctorId = Taro.getStorageSync('UserId') // 当前医生ID
|
||||
|
||||
// 第一步:创建处方主表记录
|
||||
console.log('开始创建处方记录...')
|
||||
const prescriptionData: ClinicPrescription = {
|
||||
userId: orderData.patient.userId,
|
||||
doctorId: doctorId,
|
||||
prescriptionType: orderData.prescription?.prescriptionType || 0, // 处方类型
|
||||
diagnosis: orderData.diagnosis, // 诊断结果
|
||||
treatmentPlan: orderData.treatmentPlan, // 治疗方案
|
||||
decoctionInstructions: orderData.decoctionInstructions, // 煎药说明
|
||||
image: orderData.images ? JSON.stringify(orderData.images) : '', // 病例图片
|
||||
orderPrice: getTotalPrice(), // 订单总金额
|
||||
price: getMedicinePrice(), // 药品单价
|
||||
payPrice: getTotalPrice(), // 实付金额
|
||||
status: 0, // 状态:0正常
|
||||
isInvalid: 0, // 未失效
|
||||
isSettled: 0, // 未结算
|
||||
comments: `患者:${orderData.patient.realName},年龄:${orderData.patient.age}岁`
|
||||
}
|
||||
|
||||
const createdPrescription = await addClinicPrescription(prescriptionData)
|
||||
console.log('处方创建成功:', createdPrescription)
|
||||
|
||||
if (!createdPrescription || !createdPrescription.id) {
|
||||
throw new Error('处方创建失败,未返回处方ID')
|
||||
}
|
||||
|
||||
const prescriptionId = createdPrescription.id
|
||||
|
||||
// 第二步:创建处方明细记录(药品列表)
|
||||
if (orderData.prescription?.items && orderData.prescription.items.length > 0) {
|
||||
console.log('开始创建处方明细...')
|
||||
for (const item of orderData.prescription.items) {
|
||||
const prescriptionItemData = {
|
||||
prescriptionId: prescriptionId, // 关联处方ID
|
||||
prescriptionNo: createdPrescription.orderNo, // 处方编号
|
||||
medicineId: item.medicineId,
|
||||
medicineName: item.medicineName,
|
||||
specification: item.specification,
|
||||
dosage: item.dosage,
|
||||
usageFrequency: item.usageFrequency,
|
||||
days: item.days,
|
||||
amount: item.amount,
|
||||
unitPrice: item.unitPrice,
|
||||
quantity: item.quantity,
|
||||
userId: orderData.patient.userId,
|
||||
comments: item.comments
|
||||
}
|
||||
await addClinicPrescriptionItem(prescriptionItemData)
|
||||
}
|
||||
console.log('处方明细创建成功')
|
||||
}
|
||||
|
||||
// 第三步:创建订单记录,关联处方ID
|
||||
console.log('开始创建订单记录...')
|
||||
const clinicOrderData = {
|
||||
userId: orderData.patient.userId,
|
||||
doctorId: Taro.getStorageSync('UserId'), // 当前医生ID
|
||||
doctorId: doctorId,
|
||||
type: 0, // 订单类型:诊所订单
|
||||
title: `${orderData.patient.realName}的处方订单`,
|
||||
totalPrice: getTotalPrice(),
|
||||
payPrice: getTotalPrice(),
|
||||
buyerRemarks: orderData.diagnosis,
|
||||
buyerRemarks: `诊断:${orderData.diagnosis}`,
|
||||
merchantRemarks: orderData.treatmentPlan,
|
||||
comments: JSON.stringify({
|
||||
diagnosis: orderData.diagnosis,
|
||||
treatmentPlan: orderData.treatmentPlan,
|
||||
decoctionInstructions: orderData.decoctionInstructions,
|
||||
prescriptionId: orderData.prescription?.id,
|
||||
images: orderData.images
|
||||
prescriptionId: prescriptionId, // 关联处方ID
|
||||
prescriptionNo: createdPrescription.orderNo, // 处方编号
|
||||
patientName: orderData.patient.realName,
|
||||
patientAge: orderData.patient.age
|
||||
}),
|
||||
payStatus: '0', // 未付款
|
||||
orderStatus: 0, // 待支付
|
||||
deliveryStatus: 10, // 未发货
|
||||
}
|
||||
|
||||
console.log('提交订单数据:', clinicOrderData)
|
||||
|
||||
// 调用API创建订单
|
||||
await addClinicOrder(clinicOrderData)
|
||||
await addClinicPrescription(clinicOrderData)
|
||||
console.log('订单创建成功')
|
||||
|
||||
// 清除临时数据
|
||||
Taro.removeStorageSync('tempOrderData')
|
||||
@@ -128,7 +181,7 @@ const DoctorOrderConfirm = () => {
|
||||
}, 2000)
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('创建订单失败:', error)
|
||||
console.error('创建处方/订单失败:', error)
|
||||
Taro.showToast({
|
||||
title: error.message || '发送失败,请重试',
|
||||
icon: 'error'
|
||||
|
||||
@@ -2,21 +2,15 @@ import React, {useState, useEffect, useCallback} from 'react'
|
||||
import {View, Text, ScrollView} from '@tarojs/components'
|
||||
import {Empty, Tag, PullToRefresh, Loading} from '@nutui/nutui-react-taro'
|
||||
import Taro from '@tarojs/taro'
|
||||
import {pageShopDealerOrder} from '@/api/shop/shopDealerOrder'
|
||||
import {useDealerUser} from '@/hooks/useDealerUser'
|
||||
import type {ShopDealerOrder} from '@/api/shop/shopDealerOrder/model'
|
||||
|
||||
interface OrderWithDetails extends ShopDealerOrder {
|
||||
orderNo?: string
|
||||
customerName?: string
|
||||
userCommission?: string
|
||||
}
|
||||
import {ClinicPrescription} from "@/api/clinic/clinicPrescription/model";
|
||||
import {pageClinicPrescription} from "@/api/clinic/clinicPrescription";
|
||||
|
||||
const DealerOrders: React.FC = () => {
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [refreshing, setRefreshing] = useState<boolean>(false)
|
||||
const [loadingMore, setLoadingMore] = useState<boolean>(false)
|
||||
const [orders, setOrders] = useState<OrderWithDetails[]>([])
|
||||
const [orders, setOrders] = useState<ClinicPrescription[]>([])
|
||||
const [currentPage, setCurrentPage] = useState<number>(1)
|
||||
const [hasMore, setHasMore] = useState<boolean>(true)
|
||||
|
||||
@@ -24,8 +18,7 @@ const DealerOrders: React.FC = () => {
|
||||
|
||||
// 获取订单数据
|
||||
const fetchOrders = useCallback(async (page: number = 1, isRefresh: boolean = false) => {
|
||||
if (!dealerUser?.userId) return
|
||||
|
||||
console.log('获取订单数据')
|
||||
try {
|
||||
if (isRefresh) {
|
||||
setRefreshing(true)
|
||||
@@ -35,17 +28,14 @@ const DealerOrders: React.FC = () => {
|
||||
setLoadingMore(true)
|
||||
}
|
||||
|
||||
const result = await pageShopDealerOrder({
|
||||
const result = await pageClinicPrescription({
|
||||
page,
|
||||
limit: 10
|
||||
})
|
||||
|
||||
if (result?.list) {
|
||||
const newOrders = result.list.map(order => ({
|
||||
...order,
|
||||
orderNo: `${order.orderId}`,
|
||||
customerName: `用户${order.userId}`,
|
||||
userCommission: order.firstMoney || '0.00'
|
||||
...order
|
||||
}))
|
||||
|
||||
if (page === 1) {
|
||||
@@ -102,7 +92,7 @@ const DealerOrders: React.FC = () => {
|
||||
return 'warning'
|
||||
}
|
||||
|
||||
const renderOrderItem = (order: OrderWithDetails) => (
|
||||
const renderOrderItem = (order: ClinicPrescription) => (
|
||||
<View key={order.id} className="bg-white rounded-lg p-4 mb-3 shadow-sm">
|
||||
<View className="flex justify-between items-start mb-1">
|
||||
<Text className="font-semibold text-gray-800">
|
||||
@@ -117,15 +107,9 @@ const DealerOrders: React.FC = () => {
|
||||
<Text className="text-sm text-gray-400">
|
||||
订单金额:¥{order.orderPrice || '0.00'}
|
||||
</Text>
|
||||
<Text className="text-sm text-orange-500 font-semibold">
|
||||
我的佣金:¥{order.userCommission}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View className="flex justify-between items-center">
|
||||
<Text className="text-sm text-gray-400">
|
||||
客户:{order.customerName}
|
||||
</Text>
|
||||
<Text className="text-sm text-gray-400">
|
||||
{order.createTime}
|
||||
</Text>
|
||||
|
||||
Reference in New Issue
Block a user