feedback-popup.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="fb-overlay" v-if="visible" @tap="close">
  3. <view class="fb-body" @tap.stop>
  4. <view class="fb-header">
  5. <text class="fb-title">报告反馈</text>
  6. <text class="fb-close" @tap="close">×</text>
  7. </view>
  8. <!-- 结果态:已提交,展示解答 -->
  9. <block v-if="submitted">
  10. <view class="fb-quote">
  11. <text class="fb-quote-label">{{ typeLabel }}</text>
  12. <text class="fb-quote-text">{{ submittedContent }}</text>
  13. </view>
  14. <view class="fb-answer">
  15. <text class="fb-answer-label">解答</text>
  16. <view class="fb-answer-loading" v-if="aiStatus === 'pending'">
  17. <text class="fb-answer-loading-text">正在生成解答...</text>
  18. </view>
  19. <text class="fb-answer-text" v-else-if="aiStatus === 'answered'">{{ aiAnswer }}</text>
  20. <text class="fb-answer-text fb-answer-failed" v-else>解答暂不可用,可稍后在「我的反馈」中查看</text>
  21. </view>
  22. <view class="fb-note">解答由智能助手生成,仅供参考,不构成医疗建议</view>
  23. <view class="fb-actions">
  24. <view class="fb-btn fb-btn-cancel" @tap="goMyFeedback">我的反馈</view>
  25. <view class="fb-btn fb-btn-submit" @tap="close">完成</view>
  26. </view>
  27. </block>
  28. <!-- 填写态 -->
  29. <block v-else>
  30. <textarea class="fb-textarea" v-model="content" placeholder="请描述您对该报告的疑问或建议..." maxlength="500" />
  31. <picker :value="typeIndex" :range="typeLabels" @change="onTypeChange">
  32. <view class="fb-picker">
  33. <text>{{ typeLabels[typeIndex] }}</text>
  34. <text class="fb-arrow">▼</text>
  35. </view>
  36. </picker>
  37. <view class="fb-hint" v-if="quotaHint">{{ quotaHint }}</view>
  38. <view class="fb-actions">
  39. <view class="fb-btn fb-btn-cancel" @tap="close">取消</view>
  40. <view class="fb-btn fb-btn-submit" :class="{ 'fb-btn-disabled': submitting }" @tap="submit">{{ submitText }}</view>
  41. </view>
  42. </block>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import { submitFeedback } from '../utils/api.js'
  48. export default {
  49. props: {
  50. visible: Boolean,
  51. reportId: Number,
  52. draftId: Number
  53. },
  54. data: function() {
  55. return {
  56. content: '',
  57. types: [
  58. { label: '疑问', value: 'question' },
  59. { label: '建议', value: 'suggestion' }
  60. ],
  61. typeIndex: 0,
  62. submitting: false,
  63. // 提交后结果态
  64. submitted: false,
  65. submittedContent: '',
  66. submittedType: '',
  67. aiStatus: '',
  68. aiAnswer: '',
  69. quotaHint: ''
  70. }
  71. },
  72. computed: {
  73. typeLabels: function() {
  74. var arr = []
  75. for (var i = 0; i < this.types.length; i++) {
  76. arr.push(this.types[i].label)
  77. }
  78. return arr
  79. },
  80. typeLabel: function() {
  81. for (var i = 0; i < this.types.length; i++) {
  82. if (this.types[i].value === this.submittedType) return this.types[i].label
  83. }
  84. return '反馈'
  85. },
  86. submitText: function() {
  87. return this.submitting ? '提交中...' : '提交'
  88. }
  89. },
  90. watch: {
  91. visible: function(val) {
  92. if (val) {
  93. // 每次打开重置为填写态
  94. this.submitted = false
  95. this.submittedContent = ''
  96. this.submittedType = ''
  97. this.aiStatus = ''
  98. this.aiAnswer = ''
  99. this.quotaHint = ''
  100. this.submitting = false
  101. }
  102. }
  103. },
  104. methods: {
  105. onTypeChange: function(e) {
  106. this.typeIndex = e.detail.value
  107. },
  108. close: function() {
  109. this.$emit('close')
  110. },
  111. goMyFeedback: function() {
  112. this.close()
  113. uni.navigateTo({ url: '/pages/health/my-feedback' })
  114. },
  115. submit: function() {
  116. if (!this.content.trim()) {
  117. uni.showToast({ title: '请填写内容', icon: 'none' })
  118. return
  119. }
  120. if (this.submitting) return
  121. var self = this
  122. var typeValue = this.types[this.typeIndex].value
  123. var text = this.content.trim()
  124. this.submitting = true
  125. var payload = {
  126. type: typeValue,
  127. content: text
  128. }
  129. if (this.reportId) payload.reportId = this.reportId
  130. if (this.draftId) payload.draftId = this.draftId
  131. submitFeedback(payload).then(function(res) {
  132. if (res.code === 200 && res.data) {
  133. self.submitted = true
  134. self.submittedContent = res.data.content || text
  135. self.submittedType = res.data.feedbackType || typeValue
  136. self.aiStatus = res.data.aiStatus || 'answered'
  137. self.aiAnswer = res.data.aiAnswer || ''
  138. self.content = ''
  139. self.typeIndex = 0
  140. } else {
  141. var msg = res.message || '提交失败'
  142. if (msg.indexOf('每日仅限') !== -1) {
  143. self.quotaHint = msg
  144. } else {
  145. uni.showToast({ title: msg, icon: 'none' })
  146. }
  147. }
  148. }).catch(function() {
  149. uni.showToast({ title: '提交失败', icon: 'none' })
  150. }).then(function() {
  151. self.submitting = false
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style scoped>
  158. .fb-overlay {
  159. position: fixed;
  160. top: 0;
  161. left: 0;
  162. right: 0;
  163. bottom: 0;
  164. background: rgba(0,0,0,0.4);
  165. z-index: 999;
  166. display: flex;
  167. align-items: flex-end;
  168. }
  169. .fb-body {
  170. background: #fff;
  171. border-radius: 20rpx 20rpx 0 0;
  172. padding: 30rpx;
  173. width: 100%;
  174. box-sizing: border-box;
  175. }
  176. .fb-header {
  177. display: flex;
  178. justify-content: space-between;
  179. align-items: center;
  180. margin-bottom: 20rpx;
  181. }
  182. .fb-title {
  183. font-size: 32rpx;
  184. font-weight: 600;
  185. color: #333;
  186. }
  187. .fb-close {
  188. font-size: 40rpx;
  189. color: #999;
  190. padding: 0 10rpx;
  191. }
  192. .fb-textarea {
  193. width: 100%;
  194. height: 200rpx;
  195. border: 1rpx solid #eee;
  196. border-radius: 12rpx;
  197. padding: 20rpx;
  198. font-size: 26rpx;
  199. box-sizing: border-box;
  200. margin-bottom: 16rpx;
  201. }
  202. .fb-picker {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. padding: 20rpx;
  207. border: 1rpx solid #eee;
  208. border-radius: 12rpx;
  209. margin-bottom: 20rpx;
  210. font-size: 26rpx;
  211. color: #333;
  212. }
  213. .fb-arrow {
  214. color: #999;
  215. font-size: 22rpx;
  216. }
  217. .fb-hint {
  218. font-size: 24rpx;
  219. color: #E6A23C;
  220. margin-bottom: 16rpx;
  221. line-height: 1.5;
  222. }
  223. .fb-actions {
  224. display: flex;
  225. }
  226. .fb-btn {
  227. flex: 1;
  228. text-align: center;
  229. padding: 20rpx;
  230. border-radius: 12rpx;
  231. font-size: 28rpx;
  232. }
  233. .fb-btn-cancel {
  234. border: 1rpx solid #ddd;
  235. color: #666;
  236. margin-right: 20rpx;
  237. }
  238. .fb-btn-submit {
  239. background: #4A9BD7;
  240. color: #fff;
  241. }
  242. .fb-btn-disabled {
  243. opacity: 0.6;
  244. }
  245. /* ===== 结果态 ===== */
  246. .fb-quote {
  247. background: #F5FAFE;
  248. border-radius: 12rpx;
  249. padding: 20rpx;
  250. margin-bottom: 20rpx;
  251. }
  252. .fb-quote-label {
  253. display: block;
  254. font-size: 24rpx;
  255. color: #4A9BD7;
  256. margin-bottom: 8rpx;
  257. }
  258. .fb-quote-text {
  259. font-size: 26rpx;
  260. color: #333;
  261. line-height: 1.6;
  262. word-break: break-all;
  263. }
  264. .fb-answer {
  265. border: 1rpx solid #eee;
  266. border-radius: 12rpx;
  267. padding: 20rpx;
  268. margin-bottom: 16rpx;
  269. }
  270. .fb-answer-label {
  271. display: block;
  272. font-size: 24rpx;
  273. color: #10B981;
  274. margin-bottom: 10rpx;
  275. }
  276. .fb-answer-text {
  277. font-size: 26rpx;
  278. color: #333;
  279. line-height: 1.7;
  280. word-break: break-all;
  281. }
  282. .fb-answer-failed {
  283. color: #999;
  284. }
  285. .fb-answer-loading {
  286. padding: 8rpx 0;
  287. }
  288. .fb-answer-loading-text {
  289. font-size: 26rpx;
  290. color: #999;
  291. }
  292. .fb-note {
  293. font-size: 22rpx;
  294. color: #bbb;
  295. line-height: 1.5;
  296. margin-bottom: 20rpx;
  297. }
  298. </style>