C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.4 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. console.log("停车支付去")
  36. //wx.redirectTo({
  37. // url: '/pages/pay/pay',
  38. //})
  39. },
  40. passb: function() {
  41. wx.showToast({
  42. title: '货物在路上~',
  43. })
  44. },
  45. passc: function() {
  46. wx.showToast({
  47. title: '宝宝最可爱~',
  48. })
  49. },
  50. orderPay: function() {
  51. wx.redirectTo({
  52. url: '/pages/pay/pay'
  53. });
  54. },
  55. bindCar: function(carNum) {
  56. var that = this
  57. // ETCP
  58. var etcpData = {
  59. etcpToken: app.globalData.etcpToken,
  60. carNumber: carNum,
  61. }
  62. // 停简单
  63. var tjdData = {
  64. carNumber: carNum,
  65. }
  66. var postData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
  67. Http.post({
  68. url: config.api.bindCar,
  69. data: postData,
  70. })
  71. .then(res => {
  72. console.log(res)
  73. that.setData({
  74. addCar: null
  75. })
  76. that.initUsrCarList()
  77. wx.showModal({
  78. title: '提示',
  79. showCancel: false,
  80. content: "绑车牌成功!",
  81. success: function() {}
  82. })
  83. })
  84. .catch(error => {
  85. console.log(error)
  86. wx.showModal({
  87. title: '提示',
  88. showCancel: false,
  89. content: error.data.message,
  90. success: function() {}
  91. })
  92. })
  93. },
  94. unbindCar: function(carNum) {
  95. var that = this
  96. // carLogin
  97. app.userCarLogin()
  98. var postData =
  99. (app.globalData.parkVendor == 1) ? {
  100. etcpToken: app.globalData.etcpToken,
  101. carNumber: carNum,
  102. } : {
  103. carNumber: carNum,
  104. }
  105. Http.post({
  106. url: config.api.unbindCar,
  107. data: postData,
  108. })
  109. .then(res => {
  110. console.log(res)
  111. that.initUsrCarList()
  112. wx.showModal({
  113. title: '提示',
  114. showCancel: false,
  115. content: "解绑车牌成功!",
  116. success: function() {}
  117. })
  118. })
  119. .catch(error => {
  120. wx.showModal({
  121. title: '提示',
  122. showCancel: false,
  123. content: "解绑车牌失败!",
  124. success: function() {}
  125. })
  126. })
  127. },
  128. unbindCarBtn: function(e) {
  129. console.log(e)
  130. var that = this
  131. var carNum = e.currentTarget.dataset.car
  132. that.unbindCar(carNum)
  133. },
  134. getStopFee: function() {
  135. var that = this
  136. for (var i = 0; i < that.data.carList.length; i++) {
  137. var carItem = that.data.carList[i]
  138. var postData =
  139. (app.globalData.parkVendor == 1) ? {
  140. etcpToken: app.globalData.etcpToken,
  141. carNumber: carItem.carNumber,
  142. } : {
  143. carNumber: carItem.carNumber,
  144. outCarId: carItem.outCarId,
  145. }
  146. var stopFee = 'carList[' + i + '].stopFee'
  147. Http.post({
  148. url: config.api.getCarStopFee,
  149. data: postData
  150. })
  151. .then(res => {
  152. console.log(res)
  153. that.setData({
  154. [stopFee]: res.data
  155. })
  156. })
  157. }
  158. },
  159. initPark: function() {
  160. var that = this
  161. // 车场信息获取
  162. Http.get({
  163. url: config.api.getParkInfo,
  164. data: {}
  165. })
  166. .then(res => {
  167. console.log(res)
  168. that.setData({
  169. park: res.data,
  170. })
  171. })
  172. },
  173. initUsrCarList: function() {
  174. var that = this
  175. // 绑定车获取
  176. Http.get({
  177. url: config.api.getUserCarList,
  178. data: {}
  179. }).then(res => {
  180. console.log(res);
  181. that.setData({
  182. carList: res.data
  183. })
  184. // 获取 停车费
  185. that.getStopFee()
  186. })
  187. },
  188. init: function() {
  189. var that = this
  190. app.parkInitCallback = token => {
  191. that.initPark()
  192. that.initUsrCarList()
  193. }
  194. if (app.globalData.token && app.globalData.token != null) {
  195. app.parkInitCallback(app.globalData.token)
  196. }
  197. }
  198. })