综合办公系统
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ProjectPicker.vue 5.9KB

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