location-select.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="container" @click="playGlobalSound">
  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. @search="onSearch" height="40" @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 {
  22. ref,
  23. computed,
  24. onMounted
  25. } from 'vue'
  26. import {
  27. onLoad,
  28. onShow
  29. } from '@dcloudio/uni-app'
  30. // 搜索文本
  31. const searchText = ref('')
  32. // 点击全局音效
  33. function playGlobalSound(){
  34. uni.$u.playClickSound()
  35. }
  36. // 库位列表数据
  37. const locations = ref([])
  38. //根据仓库id获取库位列表
  39. function getLocationListByGodownId(godownId, code = "", type = "") {
  40. uni.$u.http.get('/app/stock/getGodownPosition?godownId=' + godownId + '&code=' + code).then(res => {
  41. if (res.code == 200) {
  42. locations.value = res.data
  43. if (type == 'select') {
  44. setTimeout(() => {
  45. locations.value.forEach(item => {
  46. if (item == code) {
  47. selectLocation(item)
  48. }
  49. })
  50. },500)
  51. }
  52. }
  53. })
  54. }
  55. // 滚动区域高度
  56. const scrollHeight = ref(0)
  57. // 搜索处理
  58. const onSearch = () => {
  59. // 实现搜索逻辑
  60. getLocationListByGodownId(godownId.value, searchText.value)
  61. }
  62. // 打开扫码
  63. const openScan = () => {
  64. // #ifdef APP-PLUS || MP-WEIXIN
  65. uni.scanCode({
  66. success: (res) => {
  67. searchText.value = res.result
  68. onSearch()
  69. },
  70. fail: (err) => {
  71. uni.showToast({
  72. title: '扫码失败',
  73. icon: 'error'
  74. })
  75. }
  76. })
  77. // #endif
  78. // #ifdef H5
  79. uni.showToast({
  80. title: 'H5环境不支持扫码',
  81. icon: 'none'
  82. })
  83. // #endif
  84. }
  85. // 选择库位
  86. const selectLocation = (item) => {
  87. // 也可以使用事件总线或页面参数的方式传值
  88. uni.$emit('updateLocation', item)
  89. // 返回上一页
  90. uni.navigateBack()
  91. }
  92. const godownId = ref('')
  93. const positionCode = ref('')
  94. onLoad((opts) => {
  95. godownId.value = opts.godownId
  96. positionCode.value = opts.positionCode
  97. getLocationListByGodownId(godownId.value)
  98. scrollHeight.value = uni.getSystemInfoSync().windowHeight - 44 - 60
  99. // #ifdef APP-PLUS
  100. uni.$u.useGlobalEvent((e) => {
  101. if (e.barcode) {
  102. searchText.value = e.barcode
  103. getLocationListByGodownId(godownId.value, e.barcode, 'select')
  104. }
  105. })
  106. // #endif
  107. })
  108. onShow(() => {
  109. uni.$u.updateActivePageOnShow()
  110. })
  111. </script>
  112. <style scoped>
  113. .container {
  114. position: relative;
  115. }
  116. .location-list {
  117. padding: 12px 0 60px;
  118. }
  119. .location-item {
  120. background-color: #fff;
  121. padding: 15px 20px;
  122. margin-bottom: 1px;
  123. font-size: 16px;
  124. }
  125. .location-item-selected {
  126. background-color: #e8f5e9;
  127. border-left: 4px solid #19be6b;
  128. }
  129. .location-item-hover {
  130. background-color: #f5f5f5;
  131. }
  132. </style>