apply.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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">¥{{ 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="selectedGuideId">
  100. <view class="section-title">费用信息</view>
  101. <view class="price-info">
  102. <view class="price-row">
  103. <text class="price-label">测评费用</text>
  104. <text class="price-value">¥{{ totalPrice }}</text>
  105. </view>
  106. <view class="price-row">
  107. <text class="price-label">成长规划师</text>
  108. <text class="price-value">{{ selectedGuideName }}</text>
  109. </view>
  110. <view class="price-row" v-if="inviteCodeInfo">
  111. <text class="price-label">邀请码优惠</text>
  112. <text class="price-value discount">-¥{{ discountAmount }}</text>
  113. </view>
  114. </view>
  115. </view>
  116. <!-- 提交按钮 -->
  117. <button class="btn-submit" @click="submit">提交申请</button>
  118. </view>
  119. </template>
  120. <script>
  121. import { getAvailableGuides, createAssessmentAppointment, getChildren } from '../../utils/api.js'
  122. export default {
  123. data() {
  124. return {
  125. availableGuides: [],
  126. selectedGuideId: null,
  127. selectedGuideName: '',
  128. selectedType: 'initial',
  129. appointmentDate: '',
  130. appointmentTime: '',
  131. selectedChildId: null,
  132. children: [],
  133. inviteCode: '',
  134. inviteCodeInfo: null,
  135. totalPrice: 0,
  136. discountAmount: 0
  137. }
  138. },
  139. onLoad(options) {
  140. // 如果有邀请码参数,自动填充
  141. if (options.inviteCode) {
  142. this.inviteCode = options.inviteCode
  143. this.validateInviteCode()
  144. }
  145. // 如果有套餐ID参数,自动选择
  146. if (options.packageId) {
  147. this.loadAvailableGuides(options.packageId)
  148. } else {
  149. this.loadAvailableGuides()
  150. }
  151. this.loadChildren()
  152. },
  153. methods: {
  154. async loadAvailableGuides(packageId) {
  155. try {
  156. const res = await getAvailableGuides(packageId)
  157. if (res.code === 200) {
  158. this.availableGuides = res.data || []
  159. // 如果有邀请码,自动选择对应的成长规划师
  160. if (this.inviteCodeInfo && this.inviteCodeInfo.guideId) {
  161. const guide = this.availableGuides.find(g => g.guideId === this.inviteInfo.guideId)
  162. if (guide) {
  163. this.selectGuide(guide)
  164. }
  165. }
  166. }
  167. } catch (e) {
  168. console.error('获取成长规划师列表失败', e)
  169. }
  170. },
  171. async loadChildren() {
  172. try {
  173. const res = await getChildren()
  174. if (res.code === 200) {
  175. this.children = res.data || []
  176. // 如果只有一个孩子,自动选择
  177. if (this.children.length === 1) {
  178. this.selectedChildId = this.children[0].id
  179. }
  180. }
  181. } catch (e) {
  182. console.error('获取孩子列表失败', e)
  183. }
  184. },
  185. selectGuide(guide) {
  186. this.selectedGuideId = guide.guideId
  187. this.selectedGuideName = guide.guideName
  188. this.calculatePrice()
  189. },
  190. selectType(type) {
  191. this.selectedType = type
  192. },
  193. onDateChange(e) {
  194. this.appointmentDate = e.detail.value
  195. },
  196. onTimeChange(e) {
  197. this.appointmentTime = e.detail.value
  198. },
  199. selectChild(child) {
  200. this.selectedChildId = child.id
  201. },
  202. calculatePrice() {
  203. if (!this.selectedGuideId) {
  204. this.totalPrice = 0
  205. return
  206. }
  207. const guide = this.availableGuides.find(g => g.guideId === this.selectedGuideId)
  208. if (guide) {
  209. this.totalPrice = guide.price
  210. this.discountAmount = 0
  211. }
  212. },
  213. async validateInviteCode() {
  214. if (!this.inviteCode) {
  215. return
  216. }
  217. try {
  218. const res = await validateInviteCode(this.inviteCode)
  219. if (res.code === 200) {
  220. this.inviteCodeInfo = res.data
  221. // 自动选择邀请码关联的成长规划师
  222. if (this.inviteCodeInfo.guideId) {
  223. const guide = this.availableGuides.find(g => g.guideId === this.inviteCodeInfo.guideId)
  224. if (guide) {
  225. this.selectGuide(guide)
  226. }
  227. }
  228. }
  229. } catch (e) {
  230. console.error('验证邀请码失败', e)
  231. }
  232. },
  233. async submit() {
  234. // 验证表单(成长规划师可选)
  235. if (!this.selectedType) {
  236. uni.showToast({ title: '请选择测评类型', icon: 'none' })
  237. return
  238. }
  239. if (!this.appointmentDate) {
  240. uni.showToast({ title: '请选择预约日期', icon: 'none' })
  241. return
  242. }
  243. if (!this.appointmentTime) {
  244. uni.showToast({ title: '请选择预约时间', icon: 'none' })
  245. return
  246. }
  247. if (!this.selectedChildId) {
  248. uni.showToast({ title: '请选择孩子', icon: 'none' })
  249. return
  250. }
  251. try {
  252. uni.showLoading({ title: '提交中...' })
  253. const userId = uni.getStorageSync('userId')
  254. const familyId = uni.getStorageSync('familyId')
  255. const res = await createAssessmentAppointment({
  256. userId: userId,
  257. familyId: familyId,
  258. childId: this.selectedChildId,
  259. teacherId: this.selectedGuideId,
  260. appointmentType: this.selectedType,
  261. appointmentDate: this.appointmentDate,
  262. appointmentTime: this.appointmentTime,
  263. durationMinutes: 60
  264. })
  265. uni.hideLoading()
  266. if (res.code === 200) {
  267. uni.showModal({
  268. title: '申请成功',
  269. content: '您的测评申请已提交,请等待成长规划师确认',
  270. showCancel: false,
  271. success: () => {
  272. uni.navigateBack()
  273. }
  274. })
  275. } else {
  276. uni.showToast({
  277. title: res.message || '提交失败',
  278. icon: 'none'
  279. })
  280. }
  281. } catch (e) {
  282. uni.hideLoading()
  283. uni.showToast({
  284. title: '提交失败',
  285. icon: 'none'
  286. })
  287. }
  288. }
  289. }
  290. }
  291. </script>
  292. <style scoped>
  293. .container {
  294. padding: 30rpx;
  295. background: #F8F8F8;
  296. min-height: 100vh;
  297. }
  298. .header {
  299. text-align: center;
  300. padding: 60rpx 0 40rpx;
  301. }
  302. .title {
  303. font-size: 48rpx;
  304. font-weight: bold;
  305. color: #333;
  306. display: block;
  307. margin-bottom: 20rpx;
  308. }
  309. .subtitle {
  310. font-size: 28rpx;
  311. color: #666;
  312. }
  313. .section {
  314. background: #fff;
  315. border-radius: 20rpx;
  316. padding: 30rpx;
  317. margin-bottom: 30rpx;
  318. }
  319. .section-title {
  320. font-size: 32rpx;
  321. font-weight: bold;
  322. color: #333;
  323. margin-bottom: 20rpx;
  324. }
  325. .guide-selector,
  326. .type-selector,
  327. .child-selector {
  328. display: flex;
  329. flex-wrap: wrap;
  330. gap: 20rpx;
  331. }
  332. .guide-item,
  333. .type-item,
  334. .child-item {
  335. position: relative;
  336. background: #F8F8F8;
  337. border: 2rpx solid #E0E0E0;
  338. border-radius: 10rpx;
  339. padding: 20rpx;
  340. min-width: 200rpx;
  341. flex: 1;
  342. }
  343. .guide-item.selected,
  344. .type-item.selected,
  345. .child-item.selected {
  346. border-color: #667eea;
  347. background: #F0F4FF;
  348. }
  349. .guide-avatar {
  350. width: 60rpx;
  351. height: 60rpx;
  352. border-radius: 50%;
  353. object-fit: cover;
  354. margin-bottom: 10rpx;
  355. }
  356. .guide-info,
  357. .child-info {
  358. display: flex;
  359. flex-direction: column;
  360. }
  361. .guide-name,
  362. .child-name {
  363. font-size: 28rpx;
  364. font-weight: bold;
  365. color: #333;
  366. margin-bottom: 5rpx;
  367. }
  368. .guide-price {
  369. font-size: 24rpx;
  370. color: #F97316;
  371. font-weight: bold;
  372. }
  373. .child-age {
  374. font-size: 24rpx;
  375. color: #999;
  376. }
  377. .guide-check,
  378. .child-check {
  379. position: absolute;
  380. top: 10rpx;
  381. right: 10rpx;
  382. width: 40rpx;
  383. height: 40rpx;
  384. background: #667eea;
  385. color: #fff;
  386. border-radius: 50%;
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. font-size: 24rpx;
  391. }
  392. .type-icon {
  393. font-size: 48rpx;
  394. display: block;
  395. margin-bottom: 10rpx;
  396. }
  397. .type-name {
  398. font-size: 28rpx;
  399. font-weight: bold;
  400. color: #333;
  401. display: block;
  402. margin-bottom: 5rpx;
  403. }
  404. .type-desc {
  405. font-size: 24rpx;
  406. color: #999;
  407. }
  408. .child-avatar {
  409. width: 60rpx;
  410. height: 60rpx;
  411. border-radius: 50%;
  412. background: linear-gradient(135deg, #667eea, #764ba2);
  413. color: #fff;
  414. display: flex;
  415. align-items: center;
  416. justify-content: center;
  417. font-size: 28rpx;
  418. font-weight: bold;
  419. margin-right: 20rpx;
  420. }
  421. .date-picker,
  422. .time-picker {
  423. margin-bottom: 20rpx;
  424. }
  425. .picker-value {
  426. display: flex;
  427. justify-content: space-between;
  428. align-items: center;
  429. height: 80rpx;
  430. background: #F8F8F8;
  431. border-radius: 10rpx;
  432. padding: 0 20rpx;
  433. font-size: 28rpx;
  434. color: #333;
  435. }
  436. .picker-arrow {
  437. font-size: 40rpx;
  438. color: #999;
  439. }
  440. .price-info {
  441. background: #F8F8F8;
  442. border-radius: 10rpx;
  443. padding: 20rpx;
  444. }
  445. .price-row {
  446. display: flex;
  447. justify-content: space-between;
  448. align-items: center;
  449. margin-bottom: 15rpx;
  450. }
  451. .price-row:last-child {
  452. margin-bottom: 0;
  453. }
  454. .price-label {
  455. font-size: 28rpx;
  456. color: #666;
  457. }
  458. .price-value {
  459. font-size: 32rpx;
  460. font-weight: bold;
  461. color: #333;
  462. }
  463. .price-value.discount {
  464. color: #F97316;
  465. }
  466. .btn-submit {
  467. width: 100%;
  468. height: 90rpx;
  469. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  470. color: #fff;
  471. border-radius: 45rpx;
  472. font-size: 32rpx;
  473. font-weight: bold;
  474. margin-top: 40rpx;
  475. }
  476. </style>