index.vue 11 KB

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