upload-report.vue 5.5 KB

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