warehouse-select.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="container" @click="playGlobalSound">
  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. function playGlobalSound(){
  23. uni.$u.playClickSound()
  24. }
  25. // 搜索文本
  26. const searchText = ref('')
  27. // 仓库列表数据
  28. const warehouses = ref([])
  29. //根据name查询仓库列表 /app/appUser/searchGodown
  30. function getGodownListByName(name = "") {
  31. uni.$u.http.post('/app/appUser/searchGodown?name=' + name).then(res => {
  32. if (res.code == 200) {
  33. warehouses.value = res.data
  34. }
  35. })
  36. }
  37. getGodownListByName()
  38. // 搜索处理
  39. const onSearch = () => {
  40. getGodownListByName(searchText.value)
  41. }
  42. // 选择仓库
  43. const selectWarehouse = (item) => {
  44. // 使用事件总线传递数据
  45. uni.$emit('updateWarehouse', item)
  46. // 返回上一页
  47. uni.navigateBack()
  48. }
  49. const selectedId = ref()
  50. onLoad((options) => {
  51. if (options.godownId) {
  52. selectedId.value = options.godownId
  53. }
  54. })
  55. </script>
  56. <style scoped>
  57. .warehouse-list {
  58. margin-top: 12px;
  59. }
  60. .warehouse-item {
  61. background-color: #fff;
  62. padding: 15px;
  63. margin-bottom: 1px;
  64. font-size: 16px;
  65. }
  66. .warehouse-item-active {
  67. background-color: #e1f3ff;
  68. color: #2979ff;
  69. }
  70. .warehouse-item-hover {
  71. background-color: #f5f5f5;
  72. }
  73. </style>