// pages/order/order.js
|
var listData = require('../../data/test-data.js');
|
var utils = require("../../utils/util.js");
|
var app = getApp();
|
var that;
|
let isUsingCoupon = false;
|
// var pointData = {
|
// sum: 1000,
|
// canUse: 100,
|
// isUse: false
|
// };
|
// var userData = {
|
// balance: 1000
|
// }
|
Page({
|
data: {
|
oldTotalMoney: 0,
|
showAddr: false,
|
showAddAddr: true,
|
totalMoney: 0, // 合计金额
|
sumMoney:0,
|
date: "",
|
showHidelayer:false,
|
voucherCost:-1,
|
deliveryMethodIndex:0,
|
// 发票信息
|
invoice: [
|
{
|
id: 0,
|
name: '不要发票'
|
},
|
{
|
id: 1,
|
name: '纸质发票--个人'
|
},
|
{
|
id: 2,
|
name: '纸质发票--企业'
|
},
|
{
|
id: 3,
|
name: '电子发票--个人'
|
},
|
{
|
id: 4,
|
name: '电子发票--企业'
|
}
|
],
|
// 积分信息
|
// point: {
|
// sum: pointData.sum,
|
// canUse: pointData.canUse,
|
// offMoney: parseInt(pointData.canUse / 100),
|
// isUse: pointData.isUse
|
// },
|
// 个人余额
|
Balance:0,
|
clientHeight: "100%",
|
overflow: "auto",
|
isSelected: true, //优惠券默认选中不使用
|
isSelected2: true, //积分默认选中不使用
|
isChecked: false, //默认不选择余额支付
|
id: -1, // 优惠券栏默认不使用
|
pointId: -1, // 积分栏默认显示不使用
|
offLast: 0, //上个折扣值
|
newMsg: ''
|
},
|
onShow() {
|
console.log(getCurrentPages())
|
wx.showLoading({
|
title: '加载中',
|
});
|
|
|
var that = this;
|
// // 显示对方发来的最新消息
|
// app.globalData.newMsgCallback = onMessage => {
|
// console.log('订单页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
|
// utils.msgTimer(that);
|
// }
|
// // 页面显示时更新未读消息的值
|
// utils.refreshUnreadMsgNum(this);
|
|
// wx.request({
|
// url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
|
// header: {
|
// "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
// },
|
// success: res => {
|
|
// // if (res.data.cltcode == "") {
|
// // wx.navigateTo({
|
// // url: '../login/login',
|
// // })
|
// // return false;
|
// // }
|
// wx.hideLoading();
|
// utils.requestError(res);
|
|
// this.setData({
|
// Address: res.data.Address
|
// })
|
// },
|
// fail: function (errmsg) {
|
// utils.requestFail(errmsg,'/shopping/confirm.do');
|
// }
|
// })
|
|
wx.request({
|
url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
this.setData({
|
Address: res.data.Address,
|
})
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg, '/shopping/confirm.do');
|
}
|
})
|
},
|
|
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady: function () {
|
|
},
|
|
// 获取地址
|
getAddress() {
|
wx.navigateTo({
|
url: '../addressList/addressList?way=select'
|
})
|
},
|
|
getOrderData(){
|
wx.request({
|
url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
this.setData({
|
Address: res.data.Address,
|
totalMoney: res.data.PayAmount,
|
CartList: res.data.CartList,
|
CouponList: res.data.CouponList,
|
PointsTimesList: res.data.PointsTimesList,
|
Points: res.data.UserPoints,
|
Balance: res.data.Balance,
|
CurrencySign: res.data.CurrencySign,
|
PreSendDate: res.data.PreSendDate,
|
balance2: res.data.Balance,
|
isAllowPayable:res.data.isAllowPayable,
|
VoucherAmount:res.data.VoucherList.VoucherAmount || 0
|
})
|
|
if (res.data.Balance>0){
|
this.setData({
|
isChecked:true
|
})
|
}
|
if(res.data.CouponList.length>0){
|
this.setData({
|
id:0,
|
})
|
}
|
isUsingCoupon=true;
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg, '/shopping/confirm.do');
|
}
|
})
|
},
|
|
onLoad() {
|
|
let deliveryMethod = app.globalData.deliveryMethod&&app.globalData.deliveryMethod.split(';');
|
this.setData({
|
RewardStatus:app.globalData.RewardStatus,
|
isAllowSelectDeliveryMethod:app.globalData.isAllowSelectDeliveryMethod,
|
deliveryMethod,
|
CouponStatus:app.globalData.CouponStatus,
|
VoucherStatus:app.globalData.VoucherStatus,
|
})
|
console.log('进入order页',deliveryMethod,this.data.isAllowSelectDeliveryMethod)
|
this.getOrderData();
|
|
|
},
|
// 日期选择器
|
bindDateChange: function (e) {
|
this.setData({
|
date: e.detail.value,
|
PreSendDate: e.detail.value
|
})
|
},
|
// 发票选择
|
// bindPickerChange: function (e) {
|
// this.setData({
|
// index: e.detail.value
|
// })
|
// },
|
|
|
// 积分按钮
|
pointUseTap: function () {
|
|
if (this.data.isShow) {
|
this.hideLayer2();
|
}
|
else {
|
this.showLayer2();
|
}
|
},
|
|
// 余额按钮
|
balanceTap: function () {
|
var check = this.data.isChecked;
|
check = !check;
|
this.setData({
|
isChecked: check
|
})
|
|
if(this.data.isChecked){
|
this.setData({
|
Balance: this.data.balance2
|
})
|
} else{
|
this.setData({
|
Balance: 0
|
})
|
}
|
|
wx.showLoading();
|
wx.request({
|
url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
data: {
|
couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
|
points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
|
balance: this.data.Balance,
|
isUsingCoupon
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
this.setData({
|
totalMoney: res.data.PayAmount,
|
CartList: res.data.CartList,
|
CouponList: res.data.CouponList,
|
PointsTimesList: res.data.PointsTimesList,
|
Points: res.data.UserPoints,
|
Balance: res.data.Balance,
|
PreSendDate: res.data.PreSendDate
|
})
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/confirm.do');
|
}
|
})
|
},
|
|
|
|
// 优惠券栏点击
|
ticketTap: function () {
|
if (this.data.isShow) {
|
this.hideLayer();
|
}
|
else {
|
this.showLayer();
|
}
|
},
|
|
// 选择优惠券
|
ticketItemTap: function (e) {
|
|
// 页面显示优惠券选择状态
|
var id = parseInt(e.detail.value);
|
this.setData({
|
id: id
|
})
|
|
if (id == -1) {
|
this.setData({
|
isSelected: true
|
})
|
isUsingCoupon=false;
|
} else {
|
this.setData({
|
isSelected: false
|
})
|
isUsingCoupon=true;
|
}
|
|
|
this.hideLayer();
|
|
wx.showLoading();
|
wx.request({
|
url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
data: {
|
couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
|
points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
|
balance: this.data.Balance,
|
isUsingCoupon
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
this.setData({
|
totalMoney: res.data.PayAmount,
|
CartList: res.data.CartList,
|
CouponList: res.data.CouponList,
|
PointsTimesList: res.data.PointsTimesList,
|
Points: res.data.UserPoints,
|
Balance: res.data.Balance,
|
PreSendDate: res.data.PreSendDate
|
})
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/confirm.do');
|
}
|
})
|
},
|
|
// 选择积分
|
pointItemTap: function (e) {
|
console.log(e)
|
// 页面显示积分选择状态
|
var pointId = parseInt(e.detail.value);
|
this.setData({
|
pointId: pointId
|
})
|
this.hideLayer2();
|
|
if (pointId==-1){
|
this.setData({
|
isSelected2: true
|
})
|
|
} else {
|
this.setData({
|
isSelected2: false
|
})
|
}
|
|
wx.showLoading();
|
wx.request({
|
url: utils.getUrl('/shopping/confirm.do?m=getConfirmInfo'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
data: {
|
couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
|
points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
|
balance: this.data.Balance,
|
isUsingCoupon
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
this.setData({
|
totalMoney: res.data.PayAmount,
|
CartList: res.data.CartList,
|
CouponList: res.data.CouponList,
|
PointsTimesList: res.data.PointsTimesList,
|
Points: res.data.UserPoints,
|
Balance: res.data.Balance,
|
PreSendDate: res.data.PreSendDate
|
})
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/confirm.do');
|
}
|
})
|
|
},
|
openHidelayer() {
|
this.setData({
|
showHidelayer: true
|
});
|
// setTimeout(()=>{
|
|
// },200)
|
|
},
|
maskTap(event) {
|
this.setData({
|
showHidelayer: event.detail.isShow
|
});
|
},
|
|
getPresentCode(e){
|
let presentCode = e.detail.value.presentCode;
|
wx.request({
|
url: utils.getUrl('/shopping/voucher.do?m=get&voucherCode='+presentCode),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
|
// wx.showModal({
|
// title:'提示',
|
// content: '礼品券使用成功! '
|
// })
|
if(res.data.state=='success'){
|
this.getOrderData();
|
wx.showToast({
|
title: '礼品券使用成功!',
|
icon: 'success',
|
duration: 2000
|
})
|
this.setData({
|
showHidelayer: false,
|
// voucherCost:res.data.voucherCost
|
});
|
}
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg, '/shopping/voucher.do?m=get&voucherCode=');
|
}
|
})
|
},
|
|
showLayer: function () {
|
// 优惠券隐藏层滑入
|
var that = this;
|
utils.showLayer(that, "translateY", 300, 0, "animationData","isShow");
|
},
|
|
hideLayer: function () {
|
// 优惠券隐藏层滑出
|
var that = this;
|
utils.hideLayer(that, "translateY", 300, "animationData", "isShow");
|
},
|
|
showLayer2: function () {
|
// 积分隐藏层滑入
|
var that = this;
|
utils.showLayer(that, "translateY", 300, 0, "animationData2", "isShow2");
|
},
|
|
hideLayer2: function () {
|
// 积分隐藏层滑出
|
var that = this;
|
utils.hideLayer(that, "translateY", 300, "animationData2", "isShow2");
|
},
|
|
// preventMove: function () {
|
// // 利用catchtouchmove阻止背景滚动 不用添加任何代码
|
// },
|
// getAuthorize(e){
|
// console.log(e)
|
// },
|
|
deliveryMethodIndexChange(e) {
|
console.log('picker发送选择改变,携带值为', e.detail.value)
|
this.setData({
|
deliveryMethodIndex: e.detail.value
|
})
|
},
|
postOrder(event){
|
console.log(event)
|
let deliveryMethod = event.detail.value.deliveryMethod||0;
|
let delivery = this.data.deliveryMethod[deliveryMethod];
|
console.log(delivery);
|
if (delivery!=='到店自提'&&!this.data.Address.FullAddress || this.data.Address.FullAddress.trim() == '') {
|
wx.showToast({
|
title: '请选择地址',
|
icon: 'none',
|
duration: 1500
|
})
|
return false
|
}
|
|
// return
|
// if (this.data.isChecked && this.data.Balance < this.data.totalMoney) {
|
// wx.showToast({
|
// title: '余额不足',
|
// icon: 'none',
|
// duration: 1500
|
// })
|
// return false
|
// }
|
wx.showLoading()
|
wx.request({
|
url: utils.getUrl('/shopping/confirm.do?m=save'),
|
header: {
|
"Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
|
},
|
// method:'POST',
|
data:{
|
paymentaddress: this.data.Address.paymentaddress,
|
couponCode: this.data.id == -1 ? "" : this.data.CouponList[this.data.id].CouponCode,
|
presenddate: event.detail.value.date,
|
paymentcomment: event.detail.value.remark,
|
points: this.data.pointId == -1 ? "0" : this.data.PointsTimesList[this.data.pointId].StartPointsAmount,
|
balance: this.data.isChecked ? this.data.Balance : 0,
|
isUsingCoupon,
|
deliverymethod:delivery||''
|
},
|
success: res => {
|
wx.hideLoading();
|
if(!utils.requestError(res)){
|
return false;
|
}
|
// let weiXinPayAmount = 0
|
if (res.data.weiXinPayAmount == 0){
|
|
// docstatus = 0 and isAllowPayable = 0
|
wx.redirectTo({
|
url: '../orderSuccess/orderSuccess?doccode='+ res.data.doccode+'&linkman='+this.data.Address.LinkName + '&isCustomer=1',
|
})
|
|
|
} else {
|
|
if(res.data.DocStatus == 0 && res.data.isAllowPayable == 0){
|
// docstatus = 0 and isAllowPayable = 0
|
wx.redirectTo({
|
url: '../orderSuccess/orderSuccess?doccode='+ res.data.doccode+'&linkman='+this.data.Address.LinkName + '&isCustomer=1',
|
})
|
} else {
|
wx.redirectTo({
|
url: '../orderPay/orderPay?doccode=' + res.data.doccode,
|
})
|
}
|
}
|
|
|
},
|
fail: function (errmsg) {
|
utils.requestFail(errmsg,'/shopping/confirm.do');
|
}
|
})
|
},
|
onDialogClose(){
|
this.setData({
|
isShowDialog:false
|
})
|
// this.postOrder(this.data.dataEvent);
|
},
|
getUserInfo(e){
|
// if (!utils.authorize(e, this)){
|
// e.detail.isAuthorize = false;
|
// contactComp.getAuthorize(e);
|
// return;
|
// }
|
utils.authorize(e, this);
|
this.postOrder(this.data.dataEvent);
|
},
|
|
placeOrder: function (event) {
|
console.log('提交订单事件',event)
|
// return;
|
let orderTemplateId = app.globalData.orderNoticeTemplateIdList;
|
let ids = [];
|
if(this.data.isAllowPayable==0){
|
ids = [orderTemplateId.payableTemplateId,orderTemplateId.templateId,orderTemplateId.shippedTemplateId];
|
} else {
|
ids = [orderTemplateId.shippedTemplateId,orderTemplateId.templateId];
|
}
|
|
utils.subscribeMessage({
|
ids:ids,
|
callback:()=>{
|
this.postOrder(event);
|
// utils.isAuthorize(this,()=>{
|
// if (this.data.isAuthorize) {
|
// this.postOrder(event);
|
// } else {
|
// this.setData({
|
// isShowDialog: true,
|
// dataEvent:event
|
// })
|
// }
|
// });
|
|
}
|
})
|
|
|
|
// if (this.data.showAddAddr) {
|
// utils.showTip("请填写收货地址", "none");
|
// return false;
|
// }
|
// else if (event.detail.value.date == "" && !this.data.PreSendDate) {
|
// utils.showTip("请填写交货日期","none");
|
// return false;
|
// }
|
|
// // 发起支付
|
// var orderDetail = this.data.detail;
|
// var userInfo = { name: this.data.name, tel: this.data.tel, addrdetail: this.data.addrdetail };
|
// var totalPrice = this.data.totalMoney;
|
// var remarks = event.detail.value.remark;
|
// wx.getStorage({
|
// key: 'openid',
|
// success: function (res) {
|
// var openId = res.data;
|
// if (!openId) {
|
// console.log('未获取到openId请刷新重试');
|
// return false;
|
// }
|
|
|
|
// //传参数金额,名称,描述,openid
|
// Bmob.Pay.wechatPay(totalPrice, '小程序商城', '描述', openId).then(function (resp) {
|
|
// //服务端返回成功
|
// var timeStamp = resp.timestamp,
|
// nonceStr = resp.noncestr,
|
// packages = resp.package,
|
// orderId = resp.out_trade_no,//订单号,如需保存请建表保存。
|
// sign = resp.sign;
|
// //发起支付
|
// wx.requestPayment({
|
// 'timeStamp': timeStamp,
|
// 'nonceStr': nonceStr,
|
// 'package': packages,
|
// 'signType': 'MD5',
|
// 'paySign': sign,F
|
// 'success': function (res) {
|
// //付款成功,这里可以写你的业务代码
|
// var User = Bmob.Object.extend("_User");
|
// var currentUser = Bmob.User.current();
|
// var objectid = currentUser.id;
|
// var Order = Bmob.Object.extend("Order");
|
// var Order = new Order();
|
// var me = new Bmob.User();
|
// me.id = objectid;
|
// Order.set("remarks", remarks);
|
// Order.set("orderUser", me);
|
// Order.set("totalprice", parseFloat(totalPrice));
|
// Order.set("orderDetail", orderDetail);
|
// Order.set("orderId", orderId);
|
// Order.set("status", 1);
|
// Order.set("userInfo", userInfo);
|
// Order.save(null, {
|
// success: function (result) {
|
// wx.redirectTo({
|
// url: '../order/index'
|
// })
|
// },
|
// error: function (result, error) {
|
|
// }
|
// });
|
// },
|
// 'fail': function (res) {
|
// console.log(res)
|
// var User = Bmob.Object.extend("_User");
|
// var currentUser = Bmob.User.current();
|
// var objectid = currentUser.id;
|
// var Order = Bmob.Object.extend("Order");
|
// var Order = new Order();
|
// var me = new Bmob.User();
|
// me.id = objectid;
|
// Order.set("remarks", remarks);
|
// Order.set("orderUser", me);
|
// Order.set("totalprice", parseInt(totalPrice));
|
// Order.set("orderDetail", orderDetail);
|
// Order.set("status", 0);
|
// Order.set("userInfo", userInfo);
|
// Order.set("orderId", orderId);
|
// Order.save(null, {
|
// success: function (result) {
|
// console.log(result.id)
|
// },
|
// error: function (result, error) {
|
|
// }
|
// });
|
// }
|
// })
|
|
// }, function (err) {
|
// console.log('服务端返回失败');
|
// console.log(err);
|
// });
|
|
// }
|
// })
|
|
// console.log(event);
|
|
|
|
}
|
|
});
|