购物车一半

This commit is contained in:
pplokijuhyg 2019-12-19 15:59:01 +08:00
parent 79afb38a63
commit 4c489c632b
2 changed files with 27 additions and 8 deletions

View File

@ -1,4 +1,5 @@
// components/shopping/shoppingitem/shoppingitem.js
import {request} from "../../../utils/bin"
Component({
/**
* 组件的属性列表
@ -7,14 +8,16 @@ Component({
shopname: String,
shopdesc: String,
price: Number,
pic: String
pic: String,
gid:Number,
num:Number
},
/**
* 组件的初始数据
*/
data: {
num: 5
},
/**
@ -25,15 +28,31 @@ Component({
if (this.data.num == 0) {
return
} else {
this.setData({
num: this.data.num - 1
request({
url:"Cart/updateNum",
urldata:{
id:this.data.gid,
num:this.data.num - 1
}
}).then((res)=>{
this.setData({
num: this.data.num - 1
})
})
}
},
add() {
this.setData({
num: this.data.num + 1
request({
url:"Cart/updateNum",
urldata:{
id:this.data.gid,
num:this.data.num + 1
}
}).then((res)=>{
this.setData({
num: this.data.num + 1
})
})
}

View File

@ -1,6 +1,6 @@
<view class="shopping">
<view class="item" wx:for="{{list}}" wx:for-index="j" wx:key="{{j}}">
<shopping-item shopname="{{item.goods_name}}" shopdesc="{{item.spec_key_name||'默认规格'}}" price="{{item.goods_price}}" pic="{{item.image}}"></shopping-item>
<shopping-item shopname="{{item.goods_name}}" shopdesc="{{item.spec_key_name||'默认规格'}}" price="{{item.goods_price}}" pic="{{item.image}}" num="{{item.goods_num}}" gid="{{item.id}}"></shopping-item>
</view>
<!-- <view class="item">
<shopping-item shopname="J`adore - Dior" shopdesc="30支 1.30kg" price="61.78"></shopping-item>