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.

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