You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1026 lines
28 KiB

2 years ago
var app = getApp();
var util = require('../../utils/util.js')
var WXAPI = require('../../utils/server.js');
2 years ago
Page({
data: {
ispayOrder: false,
pays: [],
itemData: {},
userId: 0,
paytype: 'wxPay', //支付方式
cartId: 0,
addrId: 0, //收货地址//测试--
btnDisabled: false,
productData: [],
address: {},
total: 0,
yuan: 0, //临时储存先前的总价格
d_yuan: 0, //抵扣余额显示
vprice: 0,
vid: 0,
paswnum: 0,
reduce_money: 0, //优惠金额
addemt: 1, //加入次数
vou: [],
checked: false,
score: 0, //用户积分
allowscore: 0, //当前订单可用积分
checked01: false,
allow: 0,
pass_num: 4,
remind: true,
title: '请输入支付密码',
xsmoney: true, //控制显示金额
money: false,
pay_xs: true,
pages_sx: true,
dz_stu: false,
},
go: function (e) {
console.log(e);
this.setData({
dz_stu: true,
});
var url = e.currentTarget.dataset.url
wx.navigateTo({
url: url
})
},
//下拉刷新
onPullDownRefresh: function () {
wx.showNavigationBarLoading() //在标题栏中显示加载
this.Settlement();
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh() //停止下拉刷新
},
//调取分享
onShareAppMessage: function (res) {
var that = this;
var id = that.data.productId;
var title = that.data.title;
return {
title: title,
path: '/product/detail?productId=' + id,
success: function (res) {
console.log('转发成功')
},
fail: function (res) {
console.log('转发失败')
}
}
},
onLoad: function (options) {
console.log(app.globalData)
console.log('options')
var that = this;
that.get_plug();
wx.setNavigationBarColor({
frontColor: app.d.frontColor, //
backgroundColor: app.d.bgcolor //设置页面参数
})
var uid = app.globalData.userInfo.openid; // 微信id
var plug_ins = app.globalData.userInfo.plug_ins; // 插件
var coupon = app.globalData.userInfo.coupon; // 优惠券状态
var wallet = app.globalData.userInfo.wallet; // 钱包状态
this.setData({
cartId: options.cartId, // 购物车id
num1: options.num,
type: options.type ? options.type : 0, //(1.直接结算 0购物车结算)
bgcolor: '#FF6347', // 背景颜色
userId: uid, // 微信id
plug_ins: plug_ins, // 插件
coupon: coupon, // 优惠券状态
wallet: wallet, // 钱包状态
});
this.Settlement();
},
//页面加载完成函数
onReady: function () {
},
onUnload() { //onUnload监听页面卸载
var that = this;
2 years ago
// util.getUesrBgplus(that, app, true) //刷新显示购物车数量
// util.getUesrBgplus(that, app, false) //刷新显示购物车数量
2 years ago
var cartid = that.data.cartId
var type = that.data.type
if (type == 1) { //直接结算离开页面清除购物车数量
wx.request({
url: app.d.ceshiUrl + '&action=product&m=delcart',
method: 'post',
data: {
carts: that.data.cartId, // 购物车id
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
var status = res.data.status;
if (status == 1) {
that.setData({
remind: false
});
} else {
that.setData({
remind: true
});
}
},
error: function (e) {
wx.showToast({
title: '网络异常!',
duration: 2000
});
}
});
}
},
onShow: function () {
var that = this;
console.log(that.data.dz_stu)
if (that.data.dz_stu) {
that.setData({
dz_stu: false,
});
2 years ago
// util.getUesrBgplus(that, app, false)
2 years ago
wx.navigateTo({
url: '../order/pay?cartId=' + that.data.cartId,
})
}
if (that.data.pages_sx) {
setTimeout(function () {
that.Settlement();
}, 500);
}
},
// 进入结算页面
Settlement: function () {
var that = this;
wx.request({
url: app.d.ceshiUrl + '&action=product&m=Settlement',
method: 'post',
data: {
cart_id: that.data.cartId, // 购物车id
uid: that.data.userId, // 微信id
num1: that.data.num1, //数量
type: that.data.type, //(1.直接结算 0购物车结算)
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
var status = res.data.status;
if (status == 1) {
if (that.data.allow) {
res.data.arr.coupon_money = Number(res.data.arr.coupon_money) - Number(that.data.allow);
}
if (that.data.d_yuan) {
res.data.arr.coupon_money = Number(res.data.arr.coupon_money) - Number(that.data.user_money);
}
console.log(res.data.arr);
that.setData({
addemt: res.data.arr.addemt, // 是否有收货地址
address: res.data.arr.adds, // 收货地址
addrId: res.data.arr.adds.id ? res.data.arr.adds.id : '', // 收货地址id
productData: res.data.arr.pro, // 商品信息
total: res.data.arr.price, // 总价
money: res.data.arr.money, // 优惠券金额
coupon_money: Number(parseFloat(res.data.arr.coupon_money).toFixed(3).slice(0, -1)), // 优惠后金额
user_money: res.data.arr.user_money, // 用户余额
coupon_id: res.data.arr.coupon_id, // 优惠券id
discount: res.data.arr.discount, //控制优惠方式
scorebuy: res.data.arr.scorebuy, //积分消费规则
zhekou: res.data.arr.zhekou ? res.data.arr.zhekou : '', //会员折扣
freight: res.data.arr.yunfei ? res.data.arr.yunfei : 0, //运费
});
that.setData({
remind: false
});
} else {
that.setData({
remind: true
});
wx.showToast({
title: res.data.err,
icon: 'none',
duration: 2000,
});
if (status == 0) {
setTimeout(function () {
2 years ago
// util.getUesrBgplus(that, app, false)
2 years ago
wx.navigateBack({
delta: 1
})
}, 2000);
} else {
setTimeout(function () {
2 years ago
// util.getUesrBgplus(that, app, false)
2 years ago
wx.navigateBack({
delta: 1
})
}, 2000);
}
}
},
error: function (e) {
wx.showToast({
title: '网络异常!',
duration: 2000
});
}
});
},
// 点击优惠券
tapMainMenu: function (e) { // 获取当前显示的一级菜单标识
var coupon_id = e.target.id;
var taht = this;
var showModalStatus = taht.data.showModalStatus;
taht.getvou(coupon_id);
taht.setData({
showModalStatus: false
});
},
// 我的优惠券(可以使用的优惠券)
my_coupon: function () {
var that = this;
wx.request({
url: app.d.ceshiUrl + '&action=Coupon&m=my_coupon',
method: 'post',
data: {
openid: app.globalData.userInfo.openid,
cart_id: that.data.cartId, // 购物车id