nurseWeChatAppletUI/pages/ProductList/ProductList.vue

194 lines
4.2 KiB
Vue
Raw Normal View History

<template>
<view class="app">
2022-12-01 16:59:32 +08:00
<view class="inputs">
<i class="icon"></i>
<input v-model="goodsName" type="text" name="" id="" class="input" placeholder="请输入商品名称">
</view>
<view class="productlist">
<view class="item" @tap='goCommodityDetails(item)' v-for="(item,index) in goodsList" :key="index">
<image :src="baseurl+item.goodsPictureUrl" mode=""></image>
<view class="title">
{{item.goodsName}}
</view>
<view class="price">
{{item.goodsPrice}}
</view>
</view>
<view style="width: 45%;" v-if="goodsList.length%2!=0">
</view>
</view>
</view>
</template>
<script>
import {
goodsList
} from '@/api/ProductList/ProductList.js';
import baseurl from '@/api/baseurl.js'
export default {
data() {
return {
baseurl: '',
title: '医路优品', //导航栏标题
pageNum: 1,
pageSize: 10,
goodsCategoryId: '', //请求值
goodsList: [], //商品列表list
total: 0, //list总长度
2022-12-01 16:59:32 +08:00
goodsName: '',
};
},
2022-12-01 16:59:32 +08:00
watch: { //监听
goodsName() {
this.pageNum = 1;
goodsList(this.pageSize, this.pageNum, this.goodsCategoryId, this.goodsName).then(res => {
this.goodsList = res.rows
this.total = res.total
})
},
},
2022-12-27 09:22:42 +08:00
onShow() {
var that = this
try {
const value3 = uni.getStorageSync('Refresh');
if (value3) {
that.goodsListinfo();
}
} catch (e) {}
},
onLoad(options) { //获取传值
this.title = options.title //导航栏标题
this.goodsCategoryId = options.goodsCategoryId //请求id
this.baseurl = baseurl;
2022-12-01 16:59:32 +08:00
this.goodsListinfo()
},
methods: {
// 查询商品列表
2022-12-01 16:59:32 +08:00
goodsListinfo() {
2022-12-27 09:22:42 +08:00
this.pageNum = 1;
2022-12-01 16:59:32 +08:00
goodsList(this.pageSize, this.pageNum, this.goodsCategoryId, this.goodsName).then(res => {
2022-12-27 09:22:42 +08:00
if (res.code == 200) {
res.rows.forEach(e => {
this.goodsList.push(e)
})
this.total = res.total
}
uni.removeStorageSync('Refresh');
})
},
//跳转详情页
goCommodityDetails(item) {
uni.navigateTo({
url: `/pages/CommodityDetails/CommodityDetails?goodsPrice=${item.goodsPrice}&goodsInfoId=${item.goodsInfoId}&buySource=${'SHOPPING_MALL'}`
})
},
},
onReady() { //更改导航栏文字
uni.setNavigationBarTitle({
title: this.title,
});
},
onReachBottom() { //下滑加载
if (this.goodsList.length >= this.total) {} else {
this.pageNum++;
2022-12-27 09:22:42 +08:00
goodsList(this.pageSize, this.pageNum, this.goodsCategoryId, this.goodsName).then(res => {
if (res.code == 200) {
res.rows.forEach(e => {
this.goodsList.push(e)
})
}
})
}
},
onPullDownRefresh() { //下拉刷新
this.pageNum = 1;
2022-12-01 16:59:32 +08:00
goodsList(this.pageSize, this.pageNum, this.goodsCategoryId, this.goodsName).then(res => {
this.goodsList = res.rows
this.total = res.total
})
setTimeout(function() {
uni.stopPullDownRefresh();
}, 1000);
}
}
</script>
<style lang="scss">
.app {
padding: 0;
2022-12-01 16:59:32 +08:00
.inputs {
box-shadow: 0rpx 9rpx 31rpx 9rpx rgba(0, 0, 0, 0.03);
border: 1px solid #f0f0f0;
width: 90%;
height: 65rpx;
margin: 10rpx 0 10rpx 50%;
transform: translateX(-50%);
border-radius: 20rpx;
background-color: #Ffffff;
z-index: 999;
.input {
margin: 0 auto;
position: absolute;
height: 65rpx;
// top: 8%;
left: 10%;
width: 90%;
font-size: 26rpx;
color: #000000;
}
.icon {
background: url(@/static/sousuo.png) no-repeat;
width: 30rpx;
height: 28rpx;
background-size: cover;
position: absolute;
top: 30%;
left: 3%;
}
}
.productlist {
width: 100%;
margin: 0 auto;
2022-12-01 16:59:32 +08:00
padding: 20rpx 0 0 0;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
.item {
width: 45%;
background: #FFFFFF;
border-radius: 25rpx;
padding-bottom: 10rpx;
box-shadow: 0px 4rpx 8rpx 4rpx rgba(199, 200, 202, 0.8);
margin-bottom: 40rpx;
.price {
font-size: 42rpx;
color: #D43953;
line-height: 79rpx;
padding-left: 20rpx;
}
.title {
font-size: 39rpx;
color: #000000;
line-height: 69rpx;
padding-left: 20rpx;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
image {
width: 100%;
height: 340rpx;
}
}
}
}
</style>