warehouse-select.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="container">
  3. <!-- 搜索框 -->
  4. <view class="search-area">
  5. <u-search v-model="searchText" placeholder="请输入仓库名称" :show-action="false" :clearabled="true"
  6. @change="onSearch" height="40" placeholder-style="font-size:16px"></u-search>
  7. </view>
  8. <!-- 仓库列表 -->
  9. <view class="warehouse-list">
  10. <view v-for="(item, index) in warehouses" :key="index"
  11. :class="['warehouse-item', { 'warehouse-item-active': item.id == selectedId }]"
  12. hover-class="warehouse-item-hover" @click="selectWarehouse(item)">
  13. <text>{{ index + 1 }}.{{ item.godownName }}</text>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import { ref, computed } from 'vue'
  20. import { onLoad } from '@dcloudio/uni-app'
  21. // 搜索文本
  22. const searchText = ref('')
  23. // 仓库列表数据
  24. const warehouses = ref([])
  25. //根据name查询仓库列表 /app/appUser/searchGodown
  26. function getGodownListByName(name = "") {
  27. uni.$u.http.post('/app/appUser/searchGodown?name=' + name).then(res => {
  28. if (res.code == 200) {
  29. warehouses.value = res.data
  30. }
  31. })
  32. }
  33. getGodownListByName()
  34. // 搜索处理
  35. const onSearch = () => {
  36. getGodownListByName(searchText.value)
  37. }
  38. // 选择仓库
  39. const selectWarehouse = (item) => {
  40. // 使用事件总线传递数据
  41. uni.$emit('updateWarehouse', item)
  42. // 返回上一页
  43. uni.navigateBack()
  44. }
  45. const selectedId = ref()
  46. onLoad((options) => {
  47. if (options.godownId) {
  48. selectedId.value = options.godownId
  49. }
  50. })
  51. </script>
  52. <style scoped>
  53. .warehouse-list {
  54. margin-top: 12px;
  55. }
  56. .warehouse-item {
  57. background-color: #fff;
  58. padding: 15px;
  59. margin-bottom: 1px;
  60. font-size: 16px;
  61. }
  62. .warehouse-item-active {
  63. background-color: #e1f3ff;
  64. color: #2979ff;
  65. }
  66. .warehouse-item-hover {
  67. background-color: #f5f5f5;
  68. }
  69. </style>