rewards.vue 15 KB

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