index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <view class="discover-container">
  3. <!-- 品牌头部 -->
  4. <PageBanner theme="home"
  5. tagline="家庭健康成长俱乐部"
  6. quote="给全家的一站式幸福提案" />
  7. <!-- 五行沙盘预览 -->
  8. <wuxing-sandbox mode="preview" badgeText="登录查看完整报告" @point-click="handleLogin" />
  9. <!-- 活动/商品推荐 -->
  10. <view class="recommend-section">
  11. <view class="section-header">
  12. <text class="section-title">🔥 热门推荐</text>
  13. <text class="section-more" @click="goShop">查看更多 ›</text>
  14. </view>
  15. <scroll-view scroll-x enable-flex show-scrollbar="false" class="type-filter-scroll">
  16. <view
  17. v-for="item in typeList"
  18. :key="item.value"
  19. :class="['filter-chip', currentType === item.value ? 'active' : '']"
  20. @click="onTypeChange(item.value)"
  21. >
  22. {{ item.label }}
  23. </view>
  24. </scroll-view>
  25. <view v-if="loading" class="loading-state">
  26. <text class="loading-text">加载中...</text>
  27. </view>
  28. <view v-else-if="products.length === 0" class="empty-state">
  29. <text class="empty-text">暂无商品,去商城看看吧</text>
  30. </view>
  31. <view v-else class="product-grid">
  32. <view
  33. v-for="item in products"
  34. :key="item.id"
  35. class="product-card"
  36. @click="goDetail(item.id)"
  37. >
  38. <image class="product-cover" :src="getImageUrl(item.coverImage) || '/static/default-product.png'" mode="aspectFill" />
  39. <view class="product-info">
  40. <text class="product-name">{{ item.name }}</text>
  41. <view class="product-price-row">
  42. <text class="product-price">{{ formatPriceWithSymbol(item.price) }}</text>
  43. <text v-if="item.memberPrice" class="product-member">会员{{ formatPriceWithSymbol(item.memberPrice) }}</text>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 家庭会员推荐卡片 -->
  50. <view v-if="!isMember" class="member-card" @click="goUpgrade">
  51. <view class="member-card-bg">
  52. <text class="member-card-icon">👑</text>
  53. <view class="member-card-texts">
  54. <text class="member-card-title">开通家庭会员</text>
  55. <text class="member-card-desc">享专属折扣 · 成长服务 · 规划指导</text>
  56. </view>
  57. <view class="member-card-action">
  58. <text class="member-card-btn">立即开通</text>
  59. </view>
  60. </view>
  61. </view>
  62. <!-- 知识中心 -->
  63. <view class="article-section">
  64. <view class="section-header">
  65. <text class="section-title">📖 知识中心</text>
  66. <text class="section-more" @click="goKnowledgeCenter">查看全部 ›</text>
  67. </view>
  68. <view class="article-list">
  69. <view v-for="(item, index) in featuredArticles" :key="item.id" class="article-card" @click="goArticleDetail(item.id)">
  70. <view class="article-cover" :style="{ background: coverGradients[index % coverGradients.length] }">
  71. <text class="article-cover-icon">{{ coverIcons[index % coverIcons.length] }}</text>
  72. </view>
  73. <view class="article-info">
  74. <text class="article-title">{{ item.title }}</text>
  75. <text class="article-desc">{{ item.summary || item.title }}</text>
  76. <text class="article-meta">{{ item.publishedAt ? item.publishedAt.slice(0, 10) : '' }} · {{ item.readTime || 3 }}分钟阅读</text>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <!-- 为何选择浠艾福 -->
  82. <view class="why-section">
  83. <view class="section-header">
  84. <text class="section-title">💡 为什么选择浠艾福</text>
  85. </view>
  86. <view class="feature-grid">
  87. <view class="feature-item">
  88. <text class="feature-icon">🎯</text>
  89. <text class="feature-title">科学评估</text>
  90. <text class="feature-desc">DAN少儿核心素养评估体系</text>
  91. </view>
  92. <view class="feature-item">
  93. <text class="feature-icon">🏆</text>
  94. <text class="feature-title">积分激励</text>
  95. <text class="feature-desc">完成任务得积分,兑换心愿</text>
  96. </view>
  97. <view class="feature-item">
  98. <text class="feature-icon">👨‍👩‍👧‍👦</text>
  99. <text class="feature-title">家庭参与</text>
  100. <text class="feature-desc">全家一起见证成长每一步</text>
  101. </view>
  102. <view class="feature-item">
  103. <text class="feature-icon">🌟</text>
  104. <text class="feature-title">专业规划</text>
  105. <text class="feature-desc">成长规划师一对一指导</text>
  106. </view>
  107. </view>
  108. </view>
  109. <!-- 底部登录按钮 -->
  110. <view class="login-footer">
  111. <button class="login-btn" @click="handleLogin">登录 / 注册</button>
  112. <text class="login-footer-text">登录即表示同意《用户协议》和《隐私政策》</text>
  113. </view>
  114. <!-- 底部占位 -->
  115. <view style="height: 20rpx;"></view>
  116. </view>
  117. </template>
  118. <script>
  119. import PageBanner from '../../components/PageBanner.vue'
  120. import { productList, getFeaturedArticles, getMyMembership } from '@/utils/api.js'
  121. import WuxingSandbox from '../../components/wuxing-sandbox.vue'
  122. import config from '@/config.js'
  123. export default {
  124. components: { PageBanner, WuxingSandbox },
  125. data() {
  126. return {
  127. typeList: [
  128. { label: '全部', value: '' },
  129. { label: '活动', value: 'activity' },
  130. { label: '课程', value: 'course' },
  131. { label: '实物', value: 'physical' },
  132. { label: '数字', value: 'digital' },
  133. { label: '服务', value: 'service' }
  134. ],
  135. currentType: '',
  136. products: [],
  137. loading: false,
  138. featuredArticles: [],
  139. coverGradients: [
  140. 'linear-gradient(135deg, #D6EAF8, #8FC5E8)',
  141. 'linear-gradient(135deg, #E8F5E9, #81C784)',
  142. 'linear-gradient(135deg, #FFF3E0, #FFB74D)',
  143. 'linear-gradient(135deg, #F3E5F5, #CE93D8)',
  144. 'linear-gradient(135deg, #FCE4EC, #F06292)'
  145. ],
  146. coverIcons: ['🌱', '🏃', '🎯', '🌟', '📚'],
  147. isMember: false
  148. }
  149. },
  150. onLoad(options) {
  151. if (options && options.type) {
  152. this.currentType = options.type
  153. }
  154. },
  155. onShow() {
  156. this.checkMemberStatus()
  157. this.loadProducts()
  158. this.loadFeaturedArticles()
  159. },
  160. methods: {
  161. checkMemberStatus() {
  162. var that = this
  163. getMyMembership().then(function(res) {
  164. if (res.data && res.data.memberLevel) {
  165. that.isMember = res.data.memberLevel !== 'FREE'
  166. }
  167. }).catch(function() {})
  168. },
  169. goUpgrade() {
  170. uni.navigateTo({ url: '/pages/membership/upgrade' })
  171. },
  172. loadProducts() {
  173. this.loading = true
  174. const params = { page: 1, size: 10 }
  175. if (this.currentType) {
  176. params.productType = this.currentType
  177. }
  178. productList(params).then(res => {
  179. this.loading = false
  180. if (res.code === 200 && res.data) {
  181. this.products = res.data.records || []
  182. }
  183. }).catch(() => {
  184. this.loading = false
  185. })
  186. },
  187. onTypeChange(value) {
  188. this.currentType = value
  189. this.loadProducts()
  190. },
  191. goShop() {
  192. uni.navigateTo({ url: '/pages/shop/index' })
  193. },
  194. goDetail(id) {
  195. uni.navigateTo({ url: '/pages/shop/detail/detail?id=' + id })
  196. },
  197. handleLogin() {
  198. uni.navigateTo({ url: '/pages/login/login?redirect=' + encodeURIComponent('/pages/discover/index') })
  199. },
  200. async loadFeaturedArticles() {
  201. try {
  202. const res = await getFeaturedArticles({ size: 3 })
  203. if (res.code === 200 && res.data) {
  204. let list = Array.isArray(res.data) ? res.data : (res.data.records || [])
  205. this.featuredArticles = list
  206. }
  207. } catch (e) {
  208. // 静默处理
  209. }
  210. },
  211. goArticleDetail(id) {
  212. uni.navigateTo({ url: '/pages/article-center/article-detail?id=' + id })
  213. },
  214. getImageUrl: function(path) {
  215. return config.API_BASE_URL + path
  216. },
  217. goKnowledgeCenter() {
  218. uni.navigateTo({ url: '/pages/mind-extra/articles' })
  219. }
  220. }
  221. }
  222. </script>
  223. <style scoped>
  224. .discover-container {
  225. min-height: 100vh;
  226. background: #f5f7fa;
  227. padding-bottom: 100rpx;
  228. }
  229. /* ===== 推荐 ===== */
  230. .recommend-section {
  231. margin: 20rpx 30rpx;
  232. }
  233. .section-header {
  234. display: flex;
  235. justify-content: space-between;
  236. align-items: center;
  237. margin-bottom: 20rpx;
  238. }
  239. .section-title {
  240. font-size: 30rpx;
  241. font-weight: bold;
  242. color: #333;
  243. }
  244. .section-more {
  245. font-size: 24rpx;
  246. color: #5B9BD5;
  247. }
  248. .type-filter-scroll {
  249. white-space: nowrap;
  250. margin-bottom: 20rpx;
  251. }
  252. .filter-chip {
  253. display: inline-block;
  254. padding: 8rpx 24rpx;
  255. font-size: 24rpx;
  256. color: #666;
  257. background: #f0f0f0;
  258. border-radius: 30rpx;
  259. margin-right: 16rpx;
  260. }
  261. .filter-chip.active {
  262. background: #5B9BD5;
  263. color: #fff;
  264. }
  265. .loading-state,
  266. .empty-state {
  267. display: flex;
  268. justify-content: center;
  269. padding: 60rpx 0;
  270. }
  271. .loading-text,
  272. .empty-text {
  273. font-size: 26rpx;
  274. color: #999;
  275. }
  276. .product-grid {
  277. display: flex;
  278. flex-wrap: wrap;
  279. justify-content: space-between;
  280. }
  281. .product-card {
  282. width: 48%;
  283. background: #fff;
  284. border-radius: 16rpx;
  285. overflow: hidden;
  286. margin-bottom: 20rpx;
  287. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.06);
  288. }
  289. .product-cover {
  290. width: 100%;
  291. height: 200rpx;
  292. background: #f0f0f0;
  293. }
  294. .product-info {
  295. padding: 14rpx;
  296. }
  297. .product-name {
  298. display: block;
  299. font-size: 26rpx;
  300. color: #333;
  301. margin-bottom: 10rpx;
  302. overflow: hidden;
  303. text-overflow: ellipsis;
  304. white-space: nowrap;
  305. }
  306. .product-price-row {
  307. display: flex;
  308. align-items: baseline;
  309. }
  310. .product-price {
  311. font-size: 28rpx;
  312. color: #5B9BD5;
  313. font-weight: bold;
  314. margin-right: 10rpx;
  315. }
  316. .product-member {
  317. font-size: 20rpx;
  318. color: #999;
  319. }
  320. .recommend-scroll {
  321. display: flex;
  322. white-space: nowrap;
  323. overflow-x: auto;
  324. padding-bottom: 10rpx;
  325. }
  326. .recommend-card {
  327. display: inline-flex;
  328. flex-direction: column;
  329. width: 260rpx;
  330. background: #fff;
  331. border-radius: 20rpx;
  332. overflow: hidden;
  333. margin-right: 20rpx;
  334. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  335. }
  336. .card-banner {
  337. padding: 14rpx 20rpx;
  338. background: #5B9BD5;
  339. color: #fff;
  340. font-size: 22rpx;
  341. font-weight: bold;
  342. text-align: center;
  343. }
  344. .card-body {
  345. padding: 16rpx;
  346. white-space: normal;
  347. }
  348. .card-title {
  349. font-size: 24rpx;
  350. font-weight: bold;
  351. color: #333;
  352. display: block;
  353. margin-bottom: 6rpx;
  354. }
  355. .card-desc {
  356. font-size: 20rpx;
  357. color: #999;
  358. display: block;
  359. margin-bottom: 10rpx;
  360. }
  361. .card-meta {
  362. display: flex;
  363. align-items: center;
  364. justify-content: space-between;
  365. }
  366. .card-price {
  367. font-size: 26rpx;
  368. color: #5B9BD5;
  369. font-weight: bold;
  370. }
  371. .card-tag {
  372. font-size: 18rpx;
  373. color: #5B9BD5;
  374. background: rgba(91,155,213,0.1);
  375. padding: 2rpx 10rpx;
  376. border-radius: 10rpx;
  377. }
  378. /* ===== 家庭会员推荐卡片 ===== */
  379. .member-card {
  380. margin: 20rpx 30rpx 0;
  381. }
  382. .member-card-bg {
  383. display: flex;
  384. align-items: center;
  385. background: linear-gradient(135deg, #F97316, #FB923C);
  386. border-radius: 20rpx;
  387. padding: 24rpx 30rpx;
  388. }
  389. .member-card-icon {
  390. font-size: 48rpx;
  391. margin-right: 16rpx;
  392. }
  393. .member-card-texts {
  394. flex: 1;
  395. display: flex;
  396. flex-direction: column;
  397. }
  398. .member-card-title {
  399. font-size: 30rpx;
  400. font-weight: bold;
  401. color: #fff;
  402. }
  403. .member-card-desc {
  404. font-size: 22rpx;
  405. color: rgba(255,255,255,0.85);
  406. margin-top: 4rpx;
  407. }
  408. .member-card-action {
  409. margin-left: 16rpx;
  410. }
  411. .member-card-btn {
  412. display: inline-block;
  413. padding: 8rpx 24rpx;
  414. background: #fff;
  415. color: #F97316;
  416. font-size: 24rpx;
  417. font-weight: bold;
  418. border-radius: 30rpx;
  419. }
  420. /* ===== 推荐文章 ===== */
  421. .article-section {
  422. margin: 20rpx 30rpx 0;
  423. }
  424. .article-list {
  425. display: flex;
  426. flex-direction: column;
  427. gap: 16rpx;
  428. }
  429. .article-card {
  430. display: flex;
  431. background: #fff;
  432. border-radius: 16rpx;
  433. overflow: hidden;
  434. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  435. cursor: pointer;
  436. }
  437. .article-cover {
  438. width: 180rpx;
  439. flex-shrink: 0;
  440. display: flex;
  441. align-items: center;
  442. justify-content: center;
  443. }
  444. .article-cover-icon {
  445. font-size: 48rpx;
  446. }
  447. .article-info {
  448. flex: 1;
  449. padding: 16rpx;
  450. display: flex;
  451. flex-direction: column;
  452. justify-content: center;
  453. }
  454. .article-title {
  455. font-size: 26rpx;
  456. font-weight: bold;
  457. color: #333;
  458. line-height: 1.4;
  459. overflow: hidden;
  460. text-overflow: ellipsis;
  461. white-space: nowrap;
  462. }
  463. .article-desc {
  464. font-size: 22rpx;
  465. color: #999;
  466. line-height: 1.3;
  467. margin-top: 6rpx;
  468. overflow: hidden;
  469. text-overflow: ellipsis;
  470. white-space: nowrap;
  471. }
  472. .article-meta {
  473. font-size: 20rpx;
  474. color: #ccc;
  475. margin-top: 6rpx;
  476. }
  477. /* ===== 为何选择 ===== */
  478. .why-section {
  479. margin: 30rpx;
  480. }
  481. .feature-grid {
  482. display: flex;
  483. flex-direction: row;
  484. flex-wrap: wrap;
  485. justify-content: space-between;
  486. }
  487. .feature-item {
  488. width: calc(50% - 10rpx);
  489. box-sizing: border-box;
  490. background: #fff;
  491. border-radius: 20rpx;
  492. padding: 24rpx;
  493. margin-bottom: 20rpx;
  494. display: flex;
  495. flex-direction: column;
  496. align-items: center;
  497. text-align: center;
  498. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  499. }
  500. .feature-icon {
  501. font-size: 48rpx;
  502. margin-bottom: 10rpx;
  503. }
  504. .feature-title {
  505. font-size: 24rpx;
  506. font-weight: bold;
  507. color: #333;
  508. margin-bottom: 6rpx;
  509. }
  510. .feature-desc {
  511. font-size: 20rpx;
  512. color: #999;
  513. }
  514. /* ===== 底部登录 ===== */
  515. .login-footer {
  516. margin: 40rpx 30rpx;
  517. display: flex;
  518. flex-direction: column;
  519. align-items: center;
  520. }
  521. .login-btn {
  522. width: 100%;
  523. height: 88rpx;
  524. line-height: 88rpx;
  525. background: linear-gradient(135deg, #5B9BD5, #3A7CC4);
  526. color: #fff;
  527. font-size: 32rpx;
  528. font-weight: bold;
  529. border-radius: 44rpx;
  530. text-align: center;
  531. border: none;
  532. }
  533. .login-btn::after {
  534. border: none;
  535. }
  536. .login-footer-text {
  537. font-size: 20rpx;
  538. color: #bbb;
  539. margin-top: 16rpx;
  540. }
  541. </style>