apply.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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 res = await createAssessmentAppointment({
  295. memberId: this.selectedChildId,
  296. teacherId: this.selectedGuideId,
  297. assessorId: this.selectedGuideId,
  298. appointmentType: this.selectedType,
  299. appointmentDate: this.appointmentDate,
  300. appointmentTime: this.appointmentTime,
  301. durationMinutes: 60
  302. })
  303. if (res.code === 200) {
  304. uni.showModal({
  305. title: '申请成功',
  306. content: '您的测评申请已提交,请等待成长规划师确认',
  307. showCancel: false,
  308. success: () => uni.navigateBack()
  309. })
  310. } else {
  311. uni.showToast({ title: res.message || '提交失败', icon: 'none' })
  312. }
  313. }
  314. } catch (e) {
  315. uni.showToast({ title: '提交失败', icon: 'none' })
  316. } finally {
  317. this.submitting = false
  318. uni.hideLoading()
  319. }
  320. }
  321. }
  322. }
  323. </script>
  324. <style scoped>
  325. .container {
  326. padding: 30rpx;
  327. background: #F8F8F8;
  328. min-height: 100vh;
  329. }
  330. .header {
  331. text-align: center;
  332. padding: 60rpx 0 40rpx;
  333. }
  334. .title {
  335. font-size: 48rpx;
  336. font-weight: bold;
  337. color: #333;
  338. display: block;
  339. margin-bottom: 20rpx;
  340. }
  341. .subtitle {
  342. font-size: 28rpx;
  343. color: #666;
  344. }
  345. .section {
  346. background: #fff;
  347. border-radius: 20rpx;
  348. padding: 30rpx;
  349. margin-bottom: 30rpx;
  350. }
  351. .section-title {
  352. font-size: 32rpx;
  353. font-weight: bold;
  354. color: #333;
  355. margin-bottom: 20rpx;
  356. }
  357. .guide-selector,
  358. .type-selector,
  359. .child-selector {
  360. display: flex;
  361. flex-wrap: wrap;
  362. gap: 20rpx;
  363. }
  364. .guide-item,
  365. .type-item,
  366. .child-item {
  367. position: relative;
  368. background: #F8F8F8;
  369. border: 2rpx solid #E0E0E0;
  370. border-radius: 10rpx;
  371. padding: 20rpx;
  372. min-width: 200rpx;
  373. flex: 1;
  374. }
  375. .guide-item.selected,
  376. .type-item.selected,
  377. .child-item.selected {
  378. border-color: #667eea;
  379. background: #F0F4FF;
  380. }
  381. .guide-avatar {
  382. width: 60rpx;
  383. height: 60rpx;
  384. border-radius: 50%;
  385. object-fit: cover;
  386. margin-bottom: 10rpx;
  387. }
  388. .guide-info,
  389. .child-info {
  390. display: flex;
  391. flex-direction: column;
  392. }
  393. .guide-name,
  394. .child-name {
  395. font-size: 28rpx;
  396. font-weight: bold;
  397. color: #333;
  398. margin-bottom: 5rpx;
  399. }
  400. .guide-price {
  401. font-size: 24rpx;
  402. color: #F97316;
  403. font-weight: bold;
  404. }
  405. .child-age {
  406. font-size: 24rpx;
  407. color: #999;
  408. }
  409. .guide-check,
  410. .child-check {
  411. position: absolute;
  412. top: 10rpx;
  413. right: 10rpx;
  414. width: 40rpx;
  415. height: 40rpx;
  416. background: #667eea;
  417. color: #fff;
  418. border-radius: 50%;
  419. display: flex;
  420. align-items: center;
  421. justify-content: center;
  422. font-size: 24rpx;
  423. }
  424. .type-icon {
  425. font-size: 48rpx;
  426. display: block;
  427. margin-bottom: 10rpx;
  428. }
  429. .type-name {
  430. font-size: 28rpx;
  431. font-weight: bold;
  432. color: #333;
  433. display: block;
  434. margin-bottom: 5rpx;
  435. }
  436. .type-desc {
  437. font-size: 24rpx;
  438. color: #999;
  439. }
  440. .child-avatar {
  441. width: 60rpx;
  442. height: 60rpx;
  443. border-radius: 50%;
  444. background: linear-gradient(135deg, #667eea, #764ba2);
  445. color: #fff;
  446. display: flex;
  447. align-items: center;
  448. justify-content: center;
  449. font-size: 28rpx;
  450. font-weight: bold;
  451. margin-right: 20rpx;
  452. }
  453. .date-picker,
  454. .time-picker {
  455. margin-bottom: 20rpx;
  456. }
  457. .picker-value {
  458. display: flex;
  459. justify-content: space-between;
  460. align-items: center;
  461. height: 80rpx;
  462. background: #F8F8F8;
  463. border-radius: 10rpx;
  464. padding: 0 20rpx;
  465. font-size: 28rpx;
  466. color: #333;
  467. }
  468. .picker-arrow {
  469. font-size: 40rpx;
  470. color: #999;
  471. }
  472. .price-info {
  473. background: #F8F8F8;
  474. border-radius: 10rpx;
  475. padding: 20rpx;
  476. }
  477. .price-row {
  478. display: flex;
  479. justify-content: space-between;
  480. align-items: center;
  481. margin-bottom: 15rpx;
  482. }
  483. .price-row:last-child {
  484. margin-bottom: 0;
  485. }
  486. .price-label {
  487. font-size: 28rpx;
  488. color: #666;
  489. }
  490. .price-value {
  491. font-size: 32rpx;
  492. font-weight: bold;
  493. color: #333;
  494. }
  495. .price-value.discount {
  496. color: #F97316;
  497. }
  498. .btn-submit {
  499. width: 100%;
  500. height: 90rpx;
  501. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  502. color: #fff;
  503. border-radius: 45rpx;
  504. font-size: 32rpx;
  505. font-weight: bold;
  506. margin-top: 40rpx;
  507. }
  508. </style>