create.vue 11 KB

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