C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

269 строки
6.2 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. console.log(postData)
  190. Http.post({
  191. url: config.api.getCarStopFee,
  192. data: postData
  193. })
  194. .then(res => {
  195. console.log(res)
  196. console.log(stopFee)
  197. that.setData({
  198. [stopFee]: res.data
  199. })
  200. })
  201. .catch(error => {
  202. console.log(error)
  203. })
  204. },
  205. getStopFee: function () {
  206. var that = this
  207. // carLogin
  208. for (var i = 0; i < that.data.carList.length; i++) {
  209. that.getStopFeeItem(that.data.carList[i], i)
  210. }
  211. // console.log(JSON.stringify(getStopFeeItem))
  212. },
  213. initPark: function () {
  214. var that = this
  215. // 车场信息获取
  216. Http.get({
  217. url: config.api.getParkInfo,
  218. data: {}
  219. })
  220. .then(res => {
  221. console.log(res)
  222. that.setData({
  223. park: res.data,
  224. })
  225. })
  226. },
  227. initUsrCarList: function () {
  228. var that = this
  229. // 绑定车获取
  230. Http.get({
  231. url: config.api.getUserCarList,
  232. data: {}
  233. }).then(res => {
  234. console.log(res);
  235. that.setData({
  236. carList: res.data
  237. })
  238. })
  239. },
  240. init: function () {
  241. var that = this
  242. app.parkInitCallback = token => {
  243. that.initPark()
  244. that.initUsrCarList()
  245. if (!app.globalData.carLogin) {
  246. // 共同登录
  247. Http.post({
  248. url: config.api.carInit,
  249. data: {
  250. phone: app.globalData.phone
  251. }
  252. }).then(res => {
  253. app.globalData.carLogin = true
  254. app.globalData.parkVendor = res.data.vendor
  255. if (res.data.token != "undefined") {
  256. app.globalData.etcpToken = res.data.token
  257. console.log("etcpToken", app.globalData.etcpToken)
  258. }
  259. // 获取 停车费
  260. that.getStopFee()
  261. })
  262. }
  263. }
  264. if (app.globalData.token && app.globalData.token != null) {
  265. app.parkInitCallback(app.globalData.token)
  266. }
  267. }
  268. })