效果图
wxml代码
<form bindsubmit
="mysubmit" >
<!--购物车
-产品列表
-->
<checkbox
-group bindchange
="ck" name
="xuanxiang">
<view class
="gwccp" wx
:for="{{gwc}}" wx
:for-item
="cp" wx
:for-index
="xuhao">
<!--购物车
-产品列表
-单号栏
-->
<view class
="danhao">
<view class
="danhao_zuo">时间:
{{cp
.shijian_gouwuche
}}</view
>
<view class
="danhao_you" data
-gwcid
="{{cp.gwc_id}}" bindtap
="mydel">
<image src
="/img/del.png" class
="danhao_you_img"></image
>
</view
>
</view
>
<!--产品 左中右
-->
<view class
="xiangmu">
<view class
="xiangmu_zuo"><!--购物车
-产品区块制作
-左侧
-选择项
-->
<checkbox class
="xiangmu_zuo_check" value
="{{cp.gwc_id}}" name
="xuanxiangs" checked
="{{isChecked}}"></checkbox
>
</view
>
<view class
="xiangmu_zhong"><!--购物车
-产品区块制作
-中间
-图片
-->
<image src
="{{cp.cp_tupian}}" mode
="widthFix" class
="xiangmu_zhong_img"></image
>
</view
>
<view class
="xiangmu_you"><!--购物车
-产品区块制作
-右侧
-产品信息
-->
<view class
="you_biaoti">{{cp
.cp_mingcheng
}}</view
>
<view class
="you_shuxing">库存:
{{cp
.cp_kucu
}} | 已销:
{{cp
.cp_yixiaoshou
}}</view
>
<view class
="you_jiage">
<view class
="you_jiage_zou">¥
{{cp
.jiage
}}</view
>
<view class
="you_jiage_you">
<image src
="/img/jian1.png" mode
="widthFix" class
="you_jian"
data
-gwcid
="{{cp.gwc_id}}" data
-shuliang
="{{cp.cp_shuliang}}" data
-jiage
="{{cp.jiage}}" bindtap
="myremove"></image
>
<input type
="text" value
="{{cp.cp_shuliang}}" class
="you_text" />
<image src
="/img/jia1.png" mode
="widthFix" class
="you_jia"
data
-gwcid
="{{cp.gwc_id}}" data
-shuliang
="{{cp.cp_shuliang}}" data
-jiage
="{{cp.jiage}}" bindtap
="myadd"></image
>
</view
>
</view
>
</view
>
</view
>
<view class
="huise10"></view
>
</view
>
<view class
="huise10"></view
>
<view class
="huise10"></view
>
<view class
="huise10"></view
>
<view class
="huise10"></view
>
</checkbox
-group
>
<view class
="jiesuan">
<view class
="jiesuan_zuo">
<checkbox
-group bindchange
="quanxuan">
<checkbox class
="jiesuan_zuo_check" checked
="{{allChecked}}">全选
</checkbox
>
</checkbox
-group
>
</view
>
<view class
="jiesuan_zhong">
合计:¥
{{zongfeiyong
}}
</view
>
<button class
="jiesuan_you" form
-type
="submit" size
="mini" >
结算
</button
>
</view
>
</form
>
wxss代码
.gwccp
{}
.jiesuan
{position
: fixed
; bottom
: 0px
; background
-color
: #EBEAEF
; height
: 35px
;
display
: flex
; width
: 100%; border
-top
: 1px solid #C8C7CC
; justify
-content
: center
; align
-items
: center
;}
.jiesuan_zuo
{width
: 20%; padding
: 3px
;}
.jiesuan_zuo_check
{}
.jiesuan_zhong
{width
: 60%;background
-color
: #FFFFFF
; text
-align
: center
;height
: 35px
;line
-height
: 35px
;}
.jiesuan_you
{width
: 20%; display
: flex
;height
: 35px
; background
-color
: #DD524D
; color
: #FFFFFF
;
justify
-content
: center
; align
-items
: center
; border
-radius
: 0;}
.huise10
{height
: 10px
;background
-color
: #EBEAEF
;}
.you_biaoti
{color
: #
333333; font
-size
: 14px
;}
.you_shuxing
{font
-size
: 12px
; color
: #C0C0C0
;}
.you_jiage
{font
-size
: 13px
; color
: #DD524D
; display
: flex
; align
-items
: center
;}
.you_jiage_zou
{flex
-grow
: 1;}
.you_jiage_you
{display
: flex
; border
: 1px solid #C8C7CC
; align
-items
: center
;}
.you_jian
{width
: 20px
;}
.you_text
{ width
: 30px
; text
-align
: center
;border
-left
: 1px solid #C0C0C0
;
border
-right
: 1px solid #C0C0C0
;}
.you_jia
{width
: 20px
;}
.xiangmu
{display
: flex
;padding
: 5px
; align
-items
: center
;}
.xiangmu_zuo
{width
: 8%;}
.xiangmu_zuo_check
{}
.xiangmu_zhong
{width
: 27%;}
.xiangmu_zhong_img
{width
:100%}
.xiangmu_you
{width
: 65%; padding
: 5px
;}
.danhao
{display
: flex
;padding
: 5px
; border
-bottom
: 1px solid #C8C7CC
;}
.danhao_zuo
{flex
-grow
: 1;}
.danhao_you
{}
.danhao_you_img
{width
: 19px
;height
: 19px
;}
js代码
var app
= getApp()
Page({
data
: {
user_id
:0,
gwc
:[],
cks
:[],
zongfeiyong
:0,
winHeight
: 0,
isChecked
:false,
checkedArr
:[],
allChecked
:false
},
onLoad
: function (options
) {
var _this
= this
wx
.getStorage({
key
: 'u_id',
success
:function(res
){
console
.log("用户id:"+res
.data
)
_this
.setData({
user_id
:res
.data
})
_this
.cz();
}
})
},
cz
: function(){
var _this
= this
wx
.request({
url
: app
.myapp
.php
+ "/wx_gwc_list.php",
data
:{uid
:this
.data
.user_id
},
success
:function(res
){
console
.log(res
.data
)
_this
.setData({
gwc
:res
.data
})
}
})
},
mydel
:function(e
){
console
.log("要删除的购物车id:"+e
.currentTarget
.dataset
.gwcid
)
console
.log("操作的用户id:"+this
.data
.user_id
)
wx
.request({
url
: app
.myapp
.php
+ "/wx_gwc_del.php",
data
:{
cs_gwc_id
: e
.currentTarget
.dataset
.gwcid
,
cs_user_id
: this
.data
.user_id
},
success
: (res
) => {
this
.cz();
}
})
},
myadd
:function(e
){
var _this
= this
console
.log("增加数量")
console
.log("购物车id:"+e
.currentTarget
.dataset
.gwcid
)
console
.log("操作的用户id:"+this
.data
.user_id
)
console
.log("要更新产品数量:"+e
.currentTarget
.dataset
.shuliang
)
console
.log(parseInt(e
.currentTarget
.dataset
.shuliang
)+1)
console
.log("当前选中项目:" + this
.data
.checkedArr
)
if(e
.currentTarget
.dataset
.shuliang
>= 1){
if(this
.data
.checkedArr
.includes(e
.currentTarget
.dataset
.gwcid
)){
_this
.setData({
zongfeiyong
: parseInt(_this
.data
.zongfeiyong
) + parseInt(e
.currentTarget
.dataset
.jiage
)
})
}
wx
.request({
url
: app
.myapp
.php
+ "/wx_gwc_shuxiugai.php",
data
:{
cs_cp_shu
: parseInt(e
.currentTarget
.dataset
.shuliang
)+1,
cs_gwc_id
: e
.currentTarget
.dataset
.gwcid
,
cs_user_id
: this
.data
.user_id
},
success
: () => {
this
.cz()
}
})
}
},
myremove
:function(e
){
console
.log("购物车id:"+e
.currentTarget
.dataset
.gwcid
)
console
.log("操作的用户id:"+this
.data
.user_id
)
console
.log("要更新产品数量:"+e
.currentTarget
.dataset
.shuliang
)
console
.log(parseInt(e
.currentTarget
.dataset
.shuliang
)+1)
if(e
.currentTarget
.dataset
.shuliang
>=2){
if(this
.data
.checkedArr
.includes(e
.currentTarget
.dataset
.gwcid
)){
this
.setData({
zongfeiyong
:parseInt(this
.data
.zongfeiyong
) - parseInt(e
.currentTarget
.dataset
.jiage
)
})
}
wx
.request({
url
: app
.myapp
.php
+ "/wx_gwc_shuxiugai.php",
data
:{
cs_cp_shu
: parseInt(e
.currentTarget
.dataset
.shuliang
)-1,
cs_gwc_id
: e
.currentTarget
.dataset
.gwcid
,
cs_user_id
: this
.data
.user_id
},
success
: () => {
this
.cz()
}
})
}else{
wx
.showToast({
title
:"数量不能少于1"
})
}
},
ck
:function(e
){
var _this
= this
console
.log(_this
.data
.gwc
)
console
.log(e
.detail
)
console
.log(e
.detail
.value
[0])
this
.data
.zongfeiyong
= 0;
this
.data
.cks
= e
.detail
.value
;
for(var i
=0;i
<this
.data
.gwc
.length
;i
++){
if(this
.data
.cks
.includes(this
.data
.gwc
[i
].gwc_id
)){
console
.log("当前选中产品名称:"+this
.data
.gwc
[i
].cp_mingcheng
)
console
.log("当前选中产品价格:" + this
.data
.gwc
[i
].jiage
)
_this
.data
.checkedArr
.push(_this
.data
.gwc
[i
].gwc_id
)
_this
.setData({
zongfeiyong
: parseInt(_this
.data
.zongfeiyong
) + parseInt(_this
.data
.gwc
[i
].jiage
)*parseInt(_this
.data
.gwc
[i
].cp_shuliang
)
})
}
}
console
.log("_this.data.cks.length:"+_this
.data
.cks
.length
)
console
.log("_this.data.gwc.length:"+_this
.data
.gwc
.length
)
if(_this
.data
.cks
.length
== _this
.data
.gwc
.length
){
_this
.setData({
allChecked
:true
})
}else{
_this
.setData({
allChecked
:false
})
}
},
quanxuan
:function(e
){
var _this
= this
_this
.setData({
zongfeiyong
:0
})
if (e
.detail
.value
.length
== 0) {
console
.log("取消全选")
_this
.setData({
isChecked
:false
})
}else{
console
.log("全选")
_this
.setData({
isChecked
:true
})
for(var i
=0;i
<this
.data
.gwc
.length
;i
++){
_this
.setData({
zongfeiyong
: parseInt(_this
.data
.zongfeiyong
) + parseInt(_this
.data
.gwc
[i
].jiage
)*parseInt(_this
.data
.gwc
[i
].cp_shuliang
)
})
}
}
},
mysubmit
:function(e
){
console
.log("发起结算")
console
.log("结算费用:" + this
.data
.zongfeiyong
)
console
.log("选中项目:" + e
.detail
.value
.xuanxiang
)
if(parseInt(this
.data
.zongfeiyong
)<=0){
wx
.showToast({
title
: '请选择商品',
})
}else{
wx
.navigateTo({
url
: '/pages/huiyuan/gouwuche/che_jiesuan?gwc_zfy='+this
.data
.zongfeiyong
+"&gwc_ids="+ e
.detail
.value
.xuanxiang
,
})
}
},
onReady
: function () {
},
onShow
: function () {
},
onHide
: function () {
},
onUnload
: function () {
},
onPullDownRefresh
: function () {
},
onReachBottom
: function () {
},
onShareAppMessage
: function () {
}
})
转载请注明原文地址: https://lol.8miu.com/read-14236.html