create.vue 10 KB

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