|
|
@@ -128,7 +128,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import {computed, ref,watch} from 'vue'
|
|
|
+import {computed, ref,watch,onUnmounted} from 'vue'
|
|
|
import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
|
|
|
import { productsList, productPutOnShell, productOffShell, productDelete, batchStatus } from "@/api/merchant.js";
|
|
|
import { useAppStore } from "@/stores/app";
|
|
|
@@ -147,6 +147,11 @@ const tabList = ref([
|
|
|
const searchVal = ref('')
|
|
|
const goodsList = ref([]);
|
|
|
const goodType = ref(1);
|
|
|
+
|
|
|
+// 防抖定时器和请求状态
|
|
|
+const searchTimer = ref(null);
|
|
|
+const isLoading = ref(false); // 防止重复请求
|
|
|
+
|
|
|
// Pagination
|
|
|
const params = ref({
|
|
|
page: 1,
|
|
|
@@ -331,7 +336,23 @@ const tabChange = (item) => {
|
|
|
resetSelection();
|
|
|
}
|
|
|
|
|
|
-const onSearch = () => {
|
|
|
+const onSearch = (e) => {
|
|
|
+ console.log(e)
|
|
|
+ // 如果是input事件,只处理键盘输入,不直接触发搜索
|
|
|
+ if (e && e.type === 'input') {
|
|
|
+ clearTimeout(searchTimer.value);
|
|
|
+ searchTimer.value = setTimeout(() => {
|
|
|
+ doSearch();
|
|
|
+ }, 500); // 防抖500ms
|
|
|
+ } else {
|
|
|
+ // 如果是confirm事件,立即搜索
|
|
|
+ clearTimeout(searchTimer.value);
|
|
|
+ doSearch();
|
|
|
+ }
|
|
|
+}
|
|
|
+const doSearch = () => {
|
|
|
+ if (isLoading.value) return; // 防止重复请求
|
|
|
+
|
|
|
goodsList.value = [];
|
|
|
loading.value = false;
|
|
|
goodScroll.value = true;
|
|
|
@@ -341,17 +362,18 @@ const onSearch = () => {
|
|
|
footerswitch.value = true;
|
|
|
resetSelection();
|
|
|
}
|
|
|
-
|
|
|
// 清除搜索内容
|
|
|
const onClear = () => {
|
|
|
console.log('清除搜索内容');
|
|
|
searchVal.value = '';
|
|
|
- onSearch();
|
|
|
+ clearTimeout(searchTimer.value);
|
|
|
+ doSearch(); // 直接搜索,不需要防抖
|
|
|
}
|
|
|
-
|
|
|
const getGroomList = async () => {
|
|
|
if (!goodScroll.value) return;
|
|
|
+ if (isLoading.value) return; // 防止重复请求
|
|
|
try {
|
|
|
+ isLoading.value = true;
|
|
|
loading.value = true;
|
|
|
params.value.merchantId = merchantInfo.value.id;
|
|
|
params.value.keyword = searchVal.value;
|
|
|
@@ -370,6 +392,7 @@ const getGroomList = async () => {
|
|
|
console.error(err);
|
|
|
} finally {
|
|
|
loading.value = false;
|
|
|
+ isLoading.value = false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -430,14 +453,22 @@ const goDetail = async (item) => {
|
|
|
isAllSelect.value = goodsList.value.length === selectValue.value.length;
|
|
|
return
|
|
|
}
|
|
|
- uni.navigateTo({
|
|
|
- url: "/pages/goods/goods_details/index?id="+item.id
|
|
|
- })
|
|
|
+ if(item.isShow){
|
|
|
+ uni.navigateTo({
|
|
|
+ url: "/pages/goods/goods_details/index?id="+item.id
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ uni.showToast({title:'商品已下架',icon:'none'})
|
|
|
+ }
|
|
|
+
|
|
|
};
|
|
|
|
|
|
onReachBottom(() => {
|
|
|
getGroomList();
|
|
|
});
|
|
|
+onUnmounted(() => {
|
|
|
+ clearTimeout(searchTimer.value);
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|