scan.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const {
  2. default: api
  3. } = require("../../js/api");
  4. const utils = require('../../utils/util')
  5. Page({
  6. data: {
  7. isLoggedIn: false,
  8. site:{},
  9. userInfo: {},
  10. scanTitle: '扫码加油',
  11. scanTip: '请扫描加油机键盘上的二维码'
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  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. var formatePhone = utils.formatPhone(res.data.data.userInfo.userPhoneNumber);
  30. this.setData({
  31. isLoggedIn: true,
  32. site:res.data.data.site,
  33. userInfo: {
  34. userAddress:res.data.data.userInfo.userAddress,
  35. userAvatarUrl:res.data.data.userInfo.userAvatarUrl,
  36. userPhoneNumber:formatePhone,
  37. userName:res.data.data.userInfouserName
  38. },
  39. scanTitle: '扫码加油',
  40. scanTip: '请扫码加油机键盘上的二维码'
  41. })
  42. }).catch(err => {
  43. console.log("获取站点信息失败",err)
  44. })
  45. },
  46. toLoginOrOrderPage: function () {
  47. if (!this.data.isLoggedIn) {
  48. wx.navigateTo({
  49. url: '../login/login'
  50. })
  51. } else {
  52. wx.navigateTo({
  53. url: '../historyOrder/historyOrder?paymentMode=' + this.data.site.paymentMode,
  54. })
  55. }
  56. },
  57. // 打开扫码功能
  58. scanCode: function () {
  59. wx.showLoading({
  60. title: '正在跳转',
  61. })
  62. const that = this;
  63. wx.scanCode({
  64. success(res) {
  65. console.log("扫码内容",res.result)
  66. const scanStr = res.result;
  67. if(scanStr.includes('yuwxapp')) {
  68. const id = scanStr.split('yuwxapp?id=')[1];
  69. wx.redirectTo({
  70. url: '../quantify/quantify?id=' + id,
  71. fail(err){
  72. wx.showToast({
  73. title: '跳转页面失败',
  74. icon: 'none'
  75. });
  76. }
  77. })
  78. return
  79. }
  80. if(scanStr.includes('wxapp')) {
  81. const id = scanStr.split('wxapp?id=')[1];
  82. wx.redirectTo({
  83. url: '../TransactionPage/TransactionPage?id=' + id,
  84. fail(err){
  85. wx.showToast({
  86. title: '跳转页面失败',
  87. icon: 'none'
  88. });
  89. }
  90. })
  91. }
  92. },
  93. fail(err) {
  94. console.error('扫码失败:', err);
  95. wx.showToast({
  96. title: '扫码失败',
  97. icon: 'none'
  98. });
  99. }
  100. });
  101. }
  102. });