scan.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. const {
  2. default: api
  3. } = require("../../js/api");
  4. Page({
  5. data: {
  6. isLoggedIn: false,
  7. site:{},
  8. userInfo: {},
  9. scanTitle: '扫码加油',
  10. scanTip: '请扫描加油机键盘上的二维码'
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad(options) {
  16. this.getSiteInfo()
  17. },
  18. onShow(){
  19. this.getSiteInfo()
  20. },
  21. /** 获取站点信息 */
  22. getSiteInfo(){
  23. api.request_GetSiteInfo().then(res => {
  24. if(res.data.statusCode == 203) {
  25. console.log("获取站点信息失败",res)
  26. return
  27. }
  28. console.log("站点信息",res)
  29. this.setData({
  30. isLoggedIn: true,
  31. site:res.data.data.site,
  32. userInfo: res.data.data.userInfo,
  33. scanTitle: '扫码加油',
  34. scanTip: '请扫码加油机键盘上的二维码'
  35. })
  36. }).catch(err => {
  37. console.log("获取站点信息失败",err)
  38. })
  39. },
  40. toLoginOrOrderPage: function () {
  41. if (!this.data.isLoggedIn) {
  42. wx.navigateTo({
  43. url: '../login/login'
  44. })
  45. } else {
  46. wx.navigateTo({
  47. url: '../historyOrder/historyOrder?paymentMode=' + this.data.site.paymentMode,
  48. })
  49. }
  50. },
  51. // 打开扫码功能
  52. scanCode: function () {
  53. const that = this;
  54. wx.scanCode({
  55. success(res) {
  56. console.log("扫码内容",res.result)
  57. const scanStr = res.result;
  58. if(scanStr.includes('wxapp')) {
  59. const id = scanStr.split('wxapp?id=')[1];
  60. wx.redirectTo({
  61. url: '../TransactionPage/TransactionPage?id=' + id,
  62. fail(err){
  63. wx.showToast({
  64. title: '跳转页面失败',
  65. icon: 'none'
  66. });
  67. }
  68. })
  69. }
  70. if(scanStr.includes('yuwxapp')) {
  71. const id = scanStr.split('yuwxapp?id=')[1];
  72. wx.redirectTo({
  73. url: '../quantify/quantify?id=' + id,
  74. fail(err){
  75. wx.showToast({
  76. title: '跳转页面失败',
  77. icon: 'none'
  78. });
  79. }
  80. })
  81. }
  82. },
  83. fail(err) {
  84. console.error('扫码失败:', err);
  85. wx.showToast({
  86. title: '扫码失败',
  87. icon: 'none'
  88. });
  89. }
  90. });
  91. }
  92. });