综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DevicePicker.vue 7.6KB

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