SafetyProject.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="project-list">
  3. <scroll-view
  4. scroll-y
  5. class="scroll-list"
  6. :scroll-top="scrollTopValue"
  7. scroll-with-animation
  8. refresher-enabled
  9. :refresher-triggered="isTriggered"
  10. @refresherrefresh="onRefresh"
  11. @scroll="onScroll"
  12. @scrolltolower="loadMore"
  13. :show-scrollbar="false"
  14. >
  15. <!-- uv-empty 用于查无数据时的展示 -->
  16. <uv-empty v-if="!safetyList.length && loadStatus !== 'loading'" mode="list"></uv-empty>
  17. <view
  18. class="common-list-card animate-fade-in"
  19. v-for="(item, index) in safetyList"
  20. :key="item.id"
  21. :style="{ animationDelay: `${(index % 10) * 0.05}s` }"
  22. @click="onRowClick(item)"
  23. >
  24. <view class="card-header">
  25. <text class="title">{{ item.projectName || '未命名' }}</text>
  26. <view class="status-badge" :class="getStatusType(item.projectStatus)">
  27. {{ getStatusName(item.projectStatus) }}
  28. </view>
  29. </view>
  30. <view class="card-body">
  31. <view class="info-item">
  32. <text class="label">签订日期:</text>
  33. <view class="value" style="display: flex; justify-content: space-between;">
  34. <text>{{ formatDate(item.signDate || item.approvalDate) }}</text>
  35. <text style="color: #585858;">{{ item.projectLeaderName || '-' }}</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 加载更多 -->
  41. <uv-load-more v-if="safetyList.length > 0 || loadStatus === 'loading'" :status="loadStatus" @loadmore="loadMore"></uv-load-more>
  42. </scroll-view>
  43. <!-- 返回顶部按钮 -->
  44. <uv-back-top
  45. :scrollTop="currentScrollTop"
  46. :bottom="100"
  47. :right="30"
  48. @click="backToTop"
  49. ></uv-back-top>
  50. </view>
  51. </template>
  52. <script setup lang="ts">
  53. import { ref, watch, onMounted, nextTick } from 'vue';
  54. import { storeToRefs } from 'pinia';
  55. import { debounce } from 'lodash-es';
  56. import { useProjectStore } from '@/store/modules/project';
  57. import { formatDate } from '@/utils/date';
  58. import { safetyProjectStatusOptions } from '@/constants/index';
  59. const props = defineProps({
  60. queryParams: {
  61. type: Object,
  62. default: () => ({})
  63. }
  64. });
  65. const emit = defineEmits(['goDetail']);
  66. const projectStore = useProjectStore();
  67. const { safetyList, safetyPagination, fetchSafetyLoading } = storeToRefs(projectStore);
  68. const loadStatus = ref('loadmore'); // loadmore, loading, nomore
  69. // 滚动距离状态
  70. const scrollTopValue = ref(0);
  71. const currentScrollTop = ref(0); // 监听当前滚动的准确高度用于渲染显隐
  72. const onScroll = (e: any) => {
  73. currentScrollTop.value = e.detail.scrollTop;
  74. };
  75. const backToTop = () => {
  76. scrollTopValue.value = currentScrollTop.value;
  77. nextTick(() => {
  78. scrollTopValue.value = 0;
  79. });
  80. };
  81. // ----------------- 下拉刷新功能 -----------------
  82. const isTriggered = ref(false);
  83. const onRefresh = async () => {
  84. isTriggered.value = true;
  85. await fetchData(true);
  86. isTriggered.value = false;
  87. };
  88. const getStatusName = (code: string) => {
  89. const item = safetyProjectStatusOptions.find(opt => opt.dictValue === code);
  90. return item ? item.dictLabel : code || '未知状态';
  91. };
  92. const getStatusType = (code: string) => {
  93. const item = safetyProjectStatusOptions.find(opt => opt.dictValue === code);
  94. return item ? item.type : 'info';
  95. };
  96. const fetchData = async (reset = false) => {
  97. loadStatus.value = 'loading';
  98. const { success, rows, total } = await projectStore.fetchSafetyProjects(props.queryParams, reset);
  99. if (success) {
  100. if (safetyList.value.length >= total || rows.length < safetyPagination.value.pageSize) {
  101. loadStatus.value = 'nomore';
  102. } else {
  103. loadStatus.value = 'loadmore';
  104. }
  105. } else {
  106. loadStatus.value = 'nomore';
  107. }
  108. };
  109. const loadMore = async () => {
  110. if (loadStatus.value === 'nomore' || fetchSafetyLoading.value) return;
  111. loadStatus.value = 'loading';
  112. const { success, rows, total } = await projectStore.loadMoreSafetyProjects(props.queryParams);
  113. if (success) {
  114. if (safetyList.value.length >= total || rows.length < safetyPagination.value.pageSize) {
  115. loadStatus.value = 'nomore';
  116. } else {
  117. loadStatus.value = 'loadmore';
  118. }
  119. } else {
  120. loadStatus.value = 'nomore';
  121. }
  122. };
  123. const debouncedFetchData = debounce(() => {
  124. fetchData(true);
  125. }, 500);
  126. watch(() => props.queryParams, () => {
  127. debouncedFetchData();
  128. }, { deep: true });
  129. onMounted(() => {
  130. fetchData(true);
  131. });
  132. const onRowClick = (item: any) => {
  133. emit('goDetail', { ...item, _type: 'safety' });
  134. };
  135. </script>
  136. <style lang="scss" scoped>
  137. .project-list {
  138. height: 100%;
  139. display: flex;
  140. flex-direction: column;
  141. }
  142. .scroll-list {
  143. flex: 1;
  144. height: 100%;
  145. }
  146. </style>