location-select.vue 3.1 KB

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