123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- const { default: api } = require("../../js/api");
- Page({
- data: {
- id: 4 ,
- nozzleId:0,
- order:null,
- countdown: 120,
- progressWidth: 100,
- totalSeconds: 60,
- currentSeconds: 60,
- countDownTimer:null,
- checkNozzleStatuesTimer:null,
- },
- onLoad(options) {
- console.log("收到预支付确定页信息",options)
- this.setData({
- id:options.id,
- nozzleId:options.nozzleId
- })
-
- const that = this;
- const eventChannel = this.getOpenerEventChannel();
- eventChannel.on('acceptDataFromAuthorization', function (data) {
- console.log(data)
- that.setData({
- order:data
- })
-
- if(options.id == 1) {
- that.toAuthorization();
- }
- });
- },
-
- back(){
- setTimeout(() => {
- wx.navigateBack()
- },500)
- },
-
-
- toAuthorization() {
- this.setData({
- id:1
- })
- const that = this;
- api.request_NozzleAuthorization(this.data.order.orderId).then(res => {
- console.log("授权",res)
- if(res.data.statusCode != 200) {
- that.setData({
- id:5
- })
- return
- }
- that.setData({
- id:3
- })
- that.countDown()
- that.startCheckNozzle()
- }).catch(err => {
- console.log("授权报错",err)
- that.setData({
- id:5
- })
- })
- },
-
- toUnAuthorization(){
- const that = this;
- api.request_CancelNozzleAuthorization(this.data.order.orderId).then(res => {
- console.log("取消授权",res)
- if(res.data.statusCode != 200) {
- that.countDown()
- that.startCheckNozzle()
- return
- }
- that.setData({
- id:5
- })
- })
- },
-
- toHistory() {
- setTimeout(() => {
- wx.reLaunch({
- url: '../historyOrder/historyOrder?paymentMode='+1,
- })
- },500)
- },
-
- countDown() {
- const that = this;
- let timer = setInterval(() => {
- let { currentSeconds, totalSeconds } = that.data;
- currentSeconds--;
- if (currentSeconds < 0) {
- that.toUnAuthorization()
- that.setData({
- currentSeconds: 60,
- progressWidth: 100
- })
- that.clearTimer()
- return
- }
- let aprogressWidth = (currentSeconds / totalSeconds) * 100;
- that.setData({
- currentSeconds: currentSeconds,
- progressWidth: aprogressWidth
- });
- }, 1000);
- that.setData({
- countDownTimer:timer
- })
- },
-
- startCheckNozzle(){
- const that = this;
- const timer = setInterval(() => {
- that.checkNozzleInfo()
- }, 3000);
- that.setData({
- checkNozzleStatuesTimer:timer
- })
- },
-
- checkNozzleInfo(){
- const that = this;
- api.request_GetNozzleInfo(this.data.nozzleId).then(res => {
- if (res.data.content.length != 0) {
- var nozzle = res.data.content[0];
-
- if(nozzle.status == 8) {
- that.setData({
- id:4
- })
- that.clearTimer()
- }
- }
- })
- },
- onUnload() {
- this.clearTimer()
- },
- clearTimer(){
- if (this.data.countDownTimer != null) {
- clearInterval(this.data.countDownTimer);
- this.data.countDownTimer = null;
- }
- if(this.data.checkNozzleStatuesTimer != null) {
- clearInterval(this.data.checkNozzleStatuesTimer)
- this.data.checkNozzleStatuesTimer = null;
- }
- }
- });
|