You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
5.6 KiB
JavaScript

9 months ago
const app = getApp();
var wxbarcode = require('../../utils/wxbarcode.js');
const mqttMessage = require('../../utils/mqttMessage.js');
const card = require('../../utils/card.js');
Page({
/**
* 页面的初始数据
*/
data: {
timer: null,
time: 60,
availableAmount: 0,
paycode: "",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// console.log(app.globalData.cardInfo);
// var cardInfo = app.globalData.cardInfo;
// this.setData({
// availableAmount: cardInfo.availableAmount,
// });
this.cy_getPaymentCode();
this.setData({ color: app.globalData.color });
this.cy_sengPayCodeMessage();
},
cy_sengPayCodeMessage: function () {
var data = {
'openId': wx.getStorageSync('openId'),
'formId': "123456",
'wid': app.globalData.memberWid,
'sendType': "payCode",
'method': 'get.smweixin.formId',
'memberId': wx.getStorageSync('memberId'),
'cardNo': wx.getStorageSync('cardNo')
}
var ignores = [];
app.jsapi.memberApi(app.globalData.memberAppKey, app.globalData.memberAppSecret, app.globalData.memberUrl).ajax(data, ignores,
function (json) { },
function (error) { })
},
/**
* 查询卡信息
*/
cy_selectCardInfo: function () {
var that = this;
card.wx_cardInfo(app.globalData.cardNo, function (json) {
console.log(json);
var result = json.data;
if (result.status == 1) {
var cardInfo = result.data;
wx.setStorageSync("cardInfo", cardInfo);
app.globalData.cardInfo = cardInfo;
that.setData({
availableAmount: cardInfo.availableAmount
});
} else {
wx.showToast({
title: result.errMessage,
icon: "none"
})
}
}, function (err) {
wx.showToast({
title: "网络链接失败",
icon: "none"
})
});
},
/**
* 获取
*/
cy_getPaymentCode: function () {
var that = this;
var cardNo = app.globalData.cardInfo.cardNo;
var params = {
'cardNo': cardNo,
'shopNo': app.globalData.shopNo,
'posNo': app.globalData.posNo,
'workerNo': app.globalData.workerNo,
'sourceSign': app.sourceSign,
'method': 'card.get.payCode'
}
var ignores = [];
// app.globalData.memberUrl
app.jsapi.memberApi(app.globalData.memberAppKey, app.globalData.memberAppSecret, app.globalData.memberUrl).ajax(params, ignores,
function (json) {
console.log(json);
var result = json.data;
if (result.status == 1) {
var openData = result.data;
var oldPayCode = openData.payCode;
var payCode = oldPayCode.replace(/[\s]/g, '').replace(/(\d{4})(?=\d)/g, "$1 ");
that.setData({
hidden: true,
payCode: payCode,
});
//绘画多次防止二维码出不来
var canverCount = 5;
var intt;
intt = setInterval(function () {
if (canverCount > 0) {
wxbarcode.barcode('barcode', oldPayCode, 620, 180);
wxbarcode.qrcode('qrcode', oldPayCode, 340, 340);
} else {
clearInterval(intt);
}
canverCount--;
}, 100)
if (that.data.timer != null) {
return;
}
that.data.timer = setInterval(function () {
that.data.time--;
that.setData({
time: that.data.time
});
if (that.data.time == 0) {
that.setData({
time: 60
});
that.cy_getPaymentCode();
}
}, 1000);
} else {
// that.setData({
// hidden: true
// });
wx.showToast({
title: result.message,
icon: "none"
})
}
},
function (error) {
}
);
},
/**
*
*/
cy_tapReload: function () {
if (this.data.timer) {
clearInterval(this.data.timer);
this.data.timer = null;
}
this.setData({
time: 60
})
this.cy_getPaymentCode();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
if (this.data.timer) {
clearInterval(this.data.timer);
this.data.timer = null;
}
mqttMessage.mqttunSubscribe(app.getPayCode());
wx.setScreenBrightness({
value: this.data.oldScreenBrightness,
})
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
if (this.data.timer) {
clearInterval(this.data.timer);
this.data.timer = null;
}
mqttMessage.mqttunSubscribe(app.getPayCode());
wx.setScreenBrightness({
value: this.data.oldScreenBrightness,
})
},
onShow: function () {
var that = this;
that.subscribeScanCode();
that.cy_selectCardInfo();
wx.getScreenBrightness({
success: function (e) {
that.setData({
oldScreenBrightness: e.value
})
wx.setScreenBrightness({
value: 1,
})
}
})
},
/**
* 订阅扫码主题
*/
subscribeScanCode: function () {
mqttMessage.mqttSubscribe(3);
mqttMessage.mqttOn(this);
},
onMessage: function (top, msg) {
app.globalFunction.scanPayCodeCallBack(JSON.stringify(msg));
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
return app.onShare;
}
})