upload-report.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <text class="title">上传测评报告</text>
  5. <text class="subtitle">支持 PDF / JPG / PNG 格式</text>
  6. </view>
  7. <view class="section">
  8. <view class="section-title">选择孩子</view>
  9. <view class="child-selector">
  10. <view class="child-item"
  11. :class="{ selected: selectedChildId === child.id }"
  12. v-for="child in children" :key="child.id"
  13. @click="selectedChildId = child.id">
  14. <text class="child-name">{{ child.nickname || '未命名' }}</text>
  15. <text class="child-check" v-if="selectedChildId === child.id">✓</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="section">
  20. <view class="section-title">选择文件</view>
  21. <view class="file-upload" @click="chooseFile">
  22. <text class="upload-icon">📄</text>
  23. <text class="upload-text">{{ fileName || '点击选择文件' }}</text>
  24. </view>
  25. </view>
  26. <view class="section">
  27. <view class="section-title">备注(可选)</view>
  28. <textarea class="textarea" v-model="notes" placeholder="添加备注信息..." />
  29. </view>
  30. <button class="btn-submit" :disabled="!canSubmit" @click="submitUpload">
  31. {{ uploading ? '上传中...' : '提交报告' }}
  32. </button>
  33. </view>
  34. </template>
  35. <script>
  36. import { uploadAssessmentReport } from '../../utils/api.js'
  37. export default {
  38. data() {
  39. return {
  40. children: [],
  41. selectedChildId: null,
  42. file: null,
  43. fileName: '',
  44. notes: '',
  45. uploading: false
  46. }
  47. },
  48. computed: {
  49. canSubmit() {
  50. return this.selectedChildId && this.file && !this.uploading
  51. }
  52. },
  53. onLoad() {
  54. this.loadChildren()
  55. },
  56. methods: {
  57. async loadChildren() {
  58. try {
  59. const res = await getChildren()
  60. if (res.code === 200) {
  61. this.children = res.data || []
  62. if (this.children.length === 1) {
  63. this.selectedChildId = this.children[0].id
  64. }
  65. }
  66. } catch (e) {
  67. console.error('获取孩子列表失败', e)
  68. }
  69. },
  70. chooseFile() {
  71. uni.chooseImage({
  72. count: 1,
  73. success: (res) => {
  74. this.file = res.tempFiles[0]
  75. this.fileName = this.file.name || '已选择文件'
  76. }
  77. })
  78. },
  79. async submitUpload() {
  80. if (!this.canSubmit) return
  81. this.uploading = true
  82. uni.showLoading({ title: '上传中...' })
  83. try {
  84. const res = await uploadAssessmentReport(this.file, this.selectedChildId, this.notes)
  85. uni.hideLoading()
  86. if (res.code === 200) {
  87. uni.showModal({
  88. title: '上传成功',
  89. content: '报告已提交,等待成长规划师确认',
  90. showCancel: false,
  91. success: () => uni.navigateBack()
  92. })
  93. } else {
  94. uni.showToast({ title: res.message || '上传失败', icon: 'none' })
  95. }
  96. } catch (e) {
  97. uni.hideLoading()
  98. uni.showToast({ title: '上传失败', icon: 'none' })
  99. }
  100. this.uploading = false
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. .container {
  107. padding: 30rpx;
  108. background: #F8F8F8;
  109. min-height: 100vh;
  110. }
  111. .header {
  112. text-align: center;
  113. padding: 40rpx 0 30rpx;
  114. }
  115. .title {
  116. font-size: 44rpx;
  117. font-weight: bold;
  118. color: #333;
  119. display: block;
  120. margin-bottom: 16rpx;
  121. }
  122. .subtitle {
  123. font-size: 26rpx;
  124. color: #999;
  125. }
  126. .section {
  127. background: #fff;
  128. border-radius: 20rpx;
  129. padding: 30rpx;
  130. margin-bottom: 24rpx;
  131. }
  132. .section-title {
  133. font-size: 30rpx;
  134. font-weight: bold;
  135. color: #333;
  136. margin-bottom: 20rpx;
  137. }
  138. .child-selector {
  139. display: flex;
  140. flex-wrap: wrap;
  141. gap: 16rpx;
  142. }
  143. .child-item {
  144. position: relative;
  145. background: #F8F8F8;
  146. border: 2rpx solid #E0E0E0;
  147. border-radius: 10rpx;
  148. padding: 20rpx;
  149. min-width: 160rpx;
  150. text-align: center;
  151. }
  152. .child-item.selected {
  153. border-color: #667eea;
  154. background: #F0F4FF;
  155. }
  156. .child-name {
  157. font-size: 28rpx;
  158. color: #333;
  159. }
  160. .child-check {
  161. position: absolute;
  162. top: -8rpx;
  163. right: -8rpx;
  164. width: 36rpx;
  165. height: 36rpx;
  166. background: #667eea;
  167. color: #fff;
  168. border-radius: 50%;
  169. line-height: 36rpx;
  170. text-align: center;
  171. font-size: 20rpx;
  172. }
  173. .file-upload {
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. gap: 16rpx;
  178. height: 160rpx;
  179. background: #F8F8F8;
  180. border: 2rpx dashed #CCC;
  181. border-radius: 12rpx;
  182. }
  183. .upload-icon {
  184. font-size: 48rpx;
  185. }
  186. .upload-text {
  187. font-size: 28rpx;
  188. color: #666;
  189. }
  190. .textarea {
  191. width: 100%;
  192. height: 160rpx;
  193. background: #F8F8F8;
  194. border-radius: 10rpx;
  195. padding: 20rpx;
  196. font-size: 28rpx;
  197. box-sizing: border-box;
  198. }
  199. .btn-submit {
  200. width: 100%;
  201. height: 88rpx;
  202. line-height: 88rpx;
  203. background: linear-gradient(135deg, #667eea, #764ba2);
  204. color: #fff;
  205. border-radius: 44rpx;
  206. font-size: 30rpx;
  207. margin-top: 30rpx;
  208. }
  209. .btn-submit[disabled] {
  210. opacity: 0.5;
  211. }
  212. </style>