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

217 lines
4.8 KiB

  1. import http from '../../../utils/api'
  2. const baseUrl = require('../../../utils/baseUrl')
  3. Page({
  4. data: {
  5. diagnosisList: [],
  6. // 弹窗相关
  7. showPlanPopup: false,
  8. consultationId: null,
  9. baseUrl:baseUrl,
  10. planForm: {
  11. title: '', // 新增方案标题
  12. diagnosis: '',
  13. treatmentMethod: '',
  14. treatmentDesc: '',
  15. precautions: ''
  16. }
  17. },
  18. onLoad: function() {
  19. // 页面加载时可做一些初始化
  20. },
  21. onShow: function() {
  22. this.getwzd()
  23. },
  24. // 获取问诊列表
  25. getwzd() {
  26. http.wzd({
  27. data: {},
  28. success: res => {
  29. console.log('问诊列表:', res);
  30. this.setData({
  31. diagnosisList: res.rows || []
  32. })
  33. },
  34. fail: err => {
  35. console.error('获取问诊列表失败', err);
  36. wx.showToast({
  37. title: '加载失败',
  38. icon: 'none'
  39. });
  40. }
  41. })
  42. },
  43. // 制定方案(打开弹窗)
  44. bindPlan(e) {
  45. const consultationId = e.currentTarget.dataset.id;
  46. console.log('当前咨询ID:', consultationId);
  47. // 重置表单(包含title字段)
  48. this.setData({
  49. consultationId: consultationId,
  50. planForm: {
  51. title: '',
  52. diagnosis: '',
  53. treatmentMethod: '',
  54. treatmentDesc: '',
  55. precautions: ''
  56. },
  57. showPlanPopup: true
  58. });
  59. },
  60. // 关闭弹窗
  61. closePlanPopup() {
  62. this.setData({
  63. showPlanPopup: false,
  64. consultationId: null
  65. });
  66. },
  67. // 表单输入处理函数
  68. onTitleInput(e) {
  69. this.setData({
  70. 'planForm.title': e.detail.value
  71. });
  72. },
  73. onDiagnosisInput(e) {
  74. this.setData({
  75. 'planForm.diagnosis': e.detail.value
  76. });
  77. },
  78. onTreatmentMethodInput(e) {
  79. this.setData({
  80. 'planForm.treatmentMethod': e.detail.value
  81. });
  82. },
  83. onTreatmentDescInput(e) {
  84. this.setData({
  85. 'planForm.treatmentDesc': e.detail.value
  86. });
  87. },
  88. onPrecautionsInput(e) {
  89. this.setData({
  90. 'planForm.precautions': e.detail.value
  91. });
  92. },
  93. // 提交方案
  94. submitPlan() {
  95. const { title, diagnosis, treatmentMethod, treatmentDesc } = this.data.planForm;
  96. const consultationId = this.data.consultationId;
  97. // 必填校验(包含标题)
  98. if (!title || !title.trim()) {
  99. wx.showToast({
  100. title: '请填写方案标题',
  101. icon: 'none',
  102. duration: 2000
  103. });
  104. return;
  105. }
  106. if (!diagnosis || !diagnosis.trim()) {
  107. wx.showToast({
  108. title: '请填写诊断结果',
  109. icon: 'none',
  110. duration: 2000
  111. });
  112. return;
  113. }
  114. if (!treatmentMethod || !treatmentMethod.trim()) {
  115. wx.showToast({
  116. title: '请填写治疗方式',
  117. icon: 'none',
  118. duration: 2000
  119. });
  120. return;
  121. }
  122. if (!treatmentDesc || !treatmentDesc.trim()) {
  123. wx.showToast({
  124. title: '请填写治疗方案描述',
  125. icon: 'none',
  126. duration: 2000
  127. });
  128. return;
  129. }
  130. if (!consultationId) {
  131. wx.showToast({
  132. title: '咨询ID缺失,请重试',
  133. icon: 'none'
  134. });
  135. return;
  136. }
  137. // 显示加载
  138. wx.showLoading({
  139. title: '提交中...',
  140. mask: true
  141. });
  142. // 构建提交数据(包含title)
  143. const submitData = {
  144. consultationId: consultationId,
  145. title: title.trim(), // 新增标题字段
  146. diagnosis: diagnosis.trim(),
  147. treatmentMethod: treatmentMethod.trim(),
  148. treatmentDesc: treatmentDesc.trim(),
  149. precautions: this.data.planForm.precautions?.trim() || ''
  150. };
  151. console.log('提交数据:', submitData);
  152. // 调用API
  153. http.fazdAdd({
  154. data: submitData,
  155. success: (res) => {
  156. wx.hideLoading();
  157. // 根据实际接口返回结构调整判断条件
  158. if (res.code === 200 || res.code === 0 || res.success) {
  159. wx.showToast({
  160. title: '方案提交成功',
  161. icon: 'success',
  162. duration: 2000
  163. });
  164. // 关闭弹窗
  165. this.closePlanPopup();
  166. // 刷新列表(可选)
  167. setTimeout(() => {
  168. this.getwzd();
  169. }, 500);
  170. } else {
  171. wx.showToast({
  172. title: res.msg || '提交失败',
  173. icon: 'none'
  174. });
  175. }
  176. },
  177. fail: (err) => {
  178. wx.hideLoading();
  179. console.error('提交失败', err);
  180. wx.showToast({
  181. title: '网络错误,请重试',
  182. icon: 'none'
  183. });
  184. }
  185. });
  186. },
  187. // 查看详情
  188. viewDetail: function(e) {
  189. const data = e.currentTarget.dataset.value;
  190. wx.navigateTo({
  191. url: `/pagesA/pages/askingSyDetails/askingSyDetails?data=${encodeURIComponent(JSON.stringify(data))}`,
  192. });
  193. }
  194. });