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

151 line
3.2 KiB

  1. // pages/passCar/passCar.js
  2. let config = require('../../config/config.js')
  3. let Http = require('../../utils/HttpBasics')
  4. const app = getApp();
  5. Page({
  6. data: {
  7. park: null,
  8. carList: [],
  9. addCar: null,
  10. },
  11. onLoad: function(options) {
  12. var that = this
  13. app.userCarLogin()
  14. that.init();
  15. },
  16. onShow: function(options) {
  17. var that = this
  18. console.log(options)
  19. if (that.data.addCar) {
  20. // 绑车牌
  21. if (app.globalData.carLogin) {
  22. that.bindCar(that.data.addCar)
  23. } else {
  24. app.userCarLogin()
  25. that.bindCar(that.data.addCar)
  26. }
  27. }
  28. },
  29. jumpToAdd: function() {
  30. wx.navigateTo({
  31. url: '/pages/addPark/addPark',
  32. });
  33. },
  34. jumpToPay: function() {
  35. wx.redirectTo({
  36. url: '/pages/pay/pay',
  37. })
  38. },
  39. passb: function() {
  40. wx.showToast({
  41. title: '货物在路上~',
  42. })
  43. },
  44. passc: function() {
  45. wx.showToast({
  46. title: '宝宝最可爱~',
  47. })
  48. },
  49. orderPay: function() {
  50. wx.redirectTo({
  51. url: '/pages/pay/pay'
  52. });
  53. },
  54. bindCar: function(carNum) {
  55. var that = this
  56. // ETCP
  57. var etcpData = {
  58. etcpToken: app.globalData.etcpToken,
  59. carNumber: carNum,
  60. }
  61. // 停简单
  62. var tjdData = {
  63. carNumber: carNum,
  64. }
  65. var postData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
  66. Http.post({
  67. url: config.api.bindCar,
  68. data: postData,
  69. })
  70. .then(res => {
  71. console.log(res)
  72. wx.showModal({
  73. title: '提示',
  74. showCancel: false,
  75. content: "绑车牌成功!",
  76. success: function() {}
  77. })
  78. })
  79. .catch(error => {
  80. console.log(error)
  81. wx.showModal({
  82. title: '提示',
  83. showCancel: false,
  84. content: error.data.message,
  85. success: function() {}
  86. })
  87. })
  88. },
  89. unbindCar: function(carNum) {
  90. var that = this
  91. // carLogin
  92. app.userCarLogin()
  93. var postData =
  94. (parkVendor == 1) ? {
  95. etcpToken: that.data.etcpToken,
  96. carNumber: carNum,
  97. } : {
  98. carNumber: carNum,
  99. }
  100. Http.post({
  101. url: config.api.unbindCar,
  102. data: postData,
  103. })
  104. .then(res => {
  105. console.log(res)
  106. wx.showModal({
  107. title: '提示',
  108. showCancel: false,
  109. content: "解绑车牌成功!",
  110. success: function() {}
  111. })
  112. })
  113. .catch(error => {
  114. wx.showModal({
  115. title: '提示',
  116. showCancel: false,
  117. content: "解绑车牌失败!",
  118. success: function() {}
  119. })
  120. })
  121. },
  122. init: function() {
  123. var that = this
  124. app.parkInitCallback = token => {
  125. // 车场信息获取
  126. Http.get({
  127. url: config.api.getParkInfo,
  128. data: {}
  129. })
  130. .then(res => {
  131. console.log(res)
  132. that.setData({
  133. park: res.data,
  134. })
  135. })
  136. //绑定车获取
  137. Http.get({
  138. url: config.api.getUserCarList,
  139. data: {}
  140. }).then(res => {
  141. console.log(res);
  142. that.setData({
  143. carList: res.data
  144. })
  145. })
  146. }
  147. if (app.globalData.token && app.globalData.token != null) {
  148. app.parkInitCallback(app.globalData.token)
  149. }
  150. }
  151. })