luban-mall/pages/tabbar/index/index.vue

321 lines
8.3 KiB
Vue
Raw Permalink Normal View History

2022-07-08 08:15:29 +00:00
<template>
<view class="pad-b150" v-if="!ifLoading">
2022-07-14 06:46:41 +00:00
<status-nav :ifReturn="false" :navBarTitle="indexTitle" :marginBottom="0"></status-nav>
2022-07-08 08:15:29 +00:00
<!-- 搜索 -->
<view class="search-bg">
<view class="search flex">
<image class="search-img" src="/static/public/icon-search.png" mode="widthFix"></image>
<input class="search-input" v-model="keyword" type="text" placeholder="请输入关键词" placeholder-style="color: #666666">
<view class="search-line"></view>
<view class="search-btn flex" @tap="toSearch"></view>
</view>
</view>
<!-- 轮播图 -->
<view class="banner">
<swiper-pu newRadius="0" :bannerList="bannerList" newHeight="372rpx" newBottom="20rpx" :isplay='isplay'></swiper-pu>
</view>
<!-- 推荐列表 -->
<view class="flag-list flex">
<view class="flag-item" @tap="toLink(item.url)" v-for="(item,index) in recommendList" :key="index">
<view class="flag-img"><image class="search-img" :src="item.src" mode="widthFix"></image></view>
<view class="flag-txt clips1">{{item.title}}</view>
</view>
</view>
<!-- 推荐商品 -->
<view class="index-product-list" v-for="(item,index) in productList" :key="index">
<view class="product-list-title flex">
<view class="txt">
<text>{{item.title}}</text>
<view class="line"></view>
</view>
<view class="more" @tap="toMore">
<image src="/static/public/icon-more.png" mode="widthFix"></image>
</view>
</view>
<product-list :list="item.goods" :newWidth="item.goods.length*460-490+'rpx'" @toDetail="toShopDetail"></product-list>
</view>
<!-- 疑难解答&行业资讯 -->
<view class="index-news">
<nav-tab :list="navTabList" :maxNum="1" @chooseEv="chooseEv"></nav-tab>
2022-07-15 10:29:01 +00:00
<pull-list :list="askList" @toDetail="toArticleDetail" v-if="isLoading && showIndex==0"></pull-list>
<pull-list :list="articleList" @toDetail="toArticleDetail" v-if="isLoading && showIndex==1"></pull-list>
2022-07-08 08:15:29 +00:00
</view>
<!-- 购物车btn -->
<enter-cart></enter-cart>
<!-- 底部tab -->
<foot-tab></foot-tab>
</view>
</template>
<script>
import statusNav from '@/components/status-navs/status-nav';
2022-07-15 01:04:30 +00:00
import swiperPu from '@/components/swipers/swiper-pu';
2022-07-08 08:15:29 +00:00
import enterCart from '@/components/enter-cart/enter-cart.vue';
import footTab from '@/components/foot-tab/foot-tab.vue';
import productList from '@/components/product-list/product-list.vue';
import navTab from '@/components/nav-tab/nav-tab.vue';
import pullList from '@/components/pull-list/pull-list.vue';
2022-07-15 01:04:30 +00:00
import {getCartNum} from '@/jsFile/public-api.js';
2022-07-08 08:15:29 +00:00
export default {
components:{
statusNav,
swiperPu,
productList,
navTab,
pullList,
footTab,
enterCart,
},
data() {
return {
padt:uni.getSystemInfoSync().statusBarHeight + 50,
headHeight:'',//头部导航高
keyword:'', //关键词
bannerList:[], //轮播图列表
isplay:false, //是否自动轮播
playTimer:null, //间隔时间
recommendList:[], //推荐列表
productList:[],// 产品列表
articleNavId:'',//文章导航id
2022-07-15 10:29:01 +00:00
askList:[], //疑难解答列表
2022-07-08 08:15:29 +00:00
articleList:[], //文章列表
navTabList:[],//导航列表
ifLoading:true,
2022-07-15 01:04:30 +00:00
indexTitle:'',//标题
2022-07-15 03:05:54 +00:00
cacheBusinessId:-1, //商户id
2022-07-15 10:29:01 +00:00
isLoading:false,
showIndex:0, //文章显示位置
2022-07-08 08:15:29 +00:00
}
},
2022-07-12 10:07:08 +00:00
onLoad(op) {
if(op.business_id){
2022-07-15 03:05:54 +00:00
this.cacheBusinessId = op.business_id;
}
},
onShow() {
if(this.cacheBusinessId !== -1){
this.$requst.post('/api/index/change-business',{business_id:this.cacheBusinessId}).then(res=>{
2022-07-12 10:07:08 +00:00
if(res.code == 0){
this.getHomeData();
this.getArticleNav();
2022-07-15 01:04:30 +00:00
this.userInfoEv();
2022-07-12 10:07:08 +00:00
}
})
}else{
this.getHomeData();
this.getArticleNav();
2022-07-15 01:04:30 +00:00
this.userInfoEv();
2022-07-12 10:07:08 +00:00
}
2022-07-25 03:18:38 +00:00
getCartNum();
2022-07-08 08:15:29 +00:00
this.playTimer = setTimeout(()=>{
this.isplay = true;
},2000)
},
onReady() {
2022-07-11 10:35:14 +00:00
},
// 分享到微信
onShareAppMessage() {
let path = uni.getStorageSync('page-path-options')+'?business_id='+uni.getStorageSync('business_id');
return {
path:path
}
},
// 分享到朋友圈
onShareTimeline(res){
let path = uni.getStorageSync('page-path-options')+'?business_id='+uni.getStorageSync('business_id');
return {
path:path
}
2022-07-08 08:15:29 +00:00
},
onReachBottom(e) {
if(this.articleList.length<this.total){
this.page++;
this.getArticleList();
}
},
onHide() {
clearTimeout(this.playTimer);
2022-07-08 08:50:30 +00:00
this.isplay =false;
2022-07-08 08:15:29 +00:00
},
methods: {
2022-07-15 01:04:30 +00:00
// 查询用户信息
userInfoEv(){
this.$requst.get('/api/user/info').then(res=>{
if(res.code==0){
uni.setStorageSync('business_id',res.data.business_id);
uni.setStorageSync('business_code',res.data.business_code);
this.getCompanyList(res.data.business_id);
}
})
},
2022-07-14 06:46:41 +00:00
// 查询工厂列表
getCompanyList(business_id){
this.$requst.post('/api/business/info',{business_id:business_id}).then(res=>{
if(res.code==0) {
this.indexTitle = res.data.alias;
}
})
},
2022-07-08 08:15:29 +00:00
// 获取首页数据
getHomeData(){
this.$requst.get('/api/index/home').then(res=>{
if(res.code == 0){
let bannerArr = [];
let isVideo = false
res.data.banner.forEach(item=>{
let obj = {
imgSrc:item.src,
url:item.url,
isVideo:isVideo,
}
bannerArr.push(obj)
})
this.bannerList = bannerArr;
this.recommendList =res.data['banner-next-2'];
this.productList = res.data.spu;
this.ifLoading = false;
}
})
},
// 获取文章栏目
getArticleNav(){
this.$requst.get('/api/archives/category').then(res=>{
if(res.code == 0){
2022-07-15 10:29:01 +00:00
let newArr = [];
2022-07-08 08:15:29 +00:00
res.data.forEach(item=>{
let obj = {
id:item.id,
name:item.title
}
2022-07-15 10:29:01 +00:00
newArr.push(obj)
2022-07-08 08:15:29 +00:00
})
2022-07-15 10:29:01 +00:00
this.navTabList = newArr;
2022-07-08 08:15:29 +00:00
// 获取文章列表
2022-07-15 10:29:01 +00:00
this.getAskList();
2022-07-08 08:15:29 +00:00
this.getArticleList();
}
})
},
// 切换事件
chooseEv(index,id){
2022-07-15 10:29:01 +00:00
if(this.showIndex !== index){
this.showIndex = index;
2022-07-08 08:15:29 +00:00
}
},
2022-07-15 10:29:01 +00:00
// 获取疑难解答列表
getAskList(){
uni.showLoading({
title: '加载中'
});
this.isLoading = false;
let params = {
page:this.page,
size:this.size,
category_id:this.navTabList[0].id
}
this.$requst.get('/api/archives/list',params).then(res=>{
if(res.code == 0){
this.total = res.data.total;
let newArr = [];
res.data.list.forEach(item=>{
let obj = {
id:item.id,
title:item.title,
time:this.dateFormat(item.published_at.replace(/-/g,'/')),
src:item.cover
}
newArr.push(obj)
})
this.askList = newArr;
}
uni.hideLoading();
this.isLoading = true;
})
},
2022-07-08 08:15:29 +00:00
// 获取文章列表
getArticleList(){
2022-07-14 02:00:23 +00:00
uni.showLoading({
title: '加载中'
});
2022-07-15 10:29:01 +00:00
this.isLoading = false;
2022-07-08 08:15:29 +00:00
let params = {
page:this.page,
size:this.size,
2022-07-15 10:29:01 +00:00
category_id:this.navTabList[1].id
2022-07-08 08:15:29 +00:00
}
this.$requst.get('/api/archives/list',params).then(res=>{
if(res.code == 0){
this.total = res.data.total;
let newArr = [];
res.data.list.forEach(item=>{
let obj = {
id:item.id,
title:item.title,
2022-07-14 02:00:23 +00:00
time:this.dateFormat(item.published_at.replace(/-/g,'/')),
2022-07-08 08:15:29 +00:00
src:item.cover
}
newArr.push(obj)
})
this.articleList = newArr;
}
uni.hideLoading();
2022-07-15 10:29:01 +00:00
this.isLoading = true;
2022-07-08 08:15:29 +00:00
})
},
// 时间格式转换
dateFormat (dateData) {
var date = new Date(dateData)
var y = date.getFullYear()
var m = date.getMonth() + 1
m = m < 10 ? '0' + m : m
var d = date.getDate()
d = d < 10 ? '0' + d : d
const time = y + '.' + m + '.' + d
return time
},
// 去商品列表
toMore(){
uni.navigateTo({
url:`/pages/tabbar/cate/cate`
})
},
//去推荐详情页
toLink(url){
if(url !== ''){
uni.navigateTo({
url: `/${url}`
})
}
},
//去商品详情
toShopDetail(id){
uni.navigateTo({
url:`/pagesA/shop/detail?id=${id.id}&source=shop`
})
},
//去文章详情
toArticleDetail(id){
uni.navigateTo({
url:`/pages/tabbar/news/detail?id=${id.id}`
})
},
// 去搜索页面
toSearch(){
2022-07-11 10:35:14 +00:00
if(this.keyword !== ''){
uni.navigateTo({
url:`/pagesB/search/search?keyword=${this.keyword}`
})
}
2022-07-08 08:15:29 +00:00
},
}
}
</script>
<style scoped>
2022-07-08 10:21:46 +00:00
2022-07-08 08:15:29 +00:00
</style>