119 lines
3.3 KiB
JavaScript
119 lines
3.3 KiB
JavaScript
// pages/surgery/detail/index.js
|
|
const { surgeryApi } = require("../../../utils/api");
|
|
const dayjs = require("../../../miniprogram_npm/dayjs/index");
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
surgeryId: null, // 手术ID
|
|
surgery: null, // 手术数据
|
|
loading: true, // 加载状态
|
|
loadError: false, // 加载错误状态
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
if (options && options.id) {
|
|
const surgeryId = Number(options.id);
|
|
this.setData({ surgeryId });
|
|
this.fetchSurgeryDetail(surgeryId);
|
|
} else {
|
|
wx.showToast({
|
|
title: '参数错误',
|
|
icon: 'error'
|
|
});
|
|
// 返回上一页
|
|
setTimeout(() => {
|
|
wx.navigateBack();
|
|
}, 1500);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 获取手术详情数据
|
|
*/
|
|
async fetchSurgeryDetail(surgeryId) {
|
|
this.setData({
|
|
loading: true,
|
|
loadError: false
|
|
});
|
|
|
|
try {
|
|
// 修正API调用方法名 - 从getSurgeryDetail改为getSurgeryById
|
|
const res = await surgeryApi.getSurgeryById(surgeryId);
|
|
|
|
// 处理手术数据,格式化日期和设备数据
|
|
const surgery = res.data;
|
|
|
|
// 处理医生和科室信息
|
|
const hasDoctor = !!surgery.doctor;
|
|
const hasDepartment = !!surgery.doctor?.department;
|
|
const doctorName = hasDoctor ? surgery.doctor.name : '未知医生';
|
|
const departmentName = hasDepartment ? surgery.doctor.department.name : '未知科室';
|
|
|
|
// 格式化设备数据,将设备名称和子设备名称结合显示
|
|
let devices = [];
|
|
if (surgery.surgerySubDevices && surgery.surgerySubDevices.length > 0) {
|
|
devices = surgery.surgerySubDevices.map(item => {
|
|
// 获取主设备名称和子设备名称(通常是编号)
|
|
const deviceName = item.subDevice.device.name || '未知设备';
|
|
const subDeviceName = item.subDevice.name || '';
|
|
|
|
// 格式化使用时间
|
|
let startTimeDisplay = '未设置';
|
|
let endTimeDisplay = '未设置';
|
|
if (item.start_time) {
|
|
startTimeDisplay = dayjs(item.start_time).format('YYYY-MM-DD HH:mm');
|
|
}
|
|
if (item.end_time) {
|
|
endTimeDisplay = dayjs(item.end_time).format('YYYY-MM-DD HH:mm');
|
|
}
|
|
|
|
return {
|
|
id: item.sub_device_id,
|
|
surgerySubDeviceId: item.id,
|
|
// 组合成"设备名称-子设备号"的格式
|
|
displayName: `${deviceName}-${subDeviceName}`,
|
|
startTime: item.start_time,
|
|
endTime: item.end_time,
|
|
startTimeDisplay,
|
|
endTimeDisplay
|
|
};
|
|
});
|
|
}
|
|
|
|
const formattedSurgery = {
|
|
...surgery,
|
|
formattedTime: dayjs(surgery.surgery_time).format('YYYY年MM月DD日 HH:mm'),
|
|
doctorName,
|
|
departmentName,
|
|
devices
|
|
};
|
|
|
|
this.setData({
|
|
surgery: formattedSurgery,
|
|
loading: false
|
|
});
|
|
} catch (error) {
|
|
this.setData({
|
|
loading: false,
|
|
loadError: true
|
|
});
|
|
wx.showToast({
|
|
title: '获取手术详情失败',
|
|
icon: 'error'
|
|
});
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 返回上一级页面
|
|
*/
|
|
goBack() {
|
|
wx.navigateBack();
|
|
}
|
|
}) |