apply.vue 15 KB

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