supplement.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <view class="header">
  4. <text class="title">补充测评材料</text>
  5. <text class="subtitle">为已有成长记录补充额外报告</text>
  6. </view>
  7. <view class="form" v-if="step === 1">
  8. <view class="form-item">
  9. <text class="label">报告日期</text>
  10. <picker mode="date" :value="reportDate" @change="onDateChange">
  11. <view class="picker-input">{{ reportDate || '请选择日期' }}</view>
  12. </picker>
  13. </view>
  14. <view class="form-item">
  15. <text class="label">选择报告文件</text>
  16. <view class="upload-area" @click="chooseFile">
  17. <text class="upload-icon" v-if="!fileName">+</text>
  18. <text class="upload-text" v-if="!fileName">点击选择PDF文件</text>
  19. <text class="file-name" v-if="fileName">{{ fileName }}</text>
  20. </view>
  21. </view>
  22. <view class="form-item">
  23. <text class="label">综合得分(选填)</text>
  24. <input class="input" v-model="formData.overallScore" type="number" placeholder="0-100" />
  25. </view>
  26. <button class="btn-submit" @click="uploadAndParse" :disabled="!canUpload">上传并解析</button>
  27. </view>
  28. <view class="form" v-else-if="step === 2">
  29. <view class="form-item">
  30. <text class="label">解析结果预览</text>
  31. </view>
  32. <view class="preview-card" v-if="parsedData">
  33. <view class="preview-row" v-if="parsedData.overallScore">
  34. <text class="preview-label">综合得分</text>
  35. <text class="preview-value">{{ parsedData.overallScore }}</text>
  36. </view>
  37. <view class="preview-row" v-if="parsedData.assessmentSummary">
  38. <text class="preview-label">测评总结</text>
  39. <text class="preview-value summary">{{ parsedData.assessmentSummary }}</text>
  40. </view>
  41. </view>
  42. <view class="btn-group">
  43. <button class="btn-secondary" @click="reset">重新上传</button>
  44. <button class="btn-submit" @click="confirmCreate">确认补充</button>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import { uploadAndParseReport, createGrowthSupplement, getChildren } from '../../utils/api.js'
  51. import fontScaleMixin from '@/mixins/font-scale.js'
  52. export default {
  53. mixins: [fontScaleMixin],
  54. data() {
  55. return {
  56. step: 1,
  57. parentRecordId: null,
  58. memberId: null,
  59. reportDate: '',
  60. fileName: '',
  61. filePath: '',
  62. sourceFileUrl: '',
  63. parsedData: null,
  64. formData: {
  65. overallScore: ''
  66. }
  67. }
  68. },
  69. computed: {
  70. canUpload() {
  71. return this.reportDate && this.filePath
  72. }
  73. },
  74. onLoad(options) {
  75. this.parentRecordId = options.recordId || null
  76. this.memberId = options.memberId || null
  77. if (!this.parentRecordId) {
  78. uni.showToast({ title: '缺少档案ID', icon: 'none' })
  79. }
  80. },
  81. methods: {
  82. onDateChange(e) {
  83. this.reportDate = e.detail.value
  84. },
  85. chooseFile() {
  86. var self = this
  87. uni.chooseMessageFile({
  88. count: 1,
  89. type: 'file',
  90. extension: ['pdf'],
  91. success: function(res) {
  92. if (res.tempFiles && res.tempFiles.length > 0) {
  93. self.fileName = res.tempFiles[0].name
  94. self.filePath = res.tempFiles[0].path
  95. }
  96. },
  97. fail: function() {
  98. uni.showToast({ title: '请选择PDF文件', icon: 'none' })
  99. }
  100. })
  101. },
  102. async uploadAndParse() {
  103. if (!this.canUpload) return
  104. uni.showLoading({ title: '上传解析中...' })
  105. try {
  106. var res = await uploadAndParseReport(this.filePath)
  107. uni.hideLoading()
  108. if (res.code === 200) {
  109. this.sourceFileUrl = res.data.sourceFileUrl
  110. this.parsedData = res.data.parsed
  111. if (this.parsedData && this.parsedData.overallScore && !this.formData.overallScore) {
  112. this.formData.overallScore = String(this.parsedData.overallScore)
  113. }
  114. this.step = 2
  115. } else {
  116. uni.showToast({ title: res.message || '解析失败', icon: 'none' })
  117. }
  118. } catch (e) {
  119. uni.hideLoading()
  120. uni.showToast({ title: e.message || '上传失败', icon: 'none' })
  121. }
  122. },
  123. async confirmCreate() {
  124. uni.showLoading({ title: '创建中...' })
  125. try {
  126. var submitData = {
  127. parentRecordId: this.parentRecordId,
  128. memberId: this.memberId,
  129. sourceFileUrl: this.sourceFileUrl,
  130. reportDate: this.reportDate
  131. }
  132. if (this.parsedData) {
  133. if (this.parsedData.overallScore) submitData.overallScore = this.parsedData.overallScore
  134. if (this.parsedData.attentionScore) submitData.attentionScore = this.parsedData.attentionScore
  135. if (this.parsedData.focusScore) submitData.focusScore = this.parsedData.focusScore
  136. if (this.parsedData.memoryScore) submitData.memoryScore = this.parsedData.memoryScore
  137. if (this.parsedData.logicScore) submitData.logicScore = this.parsedData.logicScore
  138. if (this.parsedData.perceptionScore) submitData.perceptionScore = this.parsedData.perceptionScore
  139. if (this.parsedData.spatialScore) submitData.spatialScore = this.parsedData.spatialScore
  140. if (this.parsedData.processingSpeedScore) submitData.processingSpeedScore = this.parsedData.processingSpeedScore
  141. if (this.parsedData.emotionScore) submitData.emotionScore = this.parsedData.emotionScore
  142. if (this.parsedData.resilienceScore) submitData.resilienceScore = this.parsedData.resilienceScore
  143. if (this.parsedData.assessmentSummary) submitData.assessmentSummary = this.parsedData.assessmentSummary
  144. if (this.parsedData.growthSuggestions) submitData.growthSuggestions = this.parsedData.growthSuggestions
  145. } else {
  146. if (this.formData.overallScore) submitData.overallScore = parseInt(this.formData.overallScore)
  147. }
  148. var res = await createGrowthSupplement(submitData)
  149. uni.hideLoading()
  150. if (res.code === 200) {
  151. uni.showToast({ title: '补充成功', icon: 'success' })
  152. setTimeout(function() {
  153. uni.navigateBack()
  154. }, 500)
  155. } else {
  156. uni.showToast({ title: res.message || '创建失败', icon: 'none' })
  157. }
  158. } catch (e) {
  159. uni.hideLoading()
  160. uni.showToast({ title: e.message || '创建失败', icon: 'none' })
  161. }
  162. },
  163. reset() {
  164. this.step = 1
  165. this.fileName = ''
  166. this.filePath = ''
  167. this.sourceFileUrl = ''
  168. this.parsedData = null
  169. }
  170. }
  171. }
  172. </script>
  173. <style scoped lang="scss">
  174. .container {
  175. padding: $uni-space-page;
  176. background: $facade-fill-page;
  177. min-height: 100vh;
  178. }
  179. .header {
  180. text-align: center;
  181. padding: 40rpx 0 $uni-space-lg;
  182. }
  183. .title {
  184. font-size: calc(40rpx * var(--font-scale, 1));
  185. font-weight: bold;
  186. color: $facade-text-strong;
  187. display: block;
  188. margin-bottom: 10rpx;
  189. }
  190. .subtitle {
  191. font-size: calc(26rpx * var(--font-scale, 1));
  192. color: $facade-text-muted;
  193. }
  194. .form {
  195. background: $app-surface;
  196. border-radius: 24rpx;
  197. padding: $uni-space-lg;
  198. }
  199. .form-item {
  200. margin-bottom: $uni-space-lg;
  201. }
  202. .label {
  203. font-size: calc(28rpx * var(--font-scale, 1));
  204. color: $facade-text-strong;
  205. display: block;
  206. margin-bottom: 16rpx;
  207. font-weight: bold;
  208. }
  209. .input {
  210. width: 100%;
  211. height: 76rpx;
  212. border: 1rpx solid $facade-hairline;
  213. border-radius: 8rpx;
  214. padding: 0 20rpx;
  215. font-size: calc(28rpx * var(--font-scale, 1));
  216. box-sizing: border-box;
  217. }
  218. .upload-area {
  219. display: flex;
  220. flex-direction: column;
  221. align-items: center;
  222. justify-content: center;
  223. height: 200rpx;
  224. border: 2rpx dashed $facade-text-ghost;
  225. border-radius: 16rpx;
  226. background: $facade-fill-ghost;
  227. }
  228. .upload-icon {
  229. font-size: calc($uni-font-size-4xl * var(--font-scale, 1));
  230. color: $facade-text-muted;
  231. line-height: 1;
  232. }
  233. .upload-text {
  234. font-size: calc(26rpx * var(--font-scale, 1));
  235. color: $facade-text-muted;
  236. margin-top: 10rpx;
  237. }
  238. .file-name {
  239. font-size: calc(28rpx * var(--font-scale, 1));
  240. color: $accent-indigo;
  241. word-break: break-all;
  242. text-align: center;
  243. }
  244. .picker-input {
  245. height: 76rpx;
  246. line-height: 76rpx;
  247. border: 1rpx solid $facade-hairline;
  248. border-radius: 8rpx;
  249. padding: 0 20rpx;
  250. font-size: calc(28rpx * var(--font-scale, 1));
  251. color: $facade-text-strong;
  252. }
  253. .btn-submit {
  254. width: 100%;
  255. height: 88rpx;
  256. line-height: 88rpx;
  257. background: linear-gradient(135deg, $accent-indigo 0%, $accent-indigo-deep 100%);
  258. color: $app-surface;
  259. border-radius: 24rpx;
  260. font-size: calc(32rpx * var(--font-scale, 1));
  261. font-weight: bold;
  262. text-align: center;
  263. }
  264. .btn-submit[disabled] {
  265. opacity: 0.5;
  266. }
  267. .preview-card {
  268. background: $dim-wisdom-tint-5;
  269. border-radius: 16rpx;
  270. padding: 24rpx;
  271. margin-bottom: $uni-space-lg;
  272. }
  273. .preview-row {
  274. display: flex;
  275. margin-bottom: 16rpx;
  276. }
  277. .preview-label {
  278. font-size: calc(26rpx * var(--font-scale, 1));
  279. color: $facade-text-body;
  280. width: 160rpx;
  281. flex-shrink: 0;
  282. }
  283. .preview-value {
  284. font-size: calc(26rpx * var(--font-scale, 1));
  285. color: $facade-text-strong;
  286. flex: 1;
  287. }
  288. .preview-value.summary {
  289. max-height: 200rpx;
  290. overflow: hidden;
  291. text-overflow: ellipsis;
  292. display: -webkit-box;
  293. -webkit-line-clamp: 4;
  294. -webkit-box-orient: vertical;
  295. }
  296. .btn-group {
  297. display: flex;
  298. gap: 20rpx;
  299. }
  300. .btn-secondary {
  301. flex: 1;
  302. height: 88rpx;
  303. line-height: 88rpx;
  304. background: $app-surface;
  305. color: $accent-indigo;
  306. border: 2rpx solid $accent-indigo;
  307. border-radius: 24rpx;
  308. font-size: calc(30rpx * var(--font-scale, 1));
  309. font-weight: bold;
  310. text-align: center;
  311. }
  312. .btn-group .btn-submit {
  313. flex: 1;
  314. }
  315. </style>