leave-unused/pages/goods/goods.vue

115 lines
2.8 KiB
Vue
Raw Normal View History

<template>
<view class="pad-x20" v-if="isLoading">
<!-- 头部 -->
<status-nav :ifReturn="true" navBarTitle="我的发布"></status-nav>
<!-- 商品列表 -->
<goods-list :goodsList="goodsList" :isOperate="true" @changeStateEv="changeStateEv"></goods-list>
<!-- 没有更多 -->
<view class="no-more mar-s20 font24 color-99">没有更多数据了</view>
</view>
</template>
<script>
import goodsList from '@/components/goods-list/goods-list.vue';
export default {
components:{
goodsList
},
data() {
return {
statusHeight:uni.getSystemInfoSync().statusBarHeight, //状态栏高度
goodsList:[], //商品列表
page:1, //页数
size:10, //条数
total:0, //总数
isLoading:false, //是否加载完成
}
},
onShow() {
// 查询商品列表
this.getGoodsList();
},
onShareAppMessage(res) {
let shareObj = {
title:'老农极鲜',
path: uni.getStorageSync('page-path-options')+'?invite_code='+uni.getStorageSync('invite_code'),
imageUrl:'/static/img/shear-index.jpg',
}
// 返回shareObj
return shareObj;
},
onShareTimeline(res){
let shareObj = {
title:'老农极鲜',
query: '?invite_code='+uni.getStorageSync('invite_code'),
path: uni.getStorageSync('page-path-options')+'?invite_code='+uni.getStorageSync('invite_code'),
imageUrl:'/static/img/shear-index.jpg',
}
// 返回shareObj
return shareObj;
},
onReachBottom(e) {
if(this.goodsList.length<this.total){
this.page++;
// 查询商品列表
this.getGoodsList();
}
},
methods: {
// 查询商品列表
getGoodsList(){
2022-10-20 13:07:14 +00:00
uni.showLoading({
title:'加载中'
})
let params = {
page:this.page,
size:this.size,
}
if(this.page==1) this.goodsList = [];
this.$requst.get('/api/v1/user/goods',params).then(res=>{
if(res.code == 0){
console.log(res,'我的发布列表')
this.total = res.data.total;
let goodsArr = [];
res.data.list.forEach(item=>{
let obj = {
id:item.id,
cover:item.cover,
name:item.title,
original_price:item.original_price,
price:item.price
}
goodsArr.push(obj)
})
this.goodsList = this.goodsList.concat(goodsArr);
}
uni.hideLoading();
this.isLoading = true;
})
},
// 更改显示状态
changeStateEv(id,index){
if(this.goodsList[index].state==0){
this.goodsList[index].state = 1;
this.$toolAll.tools.showToast('状态变更成功');
}else{
this.goodsList[index].state = 0;
this.$toolAll.tools.showToast('状态变更成功');
}
},
// 去详情页
goDetail(id){
uni.navigateTo({
url:`/pages/index/detail?id=${id}`
})
},
}
}
</script>
<style scoped>
.no-more{
text-align: center;
line-height: 2;
}
</style>