index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. uni.showToast({ title: error.message || error.msg || '请求失败', icon: 'none' });
  159. }
  160. },
  161. onDateChange(e) {
  162. const val = e.detail.value;
  163. const [y, m] = val.split('-');
  164. this.year = parseInt(y, 10);
  165. this.month = parseInt(m, 10);
  166. this.fetchData();
  167. },
  168. navBack() {
  169. uni.navigateBack();
  170. },
  171. switchTab(index) {
  172. this.currentTab = index;
  173. }
  174. }
  175. }
  176. </script>
  177. <style>
  178. /* 基础容器 */
  179. .container {
  180. background-color: #F5F7FA;
  181. min-height: 100vh;
  182. display: flex;
  183. flex-direction: column;
  184. }
  185. /* 导航栏 */
  186. .nav-bar {
  187. background-color: #fff;
  188. padding-top: var(--status-bar-height);
  189. padding-left: 30rpx;
  190. padding-right: 30rpx;
  191. height: 88rpx;
  192. box-sizing: content-box;
  193. display: flex;
  194. justify-content: space-between;
  195. align-items: center;
  196. position: sticky;
  197. top: 0;
  198. z-index: 100;
  199. }
  200. .nav-left {
  201. height: 100%;
  202. display: flex;
  203. align-items: center;
  204. width: 60rpx;
  205. }
  206. .back-icon {
  207. width: 40rpx;
  208. height: 40rpx;
  209. transform: rotate(180deg);
  210. }
  211. .nav-title {
  212. font-size: 28rpx; /* 14pt (Strict) */
  213. font-weight: bold;
  214. color: #333;
  215. }
  216. .nav-right {
  217. width: 60rpx;
  218. }
  219. /* 内容区域 */
  220. .content-area {
  221. flex: 1;
  222. display: flex;
  223. flex-direction: column;
  224. }
  225. /* 筛选区域 */
  226. .filter-area {
  227. background-color: #fff;
  228. display: flex;
  229. justify-content: space-between;
  230. align-items: center;
  231. padding: 0 30rpx;
  232. margin-bottom: 20rpx;
  233. }
  234. /* Tabs */
  235. .tabs-row {
  236. display: flex;
  237. padding-top: 20rpx;
  238. padding-bottom: 2rpx;
  239. gap: 40rpx;
  240. }
  241. .tab-item {
  242. padding-bottom: 16rpx;
  243. font-size: 28rpx;
  244. color: #666;
  245. position: relative;
  246. display: flex;
  247. flex-direction: column;
  248. align-items: center;
  249. min-width: 100rpx;
  250. }
  251. .tab-item.active {
  252. font-weight: bold;
  253. color: #FF9800;
  254. }
  255. .tab-line {
  256. width: 40rpx;
  257. height: 4rpx;
  258. background-color: #FF9800;
  259. border-radius: 4rpx;
  260. position: absolute;
  261. bottom: 0;
  262. }
  263. /* 日期选择器 */
  264. .date-picker-wrap {
  265. display: flex;
  266. align-items: center;
  267. }
  268. .date-picker {
  269. background-color: #F5F7FA;
  270. padding: 8rpx 20rpx;
  271. border-radius: 30rpx;
  272. display: flex;
  273. align-items: center;
  274. }
  275. .date-text {
  276. font-size: 26rpx;
  277. color: #333;
  278. margin-right: 8rpx;
  279. }
  280. .arrow-down {
  281. font-size: 24rpx;
  282. color: #999;
  283. }
  284. /* 列表容器 */
  285. .bill-list {
  286. flex: 1;
  287. padding: 0 20rpx;
  288. box-sizing: border-box;
  289. }
  290. /* 月份卡片 */
  291. .month-group {
  292. background-color: #fff;
  293. border-radius: 16rpx;
  294. padding: 0 20rpx;
  295. margin-bottom: 20rpx;
  296. box-shadow: 0 2rpx 6rpx rgba(0,0,0,0.02);
  297. }
  298. .group-header {
  299. display: flex;
  300. justify-content: space-between;
  301. align-items: center;
  302. padding: 24rpx 10rpx;
  303. border-bottom: 1rpx solid #f9f9f9;
  304. }
  305. .month-title {
  306. font-size: 30rpx;
  307. font-weight: bold;
  308. color: #333;
  309. }
  310. .month-summary {
  311. font-size: 24rpx;
  312. color: #999;
  313. }
  314. /* 列表项 */
  315. .list-item {
  316. display: flex;
  317. align-items: center;
  318. padding: 30rpx 10rpx;
  319. border-bottom: 1rpx solid #f9f9f9;
  320. }
  321. .list-item:last-child {
  322. border-bottom: none;
  323. }
  324. /* 左侧图标 */
  325. .item-icon-box {
  326. width: 80rpx;
  327. height: 80rpx;
  328. border-radius: 50%;
  329. display: flex;
  330. justify-content: center;
  331. align-items: center;
  332. margin-right: 20rpx;
  333. flex-shrink: 0;
  334. }
  335. .item-icon-box.income {
  336. background-color: #FFF8E1; /* Light Yellow for Points */
  337. }
  338. .item-icon-box.expense {
  339. background-color: #F5F5F5; /* Light Grey for Points */
  340. }
  341. .item-icon-symbol {
  342. font-size: 40rpx;
  343. font-weight: 300;
  344. line-height: 1;
  345. margin-top: -4rpx;
  346. }
  347. .item-icon-box.income .item-icon-symbol {
  348. color: #FF9800; /* Orange */
  349. }
  350. .item-icon-box.expense .item-icon-symbol {
  351. color: #333; /* Black */
  352. }
  353. /* 中间内容 */
  354. .item-center {
  355. flex: 1;
  356. display: flex;
  357. flex-direction: column;
  358. justify-content: space-around;
  359. height: 80rpx;
  360. }
  361. .item-title {
  362. font-size: 28rpx;
  363. font-weight: 500;
  364. color: #333;
  365. }
  366. .item-desc {
  367. font-size: 22rpx;
  368. color: #999;
  369. margin-top: 8rpx;
  370. }
  371. /* 右侧数据 */
  372. .item-right {
  373. display: flex;
  374. flex-direction: column;
  375. align-items: flex-end;
  376. justify-content: space-around;
  377. height: 80rpx;
  378. margin-left: 10rpx;
  379. }
  380. .item-amount {
  381. font-size: 30rpx;
  382. font-weight: bold;
  383. }
  384. .item-amount.income {
  385. color: #FF9800;
  386. }
  387. .item-amount.expense {
  388. color: #333;
  389. }
  390. .item-tag {
  391. display: inline-flex;
  392. justify-content: flex-end;
  393. margin-top: 6rpx;
  394. }
  395. .item-tag text {
  396. background-color: #FFFFFF;
  397. border: 1rpx solid #eee;
  398. padding: 2rpx 8rpx;
  399. border-radius: 6rpx;
  400. font-size: 20rpx;
  401. color: #999;
  402. }
  403. .list-padding-bottom {
  404. height: 40rpx;
  405. }
  406. </style>