init
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<s-pages class="set-wrap" title="搜索" color="#ffffff">
|
||||
<card_search :modelValue="searchText" class="goods_search" @search="search"></card_search>
|
||||
|
||||
<pages_commodity
|
||||
class="commodity"
|
||||
ref="pageCommodity"
|
||||
:dataList="dataObj.dataList"
|
||||
@getData="getData"
|
||||
:subclassification="subclassification"
|
||||
:height="height"
|
||||
source="search"
|
||||
:type="2"
|
||||
></pages_commodity>
|
||||
</s-pages>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import SpuApi from '@/sheep/api/product/spu';
|
||||
import CategoryApi from '@/sheep/api/product/category';
|
||||
import { handleTree } from '@/sheep/helper/utils';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
let pageCommodity = ref(null);
|
||||
let height = ref('100%');
|
||||
let sysInfo = uni.getSystemInfoSync();
|
||||
const windowHeight = sysInfo.windowHeight;
|
||||
height.value =
|
||||
windowHeight -
|
||||
sysInfo.statusBarHeight -
|
||||
uni.upx2px(88) -
|
||||
uni.upx2px(80) -
|
||||
uni.upx2px(96) +
|
||||
'px';
|
||||
const subclassification = ref([]);
|
||||
const dataObj = reactive({
|
||||
categoryList: [], // 商品分类树
|
||||
dataList: [], // 商品列表
|
||||
});
|
||||
const getData = async (mescroll) => {
|
||||
let res = await SpuApi.getSpuPage({
|
||||
pageNo: mescroll?.num || 1,
|
||||
pageSize: mescroll?.size || 10,
|
||||
keyword: searchText.value,
|
||||
...mescroll.params,
|
||||
});
|
||||
if (res.code !== 0) {
|
||||
pageCommodity.value.requestResult(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const curPageData = res.data.list || []; // 当前页数据
|
||||
// if (curPageData.length) {
|
||||
// curPageData.forEach((item) => {
|
||||
// item.categoryText = changeArr(item.categoryId, dataObj.categoryList);
|
||||
// });
|
||||
// }
|
||||
if (mescroll?.num == 1) dataObj.dataList = []; // 第一页需手动制空列表
|
||||
dataObj.dataList = dataObj.dataList.concat(curPageData); //追加新数据
|
||||
// mescroll.endSuccess(curPageData.length); // 请求成功, 结束加载
|
||||
pageCommodity.value.requestResult(true, curPageData.length);
|
||||
};
|
||||
let searchText = ref(null);
|
||||
const search = (text) => {
|
||||
searchText.value = text;
|
||||
pageCommodity.value.changeData();
|
||||
};
|
||||
// 获取分类
|
||||
const getcategoryList = async () => {
|
||||
const { code, data } = await CategoryApi.getCategoryList();
|
||||
if (code !== 0) {
|
||||
return;
|
||||
}
|
||||
// dataObj.categoryList = data;
|
||||
dataObj.categoryList = handleTree(data);
|
||||
console.log(dataObj.categoryList);
|
||||
if (dataObj.categoryList.length) {
|
||||
dataObj.c_id = dataObj.categoryList[0].id;
|
||||
}
|
||||
classifyChange(0);
|
||||
};
|
||||
const classifyChange = (i) => {
|
||||
dataObj.index = i;
|
||||
dataObj.c_id = dataObj.categoryList[i]?.id;
|
||||
subclassification.value = dataObj.categoryList[i]?.children || [];
|
||||
|
||||
// upCallback({
|
||||
// num: 1,
|
||||
// size: 10,
|
||||
// });
|
||||
|
||||
// pageCommodity.value.changeData()
|
||||
if (pageCommodity.value) {
|
||||
pageCommodity.value.clearAll();
|
||||
}
|
||||
};
|
||||
onLoad(async (e) => {
|
||||
searchText.value = e.keyword || '';
|
||||
let res = await getcategoryList();
|
||||
// upCallback();
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.goods_search {
|
||||
padding: 0 32rpx;
|
||||
box-sizing: border-box;
|
||||
background-color: #fff;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user