income.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. <script lang="ts" setup>
  2. import type { AccountDetailItem } from '@/api/income'
  3. import { useRequest } from 'alova/client'
  4. import { storeToRefs } from 'pinia'
  5. import { computed, ref, watch } from 'vue'
  6. import { getAccountCount } from '@/api/home'
  7. import { getAccountDetailTotalAmount, getCouponIssuerAccountByPageMap } from '@/api/income'
  8. import { useScroll } from '@/hooks/useScroll'
  9. import { useShare } from '@/hooks/useShare'
  10. import { useUserStore } from '@/store'
  11. import { useTokenStore } from '@/store/token'
  12. import { changtime, menuButtonInfo, safeAreaInsets, systemInfo } from '@/utils'
  13. import { getImageUrl } from '@/utils/imageUtil'
  14. definePage({
  15. style: {
  16. navigationBarTitleText: '收益',
  17. navigationStyle: 'custom',
  18. },
  19. })
  20. const userStore = useUserStore()
  21. const tokenStore = useTokenStore()
  22. // 使用storeToRefs解构userInfo
  23. const { userInfo } = storeToRefs(userStore)
  24. const { hasLogin } = storeToRefs(tokenStore)
  25. const show = ref(false)
  26. const filterValue = ref(Date.now())
  27. // 发券人账户表-通过userId查询账户信息
  28. const { send: getAccountCountRequest, data: accountCountData } = useRequest(getAccountCount, {
  29. immediate: false,
  30. })
  31. const refreshing = ref(false)
  32. const status = ref(0) // 0-待结算, 1-已结算/成功
  33. const type = ref(1) // 明细类型: 1-佣金收入, 2-提现支出, 3-退款扣减, 4-系统调整
  34. const { send: getAccountDetailTotalAmountRequest, data: accountDetailTotalAmountData } = useRequest(() => getAccountDetailTotalAmount({ status: status.value, year: changtime(filterValue.value, 'YYYY'), month: changtime(filterValue.value, 'MM'), type: type.value }), {
  35. immediate: false,
  36. })
  37. // 获取账户明细分页数据(Map格式)---待结算
  38. const {
  39. list: pendingSettlementData,
  40. loading: pendingSettlementLoading,
  41. finished: pendingSettlementFinished,
  42. refresh: pendingSettlementRefresh,
  43. loadMore: pendingSettlementLoadMore,
  44. } = useScroll<AccountDetailItem>({
  45. fetchData: async (page, pageSize) => {
  46. const response = await getCouponIssuerAccountByPageMap({
  47. pageNo: page,
  48. pageSize,
  49. status: 0,
  50. year: changtime(filterValue.value, 'YYYY'),
  51. month: changtime(filterValue.value, 'MM'),
  52. type: type.value,
  53. })
  54. return response.detailList || []
  55. },
  56. pageSize: 7,
  57. })
  58. // 获取账户明细分页数据(Map格式)---已结算
  59. const {
  60. list: settledData,
  61. loading: settledLoading,
  62. finished: settledFinished,
  63. refresh: settledRefresh,
  64. loadMore: settledLoadMore,
  65. } = useScroll<AccountDetailItem>({
  66. fetchData: async (page, pageSize) => {
  67. const response = await getCouponIssuerAccountByPageMap({
  68. pageNo: page,
  69. pageSize,
  70. status: 1,
  71. year: changtime(filterValue.value, 'YYYY'),
  72. month: changtime(filterValue.value, 'MM'),
  73. type: type.value,
  74. })
  75. return response.detailList || []
  76. },
  77. pageSize: 7,
  78. })
  79. async function confirm() {
  80. // 函数实现
  81. show.value = false
  82. if (status.value === 0) {
  83. await pendingSettlementRefresh()
  84. }
  85. else {
  86. await settledRefresh()
  87. }
  88. }
  89. function cancel() {
  90. show.value = false
  91. }
  92. function close() {
  93. show.value = false
  94. }
  95. // 下拉刷新
  96. async function onRefresh() {
  97. refreshing.value = true
  98. // 重置列表并重新加载数据
  99. if (status.value === 0) {
  100. await pendingSettlementRefresh()
  101. }
  102. else {
  103. await settledRefresh()
  104. }
  105. refreshing.value = false
  106. }
  107. // 上拉加载更多
  108. function onLoadMore() {
  109. console.log(status.value, '执行了')
  110. if (status.value === 0) {
  111. pendingSettlementLoadMore()
  112. }
  113. else {
  114. settledLoadMore()
  115. }
  116. }
  117. const list = ref<AccountDetailItem[]>([])
  118. onShow(async () => {
  119. // 登录后查询收益数据
  120. if (hasLogin) {
  121. await getAccountCountRequest()
  122. await getAccountDetailTotalAmountRequest()
  123. // 数据会在useScroll的onMounted中自动加载,这里不需要额外调用
  124. }
  125. })
  126. // 创建分享hook实例
  127. const { getShareConfig, getTimelineShareConfig } = useShare()
  128. // #ifdef MP-WEIXIN
  129. // 分享给好友生命周期函数
  130. onShareAppMessage(async (options) => {
  131. return await getShareConfig()
  132. })
  133. // 分享到朋友圈生命周期函数
  134. onShareTimeline(async () => {
  135. return await getTimelineShareConfig()
  136. })
  137. // #endif
  138. const isUnlock = computed(() => accountCountData && accountCountData?.status === 0)
  139. watch(() => accountCountData, (newVal) => {
  140. console.log(newVal)
  141. })
  142. function showTimeFilter() {
  143. show.value = true
  144. }
  145. const wjsList = ref<AccountDetailItem[]>([])
  146. const yjsList = ref<AccountDetailItem[]>([])
  147. const activeTab = ref('pending')
  148. async function changeTab(tab: string) {
  149. if (activeTab.value === tab)
  150. return
  151. activeTab.value = tab
  152. status.value = tab === 'pending' ? 0 : 1
  153. await getAccountDetailTotalAmountRequest()
  154. // 切换标签时刷新对应列表数据
  155. if (tab === 'pending') {
  156. await pendingSettlementRefresh()
  157. }
  158. else {
  159. await settledRefresh()
  160. }
  161. }
  162. function goPage(page: string) {
  163. uni.navigateTo({
  164. url: `/pages-A/${page}/index`,
  165. })
  166. }
  167. </script>
  168. <template>
  169. <view class="profile-container"
  170. :style="{ height: `calc(100vh - ${safeAreaInsets.top}px - ${safeAreaInsets.bottom}px)` }">
  171. <!-- 顶部区域 -->
  172. <view class="income-header"
  173. :style="{ background: `url(${getImageUrl('@img/income/income-bg.png')})`, backgroundSize: '100% 110%', backgroundPosition: 'left bottom', backgroundRepeat: 'no-repeat' }">
  174. <view class="income-header-avatar-info"
  175. :style="{ paddingTop: `calc(${safeAreaInsets.top}px + ${menuButtonInfo.height}px)` }">
  176. <view class="income-header-balance">
  177. 当前账户余额(元)
  178. </view>
  179. <view class="income-header-balance-num">
  180. <view class="income-header-balance-num-amount">
  181. {{ accountCountData?.balance || 0 }}
  182. </view>
  183. <view class="income-header-balance-num-btns">
  184. <view v-if="isUnlock" class="income-header-balance-num-btn js" @click="goPage('unlockRewards')">
  185. 解锁
  186. </view>
  187. </view>
  188. </view>
  189. </view>
  190. <view class="income-header-tips">
  191. <view class="income-header-tips-item">
  192. <view class="income-header-tips-item-num">
  193. {{ accountCountData?.withdrawableAmount || 0 }}
  194. </view>
  195. <view class="income-header-tips-item-des">
  196. 可提现金额
  197. </view>
  198. </view>
  199. <view class="income-header-tips-item">
  200. <view class="income-header-tips-item-num">
  201. {{ accountCountData?.unsettledAmount || 0 }}
  202. </view>
  203. <view class="income-header-tips-item-des">
  204. 未结算金额
  205. </view>
  206. </view>
  207. <view class="income-header-tips-item">
  208. <view class="income-header-tips-item-num">
  209. {{ accountCountData?.totalCommission || 0 }}
  210. </view>
  211. <view class="income-header-tips-item-des">
  212. 累计收益
  213. </view>
  214. </view>
  215. </view>
  216. </view>
  217. <!-- 公告 -->
  218. <view v-if="isUnlock" class="income-header-notice">
  219. <view class="income-header-notice-icon">
  220. <image :src="getImageUrl('@img/income/notice.png')" mode="aspectFit" />
  221. </view>
  222. <view class="income-header-notice-content">
  223. 在考核周期内未达标已锁定收益,<text>前往查看~</text>
  224. </view>
  225. </view>
  226. <!-- 菜单 -->
  227. <view class="income-header-menu" :style="{ marginTop: isUnlock ? '24rpx' : '-50rpx' }">
  228. <!-- 结算筛选 -->
  229. <view class="income-header-menu-filter">
  230. <view class="income-header-menu-filter-item" :class="[activeTab === 'pending' ? 'active' : '']"
  231. @click="changeTab('pending')">
  232. 待结算
  233. </view>
  234. <view class="income-header-menu-filter-item" :class="[activeTab === 'settled' ? 'active' : '']"
  235. @click="changeTab('settled')">
  236. 已结算
  237. </view>
  238. </view>
  239. <!-- 时间筛选 -->
  240. <view class="income-menu-time-filter">
  241. <view class="income-menu-time-filter-text" @click="showTimeFilter">
  242. <text>{{ changtime(filterValue) }}</text>
  243. <up-icon name="arrow-down" color="#666666" size="14" />
  244. <up-datetime-picker v-model="filterValue" :show="show" mode="year-month" close-on-click-overlay
  245. @confirm="confirm" @cancel="cancel" />
  246. </view>
  247. <view>
  248. 合计:¥{{ accountDetailTotalAmountData?.totalAmount || 0 }}
  249. </view>
  250. </view>
  251. <!-- 优惠券列表 -->
  252. <scroll-view class="income-header-menu-list" :scroll-y="true" :refresher-enabled="true"
  253. :refresher-triggered="refreshing" @refresherrefresh="onRefresh" @scrolltolower="onLoadMore">
  254. <template v-for="item in activeTab === 'pending' ? pendingSettlementData || [] : settledData || []"
  255. :key="item.id">
  256. <view class="income-header-menu-item">
  257. <view class="income-header-menu-icon">
  258. <image v-if="activeTab === 'settled'" :src="getImageUrl('@img/income/hb.png')"
  259. mode="aspectFit" />
  260. <image v-else :src="getImageUrl('@img/income/djs.png')" mode="aspectFit" />
  261. <view class="income-header-menu-text">
  262. <view class="income-header-menu-text-nickname">
  263. {{ item.receiveUserName }}
  264. </view>
  265. <view>{{ item.couponName }}</view>
  266. </view>
  267. </view>
  268. <view class="income-header-menu-left">
  269. <view class="income-header-menu-left-amount">
  270. ¥{{ item.changeAmount }}
  271. </view>
  272. <view class="income-header-menu-left-time">
  273. {{ item.settleTime }}
  274. </view>
  275. </view>
  276. </view>
  277. </template>
  278. <!-- 加载状态提示 -->
  279. <view v-if="(activeTab === 'pending' ? pendingSettlementLoading : settledLoading)" class="loading-tip">
  280. 加载中...
  281. </view>
  282. <view
  283. v-else-if="(activeTab === 'pending' ? pendingSettlementFinished : settledFinished) && (activeTab === 'pending' ? pendingSettlementData.length : settledData.length) > 0"
  284. class="finished-tip">
  285. 没有更多数据了
  286. </view>
  287. <!-- 空状态 -->
  288. <u-empty
  289. v-if="(activeTab === 'pending' ? pendingSettlementData.length === 0 : settledData.length === 0)"
  290. class="p-b-12 pt-12" mode="list" />
  291. </scroll-view>
  292. </view>
  293. </view>
  294. </template>
  295. <style lang="scss" scoped>
  296. .profile-container {
  297. background-color: #f5f5f5;
  298. line-height: 1;
  299. display: flex;
  300. flex-direction: column;
  301. /* 添加这行,设置容器高度为视口高度 */
  302. .income-header {
  303. height: 526rpx;
  304. .income-header-avatar-info {
  305. display: flex;
  306. flex-direction: column;
  307. gap: 30rpx;
  308. padding: 0 24rpx;
  309. .income-header-balance {
  310. font-weight: 400;
  311. font-size: 26rpx;
  312. color: #ffffff;
  313. }
  314. .income-header-balance-num {
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: center;
  318. .income-header-balance-num-amount {
  319. font-weight: 500;
  320. font-size: 65rpx;
  321. color: #ffffff;
  322. }
  323. .income-header-balance-num-btns {
  324. display: flex;
  325. gap: 15rpx;
  326. .income-header-balance-num-btn {
  327. padding: 20rpx 40rpx;
  328. border-radius: 33rpx;
  329. font-weight: 400;
  330. font-size: 26rpx;
  331. &.js {
  332. background: #da4c47;
  333. color: #ffffff;
  334. }
  335. &.tx {
  336. background: #bfbfbf;
  337. color: #747474;
  338. }
  339. }
  340. }
  341. }
  342. }
  343. .income-header-tips {
  344. height: 124rpx;
  345. display: flex;
  346. background: linear-gradient(114deg, #f67873, #fb847f, #f67873);
  347. border-radius: 10rpx;
  348. margin: 47rpx 24rpx 0 24rpx;
  349. .income-header-tips-item {
  350. flex: 1;
  351. display: flex;
  352. flex-direction: column;
  353. justify-content: center;
  354. align-items: center;
  355. gap: 15rpx;
  356. font-weight: 500;
  357. font-size: 34rpx;
  358. color: #ffffff;
  359. line-height: 1;
  360. position: relative;
  361. &:not(:last-child):after {
  362. content: '';
  363. position: absolute;
  364. top: 50%;
  365. right: 0;
  366. transform: translateY(-50%);
  367. width: 2px;
  368. height: 40rpx;
  369. background: #ffffff;
  370. }
  371. .income-header-tips-item-num {
  372. font-weight: bold;
  373. }
  374. .income-header-tips-item-des {
  375. font-weight: 400;
  376. font-size: 24rpx;
  377. color: #ffffff;
  378. }
  379. }
  380. }
  381. }
  382. .income-header-notice {
  383. margin: -50rpx 24rpx 24rpx 24rpx;
  384. background: #ffffff;
  385. border-radius: 10rpx;
  386. display: flex;
  387. align-items: center;
  388. gap: 20rpx;
  389. padding: 28rpx 20rpx;
  390. .income-header-notice-icon {
  391. width: 52rpx;
  392. height: 35rpx;
  393. image {
  394. width: 100%;
  395. height: 100%;
  396. }
  397. }
  398. .income-header-notice-content {
  399. font-weight: 400;
  400. font-size: 24rpx;
  401. color: #333333;
  402. text {
  403. color: #c52d27;
  404. }
  405. }
  406. }
  407. .income-header-menu {
  408. // background: #ffffff;
  409. border-radius: 10rpx 10rpx 0rpx 0rpx;
  410. margin-left: 24rpx;
  411. margin-bottom: 24rpx;
  412. margin-right: 23rpx;
  413. flex: 1;
  414. display: flex;
  415. flex-direction: column;
  416. min-height: 0;
  417. .income-header-menu-filter {
  418. display: flex;
  419. justify-content: space-between;
  420. align-items: center;
  421. font-weight: 500;
  422. font-size: 32rpx;
  423. color: #333333;
  424. height: 90rpx;
  425. background: #ffffff;
  426. box-shadow: 0rpx 3rpx 7rpx 0rpx rgba(213, 213, 213, 0.29);
  427. border-radius: 10rpx 10rpx 0rpx 0rpx;
  428. .income-header-menu-filter-item {
  429. flex: 1;
  430. display: flex;
  431. justify-content: center;
  432. align-items: center;
  433. position: relative;
  434. height: 100%;
  435. &.active {
  436. color: #ed6b66;
  437. &:after {
  438. content: '';
  439. position: absolute;
  440. bottom: 0;
  441. left: 50%;
  442. transform: translateX(-50%);
  443. width: 67rpx;
  444. height: 6rpx;
  445. background: #ed6b66;
  446. border-radius: 3rpx;
  447. }
  448. }
  449. }
  450. }
  451. .income-menu-time-filter {
  452. display: flex;
  453. justify-content: space-between;
  454. align-items: center;
  455. font-weight: 400;
  456. font-size: 24rpx;
  457. color: #333333;
  458. padding: 30rpx 20rpx 14rpx;
  459. background: #ffffff;
  460. margin-top: 4rpx;
  461. .income-menu-time-filter-text {
  462. font-weight: 400;
  463. font-size: 26rpx;
  464. color: #000000;
  465. display: flex;
  466. align-items: center;
  467. gap: 12rpx;
  468. }
  469. }
  470. .income-header-menu-list {
  471. background: #ffffff;
  472. flex: 1;
  473. min-height: calc(30vh - 100rpx);
  474. overflow-y: auto;
  475. /* 确保内容超出时可滚动 */
  476. .income-header-menu-item {
  477. height: 88rpx;
  478. display: flex;
  479. justify-content: space-between;
  480. align-items: center;
  481. border-bottom: 1px solid #eeeeee;
  482. padding: 32rpx 0 29rpx;
  483. margin: 0 20rpx;
  484. &:last-child {
  485. border-bottom: none;
  486. }
  487. .income-header-menu-icon {
  488. display: flex;
  489. justify-content: center;
  490. align-items: center;
  491. gap: 19rpx;
  492. image {
  493. width: 60rpx;
  494. height: 60rpx;
  495. }
  496. .income-header-menu-text {
  497. font-weight: 400;
  498. font-size: 24rpx;
  499. color: #888888;
  500. .income-header-menu-text-nickname {
  501. font-size: 28rpx;
  502. color: #222222;
  503. margin-bottom: 18rpx;
  504. }
  505. }
  506. }
  507. .income-header-menu-left {
  508. font-weight: 400;
  509. font-size: 24rpx;
  510. color: #888888;
  511. .income-header-menu-left-amount {
  512. font-size: 28rpx;
  513. color: #222222;
  514. margin-bottom: 18rpx;
  515. text-align: right;
  516. }
  517. }
  518. }
  519. .loading-tip,
  520. .finished-tip {
  521. text-align: center;
  522. padding: 20rpx 0;
  523. color: #999;
  524. font-size: 24rpx;
  525. }
  526. }
  527. }
  528. }
  529. </style>