index.vue 7.8 KB

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