C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

331 rader
7.7 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. payList: [],
  10. addCar: null,
  11. tcq: 2,
  12. flag: '',
  13. extraData:{}
  14. },
  15. /*车牌动态样式 */
  16. changeStyle: function () {
  17. var height = this.data.dataHeight == '150rpx' ? '80rpx' : '150rpx';
  18. var lineHeight = this.data.dataHeight == '150rpx' ? '80rpx' : '150rpx';
  19. var fontWeight = this.data.fontWeight == '600' ? '500' : '600';
  20. this.setData({
  21. dataHeight: height,
  22. dataLineHeight: lineHeight,
  23. dataFontWeight: fontWeight
  24. });
  25. },
  26. onLoad: function (options) {
  27. var that = this
  28. that.getList();
  29. },
  30. onShow: function (options) {
  31. var that = this;
  32. console.log("车牌号")
  33. if (that.data.addCar) {
  34. // 绑车牌
  35. if (app.globalData.carLogin) {
  36. that.bindCar(that.data.addCar)
  37. } else {
  38. that.bindCar(that.data.addCar)
  39. }
  40. that.setData({
  41. addCar: null
  42. })
  43. }
  44. },
  45. //我的停车券的显示与消失
  46. showquan: function () {
  47. let that = this;
  48. if (that.data.tcq == 1) {
  49. that.setData({
  50. tcq: 2
  51. })
  52. }
  53. else if (that.data.tcq == 2) {
  54. that.setData({
  55. tcq: 1
  56. })
  57. }
  58. },
  59. jumpToAdd: function () {
  60. wx.navigateTo({
  61. url: '/pages/addPark/addPark',
  62. });
  63. },
  64. passc: function () {
  65. wx.showToast({
  66. title: '宝宝最可爱~',
  67. })
  68. },
  69. // orderPay: function () {
  70. // wx.redirectTo({
  71. // url: '/pages/pay/pay'
  72. // });
  73. // },
  74. //券绑定车牌
  75. bindCoupon: function (e) {
  76. var that = this;
  77. console.log(e.currentTarget.dataset.checkbind);
  78. /**
  79. * 如果1 已经绑定
  80. * 0 没有绑定
  81. */
  82. for (let car of that.data.carList) {
  83. if (car.stopFee.parkingFee) {
  84. that.data.payList.push(car)
  85. }
  86. }
  87. var etcpData = {
  88. etcpToken: app.globalData.etcpToken,
  89. carNumber: that.data.payList[0].carNumber ? that.data.payList[0].carNumber : '',
  90. couponFreeId: that.data.couponList[0].couponFreeId ? that.data.couponList[0].couponFreeId:'',
  91. merchantId: that.data.couponList[0].merchantId ? that.data.couponList[0].merchantId:'',
  92. }
  93. console.log(etcpData)
  94. // 停简单
  95. var tjdData = {
  96. carNumber: that.data.payList[0].carNumber,
  97. }
  98. var postCouponData = (app.globalData.parkVendor == 1) ? etcpData : tjdData;
  99. Http.post({
  100. url: config.api.getCarCoupon,
  101. data: postCouponData,
  102. })
  103. .then(res => {
  104. that.setData({
  105. flag: '1'
  106. });
  107. // that.initUsrCarList()
  108. wx.showModal({
  109. title: '提示',
  110. showCancel: false,
  111. content: "车牌绑定优免券成功!",
  112. success: function (res) {
  113. }
  114. })
  115. })
  116. .catch(error => {
  117. console.log(error);
  118. if (error.code==2056){
  119. that.setData({
  120. flags:'alreadybind'
  121. })
  122. }
  123. })
  124. },
  125. //获取名下停车券列表
  126. getList() {
  127. var that = this;
  128. Http.get({
  129. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  130. data: {
  131. pageNum: 1,
  132. pageSize: 8,
  133. couponOrderStatus: 0
  134. }
  135. }).then(res => {
  136. that.init();
  137. that.setData({
  138. couponList: res.data.list
  139. })
  140. setTimeout(function () {
  141. wx.hideLoading();
  142. }, 1200);
  143. });
  144. },
  145. bindCar: function (carNum) {
  146. var that = this
  147. // ETCP
  148. var etcpData = {
  149. etcpToken: app.globalData.etcpToken,
  150. carNumber: carNum,
  151. }
  152. var tjdData = {
  153. carNumber: carNum,
  154. }
  155. var postData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
  156. Http.post({
  157. url: config.api.bindCar,
  158. data: postData,
  159. })
  160. .then(res => {
  161. console.log(res)
  162. that.setData({
  163. addCar: null
  164. })
  165. that.initUsrCarList()
  166. wx.showModal({
  167. title: '提示',
  168. showCancel: false,
  169. content: "绑车牌成功!",
  170. success: function () { }
  171. })
  172. })
  173. .catch(error => {
  174. console.log(error)
  175. wx.showModal({
  176. title: '提示',
  177. showCancel: false,
  178. content: error.data.message,
  179. success: function () { }
  180. })
  181. })
  182. },
  183. unbindCar: function (carNum) {
  184. var that = this
  185. var postData =
  186. (app.globalData.parkVendor == 1) ? {
  187. etcpToken: app.globalData.etcpToken,
  188. carNumber: carNum,
  189. } : {
  190. carNumber: carNum,
  191. }
  192. Http.post({
  193. url: config.api.unbindCar,
  194. data: postData,
  195. })
  196. .then(res => {
  197. console.log(res)
  198. that.initUsrCarList()
  199. wx.showModal({
  200. title: '提示',
  201. showCancel: false,
  202. content: "解绑车牌成功!",
  203. success: function () { }
  204. })
  205. })
  206. .catch(error => {
  207. wx.showModal({
  208. title: '提示',
  209. showCancel: false,
  210. content: "解绑车牌失败!",
  211. success: function () { }
  212. })
  213. })
  214. },
  215. unbindCarBtn: function (e) {
  216. console.log(e)
  217. var that = this
  218. var carNum = e.currentTarget.dataset.car
  219. that.unbindCar(carNum)
  220. },
  221. getStopFeeItem: function (carItem, i) {
  222. var that = this;
  223. var postData =
  224. (app.globalData.parkVendor == 1) ? {
  225. etcpToken: app.globalData.etcpToken,
  226. carNumber: carItem.carNumber,
  227. } : {
  228. carNumber: carItem.carNumber,
  229. outCarId: carItem.outCarId,
  230. }
  231. var stopFee = 'carList[' + i + '].stopFee'
  232. var extraData = 'carList[' + i + '].extraData';
  233. console.log(extraData);
  234. var extraDataStr = { params: { CarNumber: carItem.carNumber } };
  235. that.setData({
  236. extraData: extraDataStr
  237. })
  238. Http.post({
  239. url: config.api.getCarStopFee,
  240. data: postData
  241. })
  242. .then(res => {
  243. /**
  244. * 停车费用
  245. */
  246. that.setData({
  247. [stopFee]: res.data,
  248. [extraData]: extraDataStr,
  249. buttonBox: res.data.parkingFee
  250. }),
  251. console.log('res>>>' + JSON.stringify(that.data.buttonBox))
  252. })
  253. .catch(error => {
  254. console.log(error)
  255. })
  256. },
  257. getStopFee: function () {
  258. var that = this
  259. // carLogin
  260. for (var i = 0; i < that.data.carList.length; i++) {
  261. that.getStopFeeItem(that.data.carList[i], i)
  262. }
  263. // console.log(JSON.stringify(getStopFeeItem))
  264. },
  265. initPark: function () {
  266. var that = this
  267. // 车场信息获取
  268. Http.get({
  269. url: config.api.getParkInfo,
  270. data: {}
  271. })
  272. .then(res => {
  273. that.setData({
  274. park: res.data,
  275. })
  276. })
  277. },
  278. initUsrCarList: function () {
  279. var that = this
  280. // 绑定车获取
  281. Http.get({
  282. url: config.api.getUserCarList,
  283. data: {}
  284. }).then(res => {
  285. that.setData({
  286. carList: res.data
  287. })
  288. console.log('aaaa' + JSON.stringify(that.data.carList) );
  289. })
  290. },
  291. init: function () {
  292. var that = this
  293. app.parkInitCallback = token => {
  294. that.initPark()
  295. that.initUsrCarList()
  296. if (!app.globalData.carLogin) {
  297. // 共同登录
  298. Http.post({
  299. url: config.api.carInit,
  300. data: {
  301. phone: app.globalData.phone
  302. }
  303. }).then(res => {
  304. app.globalData.carLogin = true
  305. app.globalData.parkVendor = res.data.vendor
  306. if (res.data.token != "undefined") {
  307. app.globalData.etcpToken = res.data.token
  308. console.log("etcpToken", app.globalData.etcpToken)
  309. }
  310. // 获取 停车费
  311. that.getStopFee()
  312. })
  313. }
  314. }
  315. if (app.globalData.token && app.globalData.token != null) {
  316. app.parkInitCallback(app.globalData.token)
  317. }
  318. }
  319. })