123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- const { default: api } = require("../../js/api");
- Page({
- data: {
- id: 4 , // 初始ID值
- nozzleId:0,
- order:null,
- countdown: 120,
- progressWidth: 100, // 初始进度条宽度为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
- }) // 保存定时器,以便在onUnload中清除
- },
- /** 轮询检查油枪状态 */
- 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;
- }
- }
- });
|