apply.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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" :loading="submitting" :disabled="submitting" @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. submitting: false
  150. }
  151. },
  152. onLoad(options) {
  153. this.quotaId = options.quotaId || null
  154. if (this.quotaId) {
  155. this.loadQuotaInfo()
  156. }
  157. if (options.inviteCode) {
  158. this.inviteCode = options.inviteCode
  159. this.validateInviteCode()
  160. }
  161. this.loadChildren()
  162. },
  163. methods: {
  164. async loadQuotaInfo() {
  165. try {
  166. const res = await getAssessmentQuotas()
  167. if (res.code === 200) {
  168. const quotas = res.data || []
  169. const current = quotas.find(q => q.id == this.quotaId)
  170. if (current) {
  171. this.quotaRemaining = current.remainingSessions
  172. }
  173. }
  174. } catch (e) {
  175. console.error('获取额度信息失败', e)
  176. }
  177. },
  178. async loadAvailableGuides(packageId) {
  179. try {
  180. const res = await getAvailableGuides(packageId)
  181. if (res.code === 200) {
  182. this.availableGuides = res.data || []
  183. if (this.inviteCodeInfo && this.inviteCodeInfo.guideId) {
  184. const guide = this.availableGuides.find(g => g.guideId === this.inviteCodeInfo.guideId)
  185. if (guide) {
  186. this.selectGuide(guide)
  187. }
  188. }
  189. }
  190. } catch (e) {
  191. console.error('获取成长规划师列表失败', e)
  192. }
  193. },
  194. async loadChildren() {
  195. try {
  196. const res = await getChildren()
  197. if (res.code === 200) {
  198. this.children = res.data || []
  199. if (this.children.length === 1) {
  200. this.selectedChildId = this.children[0].id
  201. }
  202. }
  203. } catch (e) {
  204. console.error('获取孩子列表失败', e)
  205. }
  206. },
  207. selectGuide(guide) {
  208. this.selectedGuideId = guide.guideId
  209. this.selectedGuideName = guide.guideName
  210. this.calculatePrice()
  211. },
  212. selectType(type) {
  213. this.selectedType = type
  214. },
  215. onDateChange(e) {
  216. this.appointmentDate = e.detail.value
  217. },
  218. onTimeChange(e) {
  219. this.appointmentTime = e.detail.value
  220. },
  221. selectChild(child) {
  222. this.selectedChildId = child.id
  223. },
  224. calculatePrice() {
  225. if (!this.selectedGuideId) {
  226. this.totalPrice = 0
  227. return
  228. }
  229. const guide = this.availableGuides.find(g => g.guideId === this.selectedGuideId)
  230. if (guide) {
  231. this.totalPrice = guide.price
  232. this.discountAmount = 0
  233. }
  234. },
  235. async validateInviteCode() {
  236. if (!this.inviteCode) return
  237. try {
  238. const res = await validateInviteCode(this.inviteCode)
  239. if (res.code === 200) {
  240. this.inviteCodeInfo = res.data
  241. if (this.inviteCodeInfo.guideId) {
  242. const guide = this.availableGuides.find(g => g.guideId === this.inviteCodeInfo.guideId)
  243. if (guide) {
  244. this.selectGuide(guide)
  245. }
  246. }
  247. }
  248. } catch (e) {
  249. console.error('验证邀请码失败', e)
  250. }
  251. },
  252. async submit() {
  253. if (this.submitting) return
  254. if (!this.selectedType) {
  255. uni.showToast({ title: '请选择测评类型', icon: 'none' })
  256. return
  257. }
  258. if (!this.appointmentDate) {
  259. uni.showToast({ title: '请选择预约日期', icon: 'none' })
  260. return
  261. }
  262. if (!this.appointmentTime) {
  263. uni.showToast({ title: '请选择预约时间', icon: 'none' })
  264. return
  265. }
  266. if (!this.selectedChildId) {
  267. uni.showToast({ title: '请选择孩子', icon: 'none' })
  268. return
  269. }
  270. this.submitting = true
  271. uni.showLoading({ title: '提交中...' })
  272. try {
  273. if (this.quotaId) {
  274. const res = await createAssessmentAppointmentWithQuota({
  275. memberId: this.selectedChildId,
  276. guideId: this.selectedGuideId,
  277. assessorId: this.selectedGuideId,
  278. quotaId: this.quotaId,
  279. appointmentDate: this.appointmentDate,
  280. appointmentTime: this.appointmentTime,
  281. notes: ''
  282. })
  283. if (res.code === 200) {
  284. uni.showModal({
  285. title: '预约成功',
  286. content: '您的测评预约已提交,请等待成长规划师确认',
  287. showCancel: false,
  288. success: () => uni.navigateBack()
  289. })
  290. } else {
  291. uni.showToast({ title: res.message || '预约失败', icon: 'none' })
  292. }
  293. } else {
  294. const userId = uni.getStorageSync('userId')
  295. const res = await createAssessmentAppointment({
  296. userId: userId,
  297. memberId: 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. if (res.code === 200) {
  306. uni.showModal({
  307. title: '申请成功',
  308. content: '您的测评申请已提交,请等待成长规划师确认',
  309. showCancel: false,
  310. success: () => uni.navigateBack()
  311. })
  312. } else {
  313. uni.showToast({ title: res.message || '提交失败', icon: 'none' })
  314. }
  315. }
  316. } catch (e) {
  317. uni.showToast({ title: '提交失败', icon: 'none' })
  318. } finally {
  319. this.submitting = false
  320. uni.hideLoading()
  321. }
  322. }
  323. }
  324. }
  325. </script>
  326. <style scoped>
  327. .container {
  328. padding: 30rpx;
  329. background: #F8F8F8;
  330. min-height: 100vh;
  331. }
  332. .header {
  333. text-align: center;
  334. padding: 60rpx 0 40rpx;
  335. }
  336. .title {
  337. font-size: 48rpx;
  338. font-weight: bold;
  339. color: #333;
  340. display: block;
  341. margin-bottom: 20rpx;
  342. }
  343. .subtitle {
  344. font-size: 28rpx;
  345. color: #666;
  346. }
  347. .section {
  348. background: #fff;
  349. border-radius: 20rpx;
  350. padding: 30rpx;
  351. margin-bottom: 30rpx;
  352. }
  353. .section-title {
  354. font-size: 32rpx;
  355. font-weight: bold;
  356. color: #333;
  357. margin-bottom: 20rpx;
  358. }
  359. .guide-selector,
  360. .type-selector,
  361. .child-selector {
  362. display: flex;
  363. flex-wrap: wrap;
  364. gap: 20rpx;
  365. }
  366. .guide-item,
  367. .type-item,
  368. .child-item {
  369. position: relative;
  370. background: #F8F8F8;
  371. border: 2rpx solid #E0E0E0;
  372. border-radius: 10rpx;
  373. padding: 20rpx;
  374. min-width: 200rpx;
  375. flex: 1;
  376. }
  377. .guide-item.selected,
  378. .type-item.selected,
  379. .child-item.selected {
  380. border-color: #667eea;
  381. background: #F0F4FF;
  382. }
  383. .guide-avatar {
  384. width: 60rpx;
  385. height: 60rpx;
  386. border-radius: 50%;
  387. object-fit: cover;
  388. margin-bottom: 10rpx;
  389. }
  390. .guide-info,
  391. .child-info {
  392. display: flex;
  393. flex-direction: column;
  394. }
  395. .guide-name,
  396. .child-name {
  397. font-size: 28rpx;
  398. font-weight: bold;
  399. color: #333;
  400. margin-bottom: 5rpx;
  401. }
  402. .guide-price {
  403. font-size: 24rpx;
  404. color: #F97316;
  405. font-weight: bold;
  406. }
  407. .child-age {
  408. font-size: 24rpx;
  409. color: #999;
  410. }
  411. .guide-check,
  412. .child-check {
  413. position: absolute;
  414. top: 10rpx;
  415. right: 10rpx;
  416. width: 40rpx;
  417. height: 40rpx;
  418. background: #667eea;
  419. color: #fff;
  420. border-radius: 50%;
  421. display: flex;
  422. align-items: center;
  423. justify-content: center;
  424. font-size: 24rpx;
  425. }
  426. .type-icon {
  427. font-size: 48rpx;
  428. display: block;
  429. margin-bottom: 10rpx;
  430. }
  431. .type-name {
  432. font-size: 28rpx;
  433. font-weight: bold;
  434. color: #333;
  435. display: block;
  436. margin-bottom: 5rpx;
  437. }
  438. .type-desc {
  439. font-size: 24rpx;
  440. color: #999;
  441. }
  442. .child-avatar {
  443. width: 60rpx;
  444. height: 60rpx;
  445. border-radius: 50%;
  446. background: linear-gradient(135deg, #667eea, #764ba2);
  447. color: #fff;
  448. display: flex;
  449. align-items: center;
  450. justify-content: center;
  451. font-size: 28rpx;
  452. font-weight: bold;
  453. margin-right: 20rpx;
  454. }
  455. .date-picker,
  456. .time-picker {
  457. margin-bottom: 20rpx;
  458. }
  459. .picker-value {
  460. display: flex;
  461. justify-content: space-between;
  462. align-items: center;
  463. height: 80rpx;
  464. background: #F8F8F8;
  465. border-radius: 10rpx;
  466. padding: 0 20rpx;
  467. font-size: 28rpx;
  468. color: #333;
  469. }
  470. .picker-arrow {
  471. font-size: 40rpx;
  472. color: #999;
  473. }
  474. .price-info {
  475. background: #F8F8F8;
  476. border-radius: 10rpx;
  477. padding: 20rpx;
  478. }
  479. .price-row {
  480. display: flex;
  481. justify-content: space-between;
  482. align-items: center;
  483. margin-bottom: 15rpx;
  484. }
  485. .price-row:last-child {
  486. margin-bottom: 0;
  487. }
  488. .price-label {
  489. font-size: 28rpx;
  490. color: #666;
  491. }
  492. .price-value {
  493. font-size: 32rpx;
  494. font-weight: bold;
  495. color: #333;
  496. }
  497. .price-value.discount {
  498. color: #F97316;
  499. }
  500. .btn-submit {
  501. width: 100%;
  502. height: 90rpx;
  503. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  504. color: #fff;
  505. border-radius: 45rpx;
  506. font-size: 32rpx;
  507. font-weight: bold;
  508. margin-top: 40rpx;
  509. }
  510. </style>