C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

221 linhas
5.0 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. that.init();
  14. },
  15. onShow: function(options) {
  16. var that = this
  17. if (options)
  18. console.log(options)
  19. if (that.data.addCar) {
  20. // 绑车牌
  21. if (app.globalData.carLogin) {
  22. that.bindCar(that.data.addCar)
  23. } else {
  24. that.bindCar(that.data.addCar)
  25. }
  26. }
  27. },
  28. jumpToAdd: function() {
  29. wx.navigateTo({
  30. url: '/pages/addPark/addPark',
  31. });
  32. },
  33. jumpToPay: function() {
  34. console.log("停车支付去")
  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.setData({
  73. addCar: null
  74. })
  75. that.initUsrCarList()
  76. wx.showModal({
  77. title: '提示',
  78. showCancel: false,
  79. content: "绑车牌成功!",
  80. success: function() {}
  81. })
  82. })
  83. .catch(error => {
  84. console.log(error)
  85. wx.showModal({
  86. title: '提示',
  87. showCancel: false,
  88. content: error.data.message,
  89. success: function() {}
  90. })
  91. })
  92. },
  93. unbindCar: function(carNum) {
  94. var that = this
  95. var postData =
  96. (app.globalData.parkVendor == 1) ? {
  97. etcpToken: app.globalData.etcpToken,
  98. carNumber: carNum,
  99. } : {
  100. carNumber: carNum,
  101. }
  102. Http.post({
  103. url: config.api.unbindCar,
  104. data: postData,
  105. })
  106. .then(res => {
  107. console.log(res)
  108. that.initUsrCarList()
  109. wx.showModal({
  110. title: '提示',
  111. showCancel: false,
  112. content: "解绑车牌成功!",
  113. success: function() {}
  114. })
  115. })
  116. .catch(error => {
  117. wx.showModal({
  118. title: '提示',
  119. showCancel: false,
  120. content: "解绑车牌失败!",
  121. success: function() {}
  122. })
  123. })
  124. },
  125. unbindCarBtn: function(e) {
  126. console.log(e)
  127. var that = this
  128. var carNum = e.currentTarget.dataset.car
  129. that.unbindCar(carNum)
  130. },
  131. getStopFeeItem: function(carItem, i) {
  132. var that = this
  133. var postData =
  134. (app.globalData.parkVendor == 1) ? {
  135. etcpToken: app.globalData.etcpToken,
  136. carNumber: carItem.carNumber,
  137. } : {
  138. carNumber: carItem.carNumber,
  139. outCarId: carItem.outCarId,
  140. }
  141. var stopFee = 'carList[' + i + '].stopFee'
  142. console.log(postData)
  143. Http.post({
  144. url: config.api.getCarStopFee,
  145. data: postData
  146. })
  147. .then(res => {
  148. console.log(res)
  149. console.log(stopFee)
  150. that.setData({
  151. [stopFee]: res.data
  152. })
  153. })
  154. .catch(error =>{
  155. console.log(error)
  156. })
  157. },
  158. getStopFee: function() {
  159. var that = this
  160. // carLogin
  161. for (var i = 0; i < that.data.carList.length; i++) {
  162. that.getStopFeeItem(that.data.carList[i], i)
  163. }
  164. },
  165. initPark: function() {
  166. var that = this
  167. // 车场信息获取
  168. Http.get({
  169. url: config.api.getParkInfo,
  170. data: {}
  171. })
  172. .then(res => {
  173. console.log(res)
  174. that.setData({
  175. park: res.data,
  176. })
  177. })
  178. },
  179. initUsrCarList: function() {
  180. var that = this
  181. // 绑定车获取
  182. Http.get({
  183. url: config.api.getUserCarList,
  184. data: {}
  185. }).then(res => {
  186. console.log(res);
  187. that.setData({
  188. carList: res.data
  189. })
  190. })
  191. },
  192. init: function() {
  193. var that = this
  194. app.parkInitCallback = token => {
  195. that.initPark()
  196. that.initUsrCarList()
  197. if (!app.globalData.carLogin) {
  198. // 共同登录
  199. Http.post({
  200. url: config.api.carInit,
  201. data: {
  202. phone: app.globalData.phone
  203. }
  204. }).then(res => {
  205. app.globalData.carLogin = true
  206. app.globalData.parkVendor = res.data.vendor
  207. if (res.data.token != "undefined") {
  208. app.globalData.etcpToken = res.data.token
  209. console.log("etcpToken", app.globalData.etcpToken)
  210. }
  211. // 获取 停车费
  212. that.getStopFee()
  213. })
  214. }
  215. }
  216. if (app.globalData.token && app.globalData.token != null) {
  217. app.parkInitCallback(app.globalData.token)
  218. }
  219. }
  220. })