| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- const app = getApp()
- const api = require('../../../../../request/api');
- const http = require('../../../../../request/http');
- const utils = require('../../../../../utils/util.js');
- const storeKeys = require('../../../../../utils/storageKeys.js');
- Page({
- data: {
- isLoading:true,
- isIphoneX: app.globalData.isIphoneX,
- orderId: "", //订单id
- countdownTime:'30分00秒',
- timer:null,
- },
- onLoad: function (options) {
- if (options) {
- this.data.orderId = options.orderId || "";
- }
- this.getOrderDetails()
- },
- //获取礼品卡订单详情
- getOrderDetails() {
- wx.showLoading({
- title: "加载中",
- mask: true
- });
- http.request({
- url: api.URL + "/api/order.RiceCardOrder/detail&order_id=" + this.data.orderId,
- token: utils.getStorageSync(storeKeys.TOKEN),
- method: 'GET',
- success: (res) => {
- wx.hideLoading();
- let detail = res.data.data.detail || {};
- console.log(res)
- if(detail.pay_status==0 && detail.order_status==10 && detail.djs_time>0){
- this.countdown(detail.djs_time)
- }
- this.setData({
- detail,
- isLoading: false
- });
- },
- error: (res) => {}
- })
- },
- countdown(times){
- this.data.timer = setInterval(()=> {
- let minute = 0, second = 0;
- if (times > 0) {
- minute = Math.floor(times / 60);
- second = Math.floor(times - minute*60);
- } else {
- clearInterval(this.data.timer);
- utils.toast("订单已关闭")
- wx.navigateBack({
- delta: 1
- })
- }
- if(minute<10){
- minute = '0' + minute
- }
- if(second<10){
- second = '0' + second
- }
- times--;
- this.setData({
- countdownTime: minute + '分' + second + '秒'
- })
- }, 1000);
- },
- commit: utils.throttle(function (e) {
- wx.showLoading({
- title: "加载中"
- });
- let data = {
- lob_type: "rice_card", //礼品卡固定为 rice_card
- order_id: this.data.orderId //礼品卡id
- }
- http.request({
- url: api.URL + '/api/pay/repay',
- method: 'POST',
- token: utils.getStorageSync(storeKeys.TOKEN),
- data: data,
- success: (res) => {
- wx.hideLoading();
- console.log(res)
- if (res.data.data.pay_type == 20) {
- this.wxPayment(res.data.data.payment);
- }
- },
- error: (res) => {},
- })
- }, 800),
- //调起微信支付
- wxPayment(data) {
- let _this = this;
- wx.requestPayment({
- nonceStr: data.nonceStr,
- package: 'prepay_id=' + data.prepay_id,
- paySign: data.paySign,
- signType: "MD5",
- timeStamp: data.timeStamp,
- success(res) {
- console.log(res)
- if (res.errMsg == "requestPayment:ok") {
- utils.toast('支付成功');
- wx.redirectTo({
- url: "/pages/index/pages/riceCard/cardPaySuccess/cardPaySuccess?orderId=" + _this.data.orderId
- })
- }
- },
- fail(res) {
- if (res.errMsg == "requestPayment:fail cancel") {
- utils.toast('已取消支付');
- _this.getOrderDetails()
- }
- }
- })
- },
- onHide: function () {
- clearInterval(this.data.timer);
- this.data.timer = null
- },
- onUnload: function () {
- clearInterval(this.data.timer);
- this.data.timer = null
- },
- })
|