WarehouseSelector.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <u-popup :show="show" @close="handleClose" mode="bottom" round="10">
  3. <view class="warehouse-selector">
  4. <view style="flex:1">
  5. <!-- 标题 -->
  6. <view class="header">
  7. <text class="title">绑定仓库</text>
  8. </view>
  9. <!-- 搜索框 -->
  10. <view class="search-box">
  11. <u-search :inputStyle="{ 'height': '80rpx', 'font-size': '16px' }"
  12. :actionStyle="{ 'font-size': '16px', color: '#22ac38' }" v-model="searchKeyword"
  13. placeholder="搜索仓库" :show-action="true" action-text="搜索" @search="handleSearch"
  14. @custom="handleSearch" />
  15. </view>
  16. <!-- 搜索结果 -->
  17. <view class="search-result" v-if="searchResults.length > 0">
  18. <text class="section-title">搜索结果</text>
  19. <view class="tag-group">
  20. <u-tag v-for="item in searchResults" :key="item" :text="item.godownName"
  21. :plain="selectedWarehouse!==item.godownName" shape="circle" @click="selectWarehouse(item)"
  22. size="large" />
  23. </view>
  24. </view>
  25. <!-- 历史绑定 -->
  26. <view class="history-section" v-if="historyWarehouses.length>0">
  27. <text class="section-title">历史绑定</text>
  28. <view class="tag-group">
  29. <u-tag v-for="item in historyWarehouses" :key="item" :text="item"
  30. :plain="selectedWarehouse!==item.godownName" shape="circle" @click="selectWarehouse(item)"
  31. size="large" />
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 底部按钮 -->
  36. <view class="footer">
  37. <u-button @click="handleClose" text="取消" plain shape="circle" />
  38. <u-button type="primary" @click="handleConfirm" text="确定" shape="circle" />
  39. </view>
  40. </view>
  41. </u-popup>
  42. </template>
  43. <script setup>
  44. import {
  45. ref
  46. } from 'vue'
  47. const props = defineProps({
  48. show: {
  49. type: Boolean,
  50. default: false
  51. }
  52. })
  53. const emit = defineEmits(['update:show', 'warehouse-selected'])
  54. const searchKeyword = ref('')
  55. const searchResults = ref([])
  56. const historyWarehouses = ref([''])
  57. const selectedWarehouse = ref('')
  58. //仓库搜索
  59. const warehouseSearch = (name) => {
  60. console.log(name)
  61. uni.$u.http.post('/app/appUser/searchGodown?name=' + name).then(res => {
  62. if (res.code == 200) {
  63. searchResults.value = res.data
  64. }
  65. })
  66. }
  67. //获取用户绑定历史
  68. const getUserBindHistory = () => {
  69. uni.$u.http.get('/app/appUser/getUserBindGodownReocrd').then(res => {
  70. if (res.code == 200) {
  71. historyWarehouses.value = res.data
  72. }
  73. })
  74. }
  75. getUserBindHistory()
  76. const handleSearch = () => {
  77. // 实现搜索逻辑
  78. warehouseSearch(searchKeyword.value)
  79. }
  80. const selectItem = ref({})
  81. const selectWarehouse = (item) => {
  82. selectedWarehouse.value = item.godownName
  83. selectItem.value = item
  84. }
  85. const handleClose = () => {
  86. emit('update:show', false)
  87. searchKeyword.value = ''
  88. }
  89. const handleConfirm = () => {
  90. if (selectedWarehouse.value) {
  91. emit('warehouse-selected', selectItem.value)
  92. handleClose()
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .warehouse-selector {
  98. padding: 30rpx;
  99. min-height: 35vh;
  100. max-height: 80vh;
  101. overflow: auto;
  102. background-color: #fff;
  103. display: flex;
  104. flex-direction: column;
  105. }
  106. .header {
  107. text-align: center;
  108. margin-bottom: 20px;
  109. .title {
  110. font-size: 18px;
  111. font-weight: 500;
  112. }
  113. }
  114. .search-box {
  115. margin-bottom: 30rpx;
  116. }
  117. .section-title {
  118. font-size: 16px;
  119. color: #666;
  120. margin-bottom: 10px;
  121. display: block;
  122. }
  123. .tag-group {
  124. display: flex;
  125. flex-wrap: wrap;
  126. gap: 10px;
  127. margin-bottom: 20px;
  128. }
  129. .footer {
  130. position: sticky;
  131. bottom: 0;
  132. padding: 20px 0;
  133. padding-bottom: 0;
  134. display: flex;
  135. justify-content: center;
  136. gap: 30rpx;
  137. }
  138. </style>