197 行
4.7 KiB
Vue
197 行
4.7 KiB
Vue
<template>
|
||
<!-- 产品分类导航(金刚区) -->
|
||
<view class="wrap" style="margin: 0 20rpx;overflow: hidden;border-radius: 16rpx;transform: translateY(0);">
|
||
<view class="menu-category-box u-m-b-10" :style="displayList.length <= oneRowNum ? `height:180rpx;overflow: hidden;border-radius: 16rpx;transform: translateY(0);` : `height:380rpx;overflow: hidden;border-radius: 16rpx;transform: translateY(0);`">
|
||
<view class="menu-tab-box u-flex u-flex-wrap">
|
||
<view
|
||
class="tab-list u-flex-col u-col-center u-row-center"
|
||
:style="{ width: 100 / oneRowNum + '%' }"
|
||
v-for="(item, index) in displayList"
|
||
:key="index"
|
||
@tap="onItemClick(item)"
|
||
>
|
||
<template v-if="item.isMore">
|
||
<view class="more-icon-box u-flex u-row-center u-col-center">
|
||
<u-icon name="grid-fill" color="#4C7AF3" size="46"></u-icon>
|
||
</view>
|
||
<text class="tab-title">更多</text>
|
||
</template>
|
||
<template v-else>
|
||
<image class="tab-img" :src="item.image" mode="aspectFill"></image>
|
||
<text class="tab-title">{{ item.name }}</text>
|
||
</template>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import { mapGetters } from 'vuex';
|
||
|
||
/**
|
||
* shGridSwiper-金刚区宫格列表(默认2排,多余显示“更多”,点击“更多”新页面打开)
|
||
* @property {Array} list - 列表数据
|
||
* @property {Number|String} oneRowNum - 单行数量(默认5)
|
||
*/
|
||
export default {
|
||
name: 'shGridSwiper',
|
||
components: {},
|
||
data() {
|
||
return {};
|
||
},
|
||
props: {
|
||
list: {
|
||
type: Array,
|
||
default: () => {
|
||
return [];
|
||
}
|
||
},
|
||
oneRowNum: {
|
||
type: [Number, String],
|
||
default: 5
|
||
}
|
||
},
|
||
computed: {
|
||
...mapGetters(['userInfo']),
|
||
// 过滤不需要权限显示的菜单(如开启直播)
|
||
filteredList() {
|
||
if (!this.list || !this.list.length) return [];
|
||
if (this.userInfo && this.userInfo.is_live == 1) {
|
||
return this.list;
|
||
} else {
|
||
return this.list.filter(item => item.name !== '开启直播');
|
||
}
|
||
},
|
||
maxDisplayCount() {
|
||
return Number(this.oneRowNum) * 2;
|
||
},
|
||
// 首页展示的列表:固定最多2排,超过限制时最后一项替换为“更多”
|
||
displayList() {
|
||
const sourceList = this.filteredList;
|
||
if (!sourceList || !sourceList.length) return [];
|
||
const max = this.maxDisplayCount;
|
||
if (sourceList.length > max - 1) {
|
||
const result = sourceList.slice(0, max - 1);
|
||
result.push({
|
||
isMore: true,
|
||
name: '更多'
|
||
});
|
||
return result;
|
||
}
|
||
return sourceList;
|
||
}
|
||
},
|
||
methods: {
|
||
// 首页宫格项点击事件
|
||
onItemClick(item) {
|
||
if (item.isMore) {
|
||
// 将全量菜单数据缓存并跳转至全部分类新页面
|
||
uni.setStorageSync('all_grid_menu_list', this.filteredList);
|
||
this.$tools.routerTo('/pages/index/all-menu');
|
||
} else {
|
||
this.jump(item);
|
||
}
|
||
},
|
||
// 页面跳转逻辑
|
||
jump(data) {
|
||
if (!data) return;
|
||
if (data.name === '我的预约' && (!data.path || data.path === '')) {
|
||
data.path = '/pages/user/rob-order';
|
||
}
|
||
if (data.name === '开启直播' && (!data.path || data.path === '')) {
|
||
data.path = '/pages/user/live';
|
||
}
|
||
if (data.name === '在线客服') {
|
||
this.openService();
|
||
return;
|
||
}
|
||
if (data.path) {
|
||
this.$tools.routerTo(data.path);
|
||
}
|
||
},
|
||
// 在线客服入口
|
||
openService() {
|
||
// #ifdef MP-WEIXIN
|
||
wx.openCustomerServiceChat({
|
||
extInfo: {
|
||
url: 'https://work.weixin.qq.com/kfid/kfc5aec53d2111b588a'
|
||
},
|
||
corpId: 'wwc5f08e271cf73fb2',
|
||
success(res) {},
|
||
fail(res) {}
|
||
});
|
||
// #endif
|
||
|
||
// #ifdef APP-PLUS
|
||
plus.share.getServices(
|
||
res => {
|
||
let wechat = res.find(v => v.id === 'weixin');
|
||
if (wechat) {
|
||
wechat.openCustomerServiceChat(
|
||
{
|
||
corpid: 'wwc5f08e271cf73fb2',
|
||
url: 'https://work.weixin.qq.com/kfid/kfc5aec53d2111b588a'
|
||
},
|
||
res => {},
|
||
err => {}
|
||
);
|
||
} else {
|
||
uni.showToast({
|
||
title: '当前环境不支持微信操作',
|
||
icon: 'error'
|
||
});
|
||
}
|
||
},
|
||
function(e) {
|
||
uni.showToast({
|
||
title: '获取服务失败: ' + JSON.stringify(e),
|
||
icon: 'none'
|
||
});
|
||
}
|
||
);
|
||
// #endif
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
.menu-category-box {
|
||
position: relative;
|
||
background: #fff;
|
||
width: 100%;
|
||
|
||
.menu-tab-box {
|
||
.tab-list {
|
||
font-size: 26rpx;
|
||
font-weight: 500;
|
||
color: rgba(51, 51, 51, 1);
|
||
margin: 20rpx 0;
|
||
|
||
.tab-img {
|
||
width: 98rpx;
|
||
height: 98rpx;
|
||
margin-bottom: 10rpx;
|
||
border-radius: 16rpx;
|
||
}
|
||
|
||
.tab-title {
|
||
font-size: 26rpx;
|
||
font-weight: 500;
|
||
color: #333333;
|
||
line-height: 32rpx;
|
||
}
|
||
|
||
.more-icon-box {
|
||
width: 98rpx;
|
||
height: 98rpx;
|
||
border-radius: 24rpx;
|
||
background: #EEF3FE;
|
||
margin-bottom: 10rpx;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</style>
|