pplok #29
@ -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()
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
@ -18,7 +18,7 @@
 | 
			
		||||
         <text class="pri">${{price}}</text>
 | 
			
		||||
      </view>
 | 
			
		||||
      <view class="right">
 | 
			
		||||
         <text class="del">删除</text>
 | 
			
		||||
         <text class="del" bind:tap="del">删除</text>
 | 
			
		||||
         <text class="sub" bindtap="sub">结算</text>
 | 
			
		||||
      </view>
 | 
			
		||||
   </view>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user