supplement.vue 9.5 KB

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