与牧同行-小程序用户端
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.

297 lines
7.2 KiB

  1. import http from '../../../utils/api'
  2. const baseUrl = require('../../../utils/baseUrl')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. diagnosisData: {},
  9. replies: [],
  10. baseUrl: baseUrl,
  11. refreshing: false,
  12. showPlanModal: false, // 控制弹框显示
  13. planList: [] // 方案列表数据
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. if (options.id) {
  20. this.getwzdetails(options.id)
  21. }
  22. },
  23. // 问诊单详情
  24. getwzdetails(id) {
  25. http.wzdDetails({
  26. data: {
  27. id: id
  28. },
  29. success: res => {
  30. console.log(1111, res);
  31. if (res.data.images) {
  32. if (typeof res.data.images === 'string') {
  33. res.data.images = res.data.images.split(',')
  34. }
  35. } else {
  36. res.data.images = [];
  37. }
  38. this.loadDiagnosisData(res.data.formId);
  39. this.setData({
  40. diagnosisData: res.data,
  41. })
  42. }
  43. })
  44. },
  45. // 加载问诊数据(兽医回复)
  46. loadDiagnosisData(id) {
  47. http.wzdxq({
  48. data: {
  49. consultationId: id
  50. },
  51. success: res => {
  52. let replies = [];
  53. if (res && res.rows) {
  54. replies = res.rows || [];
  55. for (let i = 0; i < replies.length; i++) {
  56. const item = replies[i];
  57. if (item.images) {
  58. if (typeof item.images === 'string') {
  59. if (item.images.trim() === '') {
  60. item.images = [];
  61. } else {
  62. item.images = item.images.split(',');
  63. }
  64. } else if (Array.isArray(item.images)) {
  65. item.images = item.images.filter(img => img && img.trim() !== '');
  66. } else {
  67. item.images = [];
  68. }
  69. } else {
  70. item.images = [];
  71. }
  72. }
  73. }
  74. this.setData({
  75. replies: replies
  76. })
  77. },
  78. fail: err => {
  79. wx.showToast({
  80. title: '加载失败',
  81. icon: 'none'
  82. });
  83. }
  84. });
  85. },
  86. // 获取方案列表
  87. getplanDetails(id) {
  88. http.planDetails({
  89. data: {
  90. consultationId: id
  91. },
  92. success: res => {
  93. console.log('方案列表:', res);
  94. let list = [];
  95. if (res.rows) {
  96. list = res.rows
  97. // 处理图片字段
  98. list.forEach(item => {
  99. if (item.images) {
  100. if (typeof item.images === 'string') {
  101. item.images = item.images ? item.images.split(',') : [];
  102. }
  103. } else {
  104. item.images = [];
  105. }
  106. });
  107. }
  108. this.setData({ planList: list });
  109. },
  110. fail: err => {
  111. console.error('获取方案列表失败', err);
  112. wx.showToast({
  113. title: '获取方案失败',
  114. icon: 'none'
  115. });
  116. }
  117. });
  118. },
  119. // 显示方案弹框
  120. showPlanModal() {
  121. const consultationId = this.data.diagnosisData.id || this.data.diagnosisData.formId;
  122. if (!consultationId) {
  123. wx.showToast({ title: '问诊单ID不存在', icon: 'none' });
  124. return;
  125. }
  126. wx.showLoading({ title: '加载中...', mask: true });
  127. this.getplanDetails(consultationId);
  128. setTimeout(() => {
  129. wx.hideLoading();
  130. this.setData({ showPlanModal: true });
  131. }, 500);
  132. },
  133. // 隐藏方案弹框
  134. hidePlanModal() {
  135. this.setData({ showPlanModal: false });
  136. },
  137. // 阻止事件冒泡
  138. stopPropagation() {
  139. return;
  140. },
  141. // 阻止触摸滚动
  142. preventTouch() {
  143. return;
  144. },
  145. // 预览方案图片
  146. previewPlanImage(e) {
  147. const dataset = e.currentTarget.dataset;
  148. const currentUrl = dataset.url;
  149. const urls = dataset.urls || [];
  150. const base = dataset.base || baseUrl;
  151. const fullUrls = urls.map(item => {
  152. if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
  153. return item;
  154. }
  155. return base + item;
  156. });
  157. wx.previewImage({
  158. current: currentUrl,
  159. urls: fullUrls
  160. });
  161. },
  162. /**
  163. * 返回上一页
  164. */
  165. goBack() {
  166. wx.navigateBack();
  167. },
  168. /**
  169. * 下拉刷新
  170. */
  171. onRefresh() {
  172. this.setData({ refreshing: true });
  173. if (this.data.diagnosisData && this.data.diagnosisData.formId) {
  174. this.loadDiagnosisData(this.data.diagnosisData.formId);
  175. }
  176. setTimeout(() => {
  177. this.setData({ refreshing: false });
  178. wx.showToast({
  179. title: '刷新成功',
  180. icon: 'success'
  181. });
  182. }, 1000);
  183. },
  184. /**
  185. * 预览用户图片
  186. */
  187. previewImage(e) {
  188. const dataset = e.currentTarget.dataset;
  189. const current = dataset.url;
  190. const urls = dataset.urls || [];
  191. const urlsArray = urls.map(item => {
  192. if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
  193. return item;
  194. }
  195. return baseUrl + item;
  196. });
  197. wx.previewImage({
  198. current: current,
  199. urls: urlsArray
  200. });
  201. },
  202. /**
  203. * 预览兽医回复图片
  204. */
  205. previewReplyImage(e) {
  206. const dataset = e.currentTarget.dataset;
  207. const currentFileName = dataset.url;
  208. const currentFullUrl = dataset.fullurl;
  209. const urlsArray = dataset.urls || [];
  210. const currentIndex = dataset.currentIndex || 0;
  211. const replyIndex = dataset.replyIndex;
  212. if (replyIndex !== undefined && this.data.replies[replyIndex]) {
  213. const reply = this.data.replies[replyIndex];
  214. if (reply.images && reply.images.length > 0) {
  215. const targetUrls = reply.images;
  216. const fullUrls = targetUrls.map(img => {
  217. if (typeof img === 'string' && (img.startsWith('http://') || img.startsWith('https://'))) {
  218. return img;
  219. }
  220. return baseUrl + img;
  221. });
  222. let targetCurrentUrl = '';
  223. if (currentIndex < fullUrls.length) {
  224. targetCurrentUrl = fullUrls[currentIndex];
  225. } else if (currentFullUrl) {
  226. targetCurrentUrl = currentFullUrl;
  227. } else if (currentFileName) {
  228. targetCurrentUrl = baseUrl + currentFileName;
  229. }
  230. wx.previewImage({
  231. current: targetCurrentUrl,
  232. urls: fullUrls
  233. });
  234. return;
  235. }
  236. }
  237. if (urlsArray && urlsArray.length > 0) {
  238. const fullUrls = urlsArray.map(item => {
  239. if (typeof item === 'string' && (item.startsWith('http://') || item.startsWith('https://'))) {
  240. return item;
  241. }
  242. return baseUrl + item;
  243. });
  244. let currentUrl = '';
  245. if (currentFullUrl) {
  246. currentUrl = currentFullUrl;
  247. } else if (currentIndex < fullUrls.length) {
  248. currentUrl = fullUrls[currentIndex];
  249. } else if (currentFileName) {
  250. currentUrl = baseUrl + currentFileName;
  251. }
  252. wx.previewImage({
  253. current: currentUrl,
  254. urls: fullUrls
  255. });
  256. return;
  257. }
  258. if (currentFullUrl) {
  259. wx.previewImage({
  260. current: currentFullUrl,
  261. urls: [currentFullUrl]
  262. });
  263. } else if (currentFileName) {
  264. const fullUrl = baseUrl + currentFileName;
  265. wx.previewImage({
  266. current: fullUrl,
  267. urls: [fullUrl]
  268. });
  269. } else {
  270. wx.showToast({
  271. title: '图片预览失败',
  272. icon: 'none'
  273. });
  274. }
  275. }
  276. });