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.

239 line
5.3 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. tcq:2
  11. },
  12. onLoad: function(options) {
  13. var that = this
  14. that.init();
  15. },
  16. onShow: function(options) {
  17. var that = this
  18. if (options)
  19. console.log(options)
  20. if (that.data.addCar) {
  21. // 绑车牌
  22. if (app.globalData.carLogin) {
  23. that.bindCar(that.data.addCar)
  24. } else {
  25. that.bindCar(that.data.addCar)
  26. }
  27. that.setData({
  28. addCar: null
  29. })
  30. }
  31. },
  32. //我的停车券的显示与消失
  33. showquan:function(){
  34. let that = this;
  35. if(that.data.tcq==1){
  36. that.setData({
  37. tcq:2
  38. })
  39. }
  40. else if (that.data.tcq == 2) {
  41. that.setData({
  42. tcq: 1
  43. })
  44. }
  45. },
  46. jumpToAdd: function() {
  47. wx.navigateTo({
  48. url: '/pages/addPark/addPark',
  49. });
  50. },
  51. jumpToPay: function() {
  52. console.log("停车支付去")
  53. //wx.redirectTo({
  54. // url: '/pages/pay/pay',
  55. //})
  56. },
  57. passb: function() {
  58. wx.showToast({
  59. title: '货物在路上~',
  60. })
  61. },
  62. passc: function() {
  63. wx.showToast({
  64. title: '宝宝最可爱~',
  65. })
  66. },
  67. orderPay: function() {
  68. wx.redirectTo({
  69. url: '/pages/pay/pay'
  70. });
  71. },
  72. bindCar: function(carNum) {
  73. var that = this
  74. // ETCP
  75. var etcpData = {
  76. etcpToken: app.globalData.etcpToken,
  77. carNumber: carNum,
  78. }
  79. // 停简单
  80. var tjdData = {
  81. carNumber: carNum,
  82. }
  83. var postData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
  84. Http.post({
  85. url: config.api.bindCar,
  86. data: postData,
  87. })
  88. .then(res => {
  89. console.log(res)
  90. that.setData({
  91. addCar: null
  92. })
  93. that.initUsrCarList()
  94. wx.showModal({
  95. title: '提示',
  96. showCancel: false,
  97. content: "绑车牌成功!",
  98. success: function() {}
  99. })
  100. })
  101. .catch(error => {
  102. console.log(error)
  103. wx.showModal({
  104. title: '提示',
  105. showCancel: false,
  106. content: error.data.message,
  107. success: function() {}
  108. })
  109. })
  110. },
  111. unbindCar: function(carNum) {
  112. var that = this
  113. var postData =
  114. (app.globalData.parkVendor == 1) ? {
  115. etcpToken: app.globalData.etcpToken,
  116. carNumber: carNum,
  117. } : {
  118. carNumber: carNum,
  119. }
  120. Http.post({
  121. url: config.api.unbindCar,
  122. data: postData,
  123. })
  124. .then(res => {
  125. console.log(res)
  126. that.initUsrCarList()
  127. wx.showModal({
  128. title: '提示',
  129. showCancel: false,
  130. content: "解绑车牌成功!",
  131. success: function() {}
  132. })
  133. })
  134. .catch(error => {
  135. wx.showModal({
  136. title: '提示',
  137. showCancel: false,
  138. content: "解绑车牌失败!",
  139. success: function() {}
  140. })
  141. })
  142. },
  143. unbindCarBtn: function(e) {
  144. console.log(e)
  145. var that = this
  146. var carNum = e.currentTarget.dataset.car
  147. that.unbindCar(carNum)
  148. },
  149. getStopFeeItem: function(carItem, i) {
  150. var that = this
  151. var postData =
  152. (app.globalData.parkVendor == 1) ? {
  153. etcpToken: app.globalData.etcpToken,
  154. carNumber: carItem.carNumber,
  155. } : {
  156. carNumber: carItem.carNumber,
  157. outCarId: carItem.outCarId,
  158. }
  159. var stopFee = 'carList[' + i + '].stopFee'
  160. console.log(postData)
  161. Http.post({
  162. url: config.api.getCarStopFee,
  163. data: postData
  164. })
  165. .then(res => {
  166. console.log(res)
  167. console.log(stopFee)
  168. that.setData({
  169. [stopFee]: res.data
  170. })
  171. })
  172. .catch(error =>{
  173. console.log(error)
  174. })
  175. },
  176. getStopFee: function() {
  177. var that = this
  178. // carLogin
  179. for (var i = 0; i < that.data.carList.length; i++) {
  180. that.getStopFeeItem(that.data.carList[i], i)
  181. }
  182. },
  183. initPark: function() {
  184. var that = this
  185. // 车场信息获取
  186. Http.get({
  187. url: config.api.getParkInfo,
  188. data: {}
  189. })
  190. .then(res => {
  191. console.log(res)
  192. that.setData({
  193. park: res.data,
  194. })
  195. })
  196. },
  197. initUsrCarList: function() {
  198. var that = this
  199. // 绑定车获取
  200. Http.get({
  201. url: config.api.getUserCarList,
  202. data: {}
  203. }).then(res => {
  204. console.log(res);
  205. that.setData({
  206. carList: res.data
  207. })
  208. })
  209. },
  210. init: function() {
  211. var that = this
  212. app.parkInitCallback = token => {
  213. that.initPark()
  214. that.initUsrCarList()
  215. if (!app.globalData.carLogin) {
  216. // 共同登录
  217. Http.post({
  218. url: config.api.carInit,
  219. data: {
  220. phone: app.globalData.phone
  221. }
  222. }).then(res => {
  223. app.globalData.carLogin = true
  224. app.globalData.parkVendor = res.data.vendor
  225. if (res.data.token != "undefined") {
  226. app.globalData.etcpToken = res.data.token
  227. console.log("etcpToken", app.globalData.etcpToken)
  228. }
  229. // 获取 停车费
  230. that.getStopFee()
  231. })
  232. }
  233. }
  234. if (app.globalData.token && app.globalData.token != null) {
  235. app.parkInitCallback(app.globalData.token)
  236. }
  237. }
  238. })