Browse Source

购物车功能修改

master
caichunsheng 4 years ago
parent
commit
7cae5f4a04
  1. 90
      pages/order/orderList/index.js
  2. 10
      pages/order/orderList/index.wxml
  3. 17
      pages/order/orderList/index.wxss
  4. 8
      pages/order/postOrder/index.js
  5. 6
      pages/order/postOrder/index.wxml
  6. 6
      pages/order/scene/index.js
  7. 4
      pages/order/scene/index.wxml
  8. 18
      pages/user/cartlist/list.js

90
pages/order/orderList/index.js

@ -7,46 +7,110 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
goodsList: [], goodsList: [],
ticketList: [], ticketList: [],
productPrice: 0, productPrice: 0,
ticketPrice: 0 ticketPrice: 0,
product:"",
sku_id: '',
kjId: null,
gp_id: null,
showPrice: 0,
postFee: 0,
coupon:null,
select_allowance: false,
allowance_data: null,
allowance_price: 0,
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
console.log(app.globalData.kjId)
this.setData({ this.setData({
goodsList: app.globalData.postProduct, goodsList: app.globalData.postProduct,
ticketList: app.globalData.list ticketList: app.globalData.list,
kjId: app.globalData.kjId,
gp_id: app.globalData.gp_id || app.globalData.team_id,
}) })
console.log(this.data.goodsList,this.data.ticketList) console.log(app.globalData);
let price = 0, sku_id = [];
app.globalData.postProduct.map(item => {
if (!app.globalData.kjId && !this.data.gp_id) {
price = price + item.sku.price * item.productNum;
}
else if (this.data.gp_id) {
price = price + item.sku.event_price * item.productNum;
}
sku_id.push(item.sku.id)
})
app.globalData.list.map(item => {
price = price + item.sku.price * item.num;
sku_id.push(item.sku.id)
})
this.setData({
showPrice: app.globalData.kjId ? 0 : price,
sku_id: sku_id.join(",")
})
if (!this.data.kjId && !this.data.gp_id) {
this.couponCom = this.selectAllComponents("#coupon")[0];
}
console.log(this.data.showPrice)
}, },
order: function (){ order: function (){
console.log(app.globalData.createDate);
app.globalData.createDate.coupon_id= this.data.coupon ? this.data.coupon.id : null;
let service = "order/create", postData = {data: JSON.stringify(app.globalData.createDate)} let service = "order/create", postData = {data: JSON.stringify(app.globalData.createDate)}
commonApi.user_post(service, postData).then(res => { commonApi.user_post(service, postData).then(res => {
}) })
}, },
changePrice: function () {
let product = this.data.product, price = 0;
product.map(item => {
price = price + item.sku.price * item.productNum;
if (this.data.allowance_data && this.data.select_allowance && this.data.allowance_price) {
let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price);
price -= this.data.allowance_price * item.productNum < spread_price ? this.data.allowance_price * item.productNum : spread_price
}
})
if (this.data.coupon && this.data.showPrice != price) {
wx.showToast({
title: '订单价格发生变化,请重新选择优惠券',
icon: 'none'
})
app.globalData.couponInfo = null;
if (!this.data.kjId && !this.data.gp_id) {
this.couponCom.setNullCoupon()
}
this.setData({
coupon: null
})
}
this.setData({
showPrice: app.globalData.kjId ? 0 : price
})
},
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
onReady: function () { onReady: function () {
}, },
inputRemark: function (e) {
app.globalData.createDate.product_list.map((item)=>{
if (item.type.includes('post')) {
item.remark = e.detail.value;
}
})
},
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
this.setData({ this.setData({
productPrice: app.globalData.productPrice, coupon: app.globalData.couponInfo
ticketPrice: app.globalData.ticketPrice })
})
console.log(app.globalData.productPrice,app.globalData.ticketPrice)
}, },
/** /**

10
pages/order/orderList/index.wxml

@ -6,7 +6,7 @@
{{item.product.title}} {{item.product.title}}
</view> </view>
<view class="price"> <view class="price">
¥{{item.product.price/100}} ¥{{item.sku.price/100}}
</view> </view>
</view> </view>
<view class="item-box"> <view class="item-box">
@ -48,10 +48,16 @@
</view> </view>
</view> </view>
<view class="box-title">
<view style="flex-shrink:0">订单备注:</view>
<input type="text" bindinput="inputRemark" data-index="{{index}}" placeholder="选填"></input>
</view>
<coupon id="coupon" wx:if="{{!kjId && !gp_id && flag!='mix'}}" money="{{showPrice + postFee}}" sku="{{sku_id}}"></coupon>
<view class="fixed-bottom"> <view class="fixed-bottom">
<view class="fixed-price-box"> <view class="fixed-price-box">
<text>合计:</text> <text>合计:</text>
<text class="price">¥{{productPrice + ticketPrice}}</text> <text class="price">¥{{((showPrice + postFee - (coupon?coupon.activity.money:0))>0?(showPrice + postFee - (coupon?coupon.activity.money:0)):0)/100}}</text>
</view> </view>
<view class="fixed-btn" bindtap="order">下一步</view> <view class="fixed-btn" bindtap="order">下一步</view>
</view> </view>

17
pages/order/orderList/index.wxss

@ -1,9 +1,8 @@
page{ page{
background: #f5f5f5; background: #f5f5f5;
} }
.box{ .box{
width: 700rpx; margin: 30rpx 25rpx;
margin: 30rpx auto;
background: white; background: white;
padding: 20rpx; padding: 20rpx;
} }
@ -50,4 +49,16 @@ page{
color: #D62828; color: #D62828;
font-size: 36rpx; font-size: 36rpx;
margin-left: 10rpx; margin-left: 10rpx;
}
.box-title {
height: 113rpx;
padding: 0 20rpx;
font-size: 31rpx;
color: #000;
font-weight: 500;
display: flex;
align-items: center;
background-color: #fff;
margin: 30rpx 25rpx;
} }

8
pages/order/postOrder/index.js

@ -21,6 +21,7 @@ Page({
allowance_data: null, allowance_data: null,
allowance_price: 0, allowance_price: 0,
showAllowance: false, showAllowance: false,
flag:null,
}, },
/** /**
@ -31,7 +32,8 @@ Page({
from: options.from, from: options.from,
kjId: app.globalData.kjId, kjId: app.globalData.kjId,
gp_id: app.globalData.gp_id || app.globalData.team_id, gp_id: app.globalData.gp_id || app.globalData.team_id,
prizeId: wx.getStorageSync('prizeId') prizeId: wx.getStorageSync('prizeId'),
flag:options.flag
}) })
let price = 0, sku_id = []; let price = 0, sku_id = [];
app.globalData.postProduct.map(item => { app.globalData.postProduct.map(item => {
@ -143,7 +145,7 @@ Page({
let data = { let data = {
source: "WECHATXCX", source: "WECHATXCX",
product_list: product_list, product_list: product_list,
coupon: this.data.coupon ? this.data.coupon.id : null, coupon_id: this.data.coupon ? this.data.coupon.id : null,
originate_order_id: this.data.kjId, originate_order_id: this.data.kjId,
gp_id: app.globalData.gp_id, gp_id: app.globalData.gp_id,
team_id: app.globalData.team_id team_id: app.globalData.team_id
@ -185,7 +187,7 @@ Page({
app.globalData.createDate = data app.globalData.createDate = data
console.log(app.globalData.createDate) console.log(app.globalData.createDate)
wx.navigateTo({ wx.navigateTo({
url: '/pages/order/scene/index', url: '/pages/order/scene/index?flag='+this.data.flag,
}) })
} }
}, },

6
pages/order/postOrder/index.wxml

@ -29,8 +29,8 @@
<view style="flex:1">运费</view> <view style="flex:1">运费</view>
<text>{{item.postFee?(item.postFee==0?'包邮':(item.postFee/100)):item.sku.sku_model.post_template_name}}</text> <text>{{item.postFee?(item.postFee==0?'包邮':(item.postFee/100)):item.sku.sku_model.post_template_name}}</text>
</view> </view>
<view class="box-title"> <view class="box-title" wx:if="{{flag!='mix'}}">
<view style="flex-shrink:0">订单备注:</view> <view style="flex-shrink:0" >订单备注:</view>
<input type="text" bindinput="inputRemark" data-index="{{index}}" placeholder="选填"></input> <input type="text" bindinput="inputRemark" data-index="{{index}}" placeholder="选填"></input>
</view> </view>
<view class="all-money-box" wx:if="{{from=='cart'}}"> <view class="all-money-box" wx:if="{{from=='cart'}}">
@ -47,7 +47,7 @@
</view> </view>
</view> </view>
</view> </view>
<coupon id="coupon" wx:if="{{!kjId && !gp_id}}" money="{{showPrice + postFee}}" sku="{{sku_id}}"></coupon> <coupon id="coupon" wx:if="{{!kjId && !gp_id && flag!='mix'}}" money="{{showPrice + postFee}}" sku="{{sku_id}}"></coupon>
<view style="height:113rpx"></view> <view style="height:113rpx"></view>
<view class="fixed-bottom" wx:if="{{product}}"> <view class="fixed-bottom" wx:if="{{product}}">
<view class="fixed-price-box" wx:if="{{!prizeId}}"><text>合计:</text><text <view class="fixed-price-box" wx:if="{{!prizeId}}"><text>合计:</text><text

6
pages/order/scene/index.js

@ -26,7 +26,8 @@ Page({
showAllowance: false, showAllowance: false,
allowance_data: null, allowance_data: null,
allowance_price: 0, allowance_price: 0,
pIndex: 0 pIndex: 0,
flag:null,
}, },
/** /**
@ -38,7 +39,8 @@ Page({
type: options.type, type: options.type,
kjId: app.globalData.kjId, kjId: app.globalData.kjId,
gp_id: app.globalData.gp_id || app.globalData.team_id, gp_id: app.globalData.gp_id || app.globalData.team_id,
prizeId: wx.getStorageSync('prizeId') prizeId: wx.getStorageSync('prizeId'),
flag:options.flag
}) })
if (!app.globalData.product) { if (!app.globalData.product) {
util.back(); util.back();

4
pages/order/scene/index.wxml

@ -34,10 +34,10 @@
</view> </view>
</view> </view>
</view> </view>
<coupon wx:if="{{!kjId && !gp_id && type!='activity' && product && product.isGroup!=1}}" id="coupon" <coupon wx:if="{{!kjId && !gp_id && type!='activity' && product && product.isGroup!=1 && flag!='mix'}}" id="coupon"
money="{{singlePrice * productNum}}" sku="{{product.sku.id}}"></coupon> money="{{singlePrice * productNum}}" sku="{{product.sku.id}}"></coupon>
<view class="box" wx:if="{{type!='activity' && product && product.isGroup!=1}}"> <view class="box" wx:if="{{type!='activity' && product && product.isGroup!=1}}">
<view class="box-title"> <view class="box-title" wx:if="{{flag!='mix'}}">
<view style="flex-shrink:0">订单备注</view> <view style="flex-shrink:0">订单备注</view>
<input type="text" bindinput="changeRemark" placeholder="选填"></input> <input type="text" bindinput="changeRemark" placeholder="选填"></input>
</view> </view>

18
pages/user/cartlist/list.js

@ -17,7 +17,8 @@ Page({
list:[], list:[],
allChecked:false, allChecked:false,
allPrice:0, allPrice:0,
productType:'' productType:'',
flag:false,//判断订单是否同时有商品和票
}, },
/** /**
@ -109,7 +110,6 @@ Page({
}) })
}, },
order:function(){ order:function(){
console.log(this.data.productType)
app.globalData.couponInfo = null; app.globalData.couponInfo = null;
util.pagePoint({ util.pagePoint({
event:'cart_order' event:'cart_order'
@ -117,7 +117,6 @@ Page({
let list = this.data.list,price=0,product=[],product1=[] let list = this.data.list,price=0,product=[],product1=[]
list.map(item=>{ list.map(item=>{
if(item.checked){ if(item.checked){
console.log(item)
// item.product.type="post"; // item.product.type="post";
if(item.product.type == 'post'){ if(item.product.type == 'post'){
product.push({ product.push({
@ -128,11 +127,10 @@ Page({
}else{ }else{
product1.push(item) product1.push(item)
app.globalData.list = product1 app.globalData.list = product1
} }
if(item.product.type.includes('post')){ if(item.product.type.includes('post')){
this.data.productType = 'post' this.data.productType = 'post'
} }
console.log(this.data.productType)
} }
}) })
if(product.length==0 && product1.length==0) { if(product.length==0 && product1.length==0) {
@ -142,13 +140,19 @@ Page({
}) })
return; return;
} }
if (product.length>0 && product1.length>0) {
this.setData({
flag: 'mix'
})
}
app.globalData.postProduct = product; app.globalData.postProduct = product;
if(app.globalData.list){ if(app.globalData.list){
app.globalData.product = app.globalData.list[app.globalData.index] app.globalData.product = app.globalData.list[app.globalData.index]
} }
if(this.data.productType == 'post'){ if(this.data.productType == 'post'){
console.log(this.data.flag);
wx.navigateTo({ wx.navigateTo({
url: '/pages/order/postOrder/index?from=cart', url: '/pages/order/postOrder/index?from=cart&flag='+this.data.flag,
}) })
}else{ }else{
wx.navigateTo({ wx.navigateTo({

Loading…
Cancel
Save