nurseWeChatAppletUI/pages/shopping/shopping.vue
2023-01-03 09:02:23 +08:00

126 lines
3.0 KiB
Vue

<template>
<view class="app">
<view class="cards">
<view class="item" :style="{background:listcolor[index]}" @tap='goProductList(item)'
v-for="(item,index) in goodsCategoryList" :key="index">
<image :src="item.goodsCategoryPicture" mode=""></image>
<view class="title" style="font-size:42rpx">
{{item.goodsCategoryName}}
</view>
</view>
<view style="width:43%" v-if="goodsCategoryList.length%2!=0">
</view>
</view>
</view>
</template>
<script>
import {
goodsCategoryList
} from '@/api/shopping/shopping.js';
import baseurl from '@/api/baseurl.js'
export default {
data() {
return {
pageNum: 1, //页
pageSize: 10, //列
total: 0, //list总长度
goodsCategoryList: [], //商品列表list
// listimg:[
// {
// img:'../../static/sp.png',
// },
// {
// img:'../../static/yyss.png',
// },
// {
// img:'../../static/znsb.png',
// },
// {
// img:'../../static/cp.png',
// },
// ],
listcolor: ['#00C176', '#D43953', '#E1AE3C', '#4C7BC9', '#9e4dd0', '#00C176', '#D43953', '#E1AE3C',
'#4C7BC9', '#9e4dd0',
], //颜色随动
};
},
//1.分享给朋友
onShareAppMessage(res) {
let pages = getCurrentPages();
let url = pages[pages.length - 1].$page.fullPath
return {
title: '泉医到家',
path: url,
}
},
//2.分享到朋友圈
onShareTimeline(res) {
let pages = getCurrentPages();
let url = pages[pages.length - 1].$page.fullPath
return {
title: '泉医到家',
path: url,
}
},
//初始化加载
onLoad(options) {},
onShow() {
this.goodsCategory()
},
methods: {
//跳转到商品列表页面
goProductList(item) {
uni.navigateTo({
url: `/pages/ProductList/ProductList?title=${item.goodsCategoryName}&goodsCategoryId=${item.id}`
})
},
//获取商城信息
goodsCategory() {
goodsCategoryList(this.pageSize, this.pageNum).then(res => {
uni.removeStorageSync('Refresh');
if (res.code == 200) {
res.rows.forEach(e => {
e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
})
this.goodsCategoryList = res.rows
this.total = res.total
}
})
}
},
onReachBottom() { //下滑加载
if (this.goodsCategoryList.length >= this.total) {} else {
this.pageNum++;
goodsCategoryList(this.pageSize, this.pageNum).then(res => {
res.rows.forEach(e => {
e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
this.goodsCategoryList.push(e)
})
this.total = res.total
})
}
},
onPullDownRefresh() { //下拉刷新
this.pageNum = 1;
goodsCategoryList(this.pageSize, this.pageNum).then(res => {
res.rows.forEach(e => {
e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
})
this.goodsCategoryList = res.rows
this.total = res.total
})
setTimeout(function() {
uni.stopPullDownRefresh();
}, 1000);
}
}
</script>
<style lang="scss">
.app {
.cards {
padding: 22px 0 20px 0;
}
}
</style>