index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="list-page-container">
  3. <!-- 顶部搜索 -->
  4. <view class="search-header">
  5. <view class="search-row">
  6. <uv-input
  7. placeholder="请输入项目名称"
  8. v-model="queryParams.projectName"
  9. prefixIcon="search"
  10. prefixIconStyle="color: #999; font-size: 32rpx;"
  11. clearable
  12. shape="circle"
  13. customStyle="background-color: #f5f7fa; border: none;"
  14. @confirm="onSearch"
  15. ></uv-input>
  16. </view>
  17. </view>
  18. <!-- 列表区域 -->
  19. <view class="list-container">
  20. <scroll-view
  21. scroll-y
  22. class="scroll-list"
  23. :scroll-top="scrollTopValue"
  24. scroll-with-animation
  25. refresher-enabled
  26. :refresher-triggered="isTriggered"
  27. @refresherrefresh="onRefresh"
  28. @scroll="onScroll"
  29. @scrolltolower="loadMore"
  30. :show-scrollbar="false"
  31. >
  32. <uv-empty v-if="!list.length && loadStatus !== 'loading'" mode="list"></uv-empty>
  33. <view
  34. class="common-list-card animate-fade-in"
  35. v-for="(item, index) in list"
  36. :key="item.id"
  37. :style="{ animationDelay: `${(index % 10) * 0.05}s` }"
  38. @click="toDetail(item.id)"
  39. >
  40. <view class="card-header">
  41. <text class="title">编号:{{ item.allotNo || '-' }}</text>
  42. </view>
  43. <view class="card-body">
  44. <view class="info-item">
  45. <text class="label">项目名称:</text>
  46. <text class="value text-ellipsis">{{ item.projectName || '-' }}</text>
  47. </view>
  48. <view class="info-item">
  49. <text class="label">项目负责人:</text>
  50. <text class="value">{{ item.projectIncharge || '-' }}</text>
  51. </view>
  52. <view class="info-item">
  53. <text class="label">入账金额(元):</text>
  54. <text class="value number-font">{{ amountUnitFormatter(item.amount) }}</text>
  55. </view>
  56. <view class="info-item">
  57. <text class="label">入账时间:</text>
  58. <text class="value">{{ item.applyTime ? formatDate(item.applyTime, 'YYYY-MM-DD') : '-' }}</text>
  59. </view>
  60. </view>
  61. </view>
  62. <uv-load-more
  63. v-if="list.length > 0 || loadStatus === 'loading'"
  64. :status="loadStatus"
  65. @loadmore="loadMore"
  66. ></uv-load-more>
  67. <!-- 底部安全距离 -->
  68. <view class="safe-bottom-space"></view>
  69. </scroll-view>
  70. <uv-back-top
  71. :scrollTop="currentScrollTop"
  72. :bottom="100"
  73. :right="30"
  74. @click="backToTop"
  75. ></uv-back-top>
  76. </view>
  77. </view>
  78. </template>
  79. <script setup lang="ts">
  80. import { ref, nextTick, watch } from 'vue';
  81. import { onLoad } from '@dcloudio/uni-app';
  82. import { debounce } from 'lodash-es';
  83. import { useClaimApi } from '@/api/fund/index';
  84. import { onRouterPush } from '@/utils/router';
  85. import { formatDate } from '@/utils/date';
  86. import { DEFAULT_PAGE_SIZE } from '@/constants/index';
  87. const claimApi = useClaimApi();
  88. const queryParams = ref({
  89. projectName: '',
  90. pageNum: 1,
  91. pageSize: DEFAULT_PAGE_SIZE
  92. });
  93. const list = ref<any[]>([]);
  94. const loadStatus = ref<'loadmore' | 'loading' | 'nomore'>('loadmore');
  95. const isTriggered = ref(false);
  96. const scrollTopValue = ref(0);
  97. const currentScrollTop = ref(0);
  98. // Helper function to format amount to 2 decimal places if applicable
  99. const amountUnitFormatter = (val: any) => {
  100. if (val === null || val === undefined) return '0.00';
  101. const num = Number(val);
  102. return isNaN(num) ? '0.00' : num.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  103. };
  104. const fetchListData = async (reset = false) => {
  105. if (reset) {
  106. queryParams.value.pageNum = 1;
  107. }
  108. loadStatus.value = 'loading';
  109. try {
  110. const res: any = await claimApi.getRecordList(queryParams.value);
  111. if (res.code == 200) {
  112. const records = res.data?.list || res.list || [];
  113. if (reset) {
  114. list.value = records;
  115. } else {
  116. list.value = [...list.value, ...records];
  117. }
  118. if (records.length < queryParams.value.pageSize) {
  119. loadStatus.value = 'nomore';
  120. } else {
  121. loadStatus.value = 'loadmore';
  122. queryParams.value.pageNum += 1;
  123. }
  124. } else {
  125. loadStatus.value = 'nomore';
  126. }
  127. } catch (error) {
  128. console.error('Fetch error:', error);
  129. loadStatus.value = 'nomore';
  130. } finally {
  131. if (reset) {
  132. isTriggered.value = false;
  133. }
  134. }
  135. };
  136. const onSearch = () => {
  137. fetchListData(true);
  138. };
  139. const debouncedSearch = debounce(() => {
  140. fetchListData(true);
  141. }, 500);
  142. watch(() => queryParams.value.projectName, () => {
  143. debouncedSearch();
  144. });
  145. const onRefresh = async () => {
  146. isTriggered.value = true;
  147. await fetchListData(true);
  148. };
  149. const loadMore = () => {
  150. if (loadStatus.value !== 'loadmore') return;
  151. fetchListData(false);
  152. };
  153. const onScroll = (e: any) => {
  154. currentScrollTop.value = e.detail.scrollTop;
  155. };
  156. const backToTop = () => {
  157. scrollTopValue.value = currentScrollTop.value;
  158. nextTick(() => {
  159. scrollTopValue.value = 0;
  160. });
  161. };
  162. const toDetail = (id: number) => {
  163. onRouterPush(`/pages/fund/claim-records/detail?id=${id}`);
  164. };
  165. onLoad(() => {
  166. fetchListData(true);
  167. });
  168. </script>
  169. <style lang="scss" scoped>
  170. .list-page-container {
  171. height: calc(100vh - var(--window-top));
  172. display: flex;
  173. flex-direction: column;
  174. background-color: #f5f7fa;
  175. box-sizing: border-box;
  176. }
  177. .search-header {
  178. background-color: #fff;
  179. padding: 20rpx 30rpx;
  180. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
  181. position: sticky;
  182. top: 0;
  183. z-index: 99;
  184. }
  185. .list-container {
  186. padding: 30rpx;
  187. flex: 1;
  188. overflow: hidden;
  189. box-sizing: border-box;
  190. }
  191. .scroll-list {
  192. flex: 1;
  193. height: 100%;
  194. }
  195. .common-list-card {
  196. .card-body {
  197. .info-item {
  198. display: flex;
  199. font-size: 28rpx;
  200. margin-bottom: 12rpx;
  201. line-height: 1.5;
  202. &:last-child {
  203. margin-bottom: 0;
  204. }
  205. .label {
  206. color: #666;
  207. width: 200rpx;
  208. flex-shrink: 0;
  209. }
  210. .value {
  211. color: #333;
  212. flex: 1;
  213. word-break: break-all;
  214. }
  215. }
  216. }
  217. }
  218. .number-font {
  219. font-family: 'Helvetica Neue', Arial, sans-serif;
  220. color: #1c9bfd !important;
  221. font-weight: 500;
  222. }
  223. .text-ellipsis {
  224. overflow: hidden;
  225. white-space: nowrap;
  226. text-overflow: ellipsis;
  227. }
  228. .safe-bottom-space {
  229. height: calc(80rpx + env(safe-area-inset-bottom));
  230. width: 100%;
  231. }
  232. </style>