index.vue 6.3 KB

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