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.
298 lines
7.2 KiB
298 lines
7.2 KiB
import http from '../../../utils/api'
|
|
const baseUrl = require('../../../utils/baseUrl')
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
diagnosisData: {},
|
|
replies: [],
|
|
baseUrl: baseUrl,
|
|
refreshing: false,
|
|
showPlanModal: false, // 控制弹框显示
|
|
planList: [] // 方案列表数据
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
if (options.id) {
|
|
this.getwzdetails(options.id)
|
|
}
|
|
},
|
|
|
|
// 问诊单详情
|
|
getwzdetails(id) {
|
|
http.wzdDetails({
|
|
data: {
|
|
id: id
|
|
},
|
|
success: res => {
|
|
console.log(1111, res);
|
|
if (res.data.images) {
|
|
if (typeof res.data.images === 'string') {
|
|
res.data.images = res.data.images.split(',')
|
|
}
|
|
} else {
|
|
res.data.images = [];
|
|
}
|
|
|
|
this.loadDiagnosisData(res.data.formId);
|
|
|
|
this.setData({
|
|
diagnosisData: res.data,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
// 加载问诊数据(兽医回复)
|
|
loadDiagnosisData(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 = [];
|
|
}
|
|
}
|
|
}
|
|
this.setData({
|
|
replies: replies
|
|
})
|
|
},
|
|
fail: err => {
|
|
wx.showToast({
|
|
title: '加载失败',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
// 获取方案列表
|
|
getplanDetails(id) {
|
|
http.planDetails({
|
|
data: {
|
|
consultationId: id
|
|
},
|
|
success: res => {
|
|
console.log('方案列表:', res);
|
|
let list = [];
|
|
if (res.rows) {
|
|
list = res.rows
|
|
|
|
// 处理图片字段
|
|
list.forEach(item => {
|
|
if (item.images) {
|
|
if (typeof item.images === 'string') {
|
|
item.images = item.images ? item.images.split(',') : [];
|
|
}
|
|
} else {
|
|
item.images = [];
|
|
}
|
|
});
|
|
}
|
|
this.setData({ planList: list });
|
|
},
|
|
fail: err => {
|
|
console.error('获取方案列表失败', err);
|
|
wx.showToast({
|
|
title: '获取方案失败',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
// 显示方案弹框
|
|
showPlanModal() {
|
|
const consultationId = this.data.diagnosisData.id || this.data.diagnosisData.formId;
|
|
if (!consultationId) {
|
|
wx.showToast({ title: '问诊单ID不存在', icon: 'none' });
|
|
return;
|
|
}
|
|
wx.showLoading({ title: '加载中...', mask: true });
|
|
this.getplanDetails(consultationId);
|
|
setTimeout(() => {
|
|
wx.hideLoading();
|
|
this.setData({ showPlanModal: true });
|
|
}, 500);
|
|
},
|
|
|
|
// 隐藏方案弹框
|
|
hidePlanModal() {
|
|
this.setData({ showPlanModal: false });
|
|
},
|
|
|
|
// 阻止事件冒泡
|
|
stopPropagation() {
|
|
return;
|
|
},
|
|
|
|
// 阻止触摸滚动
|
|
preventTouch() {
|
|
return;
|
|
},
|
|
|
|
// 预览方案图片
|
|
previewPlanImage(e) {
|
|
const dataset = e.currentTarget.dataset;
|
|
const currentUrl = dataset.url;
|
|
const urls = dataset.urls || [];
|
|
const base = dataset.base || baseUrl;
|
|
|
|
const fullUrls = urls.map(item => {
|
|
if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
|
|
return item;
|
|
}
|
|
return base + item;
|
|
});
|
|
|
|
wx.previewImage({
|
|
current: currentUrl,
|
|
urls: fullUrls
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 返回上一页
|
|
*/
|
|
goBack() {
|
|
wx.navigateBack();
|
|
},
|
|
|
|
/**
|
|
* 下拉刷新
|
|
*/
|
|
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 || [];
|
|
const urlsArray = urls.map(item => {
|
|
if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
|
|
return item;
|
|
}
|
|
return baseUrl + item;
|
|
});
|
|
wx.previewImage({
|
|
current: current,
|
|
urls: urlsArray
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 预览兽医回复图片
|
|
*/
|
|
previewReplyImage(e) {
|
|
const dataset = e.currentTarget.dataset;
|
|
const currentFileName = dataset.url;
|
|
const currentFullUrl = dataset.fullurl;
|
|
const urlsArray = dataset.urls || [];
|
|
const currentIndex = dataset.currentIndex || 0;
|
|
const replyIndex = dataset.replyIndex;
|
|
|
|
if (replyIndex !== undefined && this.data.replies[replyIndex]) {
|
|
const reply = this.data.replies[replyIndex];
|
|
if (reply.images && reply.images.length > 0) {
|
|
const targetUrls = reply.images;
|
|
const fullUrls = targetUrls.map(img => {
|
|
if (typeof img === 'string' && (img.startsWith('http://') || img.startsWith('https://'))) {
|
|
return img;
|
|
}
|
|
return baseUrl + img;
|
|
});
|
|
let targetCurrentUrl = '';
|
|
if (currentIndex < fullUrls.length) {
|
|
targetCurrentUrl = fullUrls[currentIndex];
|
|
} else if (currentFullUrl) {
|
|
targetCurrentUrl = currentFullUrl;
|
|
} else if (currentFileName) {
|
|
targetCurrentUrl = baseUrl + currentFileName;
|
|
}
|
|
wx.previewImage({
|
|
current: targetCurrentUrl,
|
|
urls: fullUrls
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (urlsArray && urlsArray.length > 0) {
|
|
const fullUrls = urlsArray.map(item => {
|
|
if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
|
|
return item;
|
|
}
|
|
return baseUrl + item;
|
|
});
|
|
let currentUrl = '';
|
|
if (currentFullUrl) {
|
|
currentUrl = currentFullUrl;
|
|
} else if (currentIndex < fullUrls.length) {
|
|
currentUrl = fullUrls[currentIndex];
|
|
} else if (currentFileName) {
|
|
currentUrl = baseUrl + currentFileName;
|
|
}
|
|
wx.previewImage({
|
|
current: currentUrl,
|
|
urls: fullUrls
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (currentFullUrl) {
|
|
wx.previewImage({
|
|
current: currentFullUrl,
|
|
urls: [currentFullUrl]
|
|
});
|
|
} else if (currentFileName) {
|
|
const fullUrl = baseUrl + currentFileName;
|
|
wx.previewImage({
|
|
current: fullUrl,
|
|
urls: [fullUrl]
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: '图片预览失败',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
}
|
|
});
|