Commit 36e87100 by 赵雅纹

Merge branch 'dev_7.1.0' into feature-zyw-sc

parents b039a797 3fe018ce
...@@ -2,40 +2,25 @@ ...@@ -2,40 +2,25 @@
const wxService = require('../../utils/wxService') const wxService = require('../../utils/wxService')
wxService.page({ wxService.page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
product:{ product: {
quantity:1 quantity: 1
}, },
isAllSelect:false, isAllSelect: false,
currentHeight:52, currentHeight: 52,
startX:'', startX: '',
delBtnWidth: 66,//删除按钮宽度单位(rpx) delBtnWidth: 66,//删除按钮宽度单位(rpx)
cartList:[ cartList: [],
{ outGoods: []
imgUrl:'',
name:'1111',
sku:'1',
price:'¥456',
shows:'',
},
{
imgUrl: '',
name: '222',
sku: '2',
price: '¥222',
shows:''
}
]
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad() {
wxService.getSystemInfo().then(res => { wxService.getSystemInfo().then(res => {
const { statusBarHeight } = res const { statusBarHeight } = res
const { currentHeight, currentMarginTop, currentPaddingTop } = this.data const { currentHeight, currentMarginTop, currentPaddingTop } = this.data
...@@ -43,7 +28,6 @@ wxService.page({ ...@@ -43,7 +28,6 @@ wxService.page({
currentHeight: currentHeight + statusBarHeight, currentHeight: currentHeight + statusBarHeight,
}) })
}) })
console.log(this.data.currentHeight)
}, },
/** /**
...@@ -56,10 +40,238 @@ wxService.page({ ...@@ -56,10 +40,238 @@ wxService.page({
selected: 2 selected: 2
}) })
} }
this.init()
},
init() {
wx.showLoading({
title: '加载中'
})
const trolleySku = {
count: 1,
skuId: '1556108807316000'
}
// 加入购物车
wxService.post('/sale/trolley/put', trolleySku).then(res => {
if (res) {
const { result } = res.data
if (result == 0) {
wx.hideLoading()
this.getCartList()
}
}
})
},
// 查询 /trolley/query
getCartList() {
wx.showLoading({
title: '加载中'
})
wxService.get('/sale/trolley/query').then(res => {
console.log('query', res)
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
this.setData({
cartList: data.skuVOList
})
}
}
// let promotionIds = res.data.data.shopCartItems.map(function (item) { // 获取购物车中商品库存信息
// return item.promotionId
// }).join(',')
// if (promotionIds === '') {
// this.setData({
// cartList: [],
// })
// wx.hideLoading()
// return false
// }
})
},
minusNum: function (e) { // 减少数量
let cartList = this.data.cartList
// let proNum = cartList[e.currentTarget.dataset.index].quantity
console.log('sssse', e.currentTarget.dataset)
// if (proNum > 1) {
// proNum--
// } else {
// wx.showToast({
// title: '数量不能为0',
// icon: 'none'
// })
// return false
// }
// cartList[e.currentTarget.dataset.index].quantity = proNum
// this.setData({
// cartList: cartList
// }, function () {
// this.setTotalFee()
// this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
// })
},
addNum: function (e) { // 增加数量
var cartList = this.data.cartList
console.log('add', e.currentTarget.dataset)
var choosePro = cartList[e.currentTarget.dataset.index]
console.log(choosePro)
var proNum = choosePro.quantity
if (choosePro.quantityAverage == '0') {
if (proNum < choosePro.selectSku.inventory_num) {
proNum++
} else {
wx.showToast({
title: '不能超过库存',
icon: 'none'
})
}
} else {
if (proNum < choosePro.quantityAverage) {
proNum++
} else {
wx.showToast({
title: '每人限购' + choosePro.quantityAverage + '件',
icon: 'none'
})
}
}
cartList[e.currentTarget.dataset.index].quantity = proNum
this.setData({
cartList: cartList
}, function () {
this.setTotalFee()
this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
})
}, },
blurNum: function (e) {
var newNum = e.detail.value
console.log('blurNum', newNum)
var cartList = this.data.cartList
if (newNum === '') {
newNum = 1
}
// cartList[e.currentTarget.dataset.index].quantity = newNum
// this.setData({
// cartList: cartList
// }, function () {
// this.setTotalFee()
// this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
// })
},
inputNum: function (e) { // 输入数量
var newNum = e.detail.value
console.log('newNum', newNum)
if (newNum) {
const { cartList } = this.data
if (newNum === '0') {
newNum = 1
} else {
newNum = parseInt(newNum)
}
}
// if(newNum) {
// var cartList = this.data.cartList
// var choosePro = cartList[e.currentTarget.dataset.index]
// if (newNum === '0') {
// newNum = 1
// } else {
// newNum = parseInt(newNum)
// if (choosePro.quantityAverage == '0') {
// if (newNum > choosePro.selectSku.inventory_num) {
// newNum = choosePro.selectSku.inventory_num
// wx.showToast({
// title: '不能超过库存',
// icon: 'none'
// })
// }
// } else {
// if (newNum > choosePro.quantityAverage) {
// newNum = choosePro.quantityAverage
// wx.showToast({
// title: '每人限购' + choosePro.quantityAverage + '件',
// icon: 'none'
// })
// }
// }
// }
// cartList[e.currentTarget.dataset.index].quantity = newNum
// this.setData({
// cartList: cartList
// }, function () {
// this.setTotalFee()
// this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
// })
// }
},
goBuy() {
let cartListData = this.data.cartList || []
if (!cartListData) return false
this.handleGoBuy()
},
handleGoBuy() {
// 下单
wx.showLoading({
title: '加载中'
})
wxService.post(`/sale/trade/buyer/create`).then(res => {
if (!res) return false;
const { result, data } = res && res.data || res && res.result
if (result == 0) {
delete data.appId
wx.requestPayment(Object.assign({
success(res) {
wx.hideLoading()
wx.showToast({
title: '支付成功',
icon: 'none',
mask: true
})
},
fail(res) {
wx.hideLoading()
wx.showToast({
title: '支付失败',
icon: 'none',
mask: true
})
}
}, data))
}
})
},
// 调整商品 /trolley/add
editOk() {
wx.showLoading({
title: '加载中'
})
wxService.post('/sale/trolley/add').then(res => {
console.log('query', res)
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
this.setData({
// cartList
})
} else {
wx.showToast({
title: res.data.message,
icon: 'none'
})
}
}
})
},
//选择商品 //选择商品
selectPro(e){ selectPro(e) {
var index = e.currentTarget.dataset.index; var index = e.currentTarget.dataset.index;
this.data.cartList[index].isSelect = !this.data.cartList[index].isSelect; this.data.cartList[index].isSelect = !this.data.cartList[index].isSelect;
this.setData({ this.setData({
...@@ -68,18 +280,18 @@ wxService.page({ ...@@ -68,18 +280,18 @@ wxService.page({
}, },
//全选 //全选
allSelect(){ allSelect() {
this.setData({ this.setData({
isAllSelect: !this.data.isAllSelect isAllSelect: !this.data.isAllSelect
}) })
if (this.data.isAllSelect){ if (this.data.isAllSelect) {
this.setData({ this.setData({
cartList: this.data.cartList.map((item) =>{ cartList: this.data.cartList.map((item) => {
item.isSelect = true item.isSelect = true
return item return item
}) })
}) })
}else{ } else {
this.setData({ this.setData({
cartList: this.data.cartList.map((item) => { cartList: this.data.cartList.map((item) => {
item.isSelect = false item.isSelect = false
...@@ -90,23 +302,56 @@ wxService.page({ ...@@ -90,23 +302,56 @@ wxService.page({
}, },
//删除商品 //删除商品
deletePro(e){ deletePro(e) {
const {index, skuid} = e.currentTarget.dataset
var self = this
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
content: '确认删除该商品', content: '确认删除该商品',
success: function (res) { success(res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定') var cartList = self.data.cartList
cartList = cartList.filter((item, i) => {
return i !== index
})
self.setData({
cartList: cartList
})
self.editDelOk(skuid) //调用完成
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消') console.log('用户点击取消')
} }
} }
}) })
}, },
editDelOk(skuId) {
wx.showLoading({
title: '加载中'
})
wxService.post(`/sale/trolley/remove?skuId=${skuId}`).then(res => {
if (res) {
const { result } = res.data
if (result == 0) {
wx.hideLoading()
setTimeout(() => {
wx.showToast({
title: '删除成功'
})
setTimeout(() => {
wx.hideToast();
}, 2000)
}, 100);
} else {
wx.showToast({
title: res.data.message,
icon: 'none'
})
}
}
})
},
// 开始滑动事件 // 开始滑动事件
touchS: function (e) { touchS: function (e) {
console.log('e',e)
if (e.touches.length == 1) { if (e.touches.length == 1) {
this.setData({ this.setData({
//设置触摸起始点水平方向位置 //设置触摸起始点水平方向位置
...@@ -115,7 +360,6 @@ wxService.page({ ...@@ -115,7 +360,6 @@ wxService.page({
} }
}, },
touchM: function (e) { touchM: function (e) {
console.log('333',e)
if (e.touches.length == 1) { if (e.touches.length == 1) {
//手指移动时水平方向位置 //手指移动时水平方向位置
var moveX = e.touches[0].clientX; var moveX = e.touches[0].clientX;
...@@ -135,7 +379,6 @@ wxService.page({ ...@@ -135,7 +379,6 @@ wxService.page({
var index = e.currentTarget.dataset.index; var index = e.currentTarget.dataset.index;
var cartList = this.data.cartList; var cartList = this.data.cartList;
cartList[index].shows = txtStyle; cartList[index].shows = txtStyle;
console.log("1", cartList[index].shows);
//更新列表的状态 //更新列表的状态
this.setData({ this.setData({
cartList: cartList cartList: cartList
...@@ -158,7 +401,6 @@ wxService.page({ ...@@ -158,7 +401,6 @@ wxService.page({
var index = e.currentTarget.dataset.index; var index = e.currentTarget.dataset.index;
var cartList = this.data.cartList; var cartList = this.data.cartList;
cartList[index].shows = txtStyle; cartList[index].shows = txtStyle;
console.log("1", cartList[index].shows);
//更新列表的状态 //更新列表的状态
this.setData({ this.setData({
cartList: cartList cartList: cartList
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
</view> </view>
<!-- 购物车列表 --> <!-- 购物车列表 -->
<view class="cart-content"> <view class="cart-content" wx:if="{{cartList.length}}">
<view class="cart-item" wx:for="{{cartList}}" wx:key="{{index}}"> <view class="cart-item" wx:for="{{cartList}}" wx:key="{{index}}">
<view class="cart-list" bindtouchstart="touchS" bindtouchmove="touchM" bindtouchend="touchE" style="{{item.shows}}" data-index="{{index}}"> <view class="cart-list" bindtouchstart="touchS" bindtouchmove="touchM" bindtouchend="touchE" style="{{item.shows}}" data-index="{{index}}">
<view class="select-radio" catchtap="selectPro" data-index="{{index}}"> <view class="select-radio" catchtap="selectPro" data-index="{{index}}">
...@@ -24,67 +24,26 @@ ...@@ -24,67 +24,26 @@
<view class="pro-info"> <view class="pro-info">
<image class="pro-img" src="/assets/imgs/7_1_0/icon.png" mode="widthFix"></image> <image class="pro-img" src="/assets/imgs/7_1_0/icon.png" mode="widthFix"></image>
<view class="pro-right-info"> <view class="pro-right-info">
<view class="pro-name">{{item.name}}</view> <view class="pro-name">{{item.productName}}</view>
<view class="pro-sku">{{item.sku}}</view> <view class="pro-sku">{{item.skuSpec}}</view>
<view class="pro-price"> <view class="pro-price">
<view class="price">{{item.price}}</view> <view class="price">{{item.price}}</view>
<view class="pro-num-edit"> <view class="pro-num-edit">
<button class="redus-num" data-index="{{j}}" catchtap="minusNum">-</button> <button class="redus-num" data-index="{{j}}" catchtap="minusNum">-</button>
<input class="pro-num-edit-input" type="number" data-index="{{j}}" catchtap bindblur="blurNum" bindinput="inputNum" value="{{product.quantity}}"></input> <input class="pro-num-edit-input" type="number" data-index="{{j}}" catchtap bindblur="blurNum" bindinput="inputNum" value="{{item.count}}"></input>
<button class="add-num" data-index="{{j}}" catchtap="addNum">+</button> <button class="add-num" data-index="{{j}}" catchtap="addNum">+</button>
</view> </view>
</view> </view>
</view> </view>
</view> </view>
</view> </view>
<view class="delete" bindtap="deletePro">删除</view> <view class="delete" data-index="{{index}}" data-skuId="{{item.skuId}}" bindtap="deletePro">删除</view>
</view> </view>
<!-- <view class="cart-item" bindtouchstart="touchS" bindtouchmove="touchM" bindtouchend="touchE" style="{{shows}}" >
<view class="cart-list" >
<view class="select-radio">
<view class="{{isSelect ? 'theme-color' : ''}} circle-radio" >
<image wx:if="{{isSelect}}" class="tick-success" src="/assets/imgs/7_1_0/tick-success.png" mode="widthFix"></image>
</view>
</view>
<view class="pro-info">
<image class="pro-img" src="/assets/imgs/7_1_0/icon.png" mode="widthFix"></image>
<view class="pro-right-info">
<view class="pro-name">商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称</view>
<view class="pro-sku">规格</view>
<view class="pro-price">
<view class="price">¥256</view>
<view class="pro-num-edit">
<button class="redus-num" data-index="{{j}}" catchtap="minusNum">-</button>
<input class="pro-num-edit-input" type="number" data-index="{{j}}" catchtap bindblur="blurNum" bindinput="inputNum" value="{{product.quantity}}"></input>
<button class="add-num" data-index="{{j}}" catchtap="addNum">+</button>
</view>
</view>
</view>
</view>
</view>
<view class="delete">删除</view>
</view> -->
</view> </view>
<!-- 失效宝贝 --> <!-- 失效宝贝 -->
<view class="overdue-pro"> <view class="overdue-pro" wx:if="{{outGoods.length}}">
<view class="clear-btn">清除失效商品</view> <view class="clear-btn">清除失效商品</view>
<view class="overdue-list clearflex">
<view class="overdue-status">失效</view>
<view class="pro-info">
<image class="pro-img" src="/assets/imgs/7_1_0/icon.png" mode="widthFix"></image>
<view class="pro-right-info">
<view class="pro-name overdue-name">商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称商品名称</view>
<view class="pro-sku">规格</view>
<view class="pro-price">
<view class="price overdue-price">¥256</view>
</view>
</view>
</view>
</view>
<view class="overdue-list clearflex"> <view class="overdue-list clearflex">
<view class="overdue-status">失效</view> <view class="overdue-status">失效</view>
<view class="pro-info"> <view class="pro-info">
...@@ -100,7 +59,7 @@ ...@@ -100,7 +59,7 @@
</view> </view>
</view> </view>
<view class="empty">亲,您的购物车还空空的哟~</view> <view class="empty" wx-if="{{cartList !== null && cartList.length == 0}}">亲,您的购物车还空空的哟~</view>
<!-- 底部 --> <!-- 底部 -->
<view class="cart-bottom" style="bottom:{{currentHeight}}px"> <view class="cart-bottom" style="bottom:{{currentHeight}}px">
...@@ -116,7 +75,7 @@ ...@@ -116,7 +75,7 @@
<text class="total-price">¥306</text> <text class="total-price">¥306</text>
</view> </view>
</view> </view>
<view class="theme-color buy-btn">立即购买</view> <view class="theme-color buy-btn" bindtap="goBuy">立即购买</view>
</view> </view>
</view> </view>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment