123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- // pages/my/cashier/cashier.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- order_no: "",
- pageinfo: {},
- price: 0,
- give_price: 0,
- is_online: 1,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var that = this;
- this.setData({
- order_no: options.order_no,
- is_online: wx.getStorageSync('is_online')
- });
- app.api.useApi(app.globalData.baseAppUrl + "api/recharge/order", {
- order_no: options.order_no,
- }, "get").then(function (res) {
- console.log(res)
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 1000);
- } else {
- var pageinfo = res.message.data
- that.setData({
- pageinfo: pageinfo,
- })
- if (pageinfo.total_money <= 0 || parseFloat(pageinfo.total_money) - parseFloat(pageinfo.price) <= 0) {
- var price = parseFloat(pageinfo.price) - parseFloat(pageinfo.total_money)
- that.setData({ price: price })
- }
- }
- }).catch(function (err) { console.log(err) })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- pay() {
- let that = this
- if (that.data.price > 0) {
- this.wxPay();
- } else {
- this.opay();
- }
- },
- opay(pay_trade_no = "") {
- var that = this;
- var no = that.data.order_no
- app.api.useApi(app.globalData.baseAppUrl + "api/payment", {
- order_no: no,
- pay_trade_no: pay_trade_no
- }, "post").then(function (res) {
- console.log(res)
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 1000);
- } else {
- wx.reLaunch({
- url: '/pages/order/detail/detail?order_no=' + no + '&subscribe=1'
- })
- }
- }).catch(function (err) { console.log(err) })
- // wx.switchTab({
- // url: '/pages/tabber/order/index',
- // })
- },
- click(e) {
- // this.pageinfo.price=e.currentTarget.dataset.price;
- this.setData({
- price: e.currentTarget.dataset.price,
- give_price: e.currentTarget.dataset.gprice,
- })
- },
- wxPay() {
- var that = this;
- var no = that.data.price
- app.api.useApi(app.globalData.baseAppUrl + "api/recharge/charge", {
- price: no.toFixed(2),
- }, "post").then(function (res) {
- console.log(res)
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 1000);
- } else {
- var paydata = res.message.data
- wx.requestPayment({
- timeStamp: paydata.timeStamp,
- nonceStr: paydata.nonceStr,
- package: paydata.package,
- signType: paydata.signType,
- paySign: paydata.paySign,
- success(res) {
- console.log(res);
- if (res.errMsg == "requestPayment:ok") {
- that.opay(paydata.pay_trade_no);
- }
- },
- fail(res) {
- wx.showLoading({
- title: "失败,请重试!",
- })
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 1000);
- console.log(res)
- }
- })
- }
- }).catch(function (err) { console.log(err) })
- },
- back: function () {
- wx.redirectTo({
- url: '/pages/order/detail/detail?order_no=' + this.data.order_no + '&subscribe=1',
- })
- }
- })
|