增加新功能
This commit is contained in:
+80
-20
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const common_classify_data = require("../../common/classify.data.js");
|
||||
const api_common = require("../../api/common.js");
|
||||
const _sfc_main = {
|
||||
data() {
|
||||
return {
|
||||
@@ -8,15 +9,33 @@ const _sfc_main = {
|
||||
tabbar: common_classify_data.classifyData,
|
||||
scrollTop: 0,
|
||||
//tab标题的滚动条位置
|
||||
current: 0,
|
||||
current: null,
|
||||
// 预设当前项的值
|
||||
menuHeight: 0,
|
||||
// 左边菜单的高度
|
||||
menuItemHeight: 0,
|
||||
// 左边菜单item的高度
|
||||
bannerList: ["/static/common/product_def_banner.png", "/static/common/product_def_banner.png", "/static/common/product_def_banner.png"]
|
||||
bannerList: [
|
||||
"/static/common/product_def_banner.png",
|
||||
"/static/common/product_def_banner.png",
|
||||
"/static/common/product_def_banner.png"
|
||||
],
|
||||
tabbarList: [],
|
||||
// 左侧的主分类
|
||||
tabbarContentList: [],
|
||||
// 右侧内容的分类
|
||||
tabbarContentLoading: false
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.getSort(0).then((resp) => {
|
||||
if (resp && resp.length !== 0) {
|
||||
const fData = resp[0];
|
||||
this.tabbarList = resp;
|
||||
this.swichMenu(fData, 0);
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
checkCategory(val) {
|
||||
this.selCategory = val;
|
||||
@@ -26,19 +45,38 @@ const _sfc_main = {
|
||||
url: "/pages/search/search"
|
||||
});
|
||||
},
|
||||
// 查询分类
|
||||
async getSort(pId) {
|
||||
const params = {
|
||||
parentId: pId
|
||||
};
|
||||
const resp = await api_common.getCascadeCategory(params);
|
||||
if (resp && resp.bizcode === 100) {
|
||||
return resp.data;
|
||||
}
|
||||
return [];
|
||||
},
|
||||
getImg() {
|
||||
return Math.floor(Math.random() * 35);
|
||||
},
|
||||
// 点击左边的栏目切换
|
||||
async swichMenu(index) {
|
||||
async swichMenu(item, index) {
|
||||
if (index == this.current)
|
||||
return;
|
||||
this.tabbarContentLoading = true;
|
||||
const firstData = await this.getSort(item.id);
|
||||
for (let fItem of firstData) {
|
||||
const twoData = await this.getSort(fItem.id);
|
||||
fItem.foods = twoData;
|
||||
}
|
||||
this.tabbarContentList = firstData;
|
||||
this.current = index;
|
||||
if (this.menuHeight == 0 || this.menuItemHeight == 0) {
|
||||
await this.getElRect("menu-scroll-view", "menuHeight");
|
||||
await this.getElRect("u-tab-item", "menuItemHeight");
|
||||
}
|
||||
this.scrollTop = index * this.menuItemHeight + this.menuItemHeight / 2 - this.menuHeight / 2;
|
||||
this.tabbarContentLoading = false;
|
||||
},
|
||||
// 获取一个目标元素的高度
|
||||
getElRect(elClass, dataVal) {
|
||||
@@ -54,18 +92,29 @@ const _sfc_main = {
|
||||
this[dataVal] = res.height;
|
||||
}).exec();
|
||||
});
|
||||
},
|
||||
// 跳转到搜索页面
|
||||
jumpProduct(item) {
|
||||
common_vendor.index.navigateTo({
|
||||
url: "/pages/search/search?categoryId=" + item.id
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!Array) {
|
||||
const _easycom_up_search2 = common_vendor.resolveComponent("up-search");
|
||||
const _easycom_up_swiper2 = common_vendor.resolveComponent("up-swiper");
|
||||
(_easycom_up_search2 + _easycom_up_swiper2)();
|
||||
const _easycom_up_loading_page2 = common_vendor.resolveComponent("up-loading-page");
|
||||
const _easycom_up_image2 = common_vendor.resolveComponent("up-image");
|
||||
const _component_template = common_vendor.resolveComponent("template");
|
||||
(_easycom_up_search2 + _easycom_up_swiper2 + _easycom_up_loading_page2 + _easycom_up_image2 + _component_template)();
|
||||
}
|
||||
const _easycom_up_search = () => "../../uni_modules/uview-plus/components/u-search/u-search.js";
|
||||
const _easycom_up_swiper = () => "../../uni_modules/uview-plus/components/u-swiper/u-swiper.js";
|
||||
const _easycom_up_loading_page = () => "../../uni_modules/uview-plus/components/u-loading-page/u-loading-page.js";
|
||||
const _easycom_up_image = () => "../../uni_modules/uview-plus/components/u-image/u-image.js";
|
||||
if (!Math) {
|
||||
(_easycom_up_search + _easycom_up_swiper)();
|
||||
(_easycom_up_search + _easycom_up_swiper + _easycom_up_loading_page + _easycom_up_image)();
|
||||
}
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return common_vendor.e({
|
||||
@@ -85,34 +134,45 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
placeholder: "搜索"
|
||||
}),
|
||||
h: common_vendor.o((...args) => $options.jumpSearch && $options.jumpSearch(...args)),
|
||||
i: common_vendor.f($data.tabbar, (item, index, i0) => {
|
||||
i: common_vendor.f($data.tabbarList, (item, index, i0) => {
|
||||
return {
|
||||
a: common_vendor.t(item.name),
|
||||
b: index,
|
||||
c: common_vendor.n($data.current == index ? "u-tab-item-active" : ""),
|
||||
d: index,
|
||||
e: common_vendor.o(($event) => $options.swichMenu(index), index)
|
||||
e: common_vendor.o(($event) => $options.swichMenu(item, index), index)
|
||||
};
|
||||
}),
|
||||
j: $data.scrollTop,
|
||||
k: common_vendor.f($data.tabbar, (item, index, i0) => {
|
||||
k: common_vendor.p({
|
||||
list: $data.bannerList,
|
||||
height: "80px"
|
||||
}),
|
||||
l: common_vendor.p({
|
||||
loading: $data.tabbarContentLoading
|
||||
}),
|
||||
m: common_vendor.f($data.tabbarContentList, (item, index, i0) => {
|
||||
return common_vendor.e({
|
||||
a: $data.current == index
|
||||
}, $data.current == index ? {
|
||||
b: "1255c49a-1-" + i0,
|
||||
c: common_vendor.p({
|
||||
list: $data.bannerList,
|
||||
height: "80px"
|
||||
}),
|
||||
d: common_vendor.t(item.name),
|
||||
e: common_vendor.f(item.foods, (item1, index1, i1) => {
|
||||
a: common_vendor.t(item.name),
|
||||
b: item.foods && item.foods.length !== 0
|
||||
}, item.foods && item.foods.length !== 0 ? {
|
||||
c: common_vendor.f(item.foods, (item1, index1, i1) => {
|
||||
return {
|
||||
a: item1.icon,
|
||||
a: item1.icon ? item1.icon : "/static/common/def_img.jpg",
|
||||
b: common_vendor.t(item1.name),
|
||||
c: index1
|
||||
c: index1,
|
||||
d: common_vendor.o(($event) => $options.jumpProduct(item1), index1)
|
||||
};
|
||||
})
|
||||
} : {}, {
|
||||
} : {
|
||||
d: "1255c49a-3-" + i0,
|
||||
e: common_vendor.p({
|
||||
src: "/static/common/not_shopping.png",
|
||||
width: "100",
|
||||
height: "100",
|
||||
bgColor: "#f1f6ff00"
|
||||
})
|
||||
}, {
|
||||
f: index
|
||||
});
|
||||
})
|
||||
|
||||
+3
-1
@@ -2,6 +2,8 @@
|
||||
"navigationStyle": "custom",
|
||||
"usingComponents": {
|
||||
"up-search": "../../uni_modules/uview-plus/components/u-search/u-search",
|
||||
"up-swiper": "../../uni_modules/uview-plus/components/u-swiper/u-swiper"
|
||||
"up-swiper": "../../uni_modules/uview-plus/components/u-swiper/u-swiper",
|
||||
"up-loading-page": "../../uni_modules/uview-plus/components/u-loading-page/u-loading-page",
|
||||
"up-image": "../../uni_modules/uview-plus/components/u-image/u-image"
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
<view class="sort_warp data-v-1255c49a"><view class="sort_header data-v-1255c49a"><view class="sort_category_header data-v-1255c49a"><view class="{{['data-v-1255c49a', b]}}" bindtap="{{c}}"><view class="data-v-1255c49a">分类</view><view wx:if="{{a}}" class="category_item_sel_but data-v-1255c49a"></view></view><view class="{{['data-v-1255c49a', e]}}" bindtap="{{f}}"><view class="data-v-1255c49a">品牌</view><view wx:if="{{d}}" class="category_item_sel_but data-v-1255c49a"></view></view></view><view class="data-v-1255c49a" style="width:200rpx" bindtap="{{h}}"><up-search wx:if="{{g}}" class="data-v-1255c49a" u-i="1255c49a-0" bind:__l="__l" u-p="{{g}}"></up-search></view></view><view class="u-menu-wrap data-v-1255c49a"><scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view data-v-1255c49a" scroll-top="{{j}}"><view wx:for="{{i}}" wx:for-item="item" wx:key="b" class="{{['u-tab-item', 'data-v-1255c49a', item.c]}}" data-current="{{item.d}}" catchtap="{{item.e}}"><text class="u-line-1 data-v-1255c49a">{{item.a}}</text></view></scroll-view><block wx:for="{{k}}" wx:for-item="item" wx:key="f"><scroll-view wx:if="{{item.a}}" scroll-y class="right-box data-v-1255c49a"><view class="data-v-1255c49a" style="padding:0rpx 20rpx"><up-swiper wx:if="{{item.c}}" class="data-v-1255c49a" u-i="{{item.b}}" bind:__l="__l" u-p="{{item.c}}"></up-swiper></view><view class="page-view data-v-1255c49a"><view class="class-item data-v-1255c49a"><view class="item-title data-v-1255c49a"><text class="data-v-1255c49a">{{item.d}}</text></view><view class="item-container data-v-1255c49a"><view wx:for="{{item.e}}" wx:for-item="item1" wx:key="c" class="thumb-box data-v-1255c49a"><image class="item-menu-image data-v-1255c49a" src="{{item1.a}}" mode=""></image><view class="item-menu-name data-v-1255c49a">{{item1.b}}</view></view></view></view></view></scroll-view></block></view></view>
|
||||
<view class="sort_warp data-v-1255c49a"><view class="sort_header data-v-1255c49a"><view class="sort_category_header data-v-1255c49a"><view class="{{['data-v-1255c49a', b]}}" bindtap="{{c}}"><view class="data-v-1255c49a">分类</view><view wx:if="{{a}}" class="category_item_sel_but data-v-1255c49a"></view></view><view class="{{['data-v-1255c49a', e]}}" bindtap="{{f}}"><view class="data-v-1255c49a">品牌</view><view wx:if="{{d}}" class="category_item_sel_but data-v-1255c49a"></view></view></view><view class="data-v-1255c49a" style="width:200rpx" bindtap="{{h}}"><up-search wx:if="{{g}}" class="data-v-1255c49a" u-i="1255c49a-0" bind:__l="__l" u-p="{{g}}"></up-search></view></view><view class="u-menu-wrap data-v-1255c49a"><scroll-view scroll-y scroll-with-animation class="u-tab-view menu-scroll-view data-v-1255c49a" scroll-top="{{j}}"><view wx:for="{{i}}" wx:for-item="item" wx:key="b" class="{{['u-tab-item', 'data-v-1255c49a', item.c]}}" data-current="{{item.d}}" catchtap="{{item.e}}"><text class="u-line-1 data-v-1255c49a">{{item.a}}</text></view></scroll-view><block class="data-v-1255c49a" u-s="{{['d']}}"><scroll-view scroll-y class="right-box data-v-1255c49a"><view class="data-v-1255c49a" style="padding:0rpx 20rpx"><up-swiper wx:if="{{k}}" class="data-v-1255c49a" u-i="1255c49a-1" bind:__l="__l" u-p="{{k}}"></up-swiper></view><view class="page-view data-v-1255c49a"><up-loading-page wx:if="{{l}}" class="data-v-1255c49a" u-i="1255c49a-2" bind:__l="__l" u-p="{{l}}"></up-loading-page><view wx:for="{{m}}" wx:for-item="item" wx:key="f" class="class-item data-v-1255c49a"><view class="item-title data-v-1255c49a"><text class="data-v-1255c49a">{{item.a}}</text></view><view wx:if="{{item.b}}" class="item-container data-v-1255c49a"><view wx:for="{{item.c}}" wx:for-item="item1" wx:key="c" class="thumb-box data-v-1255c49a" bindtap="{{item1.d}}"><image class="item-menu-image data-v-1255c49a" src="{{item1.a}}" mode=""></image><view class="item-menu-name data-v-1255c49a">{{item1.b}}</view></view></view><view wx:else class="not_order_warp data-v-1255c49a"><view class="not_order_warp_img data-v-1255c49a"><up-image wx:if="{{item.e}}" class="data-v-1255c49a" u-i="{{item.d}}" bind:__l="__l" u-p="{{item.e}}"></up-image></view><view class="not_order_msg_warp data-v-1255c49a">暂无分类,快去添加吧~</view></view></view></view></scroll-view></block></view></view>
|
||||
+3
-2
@@ -127,6 +127,7 @@
|
||||
font-weight: normal;
|
||||
font-size: 24rpx;
|
||||
color: #303133;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
.item-container.data-v-1255c49a {
|
||||
display: flex;
|
||||
@@ -141,6 +142,6 @@
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
.item-menu-image.data-v-1255c49a {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
width: 110rpx;
|
||||
height: 110rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user