index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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="content-area">
  13. <!-- 筛选行: Tabs + 日期选择器 -->
  14. <view class="filter-area">
  15. <!-- Tabs -->
  16. <view class="tabs-row">
  17. <view class="tab-item" :class="{ active: currentTab === 0 }" @click="switchTab(0)">
  18. <text>全部</text>
  19. <view class="tab-line" v-if="currentTab === 0"></view>
  20. </view>
  21. <view class="tab-item" :class="{ active: currentTab === 1 }" @click="switchTab(1)">
  22. <text>获取</text>
  23. <view class="tab-line" v-if="currentTab === 1"></view>
  24. </view>
  25. <view class="tab-item" :class="{ active: currentTab === 2 }" @click="switchTab(2)">
  26. <text>扣减</text>
  27. <view class="tab-line" v-if="currentTab === 2"></view>
  28. </view>
  29. </view>
  30. <!-- 日期选择器 -->
  31. <view class="date-picker-wrap">
  32. <picker mode="date" fields="month" :value="currentDate" @change="onDateChange">
  33. <view class="date-picker">
  34. <text class="date-text">{{ year }}年{{ `${month}`.padStart(2, '0') }}月</text>
  35. <text class="arrow-down">﹀</text>
  36. </view>
  37. </picker>
  38. </view>
  39. </view>
  40. <!-- 列表 -->
  41. <scroll-view scroll-y class="bill-list">
  42. <view v-for="(group, gIndex) in displayGroups" :key="gIndex" class="month-group">
  43. <!-- 月份头 -->
  44. <view class="group-header">
  45. <text class="month-title">{{ group.month }}</text>
  46. <text class="month-summary">获取 {{ group.income }} 扣减 {{ group.expense }}</text>
  47. </view>
  48. <!-- 列表项 -->
  49. <view class="list-item" v-for="(item, index) in group.items" :key="index">
  50. <!-- 图标 -->
  51. <view class="item-icon-box" :class="item.type">
  52. <text class="item-icon-symbol">{{ item.type === 'income' ? '+' : '-' }}</text>
  53. </view>
  54. <!-- 中间内容 -->
  55. <view class="item-center">
  56. <text class="item-title">{{ item.title }}</text>
  57. <text class="item-desc">{{ item.time }} {{ item.desc }}</text>
  58. </view>
  59. <!-- 右侧数据 -->
  60. <view class="item-right">
  61. <text class="item-amount" :class="{ income: item.type === 'income', expense: item.type === 'expense' }">
  62. {{ item.type === 'income' ? '+' : '' }}{{ item.amount }}
  63. </text>
  64. <view class="item-tag">
  65. <text>{{ item.tag }}</text>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="list-padding-bottom"></view>
  71. </scroll-view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import { listPointsOnApp } from '@/api/fulfiller/log';
  77. import fulfillerEnum from '@/enums/fulfiller.json';
  78. const bizTypeMap = fulfillerEnum.FlfPointsBizType;
  79. export default {
  80. data() {
  81. const d = new Date();
  82. return {
  83. currentTab: 0,
  84. year: d.getFullYear(),
  85. month: d.getMonth() + 1,
  86. groups: []
  87. }
  88. },
  89. computed: {
  90. currentDate() {
  91. return `${this.year}-${String(this.month).padStart(2, '0')}`;
  92. },
  93. displayGroups() {
  94. if (this.currentTab === 0) return this.groups;
  95. return this.groups.map(group => {
  96. const filteredItems = group.items.filter(item => {
  97. const type = this.currentTab === 1 ? 'income' : 'expense';
  98. return item.type === type;
  99. });
  100. return {
  101. ...group,
  102. items: filteredItems
  103. };
  104. }).filter(group => group.items.length > 0);
  105. }
  106. },
  107. onShow() {
  108. this.fetchData();
  109. },
  110. methods: {
  111. async fetchData() {
  112. try {
  113. const res = await listPointsOnApp({
  114. year: this.year,
  115. month: this.month
  116. });
  117. if (res.code === 200) {
  118. const list = res.data || [];
  119. let incomeTotal = 0;
  120. let expenseTotal = 0;
  121. const items = list.map(item => {
  122. const isAdd = item.type === 'add';
  123. const uiType = isAdd ? 'income' : 'expense';
  124. const title = bizTypeMap[item.bizType] || item.bizType || '其他';
  125. let amountVal = Math.abs(item.amount);
  126. if (isAdd) {
  127. incomeTotal += amountVal;
  128. } else {
  129. expenseTotal += amountVal;
  130. }
  131. let amountStr = String(amountVal);
  132. if (!isAdd) amountStr = '-' + amountStr;
  133. let timeStr = item.createTime || '';
  134. if (timeStr.length >= 16) {
  135. timeStr = timeStr.substring(5, 16);
  136. }
  137. return {
  138. ...item,
  139. title: title,
  140. desc: item.reason || '',
  141. time: timeStr,
  142. amount: amountStr,
  143. type: uiType,
  144. tag: title
  145. };
  146. });
  147. this.groups = [
  148. {
  149. month: `${this.month}月 ${this.year}`,
  150. income: String(incomeTotal),
  151. expense: String(expenseTotal),
  152. items: items
  153. }
  154. ];
  155. }
  156. } catch (error) {
  157. console.error('获取积分明细记录失败', error);
  158. }
  159. },
  160. onDateChange(e) {
  161. const val = e.detail.value;
  162. const [y, m] = val.split('-');
  163. this.year = parseInt(y, 10);
  164. this.month = parseInt(m, 10);
  165. this.fetchData();
  166. },
  167. navBack() {
  168. uni.navigateBack();
  169. },
  170. switchTab(index) {
  171. this.currentTab = index;
  172. }
  173. }
  174. }
  175. </script>
  176. <style>
  177. /* 基础容器 */
  178. .container {
  179. background-color: #F5F7FA;
  180. min-height: 100vh;
  181. display: flex;
  182. flex-direction: column;
  183. }
  184. /* 导航栏 */
  185. .nav-bar {
  186. background-color: #fff;
  187. padding-top: var(--status-bar-height);
  188. padding-left: 30rpx;
  189. padding-right: 30rpx;
  190. height: 88rpx;
  191. box-sizing: content-box;
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. position: sticky;
  196. top: 0;
  197. z-index: 100;
  198. }
  199. .nav-left {
  200. height: 100%;
  201. display: flex;
  202. align-items: center;
  203. width: 60rpx;
  204. }
  205. .back-icon {
  206. width: 40rpx;
  207. height: 40rpx;
  208. transform: rotate(180deg);
  209. }
  210. .nav-title {
  211. font-size: 28rpx; /* 14pt (Strict) */
  212. font-weight: bold;
  213. color: #333;
  214. }
  215. .nav-right {
  216. width: 60rpx;
  217. }
  218. /* 内容区域 */
  219. .content-area {
  220. flex: 1;
  221. display: flex;
  222. flex-direction: column;
  223. }
  224. /* 筛选区域 */
  225. .filter-area {
  226. background-color: #fff;
  227. display: flex;
  228. justify-content: space-between;
  229. align-items: center;
  230. padding: 0 30rpx;
  231. margin-bottom: 20rpx;
  232. }
  233. /* Tabs */
  234. .tabs-row {
  235. display: flex;
  236. padding-top: 20rpx;
  237. padding-bottom: 2rpx;
  238. gap: 40rpx;
  239. }
  240. .tab-item {
  241. padding-bottom: 16rpx;
  242. font-size: 28rpx;
  243. color: #666;
  244. position: relative;
  245. display: flex;
  246. flex-direction: column;
  247. align-items: center;
  248. min-width: 100rpx;
  249. }
  250. .tab-item.active {
  251. font-weight: bold;
  252. color: #FF9800;
  253. }
  254. .tab-line {
  255. width: 40rpx;
  256. height: 4rpx;
  257. background-color: #FF9800;
  258. border-radius: 4rpx;
  259. position: absolute;
  260. bottom: 0;
  261. }
  262. /* 日期选择器 */
  263. .date-picker-wrap {
  264. display: flex;
  265. align-items: center;
  266. }
  267. .date-picker {
  268. background-color: #F5F7FA;
  269. padding: 8rpx 20rpx;
  270. border-radius: 30rpx;
  271. display: flex;
  272. align-items: center;
  273. }
  274. .date-text {
  275. font-size: 26rpx;
  276. color: #333;
  277. margin-right: 8rpx;
  278. }
  279. .arrow-down {
  280. font-size: 24rpx;
  281. color: #999;
  282. }
  283. /* 列表容器 */
  284. .bill-list {
  285. flex: 1;
  286. padding: 0 20rpx;
  287. box-sizing: border-box;
  288. }
  289. /* 月份卡片 */
  290. .month-group {
  291. background-color: #fff;
  292. border-radius: 16rpx;
  293. padding: 0 20rpx;
  294. margin-bottom: 20rpx;
  295. box-shadow: 0 2rpx 6rpx rgba(0,0,0,0.02);
  296. }
  297. .group-header {
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. padding: 24rpx 10rpx;
  302. border-bottom: 1rpx solid #f9f9f9;
  303. }
  304. .month-title {
  305. font-size: 30rpx;
  306. font-weight: bold;
  307. color: #333;
  308. }
  309. .month-summary {
  310. font-size: 24rpx;
  311. color: #999;
  312. }
  313. /* 列表项 */
  314. .list-item {
  315. display: flex;
  316. align-items: center;
  317. padding: 30rpx 10rpx;
  318. border-bottom: 1rpx solid #f9f9f9;
  319. }
  320. .list-item:last-child {
  321. border-bottom: none;
  322. }
  323. /* 左侧图标 */
  324. .item-icon-box {
  325. width: 80rpx;
  326. height: 80rpx;
  327. border-radius: 50%;
  328. display: flex;
  329. justify-content: center;
  330. align-items: center;
  331. margin-right: 20rpx;
  332. flex-shrink: 0;
  333. }
  334. .item-icon-box.income {
  335. background-color: #FFF8E1; /* Light Yellow for Points */
  336. }
  337. .item-icon-box.expense {
  338. background-color: #F5F5F5; /* Light Grey for Points */
  339. }
  340. .item-icon-symbol {
  341. font-size: 40rpx;
  342. font-weight: 300;
  343. line-height: 1;
  344. margin-top: -4rpx;
  345. }
  346. .item-icon-box.income .item-icon-symbol {
  347. color: #FF9800; /* Orange */
  348. }
  349. .item-icon-box.expense .item-icon-symbol {
  350. color: #333; /* Black */
  351. }
  352. /* 中间内容 */
  353. .item-center {
  354. flex: 1;
  355. display: flex;
  356. flex-direction: column;
  357. justify-content: space-around;
  358. height: 80rpx;
  359. }
  360. .item-title {
  361. font-size: 28rpx;
  362. font-weight: 500;
  363. color: #333;
  364. }
  365. .item-desc {
  366. font-size: 22rpx;
  367. color: #999;
  368. margin-top: 8rpx;
  369. }
  370. /* 右侧数据 */
  371. .item-right {
  372. display: flex;
  373. flex-direction: column;
  374. align-items: flex-end;
  375. justify-content: space-around;
  376. height: 80rpx;
  377. margin-left: 10rpx;
  378. }
  379. .item-amount {
  380. font-size: 30rpx;
  381. font-weight: bold;
  382. }
  383. .item-amount.income {
  384. color: #FF9800;
  385. }
  386. .item-amount.expense {
  387. color: #333;
  388. }
  389. .item-tag {
  390. display: inline-flex;
  391. justify-content: flex-end;
  392. margin-top: 6rpx;
  393. }
  394. .item-tag text {
  395. background-color: #FFFFFF;
  396. border: 1rpx solid #eee;
  397. padding: 2rpx 8rpx;
  398. border-radius: 6rpx;
  399. font-size: 20rpx;
  400. color: #999;
  401. }
  402. .list-padding-bottom {
  403. height: 40rpx;
  404. }
  405. </style>