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.

163 lines
3.5 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. that.initUsrCarList()
  73. wx.showModal({
  74. title: '提示',
  75. showCancel: false,
  76. content: "绑车牌成功!",
  77. success: function() {}
  78. })
  79. })
  80. .catch(error => {
  81. console.log(error)
  82. wx.showModal({
  83. title: '提示',
  84. showCancel: false,
  85. content: error.data.message,
  86. success: function() {}
  87. })
  88. })
  89. },
  90. unbindCar: function(e) {
  91. console.log(e)
  92. var that = this
  93. var carNum = e.currentTarget.dataset.car
  94. // carLogin
  95. app.userCarLogin()
  96. var postData =
  97. (app.globalData.parkVendor == 1) ? {
  98. etcpToken: app.globalData.etcpToken,
  99. carNumber: carNum,
  100. } : {
  101. carNumber: carNum,
  102. }
  103. Http.post({
  104. url: config.api.unbindCar,
  105. data: postData,
  106. })
  107. .then(res => {
  108. console.log(res)
  109. that.initUsrCarList()
  110. wx.showModal({
  111. title: '提示',
  112. showCancel: false,
  113. content: "解绑车牌成功!",
  114. success: function() {}
  115. })
  116. })
  117. .catch(error => {
  118. wx.showModal({
  119. title: '提示',
  120. showCancel: false,
  121. content: "解绑车牌失败!",
  122. success: function() {}
  123. })
  124. })
  125. },
  126. initPark: function() {
  127. var that = this
  128. // 车场信息获取
  129. Http.get({
  130. url: config.api.getParkInfo,
  131. data: {}
  132. })
  133. .then(res => {
  134. console.log(res)
  135. that.setData({
  136. park: res.data,
  137. })
  138. })
  139. },
  140. initUsrCarList: function () {
  141. var that = this
  142. // 绑定车获取
  143. Http.get({
  144. url: config.api.getUserCarList,
  145. data: {}
  146. }).then(res => {
  147. console.log(res);
  148. that.setData({
  149. carList: res.data
  150. })
  151. })
  152. },
  153. init: function() {
  154. var that = this
  155. app.parkInitCallback = token => {
  156. that.initPark()
  157. that.initUsrCarList()
  158. }
  159. if (app.globalData.token && app.globalData.token != null) {
  160. app.parkInitCallback(app.globalData.token)
  161. }
  162. }
  163. })