index.vue 12 KB

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