index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <view class="container">
  3. <!-- 自定义头部 -->
  4. <view class="custom-header">
  5. <view class="header-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg" style="transform: rotate(180deg);"></image>
  7. </view>
  8. <text class="header-title">履约者等级权益</text>
  9. <view class="header-right"></view>
  10. </view>
  11. <view class="header-placeholder"></view>
  12. <!-- 等级 Swiper -->
  13. <view class="swiper-container" v-if="!pageLoading">
  14. <swiper
  15. class="level-swiper"
  16. previous-margin="80rpx"
  17. next-margin="80rpx"
  18. :current="currentIndex"
  19. @change="swiperChange">
  20. <swiper-item v-for="(level, index) in processedLevels" :key="index" @click="changeLevel(index)">
  21. <view class="level-card" :style="{
  22. transform: currentIndex === index ? 'scale(1)' : 'scale(0.9)',
  23. backgroundImage: 'url(' + level.backgroundUrl + ')',
  24. backgroundSize: 'cover',
  25. backgroundPosition: 'center'
  26. }">
  27. <view class="card-content">
  28. <view class="card-header">
  29. <view class="level-badge">L{{ index + 1 }}</view>
  30. <view class="current-badge" v-if="level.isCurrent">当前等级</view>
  31. </view>
  32. <text class="level-name">{{ level.name }}</text>
  33. <text class="level-score">所需积分: {{ level.upgradePoints || 0 }}</text>
  34. <!-- Crown graphic overlay -->
  35. <image class="crown-overlay" src="/static/icons/crown.svg" mode="aspectFit"></image>
  36. </view>
  37. </view>
  38. </swiper-item>
  39. </swiper>
  40. <!-- 自定义指示点 -->
  41. <view class="swiper-dots">
  42. <view
  43. class="dot"
  44. v-for="(item, index) in processedLevels"
  45. :key="index"
  46. :class="{ active: currentIndex === index }">
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 权益标题 -->
  51. <view class="benefits-title-row" v-if="!pageLoading && currentLevel">
  52. <text class="benefits-title">专属权益</text>
  53. <text class="benefits-count">({{ currentLevel.benefits ? currentLevel.benefits.length : 0 }})</text>
  54. </view>
  55. <!-- 权益列表 -->
  56. <view class="benefits-grid" v-if="!pageLoading && currentLevel">
  57. <view
  58. class="benefit-item"
  59. v-for="(benefit, index) in currentLevel.benefits"
  60. :key="index"
  61. @click="showBenefitDetail(benefit)">
  62. <view class="benefit-icon-wrapper">
  63. <image class="benefit-icon" :src="benefit.iconUrl" mode="aspectFit" v-if="benefit.iconUrl"></image>
  64. <view class="benefit-icon-placeholder" v-else>{{ benefit.name[0] }}</view>
  65. </view>
  66. <text class="benefit-name">{{ benefit.name }}</text>
  67. </view>
  68. <view class="empty-benefits" v-if="!currentLevel.benefits || currentLevel.benefits.length === 0">
  69. <text>该等级暂无特殊权益</text>
  70. </view>
  71. </view>
  72. <!-- 权益详情弹窗 -->
  73. <view class="popup-mask" :class="{ 'show': isPopupShow }" @click="closePopup" @touchmove.stop.prevent>
  74. <view class="popup-modal" @click.stop>
  75. <view class="popup-icon-wrapper">
  76. <image class="benefit-icon-large" :src="currentBenefit.iconUrl" mode="aspectFit" v-if="currentBenefit && currentBenefit.iconUrl"></image>
  77. <view class="benefit-icon-placeholder-large" v-else>{{ currentBenefit ? currentBenefit.name[0] : '' }}</view>
  78. </view>
  79. <text class="popup-title">{{ currentBenefit ? currentBenefit.name : '' }}</text>
  80. <text class="popup-desc">{{ currentBenefit ? currentBenefit.statement : '' }}</text>
  81. <button class="popup-btn" @click="closePopup">我知道了</button>
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. import { getMyProfile } from '@/api/fulfiller/fulfiller'
  88. import { listAllLevelConfigs } from '@/api/fulfiller/levelConfig'
  89. import { listAllLevelRights } from '@/api/fulfiller/levelRights'
  90. export default {
  91. data() {
  92. return {
  93. currentIndex: 0,
  94. profile: null,
  95. levels: [], // 从后端获取的等级配置
  96. rightsList: [], // 从后端获取的所有权益列表
  97. isPopupShow: false,
  98. currentBenefit: null,
  99. pageLoading: true
  100. }
  101. },
  102. computed: {
  103. currentLevel() {
  104. return this.processedLevels[this.currentIndex];
  105. },
  106. // 合并等级与对应的权益详细信息
  107. processedLevels() {
  108. if (!this.levels.length) return [];
  109. return this.levels.map(lvl => {
  110. // 筛选出属于该等级的权益
  111. const benefits = (lvl.rights || []).map(rightId => {
  112. return this.rightsList.find(r => r.id === rightId)
  113. }).filter(Boolean); // 过滤掉未找到的
  114. return {
  115. ...lvl,
  116. isCurrent: this.profile && this.profile.level === lvl.lvNo,
  117. benefits: benefits
  118. }
  119. }).sort((a,b) => a.lvNo - b.lvNo); // 确保按级别排序
  120. }
  121. },
  122. async onLoad() {
  123. await this.initData();
  124. },
  125. methods: {
  126. async initData() {
  127. this.pageLoading = true;
  128. uni.showLoading({ title: '加载中...' });
  129. try {
  130. // 并行加载个人信息、等级配置、权益列表
  131. const [profileRes, levelsRes, rightsRes] = await Promise.all([
  132. getMyProfile(),
  133. listAllLevelConfigs(),
  134. listAllLevelRights()
  135. ]);
  136. this.profile = profileRes.data;
  137. this.levels = levelsRes.data || [];
  138. this.rightsList = rightsRes.data || [];
  139. // 默认定位到用户当前等级
  140. if (this.profile) {
  141. const idx = this.processedLevels.findIndex(lvl => lvl.lvNo === this.profile.level);
  142. if (idx !== -1) {
  143. this.currentIndex = idx;
  144. }
  145. }
  146. } catch (err) {
  147. console.error('初始化等级页面失败:', err);
  148. uni.showToast({ title: err.message || '数据加载失败', icon: 'none' });
  149. } finally {
  150. this.pageLoading = false;
  151. uni.hideLoading();
  152. }
  153. },
  154. navBack() {
  155. uni.navigateBack();
  156. },
  157. swiperChange(e) {
  158. this.currentIndex = e.detail.current;
  159. },
  160. changeLevel(index) {
  161. this.currentIndex = index;
  162. },
  163. showBenefitDetail(benefit) {
  164. this.currentBenefit = benefit;
  165. this.isPopupShow = true;
  166. },
  167. closePopup() {
  168. this.isPopupShow = false;
  169. }
  170. }
  171. }
  172. </script>
  173. <style>
  174. page {
  175. background-color: #fff;
  176. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  177. }
  178. .custom-header {
  179. position: fixed;
  180. top: 0;
  181. left: 0;
  182. width: 100%;
  183. height: 88rpx;
  184. padding-top: var(--status-bar-height);
  185. background-color: #fff;
  186. display: flex;
  187. align-items: center;
  188. justify-content: space-between;
  189. padding-left: 30rpx;
  190. padding-right: 30rpx;
  191. box-sizing: border-box;
  192. z-index: 100;
  193. }
  194. .header-placeholder {
  195. height: calc(88rpx + var(--status-bar-height));
  196. }
  197. .back-icon {
  198. width: 40rpx;
  199. height: 40rpx;
  200. }
  201. .header-title {
  202. font-size: 32rpx;
  203. font-weight: bold;
  204. color: #333;
  205. }
  206. .header-right {
  207. width: 40rpx;
  208. }
  209. .swiper-container {
  210. position: relative;
  211. padding-bottom: 30rpx;
  212. }
  213. .level-swiper {
  214. height: 360rpx;
  215. margin-top: 20rpx;
  216. }
  217. .level-card {
  218. height: 320rpx;
  219. border-radius: 30rpx;
  220. margin: 0 10rpx;
  221. transition: transform 0.3s;
  222. overflow: hidden;
  223. position: relative;
  224. box-shadow: 0 10rpx 20rpx rgba(0,0,0,0.1);
  225. background-color: #eee;
  226. }
  227. .card-content {
  228. padding: 30rpx;
  229. position: relative;
  230. z-index: 2;
  231. height: 100%;
  232. box-sizing: border-box;
  233. display: flex;
  234. flex-direction: column;
  235. }
  236. .card-header {
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: flex-start;
  240. margin-bottom: auto;
  241. }
  242. .level-badge {
  243. background: rgba(255,255,255,0.2);
  244. border: 1px solid rgba(255,255,255,0.6);
  245. padding: 2rpx 12rpx;
  246. border-radius: 10rpx;
  247. font-size: 24rpx;
  248. color: #fff;
  249. }
  250. .current-badge {
  251. background-color: rgba(255,255,255,0.9);
  252. color: #333;
  253. font-size: 20rpx;
  254. padding: 4rpx 12rpx;
  255. border-radius: 20rpx;
  256. font-weight: bold;
  257. }
  258. .level-name {
  259. font-size: 44rpx;
  260. font-weight: bold;
  261. color: #fff;
  262. margin-bottom: 10rpx;
  263. text-shadow: 0 2rpx 4rpx rgba(0,0,0,0.2);
  264. }
  265. .level-score {
  266. font-size: 24rpx;
  267. color: rgba(255,255,255,0.9);
  268. margin-bottom: 20rpx;
  269. }
  270. .crown-overlay {
  271. position: absolute;
  272. bottom: -30rpx;
  273. right: -30rpx;
  274. width: 260rpx;
  275. height: 260rpx;
  276. opacity: 0.15;
  277. z-index: 1;
  278. }
  279. .swiper-dots {
  280. display: flex;
  281. justify-content: center;
  282. margin-top: 10rpx;
  283. }
  284. .dot {
  285. width: 12rpx;
  286. height: 12rpx;
  287. background-color: #E0E0E0;
  288. border-radius: 50%;
  289. margin: 0 6rpx;
  290. transition: all 0.3s;
  291. }
  292. .dot.active {
  293. width: 24rpx;
  294. background-color: #333;
  295. border-radius: 6rpx;
  296. }
  297. .benefits-title-row {
  298. padding: 20rpx 30rpx;
  299. display: flex;
  300. align-items: baseline;
  301. }
  302. .benefits-title {
  303. font-size: 32rpx;
  304. font-weight: bold;
  305. color: #333;
  306. }
  307. .benefits-count {
  308. font-size: 28rpx;
  309. color: #999;
  310. margin-left: 10rpx;
  311. }
  312. .benefits-grid {
  313. display: flex;
  314. flex-wrap: wrap;
  315. padding: 0 20rpx;
  316. }
  317. .benefit-item {
  318. width: 25%;
  319. display: flex;
  320. flex-direction: column;
  321. align-items: center;
  322. margin-bottom: 30rpx;
  323. }
  324. .benefit-icon-wrapper {
  325. width: 88rpx;
  326. height: 88rpx;
  327. background-color: #F8F8F8;
  328. border-radius: 24rpx;
  329. display: flex;
  330. align-items: center;
  331. justify-content: center;
  332. margin-bottom: 12rpx;
  333. }
  334. .benefit-icon {
  335. width: 44rpx;
  336. height: 44rpx;
  337. }
  338. .benefit-name {
  339. font-size: 22rpx;
  340. color: #666;
  341. text-align: center;
  342. }
  343. .empty-benefits {
  344. width: 100%;
  345. padding: 60rpx 0;
  346. text-align: center;
  347. color: #ccc;
  348. font-size: 26rpx;
  349. }
  350. .popup-mask {
  351. position: fixed;
  352. top: 0;
  353. left: 0;
  354. right: 0;
  355. bottom: 0;
  356. background-color: rgba(0,0,0,0.5);
  357. z-index: 999;
  358. display: none;
  359. align-items: center;
  360. justify-content: center;
  361. }
  362. .popup-mask.show {
  363. display: flex;
  364. }
  365. .popup-modal {
  366. width: 520rpx;
  367. background-color: #fff;
  368. border-radius: 30rpx;
  369. padding: 50rpx 40rpx;
  370. display: flex;
  371. flex-direction: column;
  372. align-items: center;
  373. box-shadow: 0 10rpx 40rpx rgba(0,0,0,0.2);
  374. }
  375. .popup-icon-wrapper {
  376. width: 120rpx;
  377. height: 120rpx;
  378. background-color: #FFF8E1;
  379. border-radius: 50%;
  380. display: flex;
  381. align-items: center;
  382. justify-content: center;
  383. margin-bottom: 30rpx;
  384. }
  385. .benefit-icon-large {
  386. width: 60rpx;
  387. height: 60rpx;
  388. }
  389. .popup-title {
  390. font-size: 34rpx;
  391. font-weight: bold;
  392. color: #333;
  393. margin-bottom: 20rpx;
  394. }
  395. .popup-desc {
  396. font-size: 28rpx;
  397. color: #666;
  398. text-align: center;
  399. line-height: 1.6;
  400. margin-bottom: 40rpx;
  401. }
  402. .popup-btn {
  403. width: 90%;
  404. height: 80rpx;
  405. line-height: 80rpx;
  406. background: linear-gradient(90deg, #333 0%, #111 100%);
  407. color: #fff;
  408. font-size: 28rpx;
  409. border-radius: 40rpx;
  410. }
  411. </style>