<template>
<div class="home">
<div class="item" v-for="(item,index) of list" :key="item.id">
<van-checkbox icon-size="15px" class="font-check" v-model="item.isSelected">单选</van-checkbox>
<div class="wrap">
<van-card
:price="item.productPrice"
:desc="item.productInfo"
:title="item.productName"
:thumb="item.productCover"
/>
<van-button @click="handleDet(index)" class="delete" size="mini" type="danger">删除</van-button>
<van-stepper class="count" input-width="30px" button-size="17px" v-model="item.productCount" />
<p class="sum">小计:{{item.productPrice*item.productCount}}元</p>
</div>
</div>
<van-submit-bar
:price="sum*100"
button-text="提交订单"
>
<van-checkbox v-model="checkAll">全选</van-checkbox>
</van-submit-bar>
</div>
</template>
<script>
import axios from 'axios';
export default {
name: 'home',
data(){
return{
list:[]
}
},
mounted(){
axios.get("http://yapi.demo.qunar.com/mock/36046/cart").then(res=>{
this.list = res.data;
console.log(this.list)
})
},
computed: {
sum(){
var total =0;
this.list.forEach(item=>{
if(item.isSelected){
total = item.productCount*item.productPrice+total;
}
})
return total
},
checkAll:{
get(){
return this.list.every(item=>item.isSelected)
},
set(val){
this.list.forEach(item=>item.isSelected=val)
}
}
},
methods:{
handleDet(index){
this.list.splice(index,1)
}
}
}
</script>
<style scoped>
.item{
margin-top: 20px;
}
.font-check{
font-size: 20px;
}
.wrap{
position: relative;
}
.count{
position: absolute;
top: 50px;
left: 200px;
}
.delete{
position: absolute;
top: 50px;
left: 290px;
}
.sum{
position:absolute;
top: 60px;
left: 230px;
font-size: 15px;
}
</style>