NurseStationApp/pages/shopping/shopping.vue

132 lines
3.0 KiB
Vue
Raw Normal View History

2022-10-12 16:54:34 +08:00
<template>
2022-10-12 17:45:22 +08:00
<view class="app">
2023-03-08 09:46:11 +08:00
<view class="card">
<view class="items" :style="{background:listcolor[index % listcolor.length]}" @tap='goProductList(item)'
v-for="(item,index) in goodsCategoryList" :key="index">
2022-12-27 09:21:01 +08:00
<image :src="item.goodsCategoryPicture" mode=""></image>
2023-03-08 09:46:11 +08:00
<view class="titles" style="font-size:42rpx">
{{item.goodsCategoryName}}
2022-10-12 17:45:22 +08:00
</view>
</view>
2022-11-10 14:20:16 +08:00
<view style="width:43%" v-if="goodsCategoryList.length%2!=0">
2022-10-12 17:45:22 +08:00
</view>
</view>
2022-10-12 16:54:34 +08:00
</view>
</template>
<script>
import {
goodsCategoryList
} from '@/api/shopping/shopping.js';
import baseurl from '@/api/baseurl.js'
2022-10-12 16:54:34 +08:00
export default {
data() {
return {
2022-10-24 14:42:03 +08:00
pageNum: 1, //页
pageSize: 10, //列
total: 0, //list总长度
goodsCategoryList: [], //商品列表list
2023-03-08 09:46:11 +08:00
listcolor: ['#E69874', '#09C87E', '#E4B958', '#6592DC', '#EF6A80'] //颜色随动
};
},
2023-03-08 09:46:11 +08:00
//初始化加载
onLoad(options) {
this.pageNum = 1
this.goodsCategory()
2022-10-12 17:45:22 +08:00
},
2023-03-08 09:46:11 +08:00
onShow() {
let that = this
this.pageNum = 1
const value = uni.getStorageSync('Refresh');
if (value) {
that.goodsCategory();
}
},
2022-10-12 17:45:22 +08:00
methods: {
//跳转到商品列表页面
goProductList(item) {
uni.navigateTo({
url: `/pages/ProductList/ProductList?title=${item.goodsCategoryName}&goodsCategoryId=${item.id}`
})
2022-10-12 17:45:22 +08:00
},
//获取商城信息
goodsCategory() {
2022-10-24 14:42:03 +08:00
goodsCategoryList(this.pageSize, this.pageNum).then(res => {
2023-03-08 09:46:11 +08:00
uni.removeStorageSync('Refresh');
if (res.code == 200) {
res.rows.forEach(e => {
e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
})
this.goodsCategoryList = res.rows
this.total = res.total
}
})
}
2022-10-12 17:45:22 +08:00
},
2022-10-24 14:42:03 +08:00
onReachBottom() { //下滑加载
if (this.goodsCategoryList.length >= this.total) {} else {
this.pageNum++;
2023-03-08 09:46:11 +08:00
goodsCategoryList(this.pageSize, this.pageNum).then(res => {
res.rows.forEach(e => {
e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
this.goodsCategoryList.push(e)
})
this.total = res.total
})
2022-10-24 14:42:03 +08:00
}
},
onPullDownRefresh() { //下拉刷新
this.pageNum = 1;
goodsCategoryList(this.pageSize, this.pageNum).then(res => {
2022-10-31 09:04:45 +08:00
res.rows.forEach(e => {
2022-12-01 17:03:02 +08:00
e.goodsCategoryPicture = baseurl + e.goodsCategoryPicture
2022-10-31 09:04:45 +08:00
})
2022-10-24 14:42:03 +08:00
this.goodsCategoryList = res.rows
this.total = res.total
})
setTimeout(function() {
uni.stopPullDownRefresh();
}, 1000);
}
2022-10-12 16:54:34 +08:00
}
</script>
<style lang="scss">
2023-03-08 09:46:11 +08:00
.app {
padding: 40rpx 0 0;
background-color: #fff;
.card {
width: 100%;
display: flex;
justify-content: space-evenly;
flex-wrap: wrap;
.items {
width: 45%;
height: 360rpx;
margin-bottom: 40rpx;
z-index: 1;
border-radius: 25rpx;
position: relative;
image {
border-radius: 25rpx;
width: 100%;
height: 100%;
z-index: -1;
}
.titles {
width: 90%;
font-size: 36rpx;
color: #FCFCFC;
position: absolute;
top: 30rpx;
left: 30rpx;
z-index: 999;
}
}
}
}
2022-10-20 19:39:57 +08:00
</style>