综合办公系统
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ProjectPicker.vue 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!-- components/ProjectPicker.vue -->
  2. <template>
  3. <uni-popup ref="popup" type="bottom" @maskClick="close">
  4. <view class="modal-container">
  5. <!-- 搜索框 -->
  6. <view class="search-box">
  7. <uni-icons type="search" size="18" color="#999" />
  8. <input class="search-input" placeholder="输入项目编号/名称搜索" v-model="searchKeyword" @input="handleSearch" />
  9. </view>
  10. <!-- 项目列表 -->
  11. <scroll-view scroll-y class="list-container" @scrolltolower="loadMore" :scroll-top="scrollTop">
  12. <view v-for="(item,index) in projectList" :key="'p' + index" class="list-item"
  13. :class="{ selected: selectedProject && selectedProject.projectId === item.projectId }" @click="handleSelect(item)">
  14. <view class="item-content">
  15. <text class="project-id">{{ item.projectId }}</text>
  16. <text class="project-name">{{ item.projectName }}</text>
  17. </view>
  18. <uni-icons v-if="selectedProject && selectedProject.projectId === item.projectId" type="checkmarkempty" color="#007AFF" size="18" />
  19. </view>
  20. <!-- 加载状态 -->
  21. <view class="loading-status">
  22. <text v-if="loading">加载中...</text>
  23. <text v-else-if="!hasMore">没有更多了</text>
  24. </view>
  25. </scroll-view>
  26. <!-- 底部操作 -->
  27. <view class="footer">
  28. <button class="btn" @click="close">取消</button>
  29. <button class="btn confirm-btn" @click="confirm">确定</button>
  30. </view>
  31. </view>
  32. </uni-popup>
  33. </template>
  34. <script>
  35. import {
  36. debounce
  37. } from 'lodash-es';
  38. import {
  39. listProject,
  40. submitProject,
  41. modifyProject,
  42. delProject
  43. } from "@/api/oa/project/project";
  44. export default {
  45. name: 'ProjectPickerModal',
  46. props: {
  47. // 已选项目
  48. selected: {
  49. type: Object,
  50. default: null
  51. },
  52. // 是否显示弹窗
  53. visible: {
  54. type: Boolean,
  55. default: false
  56. }
  57. },
  58. data() {
  59. return {
  60. searchKeyword: '', // 搜索关键词
  61. projectList: [], // 项目列表
  62. currentPage: 1, // 当前页码
  63. pageSize: 10, // 每页数量
  64. hasMore: true, // 是否还有更多
  65. loading: false, // 加载状态
  66. scrollTop: 0, // 滚动位置
  67. selectedProject: null // 当前选中项目
  68. };
  69. },
  70. watch: {
  71. visible(newVal) {
  72. if (newVal) {
  73. this.$refs.popup.open();
  74. this.initData();
  75. } else {
  76. this.$refs.popup.close();
  77. }
  78. },
  79. selected: {
  80. immediate: true,
  81. handler(val) {
  82. this.selectedProject = val ? {
  83. ...val
  84. } : null;
  85. }
  86. }
  87. },
  88. created() {
  89. this.debouncedSearch = debounce(this.searchProjects, 300);
  90. },
  91. methods: {
  92. // 初始化数据
  93. initData() {
  94. this.currentPage = 1;
  95. this.hasMore = true;
  96. this.projectList = [];
  97. this.loadProjects();
  98. },
  99. // 获取项目列表
  100. async loadProjects() {
  101. if (this.loading || !this.hasMore) return;
  102. this.loading = true;
  103. try {
  104. const res = await listProject({
  105. keyword: this.searchKeyword,
  106. pageNum: this.pageNum,
  107. pageSize: this.pageSize
  108. });
  109. console.log(res)
  110. this.projectList = this.currentPage === 1 ?
  111. res.rows : [...this.projectList, ...res.rows];
  112. this.hasMore = res.total > this.currentPage * this.pageSize;
  113. this.currentPage++;
  114. } catch (error) {
  115. console.error('获取项目列表失败:', error);
  116. } finally {
  117. this.loading = false;
  118. }
  119. },
  120. // 搜索项目
  121. searchProjects() {
  122. this.currentPage = 1;
  123. this.hasMore = true;
  124. this.projectList = [];
  125. this.loadProjects();
  126. },
  127. // 处理搜索输入
  128. handleSearch() {
  129. this.debouncedSearch();
  130. },
  131. // 加载更多
  132. loadMore() {
  133. if (!this.searchKeyword) this.loadProjects();
  134. },
  135. // 选择项目
  136. handleSelect(item) {
  137. this.selectedProject = this.selectedProject?.id === item.id ? null : item;
  138. },
  139. // 确认选择
  140. confirm() {
  141. if (this.selectedProject) {
  142. this.$emit('update:selected', this.selectedProject);
  143. this.$emit('confirm', this.selectedProject);
  144. }
  145. this.close();
  146. },
  147. // 关闭弹窗
  148. close() {
  149. this.$emit('update:visible', false);
  150. }
  151. }
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. .modal-container {
  156. background: #fff;
  157. border-radius: 16px 16px 0 0;
  158. max-height: 70vh;
  159. padding: 20px;
  160. }
  161. .search-box {
  162. display: flex;
  163. align-items: center;
  164. padding: 10px;
  165. background: #f5f5f5;
  166. border-radius: 8px;
  167. margin-bottom: 15px;
  168. .search-input {
  169. flex: 1;
  170. margin-left: 8px;
  171. font-size: 14px;
  172. }
  173. }
  174. .list-container {
  175. max-height: 50vh;
  176. margin-bottom: 15px;
  177. .list-item {
  178. display: flex;
  179. align-items: center;
  180. justify-content: space-between;
  181. padding: 12px;
  182. border-bottom: 1px solid #eee;
  183. &.selected {
  184. background-color: #f8f8f8;
  185. }
  186. .item-content {
  187. flex: 1;
  188. .project-id {
  189. color: #666;
  190. font-size: 12px;
  191. margin-right: 8px;
  192. }
  193. .project-name {
  194. color: #333;
  195. font-size: 14px;
  196. }
  197. }
  198. }
  199. .loading-status {
  200. text-align: center;
  201. padding: 10px;
  202. color: #999;
  203. font-size: 12px;
  204. }
  205. }
  206. .footer {
  207. display: flex;
  208. gap: 15px;
  209. .btn {
  210. flex: 1;
  211. border-radius: 8px;
  212. &.confirm-btn {
  213. background-color: #007AFF;
  214. color: #fff;
  215. }
  216. }
  217. }
  218. </style>