luban-mall/components/list/list-one.vue

120 lines
2.8 KiB
Vue

<template>
<view>
<view class="fon36 colb bold mar-x40" v-if="ifTitle">{{title}}</view>
<view class="disjbac fw">
<view class="width48_5 fon30 mar-x30" @tap="goDetail(item.id)" v-for="(item,index) in dataList" :key="index">
<view class="" style="height: 342rpx;">
<image class="radius30 width100" :src="item.imgsrc" mode="aspectFill" style="height: 342rpx;"></image>
</view>
<view class="pad-zy20">
<view class="line-h50 mar-sx25 clips2" style="height: 90rpx;">{{item.title}}</view>
<view class="textc disjbac">
<view class="">{{item.price}}</view>
<i @tap.stop="addCartEv(item.skuId)" class="icon icon-shop-cart" style="font-size: 40rpx;"></i>
</view>
</view>
</view>
</view>
<view class="mar-s60" v-if="total==dataList.length">
<pitera textStr="—— 到底啦 ——"></pitera>
</view>
<view class="loading-box mar-s60" v-show="ifLoading">
<view class="loader-16"></view>
</view>
</view>
</template>
<script>
import pitera from '@/components/nothing/pitera';
import {getCartNum} from '@/jsFile/public-api.js';
export default {
name:"list-one",
components:{
pitera
},
props:{
// 是否显示标题
ifTitle:{
type:Boolean,
default:false
},
// 标题内容
title:{
type:String,
default:'热门推荐'
}
},
data() {
return {
dataList:[],
ifLoading:false,
total:0,
page:1,
size:10
};
},
mounted() {
this.getList();
},
methods:{
moreEv() {
if(this.total!=this.dataList.length) {
this.page++;
this.getList();
}
},
// 列表查询
getList(){
this.ifLoading = true;
let params = {
keyword:'',
page:this.page,
size:this.size
}
this.$requst.post('/api/spu/home',params).then(res=>{
if(res.code==0) {
this.total = res.data.total;
if(this.page==1) this.dataList = [];
if(res.data.list.length) {
res.data.list.forEach(item=>{
let obj = {
id:item.id,
skuId:item.skuId,
imgsrc:item.cover,
title:item.name,
price:this.$toolAll.tools.changeNum(parseInt(item.original_price)+'')
}
this.dataList.push(obj);
})
}
}
this.ifLoading = false;
})
},
// 加入购物车
addCartEv(id) {
if(this.$toolAll.tools.judgeAuth()) {
this.$requst.post('/api/order/shopping-cart-add',{sku_id:id,num:1}).then(res=>{
if(res.code==0) {
this.$toolAll.tools.showToast('加入购物车成功(*^▽^*)');
getCartNum();
} else {
this.$toolAll.tools.showToast(res.msg)
}
})
}
},
// 去详情
goDetail(id) {
uni.navigateTo({
url:`/pagesB/shop-detail/shop-detail?id=${id}`
})
}
}
}
</script>
<style scoped>
</style>