index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="container">
  3. <!-- 顶部筛选:类型标签 + 日期选择 -->
  4. <view class="filter-header">
  5. <view class="tab-bar">
  6. <view
  7. class="tab-item"
  8. v-for="(tab, idx) in tabs"
  9. :key="idx"
  10. :class="{ active: activeTab === idx }"
  11. @click="switchTab(idx)"
  12. >
  13. <text>{{ tab }}</text>
  14. <view class="tab-line" v-if="activeTab === idx"></view>
  15. </view>
  16. </view>
  17. <view class="date-filter">
  18. <picker mode="date" fields="month" :value="currentPickerDate" @change="onDateChange">
  19. <view class="picker-trigger">
  20. <text>{{ selectedYear }}年{{ String(selectedMonth).padStart(2, '0') }}月</text>
  21. <text class="arrow-icon">▼</text>
  22. </view>
  23. </picker>
  24. </view>
  25. </view>
  26. <!-- 按月分组列表 -->
  27. <scroll-view scroll-y class="main-scroll">
  28. <view v-for="(group, gIdx) in filteredGroups" :key="gIdx" class="month-group">
  29. <!-- 月份标题 -->
  30. <view class="month-header">
  31. <text class="month-title">{{ group.month }}月</text>
  32. <view class="month-summary">
  33. <text class="month-sum-text">已入账¥{{ group.credited.toFixed(2) }}</text>
  34. <text class="month-sum-text"> 待入账¥{{ group.pending.toFixed(2) }}</text>
  35. </view>
  36. </view>
  37. <!-- 记录列 -->
  38. <view class="record-item" v-for="(item, rIdx) in group.items" :key="rIdx">
  39. <view class="ri-icon" :class="item.amount > 0 ? 'ri-reward' : 'ri-penalty'">
  40. <text class="ri-icon-text">¥</text>
  41. </view>
  42. <view class="ri-content">
  43. <view class="ri-title-row">
  44. <text class="ri-date">{{ item.date }}</text>
  45. <text class="ri-title">{{ item.title }}</text>
  46. </view>
  47. <text class="ri-desc">{{ item.desc }}</text>
  48. </view>
  49. <view class="ri-right">
  50. <text class="ri-amount" :class="item.amount > 0 ? 'positive' : 'negative'">
  51. {{ item.amount > 0 ? '+' : '' }}{{ item.amount.toFixed(2) }}
  52. </text>
  53. <text class="ri-status" :class="item.statusClass">{{ item.status }}</text>
  54. </view>
  55. </view>
  56. </view>
  57. <view style="height: 40rpx;"></view>
  58. </scroll-view>
  59. </view>
  60. </template>
  61. <script>
  62. import { listOnAppReward } from '@/api/fulfiller/log';
  63. import fulfillerEnum from '@/enums/fulfiller.json';
  64. const bizTypeMap = fulfillerEnum.FlfRewardBizType;
  65. export default {
  66. data() {
  67. const now = new Date();
  68. return {
  69. tabs: ['全部', '奖励', '惩罚'],
  70. activeTab: 0,
  71. selectedYear: now.getFullYear(),
  72. selectedMonth: now.getMonth() + 1,
  73. // 原始分组数据
  74. allGroups: [],
  75. loading: false
  76. };
  77. },
  78. computed: {
  79. currentPickerDate() {
  80. return `${this.selectedYear}-${String(this.selectedMonth).padStart(2, '0')}`;
  81. },
  82. filteredGroups() {
  83. if (this.activeTab === 0) return this.allGroups;
  84. const typeKey = this.activeTab === 1 ? 'reward' : 'penalty';
  85. return this.allGroups.map(g => ({
  86. ...g,
  87. items: g.items.filter(i => i.type === typeKey)
  88. })).filter(g => g.items.length > 0);
  89. }
  90. },
  91. onShow() {
  92. this.fetchMonthData();
  93. },
  94. methods: {
  95. async fetchMonthData() {
  96. if (this.loading) return;
  97. this.loading = true;
  98. try {
  99. const params = {
  100. year: this.selectedYear,
  101. month: this.selectedMonth
  102. };
  103. const res = await listOnAppReward(params);
  104. const data = res.data || [];
  105. if (data.length === 0) {
  106. this.allGroups = [];
  107. return;
  108. }
  109. let credited = 0;
  110. const items = data.map(item => {
  111. const isAdd = item.type === 'add';
  112. const amountVal = Math.abs(item.amount) / 100;
  113. if (isAdd) credited += amountVal;
  114. let dateStr = '';
  115. if (item.createTime) {
  116. const datePart = item.createTime.split(' ')[0];
  117. const parts = datePart.split('-');
  118. if (parts.length >= 3) {
  119. dateStr = `${parts[1]}-${parts[2]}`;
  120. }
  121. }
  122. return {
  123. ...item,
  124. date: dateStr,
  125. title: bizTypeMap[item.bizType] || item.bizType || '其他',
  126. desc: item.reason || '',
  127. amount: isAdd ? amountVal : -amountVal,
  128. type: isAdd ? 'reward' : 'penalty',
  129. status: isAdd ? '已入账' : '已扣款',
  130. statusClass: isAdd ? 'credited' : 'deducted'
  131. };
  132. });
  133. this.allGroups = [{
  134. month: this.selectedMonth,
  135. year: this.selectedYear,
  136. credited: credited,
  137. pending: 0,
  138. items: items
  139. }];
  140. } catch (err) {
  141. console.error('获取奖惩明细失败:', err);
  142. uni.showToast({ title: err.message || err.msg || '请求失败', icon: 'none' });
  143. } finally {
  144. this.loading = false;
  145. }
  146. },
  147. onDateChange(e) {
  148. const val = e.detail.value;
  149. const parts = val.split('-');
  150. this.selectedYear = parseInt(parts[0]);
  151. this.selectedMonth = parseInt(parts[1]);
  152. this.fetchMonthData();
  153. },
  154. switchTab(idx) { this.activeTab = idx; }
  155. }
  156. };
  157. </script>
  158. <style>
  159. page { background-color: #F7F8FA; }
  160. .container { min-height: 100vh; background-color: #F7F8FA; }
  161. /* 筛选头部:标签 + 日期 */
  162. .filter-header {
  163. display: flex;
  164. align-items: center;
  165. justify-content: space-between;
  166. background-color: #fff;
  167. padding: 0 30rpx;
  168. border-bottom: 1rpx solid #f5f5f5;
  169. }
  170. .tab-bar {
  171. display: flex;
  172. }
  173. .date-filter {
  174. padding: 8rpx 0;
  175. }
  176. .picker-trigger {
  177. background-color: #f7f8fa;
  178. padding: 8rpx 20rpx;
  179. border-radius: 30rpx;
  180. display: flex;
  181. align-items: center;
  182. }
  183. .picker-trigger text {
  184. font-size: 24rpx;
  185. color: #333;
  186. }
  187. .arrow-icon {
  188. font-size: 18rpx;
  189. color: #999;
  190. margin-left: 8rpx;
  191. }
  192. .tab-item {
  193. padding: 18rpx 16rpx 0;
  194. font-size: 28rpx;
  195. color: #999;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: center;
  199. }
  200. .tab-item:first-child { padding-left: 0; }
  201. .tab-item.active { color: #FF9800; font-weight: bold; }
  202. /* 下划线正常流,自然居中 */
  203. .tab-line {
  204. width: 32rpx;
  205. height: 3rpx;
  206. background-color: #FF9800;
  207. border-radius: 2rpx;
  208. margin-top: 8rpx;
  209. align-self: center;
  210. }
  211. .main-scroll { flex: 1; padding: 16rpx 0; }
  212. .month-group {
  213. background-color: #fff;
  214. border-radius: 16rpx;
  215. padding: 0 24rpx;
  216. margin: 0 30rpx 16rpx;
  217. overflow: hidden;
  218. }
  219. .month-header {
  220. display: flex;
  221. align-items: center;
  222. padding: 20rpx 0;
  223. border-bottom: 1rpx solid #f5f5f5;
  224. }
  225. .month-title {
  226. font-size: 30rpx;
  227. font-weight: bold;
  228. color: #333;
  229. margin-right: 12rpx;
  230. }
  231. .month-summary { display: flex; }
  232. .month-sum-text { font-size: 22rpx; color: #999; margin-right: 10rpx; }
  233. .record-item {
  234. display: flex;
  235. align-items: center;
  236. padding: 24rpx 0;
  237. border-bottom: 1rpx solid #f9f9f9;
  238. }
  239. .ri-icon {
  240. width: 72rpx;
  241. height: 72rpx;
  242. border-radius: 50%;
  243. background-color: #FFF3E0;
  244. display: flex;
  245. align-items: center;
  246. justify-content: center;
  247. margin-right: 20rpx;
  248. flex-shrink: 0;
  249. }
  250. .ri-icon.ri-penalty { background-color: #FAFAFA; }
  251. .ri-icon-text {
  252. font-size: 30rpx;
  253. color: #FF9800;
  254. font-weight: bold;
  255. }
  256. .ri-icon.ri-penalty .ri-icon-text { color: #ccc; }
  257. .ri-content { flex: 1; }
  258. .ri-title-row { display: flex; align-items: center; margin-bottom: 6rpx; }
  259. .ri-date { font-size: 26rpx; color: #333; font-weight: bold; margin-right: 10rpx; }
  260. .ri-title { font-size: 26rpx; color: #333; }
  261. .ri-desc { font-size: 24rpx; color: #999; }
  262. .ri-right {
  263. display: flex;
  264. flex-direction: column;
  265. align-items: flex-end;
  266. margin-left: 16rpx;
  267. }
  268. .ri-amount { font-size: 30rpx; font-weight: bold; margin-bottom: 4rpx; }
  269. .ri-amount.positive { color: #FF5722; }
  270. .ri-amount.negative { color: #333; }
  271. .ri-status { font-size: 22rpx; }
  272. .ri-status.pending { color: #FF9800; }
  273. .ri-status.credited { color: #999; }
  274. .ri-status.deducted { color: #999; }
  275. </style>