supplement.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <view class="container">
  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. export default {
  52. data() {
  53. return {
  54. step: 1,
  55. parentRecordId: null,
  56. childId: null,
  57. reportDate: '',
  58. fileName: '',
  59. filePath: '',
  60. sourceFileUrl: '',
  61. parsedData: null,
  62. formData: {
  63. overallScore: ''
  64. }
  65. }
  66. },
  67. computed: {
  68. canUpload() {
  69. return this.reportDate && this.filePath
  70. }
  71. },
  72. onLoad(options) {
  73. this.parentRecordId = options.recordId || null
  74. this.childId = options.childId || null
  75. if (!this.parentRecordId) {
  76. uni.showToast({ title: '缺少档案ID', icon: 'none' })
  77. }
  78. },
  79. methods: {
  80. onDateChange(e) {
  81. this.reportDate = e.detail.value
  82. },
  83. chooseFile() {
  84. var self = this
  85. uni.chooseMessageFile({
  86. count: 1,
  87. type: 'file',
  88. extension: ['pdf'],
  89. success: function(res) {
  90. if (res.tempFiles && res.tempFiles.length > 0) {
  91. self.fileName = res.tempFiles[0].name
  92. self.filePath = res.tempFiles[0].path
  93. }
  94. },
  95. fail: function() {
  96. uni.showToast({ title: '请选择PDF文件', icon: 'none' })
  97. }
  98. })
  99. },
  100. async uploadAndParse() {
  101. if (!this.canUpload) return
  102. uni.showLoading({ title: '上传解析中...' })
  103. try {
  104. var res = await uploadAndParseReport(this.filePath)
  105. uni.hideLoading()
  106. if (res.code === 200) {
  107. this.sourceFileUrl = res.data.sourceFileUrl
  108. this.parsedData = res.data.parsed
  109. if (this.parsedData && this.parsedData.overallScore && !this.formData.overallScore) {
  110. this.formData.overallScore = String(this.parsedData.overallScore)
  111. }
  112. this.step = 2
  113. } else {
  114. uni.showToast({ title: res.message || '解析失败', icon: 'none' })
  115. }
  116. } catch (e) {
  117. uni.hideLoading()
  118. uni.showToast({ title: e.message || '上传失败', icon: 'none' })
  119. }
  120. },
  121. async confirmCreate() {
  122. uni.showLoading({ title: '创建中...' })
  123. try {
  124. var submitData = {
  125. parentRecordId: this.parentRecordId,
  126. childId: this.childId,
  127. sourceFileUrl: this.sourceFileUrl,
  128. reportDate: this.reportDate
  129. }
  130. if (this.parsedData) {
  131. if (this.parsedData.overallScore) submitData.overallScore = this.parsedData.overallScore
  132. if (this.parsedData.attentionScore) submitData.attentionScore = this.parsedData.attentionScore
  133. if (this.parsedData.focusScore) submitData.focusScore = this.parsedData.focusScore
  134. if (this.parsedData.memoryScore) submitData.memoryScore = this.parsedData.memoryScore
  135. if (this.parsedData.logicScore) submitData.logicScore = this.parsedData.logicScore
  136. if (this.parsedData.perceptionScore) submitData.perceptionScore = this.parsedData.perceptionScore
  137. if (this.parsedData.spatialScore) submitData.spatialScore = this.parsedData.spatialScore
  138. if (this.parsedData.processingSpeedScore) submitData.processingSpeedScore = this.parsedData.processingSpeedScore
  139. if (this.parsedData.emotionScore) submitData.emotionScore = this.parsedData.emotionScore
  140. if (this.parsedData.resilienceScore) submitData.resilienceScore = this.parsedData.resilienceScore
  141. if (this.parsedData.assessmentSummary) submitData.assessmentSummary = this.parsedData.assessmentSummary
  142. if (this.parsedData.growthSuggestions) submitData.growthSuggestions = this.parsedData.growthSuggestions
  143. } else {
  144. if (this.formData.overallScore) submitData.overallScore = parseInt(this.formData.overallScore)
  145. }
  146. var res = await createGrowthSupplement(submitData)
  147. uni.hideLoading()
  148. if (res.code === 200) {
  149. uni.showToast({ title: '补充成功', icon: 'success' })
  150. setTimeout(function() {
  151. uni.navigateBack()
  152. }, 500)
  153. } else {
  154. uni.showToast({ title: res.message || '创建失败', icon: 'none' })
  155. }
  156. } catch (e) {
  157. uni.hideLoading()
  158. uni.showToast({ title: e.message || '创建失败', icon: 'none' })
  159. }
  160. },
  161. reset() {
  162. this.step = 1
  163. this.fileName = ''
  164. this.filePath = ''
  165. this.sourceFileUrl = ''
  166. this.parsedData = null
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped>
  172. .container {
  173. padding: 30rpx;
  174. background: #F8F8F8;
  175. min-height: 100vh;
  176. }
  177. .header {
  178. text-align: center;
  179. padding: 40rpx 0 30rpx;
  180. }
  181. .title {
  182. font-size: 40rpx;
  183. font-weight: bold;
  184. color: #333;
  185. display: block;
  186. margin-bottom: 10rpx;
  187. }
  188. .subtitle {
  189. font-size: 26rpx;
  190. color: #999;
  191. }
  192. .form {
  193. background: #fff;
  194. border-radius: 20rpx;
  195. padding: 30rpx;
  196. }
  197. .form-item {
  198. margin-bottom: 30rpx;
  199. }
  200. .label {
  201. font-size: 28rpx;
  202. color: #333;
  203. display: block;
  204. margin-bottom: 16rpx;
  205. font-weight: bold;
  206. }
  207. .input {
  208. width: 100%;
  209. height: 76rpx;
  210. border: 1rpx solid #E0E0E0;
  211. border-radius: 10rpx;
  212. padding: 0 20rpx;
  213. font-size: 28rpx;
  214. box-sizing: border-box;
  215. }
  216. .upload-area {
  217. display: flex;
  218. flex-direction: column;
  219. align-items: center;
  220. justify-content: center;
  221. height: 200rpx;
  222. border: 2rpx dashed #ccc;
  223. border-radius: 16rpx;
  224. background: #fafafa;
  225. }
  226. .upload-icon {
  227. font-size: 64rpx;
  228. color: #999;
  229. line-height: 1;
  230. }
  231. .upload-text {
  232. font-size: 26rpx;
  233. color: #999;
  234. margin-top: 10rpx;
  235. }
  236. .file-name {
  237. font-size: 28rpx;
  238. color: #667eea;
  239. word-break: break-all;
  240. text-align: center;
  241. }
  242. .picker-input {
  243. height: 76rpx;
  244. line-height: 76rpx;
  245. border: 1rpx solid #E0E0E0;
  246. border-radius: 10rpx;
  247. padding: 0 20rpx;
  248. font-size: 28rpx;
  249. color: #333;
  250. }
  251. .btn-submit {
  252. width: 100%;
  253. height: 88rpx;
  254. line-height: 88rpx;
  255. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  256. color: #fff;
  257. border-radius: 44rpx;
  258. font-size: 32rpx;
  259. font-weight: bold;
  260. text-align: center;
  261. }
  262. .btn-submit[disabled] {
  263. opacity: 0.5;
  264. }
  265. .preview-card {
  266. background: #f9f9ff;
  267. border-radius: 12rpx;
  268. padding: 24rpx;
  269. margin-bottom: 30rpx;
  270. }
  271. .preview-row {
  272. display: flex;
  273. margin-bottom: 16rpx;
  274. }
  275. .preview-label {
  276. font-size: 26rpx;
  277. color: #666;
  278. width: 160rpx;
  279. flex-shrink: 0;
  280. }
  281. .preview-value {
  282. font-size: 26rpx;
  283. color: #333;
  284. flex: 1;
  285. }
  286. .preview-value.summary {
  287. max-height: 200rpx;
  288. overflow: hidden;
  289. text-overflow: ellipsis;
  290. display: -webkit-box;
  291. -webkit-line-clamp: 4;
  292. -webkit-box-orient: vertical;
  293. }
  294. .btn-group {
  295. display: flex;
  296. gap: 20rpx;
  297. }
  298. .btn-secondary {
  299. flex: 1;
  300. height: 88rpx;
  301. line-height: 88rpx;
  302. background: #fff;
  303. color: #667eea;
  304. border: 2rpx solid #667eea;
  305. border-radius: 44rpx;
  306. font-size: 30rpx;
  307. font-weight: bold;
  308. text-align: center;
  309. }
  310. .btn-group .btn-submit {
  311. flex: 1;
  312. }
  313. </style>