C端小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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