location-select.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view class="container">
  3. <!-- 库位列表 -->
  4. <scroll-view scroll-y class="location-list" :style="{ height: scrollHeight + 'px' }">
  5. <view v-for="(item, index) in filteredLocations" :key="index" class="location-item"
  6. hover-class="location-item-hover" @click="selectLocation(item)">
  7. <text>{{ item.code }}</text>
  8. </view>
  9. </scroll-view>
  10. <!-- 底部搜索框 -->
  11. <view class="fixed-bottom pad-20" style="background: #ffffff;">
  12. <u-search v-model="searchText" placeholder="请输入库位条码" :show-action="false" :clearabled="true"
  13. @change="onSearch" height="40" :disabled="true" @click="searchText = ''">
  14. </u-search>
  15. <u-icon name="scan" size="28" color="#19be6b" @click="openScan"></u-icon>
  16. </view>
  17. </view>
  18. </template>
  19. <script setup>
  20. import { ref, computed, onMounted } from 'vue'
  21. // 搜索文本
  22. const searchText = ref('')
  23. // 库位列表数据
  24. const locations = ref([
  25. { code: 'k001-0121' },
  26. { code: 'k001-0113' },
  27. { code: 'k001-0111' },
  28. { code: 'k001-0111' },
  29. { code: 'k001-0111' },
  30. { code: 'k001-0111' },
  31. { code: 'k001-0111' },
  32. { code: 'k001-0111' },
  33. { code: 'k001-0111' },
  34. { code: 'k001-0111' },
  35. { code: 'k001-0111' },
  36. { code: 'k001-0111' },
  37. { code: 'k001-0111' },
  38. { code: 'k001-0111' },
  39. { code: 'k001-0111' },
  40. ])
  41. // 滚动区域高度
  42. const scrollHeight = ref(0)
  43. // 过滤后的库位列表
  44. const filteredLocations = computed(() => {
  45. if (!searchText.value) return locations.value
  46. return locations.value.filter(item =>
  47. item.code.toLowerCase().includes(searchText.value.toLowerCase())
  48. )
  49. })
  50. // 搜索处理
  51. const onSearch = () => {
  52. // 实现搜索逻辑
  53. }
  54. // 打开扫码
  55. const openScan = () => {
  56. // #ifdef APP-PLUS || MP-WEIXIN
  57. uni.scanCode({
  58. success: (res) => {
  59. searchText.value = res.result
  60. onSearch()
  61. },
  62. fail: (err) => {
  63. uni.showToast({
  64. title: '扫码失败',
  65. icon: 'error'
  66. })
  67. }
  68. })
  69. // #endif
  70. // #ifdef H5
  71. uni.showToast({
  72. title: 'H5环境不支持扫码',
  73. icon: 'none'
  74. })
  75. // #endif
  76. }
  77. // 选择库位
  78. const selectLocation = (item) => {
  79. // 获取页面实例
  80. const pages = getCurrentPages()
  81. const prevPage = pages[pages.length - 2]
  82. // 也可以使用事件总线或页面参数的方式传值
  83. uni.$emit('updateLocation', item.code)
  84. // 返回上一页
  85. uni.navigateBack()
  86. }
  87. // 计算滚动区域高度
  88. onMounted(() => {
  89. const systemInfo = uni.getSystemInfoSync()
  90. // 减去标题栏高度和搜索框高度
  91. scrollHeight.value = systemInfo.windowHeight - 44 - 60
  92. })
  93. </script>
  94. <style scoped>
  95. .container {
  96. position: relative;
  97. }
  98. .location-list {
  99. padding: 12px 0 60px;
  100. }
  101. .location-item {
  102. background-color: #fff;
  103. padding: 15px;
  104. margin-bottom: 1px;
  105. font-size: 14px;
  106. }
  107. </style>