index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="container">
  3. <!-- 导航栏 -->
  4. <view class="nav-bar">
  5. <view class="nav-left" @click="navBack">
  6. <image class="back-icon" src="/static/icons/chevron_right_dark.svg"></image>
  7. </view>
  8. <text class="nav-title">我的积分</text>
  9. <view class="nav-right"></view>
  10. </view>
  11. <!-- 顶部卡片 -->
  12. <view class="points-card">
  13. <view class="card-header">
  14. <view class="equity-btn" @click="navToEquity">
  15. <image class="equity-icon" src="/static/icons/diamond_white.svg"></image>
  16. <text>积分权益</text>
  17. </view>
  18. <view class="detail-link" @click="navToDetail">
  19. <text>明细</text>
  20. </view>
  21. </view>
  22. <view class="card-body">
  23. <text class="label">当前积分</text>
  24. <text class="value">{{ points }}</text>
  25. </view>
  26. <!-- 装饰背景 -->
  27. <image class="bg-decor" src="/static/icons/star_decor.svg" mode="aspectFit"></image>
  28. </view>
  29. <!-- 最近变动 -->
  30. <view class="record-container">
  31. <view class="record-header">
  32. <text class="header-title">最近积分变动</text>
  33. <view class="header-more" @click="navToDetail">
  34. <text>查看全部</text>
  35. <image class="more-icon" src="/static/icons/chevron_right.svg"></image>
  36. </view>
  37. </view>
  38. <!-- Tabs -->
  39. <view class="tabs-row">
  40. <view class="tab-item" :class="{ active: currentTab === 0 }" @click="switchTab(0)">
  41. <text>全部</text>
  42. <view class="tab-line" v-if="currentTab === 0"></view>
  43. </view>
  44. <view class="tab-item" :class="{ active: currentTab === 1 }" @click="switchTab(1)">
  45. <text>获取</text>
  46. <view class="tab-line" v-if="currentTab === 1"></view>
  47. </view>
  48. <view class="tab-item" :class="{ active: currentTab === 2 }" @click="switchTab(2)">
  49. <text>扣减</text>
  50. <view class="tab-line" v-if="currentTab === 2"></view>
  51. </view>
  52. </view>
  53. <!-- 列表 (文本模式) -->
  54. <view class="record-list">
  55. <view class="list-item" v-for="(item, index) in displayList" :key="index">
  56. <view class="item-left">
  57. <text class="item-title">{{ item.title }}</text>
  58. <text class="item-desc">{{ item.desc }}</text>
  59. <text class="item-time">{{ item.time }}</text>
  60. </view>
  61. <view class="item-right">
  62. <text class="item-amount" :class="{ income: item.type === 'income', expense: item.type === 'expense' }">
  63. {{ item.type === 'income' ? '+' : '' }}{{ item.amount }}
  64. </text>
  65. <view class="item-tag">
  66. <text>{{ item.tag }}</text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import { pointsOnApp, pagePointsOnApp } from '@/api/fulfiller/log';
  76. import fulfillerEnum from '@/enums/fulfiller.json';
  77. const bizTypeMap = fulfillerEnum.FlfPointsBizType;
  78. export default {
  79. data() {
  80. return {
  81. points: 0,
  82. currentTab: 0,
  83. list: [],
  84. pageNum: 1,
  85. pageSize: 10,
  86. total: 0,
  87. loading: false
  88. }
  89. },
  90. computed: {
  91. displayList() {
  92. if (this.currentTab === 0) return this.list;
  93. const type = this.currentTab === 1 ? 'income' : 'expense';
  94. return this.list.filter(item => item.type === type);
  95. }
  96. },
  97. onShow() {
  98. this.fetchPoints();
  99. this.fetchList(true);
  100. },
  101. onReachBottom() {
  102. this.fetchList();
  103. },
  104. methods: {
  105. async fetchPoints() {
  106. try {
  107. const res = await pointsOnApp();
  108. if (res.code === 200) {
  109. this.points = res.data || 0;
  110. }
  111. } catch (error) {
  112. console.error('获取当前积分失败', error);
  113. }
  114. },
  115. async fetchList(reset = false) {
  116. if (reset) {
  117. this.pageNum = 1;
  118. this.list = [];
  119. this.total = 0;
  120. }
  121. if (this.loading) return;
  122. if (!reset && this.list.length >= this.total && this.total !== 0) return;
  123. this.loading = true;
  124. try {
  125. const res = await pagePointsOnApp({
  126. pageNum: this.pageNum,
  127. pageSize: this.pageSize
  128. });
  129. if (res.code === 200) {
  130. this.total = res.total || 0;
  131. const rows = res.rows || [];
  132. const mappedRows = rows.map(item => {
  133. const isAdd = item.type === 'add';
  134. const uiType = isAdd ? 'income' : 'expense';
  135. const title = bizTypeMap[item.bizType] || item.bizType || '其他';
  136. let amountStr = Math.abs(item.amount);
  137. if (!isAdd) {
  138. amountStr = '-' + amountStr;
  139. }
  140. return {
  141. ...item,
  142. title: title,
  143. desc: item.reason || '',
  144. time: item.createTime || '',
  145. amount: amountStr,
  146. type: uiType,
  147. tag: title
  148. };
  149. });
  150. this.list = this.list.concat(mappedRows);
  151. this.pageNum++;
  152. }
  153. } catch (error) {
  154. console.error('获取积分明细失败', error);
  155. } finally {
  156. this.loading = false;
  157. }
  158. },
  159. navBack() {
  160. uni.navigateBack();
  161. },
  162. navToDetail() {
  163. uni.navigateTo({
  164. url: '/pages/mine/points/detail'
  165. });
  166. },
  167. navToEquity() {
  168. // TODO: 跳转权益页
  169. },
  170. switchTab(index) {
  171. this.currentTab = index;
  172. }
  173. }
  174. }
  175. </script>
  176. <style>
  177. .container {
  178. background-color: #F8F9FA;
  179. min-height: 100vh;
  180. }
  181. .nav-bar {
  182. background-color: #fff;
  183. padding-top: var(--status-bar-height);
  184. padding-left: 30rpx;
  185. padding-right: 30rpx;
  186. height: 88rpx;
  187. box-sizing: content-box;
  188. display: flex;
  189. justify-content: space-between;
  190. align-items: center;
  191. position: sticky;
  192. top: 0;
  193. z-index: 100;
  194. }
  195. .nav-left {
  196. height: 100%;
  197. display: flex;
  198. align-items: center;
  199. width: 60rpx;
  200. }
  201. .back-icon {
  202. width: 40rpx;
  203. height: 40rpx;
  204. transform: rotate(180deg);
  205. }
  206. .nav-title {
  207. font-size: 28rpx;
  208. font-weight: bold;
  209. color: #333;
  210. }
  211. .nav-right {
  212. width: 60rpx;
  213. }
  214. /* 积分卡片 */
  215. .points-card {
  216. margin: 20rpx 30rpx;
  217. height: 300rpx;
  218. background: linear-gradient(135deg, #FFB74D 0%, #FF9800 100%);
  219. border-radius: 20rpx;
  220. position: relative;
  221. padding: 30rpx;
  222. box-sizing: border-box;
  223. overflow: hidden;
  224. color: #fff;
  225. box-shadow: 0 4rpx 16rpx rgba(255, 152, 0, 0.2);
  226. }
  227. .bg-decor {
  228. position: absolute;
  229. right: -20rpx;
  230. bottom: -20rpx;
  231. width: 180rpx;
  232. height: 180rpx;
  233. opacity: 0.3;
  234. }
  235. .card-header {
  236. display: flex;
  237. justify-content: space-between;
  238. align-items: center;
  239. }
  240. .equity-btn {
  241. display: flex;
  242. align-items: center;
  243. font-size: 26rpx;
  244. }
  245. .equity-icon {
  246. width: 32rpx; /* placeholder icon */
  247. height: 32rpx;
  248. margin-right: 8rpx;
  249. border-radius: 50%;
  250. background: rgba(255,255,255,0.3); /* circle bg for icon */
  251. }
  252. .detail-link {
  253. font-size: 24rpx;
  254. opacity: 0.9;
  255. }
  256. .card-body {
  257. margin-top: 60rpx;
  258. }
  259. .label {
  260. font-size: 26rpx;
  261. opacity: 0.9;
  262. display: block;
  263. margin-bottom: 10rpx;
  264. }
  265. .value {
  266. font-size: 64rpx;
  267. font-weight: bold;
  268. }
  269. /* 记录区域 */
  270. .record-container {
  271. background-color: #fff;
  272. border-radius: 20rpx 20rpx 0 0;
  273. padding: 30rpx;
  274. min-height: 500rpx;
  275. }
  276. .record-header {
  277. display: flex;
  278. justify-content: space-between;
  279. align-items: center;
  280. margin-bottom: 20rpx;
  281. }
  282. .header-title {
  283. font-size: 30rpx;
  284. font-weight: bold;
  285. color: #333;
  286. }
  287. .header-more {
  288. display: flex;
  289. align-items: center;
  290. }
  291. .header-more text {
  292. font-size: 24rpx;
  293. color: #999;
  294. }
  295. .more-icon {
  296. width: 24rpx;
  297. height: 24rpx;
  298. margin-left: 4rpx;
  299. }
  300. /* Tabs */
  301. .tabs-row {
  302. display: flex;
  303. border-bottom: 1rpx solid #f5f5f5;
  304. margin-bottom: 20rpx;
  305. }
  306. .tab-item {
  307. margin-right: 40rpx;
  308. padding-bottom: 12rpx;
  309. font-size: 28rpx;
  310. color: #666;
  311. position: relative;
  312. display: flex;
  313. flex-direction: column;
  314. align-items: center;
  315. }
  316. .tab-item.active {
  317. font-weight: bold;
  318. color: #333;
  319. }
  320. .tab-line {
  321. width: 28rpx;
  322. height: 4rpx;
  323. background-color: #FF9800; /* Match card color */
  324. border-radius: 4rpx;
  325. position: absolute;
  326. bottom: 0;
  327. }
  328. /* 列表 */
  329. .list-item {
  330. display: flex;
  331. justify-content: space-between;
  332. padding: 24rpx 0;
  333. border-bottom: 1rpx solid #f9f9f9;
  334. }
  335. .item-left {
  336. display: flex;
  337. flex-direction: column;
  338. }
  339. .item-title {
  340. font-size: 28rpx;
  341. color: #333;
  342. margin-bottom: 8rpx;
  343. font-weight: 500;
  344. }
  345. .item-desc {
  346. font-size: 24rpx;
  347. color: #999;
  348. margin-bottom: 6rpx;
  349. }
  350. .item-time {
  351. font-size: 22rpx;
  352. color: #ccc;
  353. }
  354. .item-right {
  355. display: flex;
  356. flex-direction: column;
  357. align-items: flex-end;
  358. }
  359. .item-amount {
  360. font-size: 30rpx;
  361. font-weight: bold;
  362. margin-bottom: 8rpx;
  363. }
  364. .item-amount.income {
  365. color: #FF9800; /* Orange for points income */
  366. }
  367. .item-amount.expense {
  368. color: #333;
  369. }
  370. .item-tag {
  371. display: inline-flex;
  372. justify-content: flex-end;
  373. }
  374. .item-tag text {
  375. background-color: #F5F5F5;
  376. padding: 4rpx 12rpx;
  377. border-radius: 6rpx;
  378. font-size: 22rpx;
  379. color: #999;
  380. }
  381. </style>