index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <uv-popup ref="popupRef" mode="bottom" round="20rpx" @close="closeDialog" closeable>
  3. <view class="select-project-container">
  4. <view class="popup-header">
  5. <text class="title">选择项目</text>
  6. </view>
  7. <view class="search-bar">
  8. <uv-input
  9. v-model="queryParams.projectName"
  10. placeholder="搜索项目名称"
  11. prefixIcon="search"
  12. shape="circle"
  13. clearable
  14. customStyle="background-color: #f5f7fa; border: none; flex: 1;"
  15. @change="onSearchInput"
  16. ></uv-input>
  17. </view>
  18. <scroll-view
  19. scroll-y
  20. class="project-list"
  21. @scrolltolower="loadMore"
  22. refresher-enabled
  23. :refresher-triggered="isTriggered"
  24. @refresherrefresh="onRefresh"
  25. >
  26. <uv-empty v-if="!list.length && loadStatus !== 'loading'" mode="list"></uv-empty>
  27. <view
  28. class="project-item"
  29. v-for="item in list"
  30. :key="item.projectId"
  31. @click="selectProject(item)"
  32. >
  33. <view class="item-header">
  34. <text class="project-name">{{ item.projectName || '未命名' }}</text>
  35. <text class="project-type">{{ getTypeName(item.projectType) }}</text>
  36. </view>
  37. <view class="item-body">
  38. <text class="info-text">项目编码:{{ item.projectCode || '-' }}</text>
  39. <text class="info-text">负责人:{{ item.projectLeaderName || '-' }}</text>
  40. </view>
  41. </view>
  42. <uv-load-more
  43. v-if="list.length > 0 || loadStatus === 'loading'"
  44. :status="loadStatus"
  45. @loadmore="loadMore"
  46. ></uv-load-more>
  47. </scroll-view>
  48. </view>
  49. </uv-popup>
  50. </template>
  51. <script lang="ts" setup>
  52. import { ref } from 'vue';
  53. import { useProjectApi } from '@/api/project/index';
  54. import { debounce } from 'lodash-es';
  55. const emit = defineEmits(['select']);
  56. const projectApi = useProjectApi();
  57. const popupRef = ref<any>(null);
  58. const queryParams = ref({
  59. projectName: '',
  60. projectStatus: '20',
  61. pageNum: 1,
  62. pageSize: 20
  63. });
  64. const list = ref<any[]>([]);
  65. const total = ref(0);
  66. const loadStatus = ref<'loadmore' | 'loading' | 'nomore'>('loadmore');
  67. const isTriggered = ref(false);
  68. const openDialog = () => {
  69. popupRef.value?.open();
  70. fetchData(true);
  71. };
  72. const closeDialog = () => {
  73. popupRef.value?.close();
  74. list.value = [];
  75. queryParams.value.pageNum = 1;
  76. queryParams.value.projectName = '';
  77. };
  78. const fetchData = async (reset = false) => {
  79. if (reset) {
  80. queryParams.value.pageNum = 1;
  81. list.value = [];
  82. }
  83. loadStatus.value = 'loading';
  84. try {
  85. const res: any = await projectApi.getList(queryParams.value);
  86. if (res.code === 200) {
  87. const rows = res.data?.list || [];
  88. total.value = res.data?.total || 0;
  89. list.value = reset ? rows : [...list.value, ...rows];
  90. if (list.value.length >= total.value || rows.length < queryParams.value.pageSize) {
  91. loadStatus.value = 'nomore';
  92. } else {
  93. loadStatus.value = 'loadmore';
  94. }
  95. } else {
  96. loadStatus.value = 'nomore';
  97. }
  98. } catch (error) {
  99. console.error(error);
  100. loadStatus.value = 'nomore';
  101. } finally {
  102. if (reset) {
  103. isTriggered.value = false;
  104. }
  105. }
  106. };
  107. const onSearchInput = debounce(() => {
  108. fetchData(true);
  109. }, 500);
  110. const onRefresh = async () => {
  111. isTriggered.value = true;
  112. await fetchData(true);
  113. };
  114. const loadMore = () => {
  115. if (loadStatus.value === 'nomore' || loadStatus.value === 'loading') return;
  116. queryParams.value.pageNum += 1;
  117. fetchData(false);
  118. };
  119. const getTypeName = (type: string | number) => {
  120. if (type == '10') return '纵向项目';
  121. if (type == '20') return '横向项目';
  122. if (type == '30') return '内部项目';
  123. if (type == '40') return '重点学科';
  124. return '未知';
  125. };
  126. const selectProject = (item: any) => {
  127. emit('select', item);
  128. closeDialog();
  129. };
  130. defineExpose({
  131. openDialog,
  132. closeDialog
  133. });
  134. </script>
  135. <style lang="scss" scoped>
  136. .select-project-container {
  137. height: 80vh;
  138. display: flex;
  139. flex-direction: column;
  140. background-color: #f5f7fa;
  141. border-radius: 20rpx 20rpx 0 0;
  142. overflow: hidden;
  143. }
  144. .popup-header {
  145. height: 96rpx;
  146. display: flex;
  147. justify-content: center;
  148. align-items: center;
  149. background-color: #fff;
  150. border-bottom: 1px solid #f0f0f0;
  151. .title {
  152. font-size: 32rpx;
  153. font-weight: bold;
  154. color: #333;
  155. }
  156. }
  157. .search-bar {
  158. padding: 20rpx 30rpx;
  159. background-color: #fff;
  160. border-bottom: 1px solid #f5f5f5;
  161. z-index: 10;
  162. }
  163. .project-list {
  164. flex: 1;
  165. height: 0;
  166. padding: 20rpx 30rpx;
  167. box-sizing: border-box;
  168. }
  169. .project-item {
  170. background-color: #fff;
  171. border-radius: 12rpx;
  172. padding: 24rpx;
  173. margin-bottom: 20rpx;
  174. box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.02);
  175. &:active {
  176. background-color: #f5f7fa;
  177. }
  178. .item-header {
  179. display: flex;
  180. justify-content: space-between;
  181. align-items: flex-start;
  182. margin-bottom: 16rpx;
  183. .project-name {
  184. font-size: 30rpx;
  185. font-weight: 500;
  186. color: #333;
  187. flex: 1;
  188. margin-right: 20rpx;
  189. }
  190. .project-type {
  191. font-size: 24rpx;
  192. color: #1c9bfd;
  193. background-color: rgba(28, 155, 253, 0.1);
  194. padding: 4rpx 12rpx;
  195. border-radius: 4rpx;
  196. white-space: nowrap;
  197. }
  198. }
  199. .item-body {
  200. display: flex;
  201. flex-direction: column;
  202. gap: 10rpx;
  203. .info-text {
  204. font-size: 26rpx;
  205. color: #666;
  206. }
  207. }
  208. }
  209. </style>