123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- // pages/scan/scan.js
- const app = getApp()
- import { userEntityRecharge } from '../../api/charge'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- scanFunctionUse: true,
- scanOverShow: false,
- scanTimer: null,
- scanSuccess: true,
- cardNo: '',
- cardSecret: ''
- },
- // 用户不允许使用摄像头时触发
- error () {
- console.log('eooro');
- app.globalData.auth.camera = false
- },
- // 重新扫码
- handleRescan () {
- this.setData({
- scanOverShow: false,
- scanFunctionUse: true
- })
- },
- // 在扫码识别成功时触发,仅在 mode="scanCode" 时生效
- handlescancode (e) {
- var that = this
- if (that.data.scanFunctionUse) {
- that.setData({
- scanFunctionUse: false
- })
- var response = e.detail.result
- if (response.indexOf('|') !== -1) {
- var code = response.split('|')[0]
- var password = response.split('|')[1]
- that.setData({
- cardNo: code,
- cardSecret: password
- })
- that.userEntityRechargeFn()
- } else {
- wx.showModal({
- content: '请扫描正确的二维码',
- confirmColor: '#333',
- showCancel: false,
- success (res) {
- if (res.confirm) {
- that.setData({
- scanFunctionUse: true
- })
- }
- }
- })
- }
- }
- },
- // 实体卡充值
- userEntityRechargeFn () {
- var that = this
- wx.showLoading({
- title: '充值中...',
- mask: true
- })
- var data = {
- cardNo: that.data.cardNo,
- cardSecret: that.data.cardSecret
- }
- userEntityRecharge(data).then(res => {
- wx.hideLoading()
- this.setData({
- scanOverShow: true,
- scanResMsg: res.msg,
- scanSuccess: true
- })
- }).catch(e => {
- wx.hideLoading()
- this.setData({
- scanOverShow: true,
- scanResMsg: e,
- scanSuccess: false
- })
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options, 'options');
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow(option) {
- if (!app.globalData.auth.camera) {
- wx.getSetting({
- success (res) {
- console.log(res.authSetting['scope.camera'], 'getSetting')
- if (!res.authSetting['scope.camera']) {
- wx.showModal({
- title: '系统提示',
- content: '请打开相机权限',
- success (res) {
- if (res.confirm) {
- console.log('用户点击确定')
- wx.openSetting({
- success (res) {
- console.log(res, 'openSetting')
- app.globalData.auth.camera = res.authSetting['scope.camera']
- }
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- }
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- this.setData({
- scanOverShow: false,
- scanFunctionUse: true
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|