index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <template>
  2. <view class="container">
  3. <!-- 顶部橙色统计卡 -->
  4. <view class="top-banner">
  5. <!-- 月份切换:箭头在背景框内紧跟文字 -->
  6. <view class="month-btn" @click="openMonthPicker">
  7. <text class="month-text">{{ selectedYear }}年{{ selectedMonth }}月 ▾</text>
  8. </view>
  9. <view class="stats-grid">
  10. <view class="stats-cell">
  11. <text class="stats-label">奖励订单</text>
  12. <text class="stats-num">{{ stats.rewardCount }}<text class="stats-unit">单</text></text>
  13. <view class="stats-divider"></view>
  14. <text class="stats-sub">月度统计</text>
  15. </view>
  16. <view class="stats-cell">
  17. <text class="stats-label">惩罚订单</text>
  18. <text class="stats-num">{{ stats.punishCount }}<text class="stats-unit">单</text></text>
  19. <view class="stats-divider"></view>
  20. <text class="stats-sub">月度统计</text>
  21. </view>
  22. <view class="stats-cell">
  23. <text class="stats-label">奖励金额</text>
  24. <text class="stats-num reward-num">{{ (stats.rewardBalance / 100).toFixed(2) }}</text>
  25. <view class="stats-divider"></view>
  26. <text class="stats-sub">月度统计</text>
  27. </view>
  28. <view class="stats-cell">
  29. <text class="stats-label">惩罚金额</text>
  30. <text class="stats-num penalty-num">{{ (stats.punishBalance / 100).toFixed(2) }}</text>
  31. <view class="stats-divider"></view>
  32. <text class="stats-sub">月度统计</text>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- 标签 + 查看全部 -->
  37. <view class="list-header">
  38. <view class="tab-bar">
  39. <view class="tab-item" v-for="(tab, idx) in tabs" :key="idx" :class="{ active: activeTab === idx }"
  40. @click="switchTab(idx)">
  41. <text>{{ tab }}</text>
  42. <view class="tab-line" v-if="activeTab === idx"></view>
  43. </view>
  44. </view>
  45. <view class="view-all-btn" @click="goToAll">
  46. <text class="view-all-text">查看全部 ›</text>
  47. </view>
  48. </view>
  49. <!-- 列表 -->
  50. <view class="record-list">
  51. <view class="record-item" v-for="(item, idx) in filteredList" :key="idx">
  52. <!-- 左侧图标 -->
  53. <view class="ri-icon" :class="item.amount > 0 ? 'ri-reward' : 'ri-penalty'">
  54. <text class="ri-icon-text">¥</text>
  55. </view>
  56. <!-- 内容 -->
  57. <view class="ri-content">
  58. <view class="ri-title-row">
  59. <text class="ri-date">{{ item.date }}</text>
  60. <text class="ri-title">{{ item.title }}</text>
  61. </view>
  62. <text class="ri-desc">{{ item.desc }}</text>
  63. </view>
  64. <!-- 右侧金额 + 状态 -->
  65. <view class="ri-right">
  66. <text class="ri-amount" :class="item.amount > 0 ? 'positive' : 'negative'">
  67. {{ item.amount > 0 ? '+' : '' }}{{ item.amount.toFixed(2) }}
  68. </text>
  69. <text class="ri-status" :class="item.statusClass">{{ item.status }}</text>
  70. </view>
  71. </view>
  72. <!-- 底部提示 -->
  73. <text class="more-hint">更多记录请点击上方的查看全部</text>
  74. </view>
  75. <!-- 月份选择器 -->
  76. <view class="picker-mask" v-if="showMonthPicker" @click="closeMonthPicker">
  77. <view class="picker-sheet" @click.stop>
  78. <!-- 顶部操作 -->
  79. <view class="picker-header">
  80. <text class="picker-cancel" @click="closeMonthPicker">取消</text>
  81. <text class="picker-title">选择时间</text>
  82. <text class="picker-confirm" @click="confirmMonthPicker">确定</text>
  83. </view>
  84. <!-- 年月两列 -->
  85. <view class="picker-body">
  86. <!-- 年 -->
  87. <scroll-view scroll-y class="picker-column" :scroll-top="yearScrollTop" @scroll="onYearScroll">
  88. <view style="height: 80rpx;"></view>
  89. <view class="picker-col-item" v-for="year in years" :key="year"
  90. :class="{ 'picker-selected': pickerYear === year }" @click="pickerYear = year">{{ year }}年
  91. </view>
  92. <view style="height: 80rpx;"></view>
  93. </scroll-view>
  94. <!-- 选中高亮条 -->
  95. <view class="picker-highlight"></view>
  96. <!-- 月 -->
  97. <scroll-view scroll-y class="picker-column" :scroll-top="monthScrollTop" @scroll="onMonthScroll">
  98. <view style="height: 80rpx;"></view>
  99. <view class="picker-col-item" v-for="month in months" :key="month"
  100. :class="{ 'picker-selected': pickerMonth === month }" @click="pickerMonth = month">{{ month
  101. }}月</view>
  102. <view style="height: 80rpx;"></view>
  103. </scroll-view>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. </template>
  109. <script>
  110. import { countOnAppReward, listOnAppReward } from '@/api/fulfiller/log';
  111. import fulfillerEnum from '@/enums/fulfiller.json';
  112. const bizTypeMap = fulfillerEnum.FlfRewardBizType;
  113. export default {
  114. data() {
  115. const now = new Date();
  116. return {
  117. tabs: ['全部', '奖励', '惩罚'],
  118. activeTab: 0,
  119. selectedYear: now.getFullYear(),
  120. selectedMonth: now.getFullYear() === 2026 && now.getMonth() < 2 ? 3 : now.getMonth() + 1, // 默认当前月,处理一下测试数据时间
  121. // 统计数据
  122. stats: {
  123. rewardCount: 0,
  124. punishCount: 0,
  125. rewardBalance: 0,
  126. punishBalance: 0
  127. },
  128. // 月份选择器状态
  129. showMonthPicker: false,
  130. pickerYear: 2026,
  131. pickerMonth: 3,
  132. years: [2024, 2025, 2026],
  133. months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
  134. yearScrollTop: 0,
  135. monthScrollTop: 0,
  136. // 奖惩记录列表
  137. records: []
  138. };
  139. },
  140. computed: {
  141. filteredList() {
  142. if (this.activeTab === 0) return this.records;
  143. const targetType = this.activeTab === 1 ? 'reward' : 'penalty';
  144. return this.records.filter(r => r.type === targetType);
  145. }
  146. },
  147. onShow() {
  148. // 设置默认选中的年月
  149. const now = new Date();
  150. if (this.selectedYear === 2026 && this.selectedMonth === 2) {
  151. // 保持默认或根据实际需求
  152. }
  153. this.fetchData();
  154. },
  155. methods: {
  156. async fetchData() {
  157. const params = {
  158. year: this.selectedYear,
  159. month: this.selectedMonth
  160. };
  161. this.fetchStats(params);
  162. this.fetchList(params);
  163. },
  164. async fetchStats(params) {
  165. try {
  166. const res = await countOnAppReward(params);
  167. if (res.code === 200) {
  168. this.stats = res.data || {
  169. rewardCount: 0,
  170. punishCount: 0,
  171. rewardBalance: 0,
  172. punishBalance: 0
  173. };
  174. }
  175. } catch (err) {
  176. console.error('获取奖惩统计失败:', err);
  177. }
  178. },
  179. async fetchList(params) {
  180. try {
  181. const res = await listOnAppReward(params);
  182. if (res.code === 200) {
  183. const list = res.data || [];
  184. this.records = list.map(item => {
  185. const isAdd = item.type === 'add';
  186. const amountVal = Math.abs(item.amount) / 100;
  187. // 格式化日期 MM-DD
  188. let dateStr = '';
  189. if (item.createTime) {
  190. const datePart = item.createTime.split(' ')[0];
  191. const parts = datePart.split('-');
  192. if (parts.length >= 3) {
  193. dateStr = `${parts[1]}-${parts[2]}`;
  194. }
  195. }
  196. return {
  197. ...item,
  198. date: dateStr,
  199. title: bizTypeMap[item.bizType] || item.bizType || '其他',
  200. desc: item.reason || '',
  201. amount: isAdd ? amountVal : -amountVal,
  202. type: isAdd ? 'reward' : 'penalty',
  203. status: isAdd ? '已入账' : '已扣款', // 简化处理状态
  204. statusClass: isAdd ? 'credited' : 'deducted'
  205. };
  206. });
  207. }
  208. } catch (err) {
  209. console.error('获取奖惩列表失败:', err);
  210. }
  211. },
  212. switchTab(idx) { this.activeTab = idx; },
  213. openMonthPicker() {
  214. this.pickerYear = this.selectedYear;
  215. this.pickerMonth = this.selectedMonth;
  216. this.showMonthPicker = true;
  217. },
  218. closeMonthPicker() { this.showMonthPicker = false; },
  219. confirmMonthPicker() {
  220. this.selectedYear = this.pickerYear;
  221. this.selectedMonth = this.pickerMonth;
  222. this.closeMonthPicker();
  223. this.fetchData();
  224. },
  225. goToAll() {
  226. uni.navigateTo({ url: '/pages/mine/rewards-all/index' });
  227. }
  228. }
  229. };
  230. </script>
  231. <style>
  232. page {
  233. background-color: #F7F8FA;
  234. }
  235. .container {
  236. min-height: 100vh;
  237. background-color: #F7F8FA;
  238. }
  239. /* 顶部橙色banner */
  240. .top-banner {
  241. background: linear-gradient(135deg, #FF9800 0%, #FF5722 100%);
  242. padding: 20rpx 30rpx 36rpx;
  243. border-radius: 20rpx;
  244. margin: 20rpx 30rpx 0;
  245. box-shadow: 0 6rpx 20rpx rgba(255, 87, 34, 0.25);
  246. }
  247. .month-btn {
  248. display: flex;
  249. align-items: center;
  250. justify-content: flex-end;
  251. margin-bottom: 20rpx;
  252. }
  253. /* 年月文字和箭头在同一个圆角背景框内 */
  254. .month-text {
  255. font-size: 24rpx;
  256. color: rgba(255, 255, 255, 0.95);
  257. background-color: rgba(255, 255, 255, 0.2);
  258. padding: 6rpx 14rpx;
  259. border-radius: 14rpx;
  260. }
  261. .stats-grid {
  262. display: flex;
  263. flex-wrap: wrap;
  264. gap: 16rpx;
  265. }
  266. .stats-cell {
  267. width: calc(50% - 8rpx);
  268. background-color: rgba(255, 255, 255, 0.15);
  269. border-radius: 12rpx;
  270. padding: 20rpx 24rpx;
  271. display: flex;
  272. flex-direction: column;
  273. box-sizing: border-box;
  274. }
  275. .stats-num {
  276. font-size: 38rpx;
  277. font-weight: bold;
  278. color: #fff;
  279. margin-bottom: 8rpx;
  280. }
  281. .stats-unit {
  282. font-size: 20rpx;
  283. font-weight: normal;
  284. }
  285. .stats-num.reward-num {
  286. color: #fff;
  287. }
  288. .stats-num.penalty-num {
  289. color: #FFF176;
  290. }
  291. .stats-label {
  292. font-size: 22rpx;
  293. color: rgba(255, 255, 255, 0.85);
  294. margin-bottom: 8rpx;
  295. }
  296. /* 统计数字下方的分割线 */
  297. .stats-divider {
  298. height: 1rpx;
  299. background-color: rgba(255, 255, 255, 0.3);
  300. margin-bottom: 10rpx;
  301. }
  302. .stats-sub {
  303. font-size: 20rpx;
  304. color: rgba(255, 255, 255, 0.65);
  305. }
  306. /* 列表头:tab栏无底部外框线 */
  307. .list-header {
  308. display: flex;
  309. align-items: center;
  310. background-color: #fff;
  311. padding: 0 16rpx 0 30rpx;
  312. margin: 16rpx 30rpx 0;
  313. border-radius: 16rpx 16rpx 0 0;
  314. }
  315. .tab-bar {
  316. display: flex;
  317. flex: 1;
  318. }
  319. .tab-item {
  320. padding: 18rpx 16rpx 0;
  321. font-size: 28rpx;
  322. color: #999;
  323. display: flex;
  324. flex-direction: column;
  325. align-items: center;
  326. position: relative;
  327. }
  328. .tab-item:first-child {
  329. padding-left: 0;
  330. }
  331. .tab-item.active {
  332. color: #FF9800;
  333. font-weight: bold;
  334. }
  335. /* 下划线用正常流,自然居中对齐文字 */
  336. .tab-line {
  337. width: 32rpx;
  338. height: 3rpx;
  339. background-color: #FF9800;
  340. border-radius: 2rpx;
  341. margin-top: 8rpx;
  342. align-self: center;
  343. }
  344. .view-all-btn {
  345. padding: 8rpx 0;
  346. margin-left: auto;
  347. }
  348. .view-all-text {
  349. font-size: 24rpx;
  350. color: #999;
  351. }
  352. /* 记录列表 */
  353. .record-list {
  354. background-color: #fff;
  355. padding: 0 30rpx;
  356. margin: 0 30rpx;
  357. border-radius: 0 0 16rpx 16rpx;
  358. }
  359. .record-item {
  360. display: flex;
  361. align-items: center;
  362. padding: 24rpx 0;
  363. border-bottom: 1rpx solid #f5f5f5;
  364. }
  365. .ri-icon {
  366. width: 72rpx;
  367. height: 72rpx;
  368. border-radius: 50%;
  369. background-color: #FFF3E0;
  370. display: flex;
  371. align-items: center;
  372. justify-content: center;
  373. margin-right: 20rpx;
  374. flex-shrink: 0;
  375. }
  376. .ri-icon.ri-penalty {
  377. background-color: #FAFAFA;
  378. }
  379. .ri-icon-text {
  380. font-size: 30rpx;
  381. color: #FF9800;
  382. font-weight: bold;
  383. }
  384. .ri-icon.ri-penalty .ri-icon-text {
  385. color: #ccc;
  386. }
  387. .ri-content {
  388. flex: 1;
  389. }
  390. .ri-title-row {
  391. display: flex;
  392. align-items: center;
  393. margin-bottom: 6rpx;
  394. }
  395. .ri-date {
  396. font-size: 26rpx;
  397. color: #333;
  398. font-weight: bold;
  399. margin-right: 10rpx;
  400. }
  401. .ri-title {
  402. font-size: 26rpx;
  403. color: #333;
  404. }
  405. .ri-desc {
  406. font-size: 24rpx;
  407. color: #999;
  408. }
  409. .ri-right {
  410. display: flex;
  411. flex-direction: column;
  412. align-items: flex-end;
  413. margin-left: 16rpx;
  414. }
  415. .ri-amount {
  416. font-size: 32rpx;
  417. font-weight: bold;
  418. margin-bottom: 4rpx;
  419. }
  420. .ri-amount.positive {
  421. color: #FF5722;
  422. }
  423. .ri-amount.negative {
  424. color: #333;
  425. }
  426. .ri-status {
  427. font-size: 22rpx;
  428. }
  429. .ri-status.pending {
  430. color: #FF9800;
  431. }
  432. .ri-status.credited {
  433. color: #999;
  434. }
  435. .ri-status.deducted {
  436. color: #999;
  437. }
  438. .more-hint {
  439. display: block;
  440. text-align: center;
  441. font-size: 24rpx;
  442. color: #ccc;
  443. padding: 30rpx 0;
  444. }
  445. /* 月份选择器 */
  446. .picker-mask {
  447. position: fixed;
  448. top: 0;
  449. left: 0;
  450. width: 100%;
  451. height: 100%;
  452. background-color: rgba(0, 0, 0, 0.5);
  453. z-index: 999;
  454. display: flex;
  455. align-items: flex-end;
  456. }
  457. .picker-sheet {
  458. width: 100%;
  459. background-color: #fff;
  460. border-radius: 24rpx 24rpx 0 0;
  461. }
  462. .picker-header {
  463. display: flex;
  464. align-items: center;
  465. justify-content: space-between;
  466. padding: 24rpx 30rpx;
  467. border-bottom: 1rpx solid #f5f5f5;
  468. }
  469. .picker-cancel {
  470. font-size: 28rpx;
  471. color: #999;
  472. }
  473. .picker-title {
  474. font-size: 30rpx;
  475. font-weight: bold;
  476. color: #333;
  477. }
  478. .picker-confirm {
  479. font-size: 28rpx;
  480. color: #FF9800;
  481. font-weight: bold;
  482. }
  483. .picker-body {
  484. display: flex;
  485. height: 400rpx;
  486. position: relative;
  487. overflow: hidden;
  488. }
  489. .picker-column {
  490. flex: 1;
  491. height: 400rpx;
  492. }
  493. .picker-col-item {
  494. height: 80rpx;
  495. line-height: 80rpx;
  496. text-align: center;
  497. font-size: 28rpx;
  498. color: #333;
  499. }
  500. .picker-col-item.picker-selected {
  501. color: #FF9800;
  502. font-weight: bold;
  503. background-color: #FFF3E0;
  504. border-radius: 8rpx;
  505. }
  506. .picker-highlight {
  507. position: absolute;
  508. top: 50%;
  509. left: 0;
  510. transform: translateY(-50%);
  511. width: 100%;
  512. height: 80rpx;
  513. border-top: 1rpx solid #f0f0f0;
  514. border-bottom: 1rpx solid #f0f0f0;
  515. pointer-events: none;
  516. }
  517. </style>