|
|
@@ -21,9 +21,7 @@
|
|
|
<div v-if="loading" style="text-align: center; color: #969799; padding: 10px 0;">加载中...</div>
|
|
|
<van-empty v-if="columns.length === 0 && !loading" description="暂无数据" />
|
|
|
</div>
|
|
|
- <div
|
|
|
- style="padding: 10px 16px; border-top: 1px solid #ebedf0; display: flex; flex-direction: column; gap: 8px;"
|
|
|
- >
|
|
|
+ <div style="padding: 10px 16px; border-top: 1px solid #ebedf0; display: flex; flex-direction: column; gap: 8px;">
|
|
|
<van-button type="default" block :disabled="noMore || loading" @click="loadMore">
|
|
|
{{ noMore ? '没有更多数据' : '加载更多' }}
|
|
|
</van-button>
|
|
|
@@ -34,10 +32,11 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { showFailToast } from 'vant';
|
|
|
+import { showFailToast, showToast } from 'vant';
|
|
|
import { ajaxApiGet } from '../common/utils';
|
|
|
import { processException } from '../common/Common.js';
|
|
|
import { ref, watch, computed, onMounted, defineProps, defineEmits, defineExpose } from 'vue';
|
|
|
+import { useRoute } from 'vue-router';
|
|
|
|
|
|
const props = defineProps({
|
|
|
show: {
|
|
|
@@ -65,6 +64,19 @@ const props = defineProps({
|
|
|
type: Boolean,
|
|
|
default: true,
|
|
|
},
|
|
|
+ isDefault: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false,
|
|
|
+ },
|
|
|
+ // 父组件 van-dialog 显示状态,用于控制何时执行默认选择逻辑
|
|
|
+ dialogShow: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false,
|
|
|
+ },
|
|
|
+ type: {
|
|
|
+ type: String,
|
|
|
+ default: '',
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
const emit = defineEmits([
|
|
|
@@ -82,9 +94,12 @@ const loading = ref(false);
|
|
|
const noMore = ref(false);
|
|
|
const selectedId = ref(props.defaultSelectedId);
|
|
|
const selectedItem = ref(null);
|
|
|
+const defaultApplied = ref(false);
|
|
|
+const route = useRoute();
|
|
|
+const warehouseId = ref(route.query.warehouseId || '');
|
|
|
|
|
|
// 计算属性
|
|
|
-const title = computed(() =>{
|
|
|
+const title = computed(() => {
|
|
|
const titleMap = {
|
|
|
stockIn: {
|
|
|
transfer: '选择中转区货位',
|
|
|
@@ -123,8 +138,10 @@ const apiUrl = computed(() => {
|
|
|
// 监听props变化
|
|
|
watch(() => props.show, newVal => {
|
|
|
visible.value = newVal;
|
|
|
- if (newVal && columns.value.length === 0) {
|
|
|
- getPositionData();
|
|
|
+ if (newVal) {
|
|
|
+ if (columns.value.length === 0) {
|
|
|
+ getPositionData();
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -138,6 +155,13 @@ watch(() => props.defaultSelectedId, newVal => {
|
|
|
selectedId.value = newVal;
|
|
|
});
|
|
|
|
|
|
+// 当父级对话框显示时触发加载并应用默认选择逻辑(仅在 type 为 stockIn 时)
|
|
|
+watch(() => props.dialogShow, (newVal, oldVal) => {
|
|
|
+ if (props.type === 'stockIn' && newVal && newVal !== oldVal) {
|
|
|
+ getPositionData(true);
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
// 搜索
|
|
|
const onSearch = () => {
|
|
|
getPositionData(true);
|
|
|
@@ -156,14 +180,16 @@ const getPositionData = (isReset = true) => {
|
|
|
currentPage.value = 1;
|
|
|
columns.value = [];
|
|
|
noMore.value = false;
|
|
|
+ // 重置默认选择已应用标记
|
|
|
+ defaultApplied.value = false;
|
|
|
}
|
|
|
|
|
|
loading.value = true;
|
|
|
const start = (currentPage.value - 1) * props.pageSize;
|
|
|
const length = props.pageSize;
|
|
|
const filter = searchKey.value;
|
|
|
-
|
|
|
- ajaxApiGet(`${apiUrl.value}?start=${start}&length=${length}&filter=${filter}`).then(
|
|
|
+ let url = apiUrl.value + '?start=' + start + '&length=' + length + '&filter=' + filter + '&warehouseId=' + warehouseId.value;
|
|
|
+ ajaxApiGet(url).then(
|
|
|
success => {
|
|
|
loading.value = false;
|
|
|
const { errorCode, errorMessage, datas, total } = success;
|
|
|
@@ -179,8 +205,24 @@ const getPositionData = (isReset = true) => {
|
|
|
|
|
|
columns.value = [...columns.value, ...newColumns];
|
|
|
noMore.value = columns.value.length >= total;
|
|
|
+
|
|
|
+ // 如果需要默认加载且尚未应用默认值,则选中第一项并通知父组件
|
|
|
+ if (isReset && props.isDefault && !defaultApplied.value) {
|
|
|
+ const first = columns.value[0];
|
|
|
+ if (first) {
|
|
|
+ selectedId.value = first.value;
|
|
|
+ selectedItem.value = first;
|
|
|
+ emit('confirm', first);
|
|
|
+ defaultApplied.value = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
noMore.value = true;
|
|
|
+ // 当需要默认选择但没有可用数据时,提示无空闲货位
|
|
|
+ if (isReset && props.isDefault && !defaultApplied.value) {
|
|
|
+ showToast('当前仓库暂无空闲货位');
|
|
|
+ defaultApplied.value = true;
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
noMore.value = true;
|
|
|
@@ -223,10 +265,10 @@ const clearSelected = () => {
|
|
|
selectedItem.value = null;
|
|
|
};
|
|
|
|
|
|
-// 组件挂载时,如果show为true则加载数据
|
|
|
+// 组件挂载时:当 type 为 stockInPhoto 时,直接加载并应用默认逻辑
|
|
|
onMounted(() => {
|
|
|
- if (props.show) {
|
|
|
- getPositionData();
|
|
|
+ if (props.type === 'stockInPhoto') {
|
|
|
+ getPositionData(true);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -238,18 +280,18 @@ defineExpose({
|
|
|
<style scoped>
|
|
|
/* 使用深度选择器确保 van-search 样式不受影响 */
|
|
|
:deep(.van-search) {
|
|
|
- padding: 8px 12px;
|
|
|
+ padding: 8px 12px;
|
|
|
}
|
|
|
|
|
|
:deep(.van-cell) {
|
|
|
- align-items: center;
|
|
|
+ align-items: center;
|
|
|
}
|
|
|
|
|
|
:deep(.van-radio) {
|
|
|
- margin-right: 0;
|
|
|
+ margin-right: 0;
|
|
|
}
|
|
|
|
|
|
:deep(.van-button) {
|
|
|
- margin-bottom: 8px;
|
|
|
+ margin-bottom: 8px;
|
|
|
}
|
|
|
</style>
|