123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- // pages/pay/pay.js
- const app = getApp();
- const { axios } = app.globalData;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- loadding: false,//正在支付中 true
- disabled: false,//支付完毕 true
- message: '',//订单备注
- paytype: "1",// 支付方式
- },
- // 提交支付
- onSubmit () {
- let { id: commodity, message: notes, useraddress } = this.data, { id: student } = useraddress, that = this;
- if (!student) {
- wx.showToast({
- title: '请选择学生',
- icon: 'error'
- })
- return false;
- }
- let { appid, user } = app.globalData, { openid } = user;
- function pay () {
- return new Promise(resolve => {
- axios({
- url: `/order/`,
- method: 'post',
- data: {
- appid, openid, notes, commodity, student
- },
- success (res) {
- that.setData({ loadding: true })
- let { data } = res.data;
- wx.requestPayment({
- timeStamp: data.timeStamp,
- nonceStr: data.nonceStr,
- package: data.package,
- signType: data.signType,
- paySign: data.paySign,
- success: function (res) {
- resolve({ type: 1, value: "支付成功" })
- },
- fail: function () {
- // 取消付款
- resolve({ type: 2, value: "支付失败" })
- },
- })
- }
- })
- })
- }
- pay().then(
- res => {
- that.setData({ loadding: false, disabled: true })
- wx.redirectTo({
- url: '/pages/order/order',
- })
- }
- );
- },
- // 挑选地址
- ChooseAddress () {
- wx.navigateTo({
- url: `/pages/adddata/adddata?data=${JSON.stringify({ source: 'pay' })}`,
- })
- },
- // 支付方式改变
- onChange (e) {
- let { detail } = e;
- this.setData({ paytype: detail })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.lxd.Ctr({
- // nav
- title: "支付", //标题
- bgc: false,//使用更改后的颜色;配合json使用
- })
- let { data } = options;
- if (!!data) {
- data = JSON.parse(data);
- this.setData({
- ...data
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let { useraddress } = app.globalData;
- this.setData({ useraddress })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- app.globalData.useraddress = {};
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- })
|