From 487fee5b045f7989f1d28b9bc962d27ef8cb755a Mon Sep 17 00:00:00 2001
From: pplokijuhyg <1162963624@qq.com>
Date: Fri, 20 Dec 2019 14:16:06 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pages/shopping/shopping.js | 117 +++++++++++++++++++++--------------
pages/shopping/shopping.wxml | 2 +-
2 files changed, 73 insertions(+), 46 deletions(-)
diff --git a/pages/shopping/shopping.js b/pages/shopping/shopping.js
index f071d4f..66d90fa 100644
--- a/pages/shopping/shopping.js
+++ b/pages/shopping/shopping.js
@@ -1,20 +1,20 @@
// pages/shopping/shopping.js
-import {request} from "../../utils/bin"
+import { request } from "../../utils/bin"
Page({
/**
* 页面的初始数据
*/
data: {
- list:[],
- select:[],
- userid:0,
- price:"0.00"
+ list: [],
+ select: [],
+ userid: 0,
+ price: "0.00"
},
- sel(a){
+ sel(a) {
console.log(a)
this.setData({
- [`select[${a.detail.index}]`]:!a.detail.select
+ [`select[${a.detail.index}]`]: !a.detail.select
})
this.num();
},
@@ -22,28 +22,31 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
- getlist(){
+ getlist() {
request({
- url:"Cart/cartList/session_id/" + wx.getStorageSync('openid'),
- data:{
- user_id:this.data.userid
+ url: "Cart/cartList/session_id/" + wx.getStorageSync('openid'),
+ data: {
+ user_id: this.data.userid
}
- }).then((res)=>{
+ }).then((res) => {
console.log(res)
this.setData({
- list:res.data.result
+ list: res.data.result
})
+ this.num()
+
})
},
- onLoad: function(options) {
+ onLoad: function (options) {
request({
- url:"User/validateOpenid"
- }).then((res)=>{
+ url: "User/validateOpenid"
+ }).then((res) => {
console.log(res)
this.setData({
- userid:res.data.data.user_id
+ userid: res.data.data.user_id
})
this.getlist()
+
})
},
sub() {
@@ -54,98 +57,122 @@ Page({
/**
* 生命周期函数--监听页面初次渲染完成
*/
- onReady: function() {
+ onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
- onShow: function() {
+ onShow: function () {
this.onLoad()
},
/**
* 生命周期函数--监听页面隐藏
*/
- onHide: function() {
+ onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
- onUnload: function() {
+ onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
- onPullDownRefresh: function() {
+ onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
- onReachBottom: function() {
+ onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
- onShareAppMessage: function() {
+ onShareAppMessage: function () {
},
- num(){
+ num() {
let num = 0;
let sel = 0;
- for(let i in this.data.select){
+ for (let i in this.data.select) {
console.log(i)
- if(this.data.select[i]){
- num += parseFloat(this.data.list[i].goods_price)*100
- sel++
+ if (this.data.select[i]) {
+ num += parseFloat(this.data.list[i].goods_price) * 100
+ sel++
}
}
- if(sel == this.data.list.length){
+ if (sel == this.data.list.length && this.data.list.length != 0) {
this.setData({
- all:true
+ all: true
})
- }else{
+ } else {
this.setData({
- all:false
+ all: false
})
}
this.setData({
- price:num/100
+ price: num / 100
})
},
- call(){
+ call() {
let sel = 0;
let select = []
- for(let i in this.data.list){
+ for (let i in this.data.list) {
console.log(i)
- if(this.data.select[i]){
- // num += parseFloat(this.data.list[i].goods_price)*100
- sel++
- }else{
+ if (this.data.select[i]) {
+ // num += parseFloat(this.data.list[i].goods_price)*100
+ sel++
+ } else {
select[i] = true
}
}
- if(sel == this.data.list.length){
+ if (sel == this.data.list.length) {
this.setData({
- all:false,
- select:[]
+ all: false,
+ select: []
})
- }else{
+ } else {
this.setData({
- all:true,
+ all: true,
select
})
}
this.num()
+ },
+ del() {
+ for (let i in this.data.list) {
+ // console.log(i)
+ if (this.data.select[i]) {
+ // num += parseFloat(this.data.list[i].goods_price)*100
+ // sel++
+ request({
+ url: "Cart/delCart",
+ urldata: {
+ id: this.data.list[i].id
+ }
+ }).then((res) => {
+ console.log('删除成功')
+ this.setData({
+ list: [],
+ select: [],
+ userid: 0,
+ price: "0.00"
+ })
+ this.onLoad()
+ })
+ }
+ }
}
})
\ No newline at end of file
diff --git a/pages/shopping/shopping.wxml b/pages/shopping/shopping.wxml
index b8a8e69..58f0a24 100644
--- a/pages/shopping/shopping.wxml
+++ b/pages/shopping/shopping.wxml
@@ -18,7 +18,7 @@
${{price}}
- 删除
+ 删除
结算