You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
274 lines
7.3 KiB
274 lines
7.3 KiB
import http from '../../../utils/api'
|
|
const baseUrl = require('../../../utils/baseUrl')
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
diagnosisData: {},
|
|
replies: [],
|
|
baseUrl: baseUrl,
|
|
refreshing: false
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
if (options.data) {
|
|
// 根据id加载兽医回复数据
|
|
const data = JSON.parse(decodeURIComponent(options.data));
|
|
|
|
// 处理用户图片 - 确保是数组格式
|
|
if (data.images) {
|
|
if (typeof data.images === 'string') {
|
|
data.images = data.images.split(',')
|
|
}
|
|
console.log('用户图片:', data.images);
|
|
} else {
|
|
data.images = [];
|
|
}
|
|
|
|
this.setData({
|
|
diagnosisData: data,
|
|
})
|
|
this.loadDiagnosisData(data.formId);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 加载问诊数据(兽医回复)
|
|
* @param {string} id - 问诊ID
|
|
*/
|
|
loadDiagnosisData(id) {
|
|
console.log('加载问诊数据:', id);
|
|
http.wzdxq({
|
|
data: {
|
|
consultationId: id
|
|
},
|
|
success: res => {
|
|
// 处理兽医回复的图片
|
|
let replies = [];
|
|
|
|
if (res && res.rows) {
|
|
replies = res.rows || [];
|
|
|
|
// 遍历每个回复,处理图片字段
|
|
for (let i = 0; i < replies.length; i++) {
|
|
const item = replies[i];
|
|
|
|
// 处理图片 - 确保是数组格式
|
|
if (item.images) {
|
|
if (typeof item.images === 'string') {
|
|
// 如果是空字符串,设为空数组
|
|
if (item.images.trim() === '') {
|
|
item.images = [];
|
|
} else {
|
|
// 按逗号分割字符串
|
|
item.images = item.images.split(',');
|
|
}
|
|
} else if (Array.isArray(item.images)) {
|
|
// 已经是数组,但需要过滤空值
|
|
item.images = item.images.filter(img => img && img.trim() !== '');
|
|
} else {
|
|
item.images = [];
|
|
}
|
|
} else {
|
|
item.images = [];
|
|
}
|
|
|
|
console.log(`兽医回复[${i}]图片:`, item.images);
|
|
}
|
|
}
|
|
|
|
console.log('兽医回复数据:', replies);
|
|
this.setData({
|
|
replies: replies
|
|
})
|
|
},
|
|
fail: err => {
|
|
console.error('加载回复失败:', err);
|
|
wx.showToast({
|
|
title: '加载失败',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 返回上一页
|
|
*/
|
|
goBack() {
|
|
wx.navigateBack();
|
|
},
|
|
|
|
/**
|
|
* 分享
|
|
*/
|
|
onShare() {
|
|
wx.showActionSheet({
|
|
itemList: ['分享给好友', '保存到相册'],
|
|
success: (res) => {
|
|
if (res.tapIndex === 0) {
|
|
wx.showToast({
|
|
title: '已分享',
|
|
icon: 'success'
|
|
});
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 下拉刷新
|
|
*/
|
|
onRefresh() {
|
|
this.setData({
|
|
refreshing: true
|
|
});
|
|
|
|
if (this.data.diagnosisData && this.data.diagnosisData.formId) {
|
|
this.loadDiagnosisData(this.data.diagnosisData.formId)
|
|
}
|
|
|
|
setTimeout(() => {
|
|
this.setData({
|
|
refreshing: false
|
|
});
|
|
wx.showToast({
|
|
title: '刷新成功',
|
|
icon: 'success'
|
|
});
|
|
}, 1000);
|
|
},
|
|
|
|
/**
|
|
* 预览用户图片
|
|
*/
|
|
previewImage(e) {
|
|
const dataset = e.currentTarget.dataset;
|
|
const current = dataset.url;
|
|
const urls = dataset.urls || [];
|
|
|
|
// 构建完整URL数组
|
|
const urlsArray = urls.map(item => {
|
|
// 如果已经是完整URL,直接返回
|
|
if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
|
|
return item;
|
|
}
|
|
// 否则拼接baseUrl
|
|
return baseUrl + item;
|
|
});
|
|
|
|
console.log('预览用户图片:', urlsArray);
|
|
wx.previewImage({
|
|
current: current,
|
|
urls: urlsArray
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 预览兽医回复图片 - 修复版
|
|
*/
|
|
previewReplyImage(e) {
|
|
const dataset = e.currentTarget.dataset;
|
|
|
|
// 获取数据 - 使用三种可能的来源
|
|
const currentFileName = dataset.url; // 当前点击的图片文件名
|
|
const currentFullUrl = dataset.fullurl; // 当前点击的图片完整URL
|
|
const urlsArray = dataset.urls || []; // 该回复的所有图片文件名数组
|
|
const currentIndex = dataset.currentIndex || 0; // 当前点击图片的索引
|
|
const replyIndex = dataset.replyIndex; // 回复在列表中的索引
|
|
|
|
console.log('预览兽医图片 - 数据集:', dataset);
|
|
|
|
// 方法1: 从replies数据中获取当前回复的图片列表
|
|
let targetUrls = [];
|
|
let targetCurrentUrl = '';
|
|
|
|
if (replyIndex !== undefined && this.data.replies[replyIndex]) {
|
|
// 从replies数据中获取完整的图片列表
|
|
const reply = this.data.replies[replyIndex];
|
|
if (reply.images && reply.images.length > 0) {
|
|
targetUrls = reply.images;
|
|
|
|
// 构建完整URL数组
|
|
const fullUrls = targetUrls.map(img => {
|
|
if (typeof img === 'string' && (img.startsWith('http://') || img.startsWith('https://'))) {
|
|
return img;
|
|
}
|
|
return baseUrl + img;
|
|
});
|
|
|
|
// 确定当前图片的完整URL
|
|
if (currentIndex < fullUrls.length) {
|
|
targetCurrentUrl = fullUrls[currentIndex];
|
|
} else if (currentFullUrl) {
|
|
targetCurrentUrl = currentFullUrl;
|
|
} else if (currentFileName) {
|
|
targetCurrentUrl = baseUrl + currentFileName;
|
|
}
|
|
|
|
console.log('预览兽医回复图片(从replies数据):', fullUrls, '当前:', targetCurrentUrl);
|
|
|
|
wx.previewImage({
|
|
current: targetCurrentUrl,
|
|
urls: fullUrls
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 方法2: 使用dataset中的数据
|
|
if (urlsArray && urlsArray.length > 0) {
|
|
// 构建完整URL数组
|
|
const fullUrls = urlsArray.map(item => {
|
|
if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
|
|
return item;
|
|
}
|
|
return baseUrl + item;
|
|
});
|
|
|
|
// 确定当前图片的完整URL
|
|
let currentUrl = '';
|
|
if (currentFullUrl) {
|
|
currentUrl = currentFullUrl;
|
|
} else if (currentIndex < fullUrls.length) {
|
|
currentUrl = fullUrls[currentIndex];
|
|
} else if (currentFileName) {
|
|
currentUrl = baseUrl + currentFileName;
|
|
}
|
|
|
|
console.log('预览兽医回复图片(从dataset):', fullUrls, '当前:', currentUrl);
|
|
|
|
wx.previewImage({
|
|
current: currentUrl,
|
|
urls: fullUrls
|
|
});
|
|
return;
|
|
}
|
|
|
|
// 方法3: 只预览单张图片
|
|
if (currentFullUrl) {
|
|
console.log('预览单张兽医图片:', [currentFullUrl]);
|
|
wx.previewImage({
|
|
current: currentFullUrl,
|
|
urls: [currentFullUrl]
|
|
});
|
|
} else if (currentFileName) {
|
|
const fullUrl = baseUrl + currentFileName;
|
|
console.log('预览单张兽医图片(拼接后):', [fullUrl]);
|
|
wx.previewImage({
|
|
current: fullUrl,
|
|
urls: [fullUrl]
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: '图片预览失败',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
}
|
|
});
|