create.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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="source-type-section">
  8. <view class="source-card" :class="sourceType === 'manual' ? 'source-active' : ''" @click="sourceType = 'manual'">
  9. <text class="source-icon">📝</text>
  10. <text class="source-name">手动创建</text>
  11. <text class="source-desc">填写孩子基本信息</text>
  12. </view>
  13. <view class="source-card" :class="sourceType === 'upload' ? 'source-active' : ''" @click="sourceType = 'upload'">
  14. <text class="source-icon">📄</text>
  15. <text class="source-name">上传报告</text>
  16. <text class="source-desc">上传PDF测评报告</text>
  17. </view>
  18. <view class="source-card" :class="sourceType === 'assessment' ? 'source-active' : ''" @click="sourceType = 'assessment'">
  19. <text class="source-icon">🎓</text>
  20. <text class="source-name">购买测评</text>
  21. <text class="source-desc">购买DAN测评服务</text>
  22. </view>
  23. </view>
  24. <view class="form" v-if="sourceType === 'manual'">
  25. <view class="form-item">
  26. <text class="label">孩子</text>
  27. <view class="child-select" @click="selectChild">
  28. <text class="select-text" v-if="selectedChild">{{ selectedChild.nickname || selectedChild.name }}</text>
  29. <text class="select-placeholder" v-else>请选择孩子</text>
  30. <text class="select-arrow">›</text>
  31. </view>
  32. </view>
  33. <view class="form-item">
  34. <text class="label">档案标题</text>
  35. <input class="input" v-model="formData.recordTitle" placeholder="例如:2026年5月成长记录" />
  36. </view>
  37. <view class="form-row">
  38. <view class="form-item half">
  39. <text class="label">身高(cm)</text>
  40. <input class="input" v-model="formData.height" type="number" placeholder="选填" />
  41. </view>
  42. <view class="form-item half">
  43. <text class="label">体重(kg)</text>
  44. <input class="input" v-model="formData.weight" type="number" placeholder="选填" />
  45. </view>
  46. </view>
  47. <view class="form-item">
  48. <text class="label">学校名称</text>
  49. <input class="input" v-model="formData.school" placeholder="选填" />
  50. </view>
  51. <view class="form-row">
  52. <view class="form-item half">
  53. <text class="label">年级</text>
  54. <picker mode="selector" :range="gradeOptions" :value="formData.grade ? (formData.grade - 1) : -1" @change="onGradeChange">
  55. <view class="picker-input">{{ formData.grade ? gradeOptions[formData.grade - 1] : '请选择年级' }}</view>
  56. </picker>
  57. </view>
  58. <view class="form-item half">
  59. <text class="label">成绩表现</text>
  60. <input class="input" v-model="formData.academicPerformance" placeholder="选填" />
  61. </view>
  62. </view>
  63. <view class="form-item">
  64. <text class="label">学校所在省</text>
  65. <input class="input" v-model="formData.schoolProvince" placeholder="选填" />
  66. </view>
  67. <view class="form-item">
  68. <text class="label">学校所在市</text>
  69. <input class="input" v-model="formData.schoolCity" placeholder="选填" />
  70. </view>
  71. <view class="form-item">
  72. <text class="label">学校所在区</text>
  73. <input class="input" v-model="formData.schoolDistrict" placeholder="选填" />
  74. </view>
  75. <view class="form-item">
  76. <text class="label">学校所在街道</text>
  77. <input class="input" v-model="formData.schoolStreet" placeholder="选填" />
  78. </view>
  79. <button class="btn-submit" @click="submitManual">创建档案</button>
  80. </view>
  81. <view class="redirect-section" v-if="sourceType === 'upload'">
  82. <view class="redirect-card">
  83. <text class="redirect-desc">上传PDF格式的DAN测评报告,系统将自动解析报告内容并创建成长档案。</text>
  84. <button class="btn-submit" @click="goUpload">上传测评报告</button>
  85. </view>
  86. </view>
  87. <view class="redirect-section" v-if="sourceType === 'assessment'">
  88. <view class="redirect-card">
  89. <text class="redirect-desc">购买DAN测评服务后,规划师完成测评录入将自动创建成长档案,无需手动填写。</text>
  90. <button class="btn-submit" @click="goPurchase">购买测评服务</button>
  91. </view>
  92. </view>
  93. </view>
  94. </template>
  95. <script>
  96. import { getChildren, createGrowthRecord } from '../../utils/api.js'
  97. export default {
  98. data() {
  99. return {
  100. sourceType: 'manual',
  101. children: [],
  102. selectedChild: null,
  103. targetChildId: '',
  104. gradeOptions: ['一年级','二年级','三年级','四年级','五年级','六年级','初一','初二','初三','高一','高二','高三'],
  105. formData: {
  106. childId: null,
  107. recordTitle: '',
  108. height: '',
  109. weight: '',
  110. school: '',
  111. grade: null,
  112. academicPerformance: '',
  113. schoolProvince: '',
  114. schoolCity: '',
  115. schoolDistrict: '',
  116. schoolStreet: ''
  117. }
  118. }
  119. },
  120. onLoad(options) {
  121. this.targetChildId = options.childId || ''
  122. if (options.sourceType) {
  123. this.sourceType = options.sourceType
  124. }
  125. this.loadChildren()
  126. if (this.targetChildId) {
  127. this.formData.recordTitle = '成长档案 - ' + this.getCurrentDate()
  128. }
  129. },
  130. methods: {
  131. getCurrentDate() {
  132. var d = new Date()
  133. return d.getFullYear() + '年' + (d.getMonth() + 1) + '月'
  134. },
  135. async loadChildren() {
  136. try {
  137. var res = await getChildren()
  138. if (res.code === 200) {
  139. this.children = res.data || []
  140. var target = null
  141. if (this.targetChildId) {
  142. target = this.children.find(function(c) { return String(c.id) === String(this.targetChildId) }.bind(this))
  143. }
  144. if (!target && this.children.length > 0) {
  145. target = this.children[0]
  146. }
  147. if (target) {
  148. this.selectedChild = target
  149. this.formData.childId = target.id
  150. }
  151. }
  152. } catch (e) {
  153. console.error(e)
  154. }
  155. },
  156. selectChild() {
  157. var items = this.children.map(function(c) { return c.nickname || c.name })
  158. var self = this
  159. uni.showActionSheet({
  160. itemList: items,
  161. success: function(res) {
  162. var idx = res.tapIndex
  163. if (idx >= 0 && idx < self.children.length) {
  164. self.selectedChild = self.children[idx]
  165. self.formData.childId = self.selectedChild.id
  166. }
  167. }
  168. })
  169. },
  170. onGradeChange(e) {
  171. this.formData.grade = e.detail.value + 1
  172. },
  173. async submitManual() {
  174. if (!this.formData.childId) {
  175. uni.showToast({ title: '请选择孩子', icon: 'none' })
  176. return
  177. }
  178. uni.showLoading({ title: '创建中...' })
  179. try {
  180. var familyId = uni.getStorageSync('familyId')
  181. var submitData = {
  182. childId: this.formData.childId,
  183. recordTitle: this.formData.recordTitle || '成长档案',
  184. height: this.formData.height || null,
  185. weight: this.formData.weight || null,
  186. school: this.formData.school || null,
  187. grade: this.formData.grade,
  188. academicPerformance: this.formData.academicPerformance || null,
  189. schoolProvince: this.formData.schoolProvince || null,
  190. schoolCity: this.formData.schoolCity || null,
  191. schoolDistrict: this.formData.schoolDistrict || null,
  192. schoolStreet: this.formData.schoolStreet || null,
  193. familyId: familyId
  194. }
  195. var res = await createGrowthRecord(submitData)
  196. uni.hideLoading()
  197. if (res.code === 200) {
  198. uni.showToast({ title: '创建成功', icon: 'success' })
  199. setTimeout(function() {
  200. uni.navigateTo({
  201. url: '/pages/growth/detail?recordId=' + res.data.id
  202. })
  203. }, 500)
  204. } else {
  205. uni.showToast({ title: res.message || '创建失败', icon: 'none' })
  206. }
  207. } catch (e) {
  208. uni.hideLoading()
  209. uni.showToast({ title: e.message || '创建失败', icon: 'none' })
  210. }
  211. },
  212. goUpload() {
  213. var url = '/pages/growth/upload'
  214. if (this.targetChildId) {
  215. url += '?childId=' + this.targetChildId
  216. }
  217. uni.navigateTo({ url: url })
  218. },
  219. goPurchase() {
  220. uni.navigateTo({
  221. url: '/pages/assessment/purchase'
  222. })
  223. }
  224. }
  225. }
  226. </script>
  227. <style scoped>
  228. .container {
  229. padding: 30rpx;
  230. background: #F8F8F8;
  231. min-height: 100vh;
  232. }
  233. .header {
  234. text-align: center;
  235. padding: 40rpx 0 30rpx;
  236. }
  237. .title {
  238. font-size: 40rpx;
  239. font-weight: bold;
  240. color: #333;
  241. display: block;
  242. margin-bottom: 10rpx;
  243. }
  244. .subtitle {
  245. font-size: 26rpx;
  246. color: #999;
  247. }
  248. .source-type-section {
  249. display: flex;
  250. gap: 16rpx;
  251. margin-bottom: 30rpx;
  252. }
  253. .source-card {
  254. flex: 1;
  255. background: #fff;
  256. border-radius: 16rpx;
  257. padding: 24rpx 16rpx;
  258. text-align: center;
  259. border: 2rpx solid #E0E0E0;
  260. }
  261. .source-active {
  262. border-color: #667eea;
  263. background: #f5f3ff;
  264. }
  265. .source-icon {
  266. font-size: 48rpx;
  267. display: block;
  268. margin-bottom: 8rpx;
  269. }
  270. .source-name {
  271. font-size: 26rpx;
  272. font-weight: bold;
  273. color: #333;
  274. display: block;
  275. margin-bottom: 4rpx;
  276. }
  277. .source-desc {
  278. font-size: 20rpx;
  279. color: #999;
  280. display: block;
  281. }
  282. .form {
  283. background: #fff;
  284. border-radius: 20rpx;
  285. padding: 30rpx;
  286. }
  287. .form-item {
  288. margin-bottom: 30rpx;
  289. }
  290. .form-row {
  291. display: flex;
  292. gap: 20rpx;
  293. }
  294. .half {
  295. flex: 1;
  296. }
  297. .label {
  298. font-size: 28rpx;
  299. color: #333;
  300. display: block;
  301. margin-bottom: 16rpx;
  302. font-weight: bold;
  303. }
  304. .input {
  305. width: 100%;
  306. height: 76rpx;
  307. border: 1rpx solid #E0E0E0;
  308. border-radius: 10rpx;
  309. padding: 0 20rpx;
  310. font-size: 28rpx;
  311. box-sizing: border-box;
  312. }
  313. .child-select {
  314. display: flex;
  315. align-items: center;
  316. height: 76rpx;
  317. border: 1rpx solid #E0E0E0;
  318. border-radius: 10rpx;
  319. padding: 0 20rpx;
  320. }
  321. .select-text {
  322. flex: 1;
  323. font-size: 28rpx;
  324. color: #333;
  325. }
  326. .select-placeholder {
  327. flex: 1;
  328. font-size: 28rpx;
  329. color: #ccc;
  330. }
  331. .select-arrow {
  332. font-size: 32rpx;
  333. color: #ccc;
  334. }
  335. .picker-input {
  336. height: 76rpx;
  337. line-height: 76rpx;
  338. border: 1rpx solid #E0E0E0;
  339. border-radius: 10rpx;
  340. padding: 0 20rpx;
  341. font-size: 28rpx;
  342. color: #333;
  343. }
  344. .btn-submit {
  345. width: 100%;
  346. height: 88rpx;
  347. line-height: 88rpx;
  348. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  349. color: #fff;
  350. border-radius: 44rpx;
  351. font-size: 32rpx;
  352. font-weight: bold;
  353. text-align: center;
  354. }
  355. .redirect-section {
  356. margin-top: 20rpx;
  357. }
  358. .redirect-card {
  359. background: #fff;
  360. border-radius: 20rpx;
  361. padding: 40rpx 30rpx;
  362. }
  363. .redirect-desc {
  364. font-size: 28rpx;
  365. color: #666;
  366. line-height: 1.6;
  367. display: block;
  368. margin-bottom: 30rpx;
  369. }
  370. </style>