create.vue 11 KB

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