feat: 首页改造
This commit is contained in:
@@ -7,24 +7,6 @@
|
||||
<text class="text-28 text-fu" style="margin-left: 12rpx">搜索</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 原来的tab切换 -->
|
||||
<!-- <view class="tab-view">
|
||||
<view
|
||||
class="tab-list"
|
||||
@click="onTab(index)"
|
||||
v-for="(item, index) in tabList"
|
||||
:key="index"
|
||||
>
|
||||
<text
|
||||
class="text-28 text-space"
|
||||
:style="{
|
||||
color: curTab == index ? '#7A35F6' : '#666',
|
||||
}"
|
||||
>{{ item.name }}</text
|
||||
>
|
||||
<view class="line" v-if="curTab == index"></view>
|
||||
</view>
|
||||
</view> -->
|
||||
<view class="tab-box">
|
||||
<view
|
||||
class="tab-item"
|
||||
@@ -33,7 +15,7 @@
|
||||
@click="onTab(index)"
|
||||
>
|
||||
<image
|
||||
:src="curTab == index ? item.img : item.greyImg"
|
||||
:src="curTab == index ? item.icon : item.icon"
|
||||
mode="aspectFill"
|
||||
class="tab-img"
|
||||
></image>
|
||||
@@ -89,46 +71,22 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { toRaw } from "vue";
|
||||
import { getCascadeCategory } from "@/api/common.js";
|
||||
import Header from "@/components/common/header.vue";
|
||||
import TopSafe from "@/components/common/top-safe.nvue";
|
||||
import MyBtn from "@/components/common/my-btn.vue";
|
||||
import PingItem from "@/components/shop/ping-item.vue";
|
||||
import { searchList } from "@/api/product.js";
|
||||
import { searchList,getGoodsTags } from "@/api/product.js";
|
||||
import CustomTabBar from "@/components/custom-tab-bar.vue";
|
||||
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
|
||||
import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue";
|
||||
|
||||
export default {
|
||||
mixins: [MescrollMixin],
|
||||
components: { Header, TopSafe, MyBtn, PingItem, CustomTabBar, MescrollUni },
|
||||
components: { Header, TopSafe, MyBtn,PingItem, CustomTabBar, MescrollUni },
|
||||
data() {
|
||||
return {
|
||||
dataList: [],
|
||||
tabList: [{ name: "推荐" }],
|
||||
tabArr: [
|
||||
{
|
||||
img: "/static/common/xrjx.png",
|
||||
greyImg: "/static/common/xrjx_grey.png",
|
||||
name: "信任精选",
|
||||
},
|
||||
{
|
||||
img: "/static/common/cdjk.png",
|
||||
greyImg: "/static/common/cdjk_grey.png",
|
||||
name: "吃的健康",
|
||||
},
|
||||
{
|
||||
img: "/static/common/qwhb.png",
|
||||
greyImg: "/static/common/qwhb_grey.png",
|
||||
name: "全网爆款",
|
||||
},
|
||||
{
|
||||
img: "/static/common/yxhw.png",
|
||||
greyImg: "/static/common/yxhw_grey.png",
|
||||
name: "严选好物",
|
||||
},
|
||||
],
|
||||
tabArr: [ ],
|
||||
curTab: 0,
|
||||
upOption: {
|
||||
auto: false,
|
||||
@@ -152,10 +110,51 @@ export default {
|
||||
mescroll: null,
|
||||
};
|
||||
},
|
||||
onLoad() {
|
||||
onLoad(options) {
|
||||
this.init();
|
||||
if(options.index){
|
||||
this.curTab = options.index;
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
if (this.tabArr.length > 0) {
|
||||
const sortParams = uni.getStorageSync('sortParams');
|
||||
if (sortParams) {
|
||||
uni.removeStorageSync('sortParams');
|
||||
const targetIndex = this.tabArr.findIndex(item => item.name === sortParams.value);
|
||||
if (targetIndex !== -1 && targetIndex !== this.curTab) {
|
||||
this.curTab = targetIndex;
|
||||
this.dataList = [];
|
||||
this.downCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 查询分类列表
|
||||
*/
|
||||
async getSortList() {
|
||||
const resp = await getGoodsTags({ type: 5 });
|
||||
if (resp && resp.bizcode === 100) {
|
||||
this.tabArr = resp.data.sort((a, b) => a.sort - b.sort);
|
||||
this.$nextTick(() => {
|
||||
this.applySortParams();
|
||||
this.downCallback();
|
||||
});
|
||||
}
|
||||
},
|
||||
applySortParams() {
|
||||
const sortParams = uni.getStorageSync('sortParams');
|
||||
if (sortParams && this.tabArr.length > 0) {
|
||||
uni.removeStorageSync('sortParams');
|
||||
const targetIndex = this.tabArr.findIndex(item => item.name === sortParams.value);
|
||||
if (targetIndex !== -1 && targetIndex !== this.curTab) {
|
||||
this.curTab = targetIndex;
|
||||
this.dataList = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
mescrollInit(mescroll) {
|
||||
this.mescroll = mescroll;
|
||||
},
|
||||
@@ -167,16 +166,14 @@ export default {
|
||||
type: 2,
|
||||
page: page.num,
|
||||
pageSize: page.size,
|
||||
isPar: true,
|
||||
isPar: true
|
||||
};
|
||||
if (this.curTab != 0) {
|
||||
params["categoryId"] = this.tabList[this.curTab].id;
|
||||
if (this.tabArr.length > 0 && this.tabArr[this.curTab]) {
|
||||
params["tag"] = this.tabArr[this.curTab].id;
|
||||
}
|
||||
searchList(params).then((res) => {
|
||||
let curPageLen = res.data.length;
|
||||
if (page.num === 1) this.dataList = [];
|
||||
this.dataList = this.dataList.concat(res.data);
|
||||
console.log(this.dataList);
|
||||
|
||||
this.waterfall();
|
||||
this.mescroll.endBySize(curPageLen, res.data.total);
|
||||
@@ -187,16 +184,6 @@ export default {
|
||||
this.mescroll && this.mescroll.resetUpScroll();
|
||||
});
|
||||
},
|
||||
async cascadeCategory() {
|
||||
getCascadeCategory({ parentId: 0 }).then((res) => {
|
||||
if (res && res.bizcode === 100) {
|
||||
res.data.forEach((item) => {
|
||||
this.tabList.push(item);
|
||||
});
|
||||
this.downCallback();
|
||||
}
|
||||
});
|
||||
},
|
||||
onTab(index) {
|
||||
if (index != this.curTab) {
|
||||
this.curTab = index;
|
||||
@@ -204,20 +191,17 @@ export default {
|
||||
this.downCallback();
|
||||
}
|
||||
},
|
||||
init() {
|
||||
this.cascadeCategory();
|
||||
init() {;
|
||||
this.getSortList();
|
||||
},
|
||||
async getSearchList() {
|
||||
const params = {
|
||||
type: 2,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
isPar: true,
|
||||
};
|
||||
if (this.curTab != 0) {
|
||||
params["categoryId"] = this.tabList[this.curTab].id;
|
||||
} else {
|
||||
params["isRecomm"] = true;
|
||||
if (this.tabArr.length > 0 && this.tabArr[this.curTab]) {
|
||||
params["type"] = this.tabArr[this.curTab].id;
|
||||
}
|
||||
const resp = await searchList(params);
|
||||
if (resp && resp.bizcode === 100) {
|
||||
|
||||
Reference in New Issue
Block a user