Files
sphc/pages/welfare/cartPay/cartPay.js
2024-05-06 15:34:15 +08:00

398 lines
10 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/cartPay/cartPay.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
goods: [],
addressType: false,//收货方式
note: '',
addressId: '',//地址ID
address: '选择收货方式',//地址
province: '',
orderPick: 2,
date: '',
time: '',
startTime: '',
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
if (this.data.orderPick == 2) {
//收货地址
if (this.data.total && this.data.province != '') {
//订单个人信息获取
wx.showLoading({
title: '加载中',
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/order/getUserInfo',
method: 'GET',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
userId: app.globalData.userId
},
success: res => {
wx.hideLoading();
console.log(res)
if (res.data.code == 1) {
let dataList = res.data.value;
this.setData({
dataList: dataList,
pay: (parseFloat(this.data.payActual) * parseFloat(dataList.userVipDiscount) / 100).toFixed(2),
})
//运费获取
wx.request({
url: app.globalData.ip + '/wisdommining/api/order/getFreight',
method: 'GET',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
freightAddress: this.data.province,
price: this.data.total,
},
success: res => {
wx.hideLoading();
console.log(res)
if (res.data.code == 1) {
this.setData({
freight: res.data.value,
payActual: (parseFloat(this.data.total) + parseFloat(res.data.value) - parseFloat(this.data.discount)).toFixed(2),
payActualIntegral: parseFloat(this.data.total),
})
this.setData({
pay: (parseFloat(this.data.payActual) * parseFloat(this.data.dataList.userVipDiscount) / 100).toFixed(2),
})
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
}
} else {
// 自提点
this.setData({
freight: 0,
payActual: (parseFloat(this.data.total) - parseFloat(this.data.discount)).toFixed(2),
payActualIntegral: parseFloat(this.data.total),
})
this.setData({
pay: (parseFloat(this.data.payActual) * parseFloat(this.data.dataList.userVipDiscount) / 100).toFixed(2),
})
console.log(this.data.address)
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let myDate = new Date();
this.setData({
startTime: myDate.getFullYear() + '-' + (parseFloat(myDate.getMonth()) + 1) + '-' + (parseFloat(myDate.getDate()) + 3)
})
if (options.goods) {
let goods = JSON.parse(options.goods)
console.log(goods)
this.setData({
goods: goods,
packageId: options.packageId
})
this.userData()
}
},
userData() {
//订单个人信息获取
wx.showLoading({
title: '加载中',
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/order/getUserInfo',
method: 'GET',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
userId: app.globalData.userId
},
success: res => {
wx.hideLoading();
console.log(res)
if (res.data.code == 1) {
let dataList = res.data.value;
this.setData({
dataList: dataList,
})
if (dataList.wisdUserAddress && this.data.orderPick == 2) {
//默认地址ID
this.setData({
addressId: dataList.wisdUserAddress.id,
address: dataList.wisdUserAddress.addressProvince + dataList.wisdUserAddress.addressCity + dataList.wisdUserAddress.addressArea + dataList.wisdUserAddress.addressDetailed,
})
}
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
},
//备注
note(e) {
this.setData({
note: e.detail.value
})
},
//选择地址类型
addressType() {
this.setData({
addressType: true,//收货
})
},
//选择收货地址
address() {
wx.navigateTo({
url: '/pages/my/my_address/my_address?orderAddress=true&addressId=' + this.data.addressId,
})
this.setData({
addressType: false,//收货
})
},
//选择自提点
ztd() {
wx.navigateTo({
url: '/pages/index/index_address/index_address?pay=true',
})
this.setData({
addressType: false,//收货
})
},
//收获 遮罩层
addressZzc() {
this.setData({
addressType: false,//收货
})
},
//选择优惠方式
reduceType() {
this.setData({
reduceType: true,//优惠
})
},
//立即支付
pay(e) {
if (this.data.addressId == '') {
wx.showToast({
title: '请选择收货方式',
icon: 'none'
})
return
}
if (this.data.orderPick == 1) {
if (this.data.date == '') {
wx.showToast({
title: '请选择提货日期',
icon: 'none'
})
return
}
if (this.data.time == '') {
wx.showToast({
title: '请选择提货时间',
icon: 'none'
})
return
}
}
wx.showModal({
title: '提示!',
content: '确认要购买吗',
success: sss => {
if (sss.confirm) {
let orderPick = this.data.orderPick;
let wisdOrderDetailList = [];
console.log(this.data.goods)
//商品信息
for (let i = 0; i < this.data.goods.length; i++) {
wisdOrderDetailList.push({
goodsId: this.data.goods[i].goodsId,
goodsNum: this.data.goods[i].num,
})
}
console.log(wisdOrderDetailList)
wx.showLoading({
title: '加载中',
mask: true
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/order/addOrder',
method: 'POST',
data: {
userId: app.globalData.userId,
addressId: this.data.addressId,
orderActualPay: 0, //微信支付的钱 其余传0
orderOtherPay: 0, //积分 现金券 折扣券 套餐0
orderPayWay: 3, //1纯微信支付 2积分支付 3套餐券 4现金券+微信支付) 5折扣券+微信支付)
orderPick: orderPick, //1自提 2物流
orderPickTime:orderPick==1?this.data.date+' '+this.data.time:'',
orderRemark: this.data.note,
orderFreight: 0,
wisdOrderDetailList: wisdOrderDetailList,
packageId: parseInt(this.data.packageId),
isCar: 0
},
success: res => {
wx.hideLoading();
console.log(res)
if (res.data.code == 1) {
//支付
this.payM({
orderNumber: res.data.value
})
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
}
}
})
},
//支付
payM(options) {
wx.showLoading({
title: '支付中',
mask: true
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/pay/payOrder',
method: 'PUT',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
userId: app.globalData.userId,
orderNumber: options.orderNumber
},
success: res => {
wx.hideLoading();
console.log(res)
if (res.data.code == 2) {
//兑换成功
wx.showToast({
title: '兑换成功~',
icon: 'none',
duration: 1500,
success() {
setTimeout(() => {
wx.redirectTo({
url: '/pages/order_details/order_details?orderNumber=' + options.orderNumber,
})
}, 1000);
}
})
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
success: sss => {
if (sss.confirm) {
wx.redirectTo({
url: '/pages/order_details/order_details?orderNumber=' + options.orderNumber,
})
}
}
})
}
}
})
},
bindDateChange: function (e) {
console.log('picker发送选择改变携带值为', e.detail.value)
this.setData({
date: e.detail.value
})
},
bindTimeChange: function (e) {
console.log('picker发送选择改变携带值为', e.detail.value)
this.setData({
time: e.detail.value
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})