upload-report.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. import { pickImage } from '../../utils/image-picker.js'
  38. export default {
  39. data() {
  40. return {
  41. children: [],
  42. selectedChildId: null,
  43. file: null,
  44. fileName: '',
  45. notes: '',
  46. uploading: false
  47. }
  48. },
  49. computed: {
  50. canSubmit() {
  51. return this.selectedChildId && this.file && !this.uploading
  52. }
  53. },
  54. onLoad() {
  55. this.loadChildren()
  56. },
  57. methods: {
  58. async loadChildren() {
  59. try {
  60. const res = await getChildren()
  61. if (res.code === 200) {
  62. this.children = res.data || []
  63. if (this.children.length === 1) {
  64. this.selectedChildId = this.children[0].id
  65. }
  66. }
  67. } catch (e) {
  68. console.error('获取测评人列表失败', e)
  69. }
  70. },
  71. chooseFile() {
  72. pickImage({
  73. count: 1,
  74. success: (res) => {
  75. this.file = res.tempFiles[0]
  76. this.fileName = this.file.name || '已选择文件'
  77. }
  78. })
  79. },
  80. async submitUpload() {
  81. if (!this.canSubmit) return
  82. this.uploading = true
  83. uni.showLoading({ title: '上传中...' })
  84. try {
  85. const res = await uploadAssessmentReport(this.file, this.selectedChildId, this.notes)
  86. uni.hideLoading()
  87. if (res.code === 200) {
  88. uni.showModal({
  89. title: '上传成功',
  90. content: '报告已提交,等待成长规划师确认',
  91. showCancel: false,
  92. success: () => uni.navigateBack()
  93. })
  94. } else {
  95. uni.showToast({ title: res.message || '上传失败', icon: 'none' })
  96. }
  97. } catch (e) {
  98. uni.hideLoading()
  99. uni.showToast({ title: '上传失败', icon: 'none' })
  100. }
  101. this.uploading = false
  102. }
  103. }
  104. }
  105. </script>
  106. <stylescoped lang="scss">
  107. .container {
  108. padding: 30rpx;
  109. background: $facade-fill-page;
  110. min-height: 100vh;
  111. }
  112. .header {
  113. text-align: center;
  114. padding: 40rpx 0 30rpx;
  115. }
  116. .title {
  117. font-size: 44rpx;
  118. font-weight: bold;
  119. color: $facade-text-strong;
  120. display: block;
  121. margin-bottom: 16rpx;
  122. }
  123. .subtitle {
  124. font-size: 26rpx;
  125. color: $facade-text-muted;
  126. }
  127. .section {
  128. background: $app-surface;
  129. border-radius: 20rpx;
  130. padding: 30rpx;
  131. margin-bottom: 24rpx;
  132. }
  133. .section-title {
  134. font-size: 30rpx;
  135. font-weight: bold;
  136. color: $facade-text-strong;
  137. margin-bottom: 20rpx;
  138. }
  139. .child-selector {
  140. display: flex;
  141. flex-wrap: wrap;
  142. gap: 16rpx;
  143. }
  144. .child-item {
  145. position: relative;
  146. background: $facade-fill-page;
  147. border: 2rpx solid $facade-hairline;
  148. border-radius: 10rpx;
  149. padding: 20rpx;
  150. min-width: 160rpx;
  151. text-align: center;
  152. }
  153. .child-item.selected {
  154. border-color: $accent-indigo;
  155. background: #F0F4FF;
  156. }
  157. .child-name {
  158. font-size: 28rpx;
  159. color: $facade-text-strong;
  160. }
  161. .child-check {
  162. position: absolute;
  163. top: -8rpx;
  164. right: -8rpx;
  165. width: 36rpx;
  166. height: 36rpx;
  167. background: $accent-indigo;
  168. color: $app-surface;
  169. border-radius: 50%;
  170. line-height: 36rpx;
  171. text-align: center;
  172. font-size: 20rpx;
  173. }
  174. .file-upload {
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. gap: 16rpx;
  179. height: 160rpx;
  180. background: $facade-fill-page;
  181. border: 2rpx dashed $facade-text-ghost;
  182. border-radius: 12rpx;
  183. }
  184. .upload-icon {
  185. font-size: 48rpx;
  186. }
  187. .upload-text {
  188. font-size: 28rpx;
  189. color: $facade-text-body;
  190. }
  191. .textarea {
  192. width: 100%;
  193. height: 160rpx;
  194. background: $facade-fill-page;
  195. border-radius: 10rpx;
  196. padding: 20rpx;
  197. font-size: 28rpx;
  198. box-sizing: border-box;
  199. }
  200. .btn-submit {
  201. width: 100%;
  202. height: 88rpx;
  203. line-height: 88rpx;
  204. background: linear-gradient(135deg, $accent-indigo, $accent-indigo-deep);
  205. color: $app-surface;
  206. border-radius: 44rpx;
  207. font-size: 30rpx;
  208. margin-top: 30rpx;
  209. }
  210. .btn-submit[disabled] {
  211. opacity: 0.5;
  212. }
  213. </style>