apply.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <text class="title">申请测评</text>
  5. <text class="subtitle">专业的DAN测评,了解孩子的专注力发展</text>
  6. </view>
  7. <!-- 成长规划师选择(可选) -->
  8. <view class="section">
  9. <view class="section-title">选择成长规划师(可选)</view>
  10. <view class="guide-selector">
  11. <view
  12. class="guide-item"
  13. :class="{ 'selected': selectedGuideId === null }"
  14. @click="selectGuide(null)"
  15. >
  16. <view class="guide-avatar guide-avatar-none">
  17. <text>🤝</text>
  18. </view>
  19. <view class="guide-info">
  20. <text class="guide-name">由系统安排</text>
  21. <text class="guide-price">购买后客服对接</text>
  22. </view>
  23. <view class="guide-check" v-if="selectedGuideId === null">✓</view>
  24. </view>
  25. <view
  26. class="guide-item"
  27. :class="{ 'selected': selectedGuideId === guide.guideId }"
  28. v-for="guide in availableGuides"
  29. :key="guide.guideId"
  30. @click="selectGuide(guide)"
  31. >
  32. <image class="guide-avatar" :src="guide.guideAvatar || '/static/default-avatar.png'" />
  33. <view class="guide-info">
  34. <text class="guide-name">{{ guide.guideName }}</text>
  35. <text class="guide-price">{{ formatPriceWithSymbol(guide.price) }}</text>
  36. </view>
  37. <view class="guide-check" v-if="selectedGuideId === guide.guideId">✓</view>
  38. </view>
  39. </view>
  40. </view>
  41. <!-- 测评类型选择 -->
  42. <view class="section">
  43. <view class="section-title">测评类型</view>
  44. <view class="type-selector">
  45. <view
  46. class="type-item"
  47. :class="{ 'selected': selectedType === type.value }"
  48. v-for="type in assessmentTypes"
  49. :key="type.value"
  50. @click="selectType(type.value)"
  51. >
  52. <text class="type-icon">{{ type.icon }}</text>
  53. <text class="type-name">{{ type.name }}</text>
  54. <text class="type-desc">{{ type.desc }}</text>
  55. </view>
  56. </view>
  57. </view>
  58. <!-- 预约时间 -->
  59. <view class="section">
  60. <view class="section-title">预约时间</view>
  61. <view class="date-picker">
  62. <picker mode="date" :value="appointmentDate" @change="onDateChange">
  63. <view class="picker-value">
  64. <text>{{ appointmentDate || '选择日期' }}</text>
  65. <text class="picker-arrow">›</text>
  66. </view>
  67. </picker>
  68. </view>
  69. <view class="time-picker">
  70. <picker mode="time" :value="appointmentTime" @change="onTimeChange">
  71. <view class="picker-value">
  72. <text>{{ appointmentTime || '选择时间' }}</text>
  73. <text class="picker-arrow">›</text>
  74. </view>
  75. </picker>
  76. </view>
  77. </view>
  78. <!-- 孩子选择 -->
  79. <view class="section">
  80. <view class="section-title">选择孩子</view>
  81. <view class="child-selector">
  82. <view
  83. class="child-item"
  84. :class="{ 'selected': selectedChildId === child.id }"
  85. v-for="child in children"
  86. :key="child.id"
  87. @click="selectChild(child)"
  88. >
  89. <view class="child-avatar">{{ child.nickname ? child.nickname[0] : '?' }}</view>
  90. <view class="child-info">
  91. <text class="child-name">{{ child.nickname || '未命名' }}</text>
  92. <text class="child-age">{{ child.age || 0 }}岁</text>
  93. </view>
  94. <view class="child-check" v-if="selectedChildId === child.id">✓</view>
  95. </view>
  96. </view>
  97. </view>
  98. <!-- 余额显示(从额度预约时) -->
  99. <view class="section" v-if="quotaId">
  100. <view class="section-title">额度信息</view>
  101. <view class="quota-info">
  102. <text class="quota-label">本次将消耗 1 次测评额度</text>
  103. <text class="quota-remaining" v-if="quotaRemaining !== null">
  104. 剩余 {{ quotaRemaining }} 次
  105. </text>
  106. </view>
  107. </view>
  108. <!-- 价格信息(非额度预约时显示) -->
  109. <view class="section" v-if="!quotaId && selectedGuideId">
  110. <view class="section-title">费用信息</view>
  111. <view class="price-info">
  112. <view class="price-row">
  113. <text class="price-label">测评费用</text>
  114. <text class="price-value">{{ formatPriceWithSymbol(totalPrice) }}</text>
  115. </view>
  116. <view class="price-row">
  117. <text class="price-label">成长规划师</text>
  118. <text class="price-value">{{ selectedGuideName }}</text>
  119. </view>
  120. <view class="price-row" v-if="inviteCodeInfo">
  121. <text class="price-label">邀请码优惠</text>
  122. <text class="price-value discount">-{{ formatPriceWithSymbol(discountAmount) }}</text>
  123. </view>
  124. </view>
  125. </view>
  126. <!-- 提交按钮 -->
  127. <button class="btn-submit" @click="submit">{{ quotaId ? '消耗额度预约' : '提交申请' }}</button>
  128. </view>
  129. </template>
  130. <script>
  131. import { getAvailableGuides, createAssessmentAppointment, getChildren, getAssessmentQuotas, createAssessmentAppointmentWithQuota } from '../../utils/api.js'
  132. export default {
  133. data() {
  134. return {
  135. quotaId: null,
  136. quotaRemaining: null,
  137. availableGuides: [],
  138. selectedGuideId: null,
  139. selectedGuideName: '',
  140. selectedType: 'initial',
  141. appointmentDate: '',
  142. appointmentTime: '',
  143. selectedChildId: null,
  144. children: [],
  145. inviteCode: '',
  146. inviteCodeInfo: null,
  147. totalPrice: 0,
  148. discountAmount: 0
  149. }
  150. },
  151. onLoad(options) {
  152. this.quotaId = options.quotaId || null
  153. if (this.quotaId) {
  154. this.loadQuotaInfo()
  155. }
  156. if (options.inviteCode) {
  157. this.inviteCode = options.inviteCode
  158. this.validateInviteCode()
  159. }
  160. this.loadChildren()
  161. },
  162. methods: {
  163. async loadQuotaInfo() {
  164. try {
  165. const res = await getAssessmentQuotas()
  166. if (res.code === 200) {
  167. const quotas = res.data || []
  168. const current = quotas.find(q => q.id == this.quotaId)
  169. if (current) {
  170. this.quotaRemaining = current.remainingSessions
  171. }
  172. }
  173. } catch (e) {
  174. console.error('获取额度信息失败', e)
  175. }
  176. },
  177. async loadAvailableGuides(packageId) {
  178. try {
  179. const res = await getAvailableGuides(packageId)
  180. if (res.code === 200) {
  181. this.availableGuides = res.data || []
  182. if (this.inviteCodeInfo && this.inviteCodeInfo.guideId) {
  183. const guide = this.availableGuides.find(g => g.guideId === this.inviteCodeInfo.guideId)
  184. if (guide) {
  185. this.selectGuide(guide)
  186. }
  187. }
  188. }
  189. } catch (e) {
  190. console.error('获取成长规划师列表失败', e)
  191. }
  192. },
  193. async loadChildren() {
  194. try {
  195. const res = await getChildren()
  196. if (res.code === 200) {
  197. this.children = res.data || []
  198. if (this.children.length === 1) {
  199. this.selectedChildId = this.children[0].id
  200. }
  201. }
  202. } catch (e) {
  203. console.error('获取孩子列表失败', e)
  204. }
  205. },
  206. selectGuide(guide) {
  207. this.selectedGuideId = guide.guideId
  208. this.selectedGuideName = guide.guideName
  209. this.calculatePrice()
  210. },
  211. selectType(type) {
  212. this.selectedType = type
  213. },
  214. onDateChange(e) {
  215. this.appointmentDate = e.detail.value
  216. },
  217. onTimeChange(e) {
  218. this.appointmentTime = e.detail.value
  219. },
  220. selectChild(child) {
  221. this.selectedChildId = child.id
  222. },
  223. calculatePrice() {
  224. if (!this.selectedGuideId) {
  225. this.totalPrice = 0
  226. return
  227. }
  228. const guide = this.availableGuides.find(g => g.guideId === this.selectedGuideId)
  229. if (guide) {
  230. this.totalPrice = guide.price
  231. this.discountAmount = 0
  232. }
  233. },
  234. async validateInviteCode() {
  235. if (!this.inviteCode) return
  236. try {
  237. const res = await validateInviteCode(this.inviteCode)
  238. if (res.code === 200) {
  239. this.inviteCodeInfo = res.data
  240. if (this.inviteCodeInfo.guideId) {
  241. const guide = this.availableGuides.find(g => g.guideId === this.inviteCodeInfo.guideId)
  242. if (guide) {
  243. this.selectGuide(guide)
  244. }
  245. }
  246. }
  247. } catch (e) {
  248. console.error('验证邀请码失败', e)
  249. }
  250. },
  251. async submit() {
  252. if (!this.selectedType) {
  253. uni.showToast({ title: '请选择测评类型', icon: 'none' })
  254. return
  255. }
  256. if (!this.appointmentDate) {
  257. uni.showToast({ title: '请选择预约日期', icon: 'none' })
  258. return
  259. }
  260. if (!this.appointmentTime) {
  261. uni.showToast({ title: '请选择预约时间', icon: 'none' })
  262. return
  263. }
  264. if (!this.selectedChildId) {
  265. uni.showToast({ title: '请选择孩子', icon: 'none' })
  266. return
  267. }
  268. try {
  269. uni.showLoading({ title: '提交中...' })
  270. if (this.quotaId) {
  271. const res = await createAssessmentAppointmentWithQuota({
  272. childId: this.selectedChildId,
  273. guideId: this.selectedGuideId,
  274. assessorId: this.selectedGuideId,
  275. quotaId: this.quotaId,
  276. appointmentDate: this.appointmentDate,
  277. appointmentTime: this.appointmentTime,
  278. notes: ''
  279. })
  280. uni.hideLoading()
  281. if (res.code === 200) {
  282. uni.showModal({
  283. title: '预约成功',
  284. content: '您的测评预约已提交,请等待成长规划师确认',
  285. showCancel: false,
  286. success: () => uni.navigateBack()
  287. })
  288. } else {
  289. uni.showToast({ title: res.message || '预约失败', icon: 'none' })
  290. }
  291. } else {
  292. const userId = uni.getStorageSync('userId')
  293. const familyId = uni.getStorageSync('familyId')
  294. const res = await createAssessmentAppointment({
  295. userId: userId,
  296. familyId: familyId,
  297. childId: this.selectedChildId,
  298. teacherId: this.selectedGuideId,
  299. assessorId: this.selectedGuideId,
  300. appointmentType: this.selectedType,
  301. appointmentDate: this.appointmentDate,
  302. appointmentTime: this.appointmentTime,
  303. durationMinutes: 60
  304. })
  305. uni.hideLoading()
  306. if (res.code === 200) {
  307. uni.showModal({
  308. title: '申请成功',
  309. content: '您的测评申请已提交,请等待成长规划师确认',
  310. showCancel: false,
  311. success: () => uni.navigateBack()
  312. })
  313. } else {
  314. uni.showToast({ title: res.message || '提交失败', icon: 'none' })
  315. }
  316. }
  317. } catch (e) {
  318. uni.hideLoading()
  319. uni.showToast({ title: '提交失败', icon: 'none' })
  320. }
  321. }
  322. }
  323. }
  324. </script>
  325. <style scoped>
  326. .container {
  327. padding: 30rpx;
  328. background: #F8F8F8;
  329. min-height: 100vh;
  330. }
  331. .header {
  332. text-align: center;
  333. padding: 60rpx 0 40rpx;
  334. }
  335. .title {
  336. font-size: 48rpx;
  337. font-weight: bold;
  338. color: #333;
  339. display: block;
  340. margin-bottom: 20rpx;
  341. }
  342. .subtitle {
  343. font-size: 28rpx;
  344. color: #666;
  345. }
  346. .section {
  347. background: #fff;
  348. border-radius: 20rpx;
  349. padding: 30rpx;
  350. margin-bottom: 30rpx;
  351. }
  352. .section-title {
  353. font-size: 32rpx;
  354. font-weight: bold;
  355. color: #333;
  356. margin-bottom: 20rpx;
  357. }
  358. .guide-selector,
  359. .type-selector,
  360. .child-selector {
  361. display: flex;
  362. flex-wrap: wrap;
  363. gap: 20rpx;
  364. }
  365. .guide-item,
  366. .type-item,
  367. .child-item {
  368. position: relative;
  369. background: #F8F8F8;
  370. border: 2rpx solid #E0E0E0;
  371. border-radius: 10rpx;
  372. padding: 20rpx;
  373. min-width: 200rpx;
  374. flex: 1;
  375. }
  376. .guide-item.selected,
  377. .type-item.selected,
  378. .child-item.selected {
  379. border-color: #667eea;
  380. background: #F0F4FF;
  381. }
  382. .guide-avatar {
  383. width: 60rpx;
  384. height: 60rpx;
  385. border-radius: 50%;
  386. object-fit: cover;
  387. margin-bottom: 10rpx;
  388. }
  389. .guide-info,
  390. .child-info {
  391. display: flex;
  392. flex-direction: column;
  393. }
  394. .guide-name,
  395. .child-name {
  396. font-size: 28rpx;
  397. font-weight: bold;
  398. color: #333;
  399. margin-bottom: 5rpx;
  400. }
  401. .guide-price {
  402. font-size: 24rpx;
  403. color: #F97316;
  404. font-weight: bold;
  405. }
  406. .child-age {
  407. font-size: 24rpx;
  408. color: #999;
  409. }
  410. .guide-check,
  411. .child-check {
  412. position: absolute;
  413. top: 10rpx;
  414. right: 10rpx;
  415. width: 40rpx;
  416. height: 40rpx;
  417. background: #667eea;
  418. color: #fff;
  419. border-radius: 50%;
  420. display: flex;
  421. align-items: center;
  422. justify-content: center;
  423. font-size: 24rpx;
  424. }
  425. .type-icon {
  426. font-size: 48rpx;
  427. display: block;
  428. margin-bottom: 10rpx;
  429. }
  430. .type-name {
  431. font-size: 28rpx;
  432. font-weight: bold;
  433. color: #333;
  434. display: block;
  435. margin-bottom: 5rpx;
  436. }
  437. .type-desc {
  438. font-size: 24rpx;
  439. color: #999;
  440. }
  441. .child-avatar {
  442. width: 60rpx;
  443. height: 60rpx;
  444. border-radius: 50%;
  445. background: linear-gradient(135deg, #667eea, #764ba2);
  446. color: #fff;
  447. display: flex;
  448. align-items: center;
  449. justify-content: center;
  450. font-size: 28rpx;
  451. font-weight: bold;
  452. margin-right: 20rpx;
  453. }
  454. .date-picker,
  455. .time-picker {
  456. margin-bottom: 20rpx;
  457. }
  458. .picker-value {
  459. display: flex;
  460. justify-content: space-between;
  461. align-items: center;
  462. height: 80rpx;
  463. background: #F8F8F8;
  464. border-radius: 10rpx;
  465. padding: 0 20rpx;
  466. font-size: 28rpx;
  467. color: #333;
  468. }
  469. .picker-arrow {
  470. font-size: 40rpx;
  471. color: #999;
  472. }
  473. .price-info {
  474. background: #F8F8F8;
  475. border-radius: 10rpx;
  476. padding: 20rpx;
  477. }
  478. .price-row {
  479. display: flex;
  480. justify-content: space-between;
  481. align-items: center;
  482. margin-bottom: 15rpx;
  483. }
  484. .price-row:last-child {
  485. margin-bottom: 0;
  486. }
  487. .price-label {
  488. font-size: 28rpx;
  489. color: #666;
  490. }
  491. .price-value {
  492. font-size: 32rpx;
  493. font-weight: bold;
  494. color: #333;
  495. }
  496. .price-value.discount {
  497. color: #F97316;
  498. }
  499. .btn-submit {
  500. width: 100%;
  501. height: 90rpx;
  502. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  503. color: #fff;
  504. border-radius: 45rpx;
  505. font-size: 32rpx;
  506. font-weight: bold;
  507. margin-top: 40rpx;
  508. }
  509. </style>