create.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. memberId: 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.memberId || ''
  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.memberId = 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.memberId = 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.memberId) {
  175. uni.showToast({ title: '请选择孩子', icon: 'none' })
  176. return
  177. }
  178. uni.showLoading({ title: '创建中...' })
  179. try {
  180. var submitData = {
  181. memberId: this.formData.memberId,
  182. recordTitle: this.formData.recordTitle || '成长档案',
  183. height: this.formData.height || null,
  184. weight: this.formData.weight || null,
  185. school: this.formData.school || null,
  186. grade: this.formData.grade,
  187. academicPerformance: this.formData.academicPerformance || null,
  188. schoolProvince: this.formData.schoolProvince || null,
  189. schoolCity: this.formData.schoolCity || null,
  190. schoolDistrict: this.formData.schoolDistrict || null,
  191. schoolStreet: this.formData.schoolStreet || null
  192. }
  193. var res = await createGrowthRecord(submitData)
  194. uni.hideLoading()
  195. if (res.code === 200) {
  196. uni.showToast({ title: '创建成功', icon: 'success' })
  197. setTimeout(function() {
  198. uni.navigateTo({
  199. url: '/pages/growth/detail?recordId=' + res.data.id
  200. })
  201. }, 500)
  202. } else {
  203. uni.showToast({ title: res.message || '创建失败', icon: 'none' })
  204. }
  205. } catch (e) {
  206. uni.hideLoading()
  207. uni.showToast({ title: e.message || '创建失败', icon: 'none' })
  208. }
  209. },
  210. goUpload() {
  211. var url = '/pages/growth/upload'
  212. if (this.targetChildId) {
  213. url += '?memberId=' + this.targetChildId
  214. }
  215. uni.navigateTo({ url: url })
  216. },
  217. goPurchase() {
  218. uni.navigateTo({
  219. url: '/pages/assessment/purchase'
  220. })
  221. }
  222. }
  223. }
  224. </script>
  225. <style scoped>
  226. .container {
  227. padding: 30rpx;
  228. background: #F8F8F8;
  229. min-height: 100vh;
  230. }
  231. .header {
  232. text-align: center;
  233. padding: 40rpx 0 30rpx;
  234. }
  235. .title {
  236. font-size: 40rpx;
  237. font-weight: bold;
  238. color: #333;
  239. display: block;
  240. margin-bottom: 10rpx;
  241. }
  242. .subtitle {
  243. font-size: 26rpx;
  244. color: #999;
  245. }
  246. .source-type-section {
  247. display: flex;
  248. gap: 16rpx;
  249. margin-bottom: 30rpx;
  250. }
  251. .source-card {
  252. flex: 1;
  253. background: #fff;
  254. border-radius: 16rpx;
  255. padding: 24rpx 16rpx;
  256. text-align: center;
  257. border: 2rpx solid #E0E0E0;
  258. }
  259. .source-active {
  260. border-color: #667eea;
  261. background: #f5f3ff;
  262. }
  263. .source-icon {
  264. font-size: 48rpx;
  265. display: block;
  266. margin-bottom: 8rpx;
  267. }
  268. .source-name {
  269. font-size: 26rpx;
  270. font-weight: bold;
  271. color: #333;
  272. display: block;
  273. margin-bottom: 4rpx;
  274. }
  275. .source-desc {
  276. font-size: 20rpx;
  277. color: #999;
  278. display: block;
  279. }
  280. .form {
  281. background: #fff;
  282. border-radius: 20rpx;
  283. padding: 30rpx;
  284. }
  285. .form-item {
  286. margin-bottom: 30rpx;
  287. }
  288. .form-row {
  289. display: flex;
  290. gap: 20rpx;
  291. }
  292. .half {
  293. flex: 1;
  294. }
  295. .label {
  296. font-size: 28rpx;
  297. color: #333;
  298. display: block;
  299. margin-bottom: 16rpx;
  300. font-weight: bold;
  301. }
  302. .input {
  303. width: 100%;
  304. height: 76rpx;
  305. border: 1rpx solid #E0E0E0;
  306. border-radius: 10rpx;
  307. padding: 0 20rpx;
  308. font-size: 28rpx;
  309. box-sizing: border-box;
  310. }
  311. .child-select {
  312. display: flex;
  313. align-items: center;
  314. height: 76rpx;
  315. border: 1rpx solid #E0E0E0;
  316. border-radius: 10rpx;
  317. padding: 0 20rpx;
  318. }
  319. .select-text {
  320. flex: 1;
  321. font-size: 28rpx;
  322. color: #333;
  323. }
  324. .select-placeholder {
  325. flex: 1;
  326. font-size: 28rpx;
  327. color: #ccc;
  328. }
  329. .select-arrow {
  330. font-size: 32rpx;
  331. color: #ccc;
  332. }
  333. .picker-input {
  334. height: 76rpx;
  335. line-height: 76rpx;
  336. border: 1rpx solid #E0E0E0;
  337. border-radius: 10rpx;
  338. padding: 0 20rpx;
  339. font-size: 28rpx;
  340. color: #333;
  341. }
  342. .btn-submit {
  343. width: 100%;
  344. height: 88rpx;
  345. line-height: 88rpx;
  346. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  347. color: #fff;
  348. border-radius: 44rpx;
  349. font-size: 32rpx;
  350. font-weight: bold;
  351. text-align: center;
  352. }
  353. .redirect-section {
  354. margin-top: 20rpx;
  355. }
  356. .redirect-card {
  357. background: #fff;
  358. border-radius: 20rpx;
  359. padding: 40rpx 30rpx;
  360. }
  361. .redirect-desc {
  362. font-size: 28rpx;
  363. color: #666;
  364. line-height: 1.6;
  365. display: block;
  366. margin-bottom: 30rpx;
  367. }
  368. </style>