|
|
@@ -1,18 +1,17 @@
|
|
|
<template>
|
|
|
<view class="container" @click="playGlobalSound">
|
|
|
- <!-- 搜索框 -->
|
|
|
<view class="search-area">
|
|
|
<u-search v-model="searchText" placeholder="请输入仓库名称" :show-action="false" :clearabled="true"
|
|
|
@change="onSearch" height="40" placeholder-style="font-size:16px"></u-search>
|
|
|
</view>
|
|
|
|
|
|
- <!-- 仓库列表 -->
|
|
|
<view class="warehouse-list">
|
|
|
- <view v-for="(item, index) in warehouses" :key="index"
|
|
|
+ <view v-for="(item, index) in displayList" :key="item.id"
|
|
|
:class="['warehouse-item', { 'warehouse-item-active': item.id == selectedId }]"
|
|
|
hover-class="warehouse-item-hover" @click="selectWarehouse(item)">
|
|
|
- <text>{{ index + 1 }}.{{ item.godownName }}</text>
|
|
|
+ <text>{{ index + 1 }}.{{ getItemName(item) }}</text>
|
|
|
</view>
|
|
|
+ <view v-if="isRepositoryMode && !loading && displayList.length === 0" class="empty-tip">暂无仓库数据</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</template>
|
|
|
@@ -21,51 +20,100 @@
|
|
|
import { ref, computed } from 'vue'
|
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
|
|
|
|
-// 点击全局音效
|
|
|
-function playGlobalSound(){
|
|
|
+const STORAGE_KEY = 'codeStorageLastRepository'
|
|
|
+
|
|
|
+function playGlobalSound() {
|
|
|
uni.$u.playClickSound()
|
|
|
}
|
|
|
|
|
|
-// 搜索文本
|
|
|
const searchText = ref('')
|
|
|
-
|
|
|
-// 仓库列表数据
|
|
|
const warehouses = ref([])
|
|
|
+const loading = ref(false)
|
|
|
+const selectedId = ref()
|
|
|
+const pageType = ref('godown')
|
|
|
+
|
|
|
+const isRepositoryMode = computed(() => pageType.value === 'repository')
|
|
|
+
|
|
|
+const displayList = computed(() => {
|
|
|
+ if (!isRepositoryMode.value) {
|
|
|
+ return warehouses.value
|
|
|
+ }
|
|
|
+ const keyword = searchText.value.trim()
|
|
|
+ if (!keyword) return warehouses.value
|
|
|
+ return warehouses.value.filter(item => getItemName(item)?.includes(keyword))
|
|
|
+})
|
|
|
+
|
|
|
+function getItemName(item) {
|
|
|
+ return isRepositoryMode.value ? item.repositoryName : item.godownName
|
|
|
+}
|
|
|
|
|
|
-//根据name查询仓库列表 /app/appUser/searchGodown
|
|
|
-function getGodownListByName(name = "") {
|
|
|
+function getGodownListByName(name = '') {
|
|
|
uni.$u.http.post('/app/appUser/searchGodown?name=' + name).then(res => {
|
|
|
if (res.code == 200) {
|
|
|
- warehouses.value = res.data
|
|
|
+ warehouses.value = res.data || []
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
-getGodownListByName()
|
|
|
|
|
|
+function getRepositoryList() {
|
|
|
+ loading.value = true
|
|
|
+ uni.$u.http.get('/activation/bookActivationInfo/getRepositoryList').then(res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ warehouses.value = res.data || []
|
|
|
+ } else {
|
|
|
+ uni.$u.toast(res.msg || '获取仓库列表失败')
|
|
|
+ }
|
|
|
+ }).finally(() => {
|
|
|
+ loading.value = false
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
-// 搜索处理
|
|
|
-const onSearch = () => {
|
|
|
- getGodownListByName(searchText.value)
|
|
|
+function loadList() {
|
|
|
+ if (isRepositoryMode.value) {
|
|
|
+ getRepositoryList()
|
|
|
+ } else {
|
|
|
+ getGodownListByName(searchText.value)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-// 选择仓库
|
|
|
-const selectWarehouse = (item) => {
|
|
|
- // 使用事件总线传递数据
|
|
|
- uni.$emit('updateWarehouse', item)
|
|
|
+function onSearch() {
|
|
|
+ if (!isRepositoryMode.value) {
|
|
|
+ getGodownListByName(searchText.value)
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- // 返回上一页
|
|
|
+function selectWarehouse(item) {
|
|
|
+ if (isRepositoryMode.value) {
|
|
|
+ uni.$emit('updateRepository', item)
|
|
|
+ uni.setStorageSync(STORAGE_KEY, {
|
|
|
+ id: item.id,
|
|
|
+ repositoryName: item.repositoryName
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.$emit('updateWarehouse', item)
|
|
|
+ }
|
|
|
uni.navigateBack()
|
|
|
}
|
|
|
|
|
|
-const selectedId = ref()
|
|
|
onLoad((options) => {
|
|
|
- if (options.godownId) {
|
|
|
- selectedId.value = options.godownId
|
|
|
+ if (options.type === 'repository') {
|
|
|
+ pageType.value = 'repository'
|
|
|
}
|
|
|
+ if (options.repositoryId) {
|
|
|
+ selectedId.value = options.repositoryId
|
|
|
+ } else if (options.godownId) {
|
|
|
+ selectedId.value = options.godownId
|
|
|
+ }
|
|
|
+ loadList()
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
+.search-area {
|
|
|
+ padding: 12px;
|
|
|
+ background-color: #fff;
|
|
|
+}
|
|
|
+
|
|
|
.warehouse-list {
|
|
|
margin-top: 12px;
|
|
|
}
|
|
|
@@ -85,4 +133,11 @@ onLoad((options) => {
|
|
|
.warehouse-item-hover {
|
|
|
background-color: #f5f5f5;
|
|
|
}
|
|
|
-</style>
|
|
|
+
|
|
|
+.empty-tip {
|
|
|
+ text-align: center;
|
|
|
+ padding: 40px 0;
|
|
|
+ color: #999;
|
|
|
+ font-size: 14px;
|
|
|
+}
|
|
|
+</style>
|