index.vue 10 KB

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