index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. uni.showToast({ title: err.message || err.msg || '请求失败', icon: 'none' });
  178. }
  179. },
  180. async fetchList(params) {
  181. try {
  182. const res = await listOnAppReward(params);
  183. if (res.code === 200) {
  184. const list = res.data || [];
  185. this.records = list.map(item => {
  186. const isAdd = item.type === 'add';
  187. const amountVal = Math.abs(item.amount) / 100;
  188. // 格式化日期 MM-DD
  189. let dateStr = '';
  190. if (item.createTime) {
  191. const datePart = item.createTime.split(' ')[0];
  192. const parts = datePart.split('-');
  193. if (parts.length >= 3) {
  194. dateStr = `${parts[1]}-${parts[2]}`;
  195. }
  196. }
  197. return {
  198. ...item,
  199. date: dateStr,
  200. title: bizTypeMap[item.bizType] || item.bizType || '其他',
  201. desc: item.reason || '',
  202. amount: isAdd ? amountVal : -amountVal,
  203. type: isAdd ? 'reward' : 'penalty',
  204. status: isAdd ? '已入账' : '已扣款', // 简化处理状态
  205. statusClass: isAdd ? 'credited' : 'deducted'
  206. };
  207. });
  208. }
  209. } catch (err) {
  210. console.error('获取奖惩列表失败:', err);
  211. uni.showToast({ title: err.message || err.msg || '请求失败', icon: 'none' });
  212. }
  213. },
  214. switchTab(idx) { this.activeTab = idx; },
  215. openMonthPicker() {
  216. this.pickerYear = this.selectedYear;
  217. this.pickerMonth = this.selectedMonth;
  218. this.showMonthPicker = true;
  219. },
  220. closeMonthPicker() { this.showMonthPicker = false; },
  221. confirmMonthPicker() {
  222. this.selectedYear = this.pickerYear;
  223. this.selectedMonth = this.pickerMonth;
  224. this.closeMonthPicker();
  225. this.fetchData();
  226. },
  227. goToAll() {
  228. uni.navigateTo({ url: '/pages/mine/rewards-all/index' });
  229. }
  230. }
  231. };
  232. </script>
  233. <style>
  234. page {
  235. background-color: #F7F8FA;
  236. }
  237. .container {
  238. min-height: 100vh;
  239. background-color: #F7F8FA;
  240. }
  241. /* 顶部橙色banner */
  242. .top-banner {
  243. background: linear-gradient(135deg, #FF9800 0%, #FF5722 100%);
  244. padding: 20rpx 30rpx 36rpx;
  245. border-radius: 20rpx;
  246. margin: 20rpx 30rpx 0;
  247. box-shadow: 0 6rpx 20rpx rgba(255, 87, 34, 0.25);
  248. }
  249. .month-btn {
  250. display: flex;
  251. align-items: center;
  252. justify-content: flex-end;
  253. margin-bottom: 20rpx;
  254. }
  255. /* 年月文字和箭头在同一个圆角背景框内 */
  256. .month-text {
  257. font-size: 24rpx;
  258. color: rgba(255, 255, 255, 0.95);
  259. background-color: rgba(255, 255, 255, 0.2);
  260. padding: 6rpx 14rpx;
  261. border-radius: 14rpx;
  262. }
  263. .stats-grid {
  264. display: flex;
  265. flex-wrap: wrap;
  266. gap: 16rpx;
  267. }
  268. .stats-cell {
  269. width: calc(50% - 8rpx);
  270. background-color: rgba(255, 255, 255, 0.15);
  271. border-radius: 12rpx;
  272. padding: 20rpx 24rpx;
  273. display: flex;
  274. flex-direction: column;
  275. box-sizing: border-box;
  276. }
  277. .stats-num {
  278. font-size: 38rpx;
  279. font-weight: bold;
  280. color: #fff;
  281. margin-bottom: 8rpx;
  282. }
  283. .stats-unit {
  284. font-size: 20rpx;
  285. font-weight: normal;
  286. }
  287. .stats-num.reward-num {
  288. color: #fff;
  289. }
  290. .stats-num.penalty-num {
  291. color: #FFF176;
  292. }
  293. .stats-label {
  294. font-size: 22rpx;
  295. color: rgba(255, 255, 255, 0.85);
  296. margin-bottom: 8rpx;
  297. }
  298. /* 统计数字下方的分割线 */
  299. .stats-divider {
  300. height: 1rpx;
  301. background-color: rgba(255, 255, 255, 0.3);
  302. margin-bottom: 10rpx;
  303. }
  304. .stats-sub {
  305. font-size: 20rpx;
  306. color: rgba(255, 255, 255, 0.65);
  307. }
  308. /* 列表头:tab栏无底部外框线 */
  309. .list-header {
  310. display: flex;
  311. align-items: center;
  312. background-color: #fff;
  313. padding: 0 16rpx 0 30rpx;
  314. margin: 16rpx 30rpx 0;
  315. border-radius: 16rpx 16rpx 0 0;
  316. }
  317. .tab-bar {
  318. display: flex;
  319. flex: 1;
  320. }
  321. .tab-item {
  322. padding: 18rpx 16rpx 0;
  323. font-size: 28rpx;
  324. color: #999;
  325. display: flex;
  326. flex-direction: column;
  327. align-items: center;
  328. position: relative;
  329. }
  330. .tab-item:first-child {
  331. padding-left: 0;
  332. }
  333. .tab-item.active {
  334. color: #FF9800;
  335. font-weight: bold;
  336. }
  337. /* 下划线用正常流,自然居中对齐文字 */
  338. .tab-line {
  339. width: 32rpx;
  340. height: 3rpx;
  341. background-color: #FF9800;
  342. border-radius: 2rpx;
  343. margin-top: 8rpx;
  344. align-self: center;
  345. }
  346. .view-all-btn {
  347. padding: 8rpx 0;
  348. margin-left: auto;
  349. }
  350. .view-all-text {
  351. font-size: 24rpx;
  352. color: #999;
  353. }
  354. /* 记录列表 */
  355. .record-list {
  356. background-color: #fff;
  357. padding: 0 30rpx;
  358. margin: 0 30rpx;
  359. border-radius: 0 0 16rpx 16rpx;
  360. }
  361. .record-item {
  362. display: flex;
  363. align-items: center;
  364. padding: 24rpx 0;
  365. border-bottom: 1rpx solid #f5f5f5;
  366. }
  367. .ri-icon {
  368. width: 72rpx;
  369. height: 72rpx;
  370. border-radius: 50%;
  371. background-color: #FFF3E0;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. margin-right: 20rpx;
  376. flex-shrink: 0;
  377. }
  378. .ri-icon.ri-penalty {
  379. background-color: #FAFAFA;
  380. }
  381. .ri-icon-text {
  382. font-size: 30rpx;
  383. color: #FF9800;
  384. font-weight: bold;
  385. }
  386. .ri-icon.ri-penalty .ri-icon-text {
  387. color: #ccc;
  388. }
  389. .ri-content {
  390. flex: 1;
  391. }
  392. .ri-title-row {
  393. display: flex;
  394. align-items: center;
  395. margin-bottom: 6rpx;
  396. }
  397. .ri-date {
  398. font-size: 26rpx;
  399. color: #333;
  400. font-weight: bold;
  401. margin-right: 10rpx;
  402. }
  403. .ri-title {
  404. font-size: 26rpx;
  405. color: #333;
  406. }
  407. .ri-desc {
  408. font-size: 24rpx;
  409. color: #999;
  410. }
  411. .ri-right {
  412. display: flex;
  413. flex-direction: column;
  414. align-items: flex-end;
  415. margin-left: 16rpx;
  416. }
  417. .ri-amount {
  418. font-size: 32rpx;
  419. font-weight: bold;
  420. margin-bottom: 4rpx;
  421. }
  422. .ri-amount.positive {
  423. color: #FF5722;
  424. }
  425. .ri-amount.negative {
  426. color: #333;
  427. }
  428. .ri-status {
  429. font-size: 22rpx;
  430. }
  431. .ri-status.pending {
  432. color: #FF9800;
  433. }
  434. .ri-status.credited {
  435. color: #999;
  436. }
  437. .ri-status.deducted {
  438. color: #999;
  439. }
  440. .more-hint {
  441. display: block;
  442. text-align: center;
  443. font-size: 24rpx;
  444. color: #ccc;
  445. padding: 30rpx 0;
  446. }
  447. /* 月份选择器 */
  448. .picker-mask {
  449. position: fixed;
  450. top: 0;
  451. left: 0;
  452. width: 100%;
  453. height: 100%;
  454. background-color: rgba(0, 0, 0, 0.5);
  455. z-index: 999;
  456. display: flex;
  457. align-items: flex-end;
  458. }
  459. .picker-sheet {
  460. width: 100%;
  461. background-color: #fff;
  462. border-radius: 24rpx 24rpx 0 0;
  463. }
  464. .picker-header {
  465. display: flex;
  466. align-items: center;
  467. justify-content: space-between;
  468. padding: 24rpx 30rpx;
  469. border-bottom: 1rpx solid #f5f5f5;
  470. }
  471. .picker-cancel {
  472. font-size: 28rpx;
  473. color: #999;
  474. }
  475. .picker-title {
  476. font-size: 30rpx;
  477. font-weight: bold;
  478. color: #333;
  479. }
  480. .picker-confirm {
  481. font-size: 28rpx;
  482. color: #FF9800;
  483. font-weight: bold;
  484. }
  485. .picker-body {
  486. display: flex;
  487. height: 400rpx;
  488. position: relative;
  489. overflow: hidden;
  490. }
  491. .picker-column {
  492. flex: 1;
  493. height: 400rpx;
  494. }
  495. .picker-col-item {
  496. height: 80rpx;
  497. line-height: 80rpx;
  498. text-align: center;
  499. font-size: 28rpx;
  500. color: #333;
  501. }
  502. .picker-col-item.picker-selected {
  503. color: #FF9800;
  504. font-weight: bold;
  505. background-color: #FFF3E0;
  506. border-radius: 8rpx;
  507. }
  508. .picker-highlight {
  509. position: absolute;
  510. top: 50%;
  511. left: 0;
  512. transform: translateY(-50%);
  513. width: 100%;
  514. height: 80rpx;
  515. border-top: 1rpx solid #f0f0f0;
  516. border-bottom: 1rpx solid #f0f0f0;
  517. pointer-events: none;
  518. }
  519. </style>