C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

224 行
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. that.setData({
  27. addCar: null
  28. })
  29. }
  30. },
  31. jumpToAdd: function() {
  32. wx.navigateTo({
  33. url: '/pages/addPark/addPark',
  34. });
  35. },
  36. jumpToPay: function() {
  37. console.log("停车支付去")
  38. //wx.redirectTo({
  39. // url: '/pages/pay/pay',
  40. //})
  41. },
  42. passb: function() {
  43. wx.showToast({
  44. title: '货物在路上~',
  45. })
  46. },
  47. passc: function() {
  48. wx.showToast({
  49. title: '宝宝最可爱~',
  50. })
  51. },
  52. orderPay: function() {
  53. wx.redirectTo({
  54. url: '/pages/pay/pay'
  55. });
  56. },
  57. bindCar: function(carNum) {
  58. var that = this
  59. // ETCP
  60. var etcpData = {
  61. etcpToken: app.globalData.etcpToken,
  62. carNumber: carNum,
  63. }
  64. // 停简单
  65. var tjdData = {
  66. carNumber: carNum,
  67. }
  68. var postData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
  69. Http.post({
  70. url: config.api.bindCar,
  71. data: postData,
  72. })
  73. .then(res => {
  74. console.log(res)
  75. that.setData({
  76. addCar: null
  77. })
  78. that.initUsrCarList()
  79. wx.showModal({
  80. title: '提示',
  81. showCancel: false,
  82. content: "绑车牌成功!",
  83. success: function() {}
  84. })
  85. })
  86. .catch(error => {
  87. console.log(error)
  88. wx.showModal({
  89. title: '提示',
  90. showCancel: false,
  91. content: error.data.message,
  92. success: function() {}
  93. })
  94. })
  95. },
  96. unbindCar: function(carNum) {
  97. var that = this
  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. getStopFeeItem: function(carItem, i) {
  135. var that = this
  136. var postData =
  137. (app.globalData.parkVendor == 1) ? {
  138. etcpToken: app.globalData.etcpToken,
  139. carNumber: carItem.carNumber,
  140. } : {
  141. carNumber: carItem.carNumber,
  142. outCarId: carItem.outCarId,
  143. }
  144. var stopFee = 'carList[' + i + '].stopFee'
  145. console.log(postData)
  146. Http.post({
  147. url: config.api.getCarStopFee,
  148. data: postData
  149. })
  150. .then(res => {
  151. console.log(res)
  152. console.log(stopFee)
  153. that.setData({
  154. [stopFee]: res.data
  155. })
  156. })
  157. .catch(error =>{
  158. console.log(error)
  159. })
  160. },
  161. getStopFee: function() {
  162. var that = this
  163. // carLogin
  164. for (var i = 0; i < that.data.carList.length; i++) {
  165. that.getStopFeeItem(that.data.carList[i], i)
  166. }
  167. },
  168. initPark: function() {
  169. var that = this
  170. // 车场信息获取
  171. Http.get({
  172. url: config.api.getParkInfo,
  173. data: {}
  174. })
  175. .then(res => {
  176. console.log(res)
  177. that.setData({
  178. park: res.data,
  179. })
  180. })
  181. },
  182. initUsrCarList: function() {
  183. var that = this
  184. // 绑定车获取
  185. Http.get({
  186. url: config.api.getUserCarList,
  187. data: {}
  188. }).then(res => {
  189. console.log(res);
  190. that.setData({
  191. carList: res.data
  192. })
  193. })
  194. },
  195. init: function() {
  196. var that = this
  197. app.parkInitCallback = token => {
  198. that.initPark()
  199. that.initUsrCarList()
  200. if (!app.globalData.carLogin) {
  201. // 共同登录
  202. Http.post({
  203. url: config.api.carInit,
  204. data: {
  205. phone: app.globalData.phone
  206. }
  207. }).then(res => {
  208. app.globalData.carLogin = true
  209. app.globalData.parkVendor = res.data.vendor
  210. if (res.data.token != "undefined") {
  211. app.globalData.etcpToken = res.data.token
  212. console.log("etcpToken", app.globalData.etcpToken)
  213. }
  214. // 获取 停车费
  215. that.getStopFee()
  216. })
  217. }
  218. }
  219. if (app.globalData.token && app.globalData.token != null) {
  220. app.parkInitCallback(app.globalData.token)
  221. }
  222. }
  223. })