综合办公系统
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

DevicePicker.vue 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <uni-popup ref="devicePopup" type="bottom" @maskClick="close">
  3. <view class="modal-container">
  4. <!-- 搜索表单 -->
  5. <view class="search-box">
  6. <!-- <uni-data-select v-model="queryParams.status" :localdata="statusOptions" style="width: 200rpx;"
  7. :clearable="false" @change="handleSearch" disabled>
  8. </uni-data-select> -->
  9. <uni-easyinput v-model="queryParams.code" placeholder="出厂编号" @change="handleSearch" clearable>
  10. </uni-easyinput>
  11. <uni-easyinput v-model="queryParams.name" placeholder="设备名称" @change="handleSearch" clearable>
  12. </uni-easyinput>
  13. <uni-easyinput v-model="queryParams.brand" placeholder="设备品牌" @change="handleSearch" clearable>
  14. </uni-easyinput>
  15. </view>
  16. <!-- 设备列表 -->
  17. <scroll-view scroll-y class="list-container" @scrolltolower="loadMore" :scroll-top="scrollTop">
  18. <view v-for="(item, index) in list" :key="index" class="list-item" :class="{ selected: isSelected(item) }"
  19. @click="handleSelect(item)">
  20. <view class="item-content">
  21. <view class="item-header">
  22. <uni-tag :text="statusText(item.status)" :type="statusType(item.status)" size="small">
  23. </uni-tag>
  24. <text class="device-code">{{ item.code }}</text>
  25. </view>
  26. <view class="item-body">
  27. <text class="device-name">{{ item.name }}</text>
  28. <text class="device-info">{{ item.brand }} {{ item.series }}</text>
  29. <text class="device-place">📍 {{ item.place }}</text>
  30. </view>
  31. </view>
  32. <uni-icons v-if="isSelected(item)" type="checkmarkempty" color="#007AFF" size="18" />
  33. </view>
  34. <!-- 加载状态 -->
  35. <view class="loading-status">
  36. <uni-load-more :status="loading ? 'loading' : (hasMore ? 'more' : 'noMore')" :contentText="{
  37. contentdown: '上拉加载更多',
  38. contentrefresh: '正在加载',
  39. contentnomore: '没有更多设备'
  40. }">
  41. </uni-load-more>
  42. </view>
  43. </scroll-view>
  44. <!-- 底部操作栏 -->
  45. <view class="footer-actions">
  46. <button class="action-btn cancel" @click="close">取消</button>
  47. <button class="action-btn confirm" @click="confirm" :disabled="!selectedList.length">确定选择</button>
  48. </view>
  49. </view>
  50. </uni-popup>
  51. </template>
  52. <script>
  53. import { listDevice, listDeviceName } from "@/api/oa/device/device";
  54. import { debounce } from 'lodash-es';
  55. export default {
  56. props: {
  57. visible: Boolean,
  58. selected: {
  59. type: [Array, Object],
  60. default: () => ([])
  61. },
  62. multiple: {
  63. type: Boolean,
  64. default: true
  65. }
  66. },
  67. data() {
  68. return {
  69. queryParams: {
  70. pageNum: 1,
  71. pageSize: 10,
  72. status: '1',
  73. type: '仪器设备',
  74. code: '',
  75. name: ''
  76. },
  77. statusOptions: [
  78. { value: '0', text: '被领用' },
  79. { value: '1', text: '可领用' },
  80. { value: '2', text: '维修中' },
  81. { value: '3', text: '已停用' },
  82. { value: '4', text: '已报废' }
  83. ],
  84. list: [],
  85. selectedList: [],
  86. hasMore: true,
  87. loading: false,
  88. scrollTop: 0
  89. }
  90. },
  91. watch: {
  92. visible(val) {
  93. val ? this.$refs.devicePopup.open() : this.$refs.devicePopup.close();
  94. if (val) this.initData();
  95. },
  96. selected: {
  97. immediate: true,
  98. handler(val) {
  99. this.selectedList = Array.isArray(val) ? [...val] : [val];
  100. }
  101. },
  102. 'queryParams.status': {
  103. handler() {
  104. this.handleSearch();
  105. }
  106. }
  107. },
  108. created() {
  109. this.debouncedSearch = debounce(this.loadData, 300);
  110. },
  111. methods: {
  112. // 初始化数据
  113. initData() {
  114. this.queryParams.pageNum = 1;
  115. this.hasMore = true;
  116. this.list = [];
  117. this.loadData();
  118. },
  119. // 加载设备数据
  120. async loadData() {
  121. if (this.loading) return;
  122. this.loading = true;
  123. try {
  124. const res = await listDevice(this.queryParams);
  125. // 如果是第一页,直接替换列表
  126. if (this.queryParams.pageNum === 1) {
  127. this.list = res.rows;
  128. } else {
  129. // 如果不是第一页,追加到列表
  130. this.list = [...this.list, ...res.rows];
  131. }
  132. // 保持已选择的设备状态
  133. const selectedDeviceIds = this.selectedList.map(item => item.deviceId);
  134. this.list.forEach(item => {
  135. if (selectedDeviceIds.includes(item.deviceId)) {
  136. const selectedItem = this.selectedList.find(s => s.deviceId === item.deviceId);
  137. if (selectedItem) {
  138. Object.assign(item, selectedItem);
  139. }
  140. }
  141. });
  142. this.hasMore = res.total > this.queryParams.pageNum * this.queryParams.pageSize;
  143. this.queryParams.pageNum++;
  144. } finally {
  145. this.loading = false;
  146. }
  147. },
  148. // 搜索处理
  149. handleSearch() {
  150. // 重置分页参数
  151. this.queryParams.pageNum = 1;
  152. this.hasMore = true;
  153. this.list = [];
  154. this.loadData();
  155. },
  156. // 选择设备
  157. handleSelect(item) {
  158. if (this.multiple) {
  159. const index = this.selectedList.findIndex(d => d.deviceId === item.deviceId);
  160. index === -1
  161. ? this.selectedList.push(item)
  162. : this.selectedList.splice(index, 1);
  163. } else {
  164. this.selectedList = [item];
  165. }
  166. },
  167. // 确认选择
  168. confirm() {
  169. const result = this.multiple ? this.selectedList : this.selectedList[0];
  170. this.$emit('update:selected', result);
  171. this.$emit('confirm', result);
  172. this.close();
  173. },
  174. // 状态显示逻辑
  175. statusText(status) {
  176. const map = { '0': '被领用', '1': '可领用', '2': '维修中', '3': '已停用', '4': '已报废' };
  177. return map[status] || '未知状态';
  178. },
  179. statusType(status) {
  180. const typeMap = { '0': 'warning', '1': 'success', '2': 'info', '3': 'error', '4': 'default' };
  181. return typeMap[status] || 'default';
  182. },
  183. isSelected(item) {
  184. return this.selectedList.some(d => d.deviceId === item.deviceId);
  185. },
  186. // 加载更多
  187. loadMore() {
  188. if (!this.hasMore || this.loading) return;
  189. this.loadData();
  190. },
  191. close() {
  192. this.$emit('update:visible', false);
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .modal-container {
  199. background: #fff;
  200. border-radius: 24rpx 24rpx 0 0;
  201. padding: 32rpx;
  202. max-height: 80vh;
  203. }
  204. .search-box {
  205. display: flex;
  206. flex-wrap: wrap;
  207. gap: 16rpx;
  208. margin-bottom: 32rpx;
  209. ::v-deep .uni-easyinput__content {
  210. border-radius: 16rpx;
  211. }
  212. }
  213. .list-container {
  214. max-height: 60vh;
  215. margin-bottom: 32rpx;
  216. .list-item {
  217. display: flex;
  218. align-items: center;
  219. padding: 24rpx;
  220. border-bottom: 1rpx solid #eee;
  221. &.selected {
  222. background-color: #f5f7fa;
  223. }
  224. .item-content {
  225. flex: 1;
  226. display: flex;
  227. flex-direction: column;
  228. gap: 8rpx;
  229. .item-header {
  230. display: flex;
  231. align-items: center;
  232. gap: 16rpx;
  233. .device-code {
  234. color: #666;
  235. font-size: 24rpx;
  236. }
  237. }
  238. .item-body {
  239. display: flex;
  240. flex-direction: column;
  241. gap: 4rpx;
  242. .device-name {
  243. color: #333;
  244. font-size: 28rpx;
  245. font-weight: 500;
  246. }
  247. .device-info {
  248. color: #666;
  249. font-size: 24rpx;
  250. }
  251. .device-place {
  252. color: #999;
  253. font-size: 24rpx;
  254. }
  255. }
  256. }
  257. }
  258. }
  259. .footer-actions {
  260. display: flex;
  261. gap: 32rpx;
  262. .action-btn {
  263. flex: 1;
  264. border-radius: 12rpx;
  265. font-size: 28rpx;
  266. &.confirm {
  267. background: #007AFF;
  268. color: #fff;
  269. &:disabled {
  270. background: #ccc;
  271. }
  272. }
  273. &.cancel {
  274. background: #f5f5f5;
  275. color: #666;
  276. }
  277. }
  278. }
  279. .loading-status {
  280. padding: 32rpx 0;
  281. text-align: center;
  282. }
  283. </style>