inputcode.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/scancode/scancode.js
  2. var app = getApp();
  3. const util = require('../../utils/utils.js')
  4. Page({
  5. data: {
  6. inputLen: 9,
  7. isFocus: true,
  8. code: '',
  9. submitState: 0,//未输入车辆编号
  10. },
  11. onFocus: function (e) {
  12. let that=this
  13. console.log(e, 'pppp')
  14. that.setData({
  15. code: e.detail.value
  16. });
  17. if (that.data.code.length == 9) {
  18. that.setData({
  19. submitState: 1
  20. });
  21. }
  22. },
  23. // setValue: function (e) {
  24. // var that = this;
  25. // that.setData({
  26. // code: e.detail.value
  27. // });
  28. // if (that.data.code.length == 9) {
  29. // that.setData({
  30. // submitState: 1
  31. // });
  32. // }
  33. // },
  34. sureSubmit: util.throttle(function () {
  35. my.showLoading()
  36. var that = this;
  37. if (that.data.code != '') {
  38. that.getBikeMessage()
  39. } else {
  40. my.showToast({
  41. content: '请输入车牌号',
  42. icon: 'none',
  43. duration: 2000
  44. })
  45. }
  46. }, 1500),
  47. //获取车辆信息
  48. getBikeMessage: function () {
  49. var that = this;
  50. my.hideLoading()
  51. app.request('/bike/' + that.data.code, '', 'GET').then(res => {
  52. if (res.status == 200) {
  53. if (res.data.is_link == 0) {
  54. my.alert({
  55. title: '提示',
  56. content: '当前车子已下线请换辆车子骑行吧~',
  57. success: function (res) {
  58. my.reLaunch({
  59. url: '/pages/index/index',
  60. })
  61. }
  62. })
  63. return;
  64. } else if (res.data.put_status == 0) {
  65. my.alert({
  66. title: '提示',
  67. content: '当前车子还未投放请换辆车子骑行吧~',
  68. })
  69. return;
  70. } else if (res.data.is_low_battery_power == 0) {
  71. my.alert({
  72. title: '提示',
  73. content: '当前车子电量过低请换辆车子骑行吧~',
  74. })
  75. return;
  76. } else if (res.data.is_trouble == 1) {
  77. my.alert({
  78. title: '提示',
  79. content: '当前车子出现故障请换辆车子骑行吧~',
  80. })
  81. return;
  82. } else if (res.data.is_riding == 1) {
  83. my.alert({
  84. title: '提示',
  85. content: '当前车子正在骑行请换辆车子骑行吧~',
  86. })
  87. return;
  88. } else {
  89. console.log(that.data.code, 'that.data.code')
  90. my.reLaunch({
  91. url: '/pages/use_bike/use_bike?code=' + that.data.code,
  92. })
  93. }
  94. } else {
  95. my.alert({
  96. title: '提示',
  97. content: res.data.message,
  98. })
  99. }
  100. }).catch(err=>{
  101. console.log(err,'找不到车12121')
  102. })
  103. },
  104. onLoad: function (options) {
  105. },
  106. onReady: function () {
  107. },
  108. onShow: function () {
  109. },
  110. onHide: function () {
  111. },
  112. onUnload: function () {
  113. },
  114. onPullDownRefresh: function () {
  115. },
  116. onReachBottom: function () {
  117. },
  118. onShareAppMessage: function () {
  119. }
  120. })