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.

128 lines
2.8 KiB

  1. let config = require("../../config/config.js");
  2. let Http = require("../../utils/HttpBasics");
  3. let app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. carList: []
  10. },
  11. initUsrCarList: function() {
  12. var that = this;
  13. // 绑定车获取
  14. Http.get({
  15. url: config.api.getUserCarList,
  16. data: {}
  17. }).then(res => {
  18. that.setData({
  19. carList: res.data
  20. });
  21. })
  22. .catch(err => {
  23. wx.showToast({
  24. title: err.message,
  25. image: "../../assets/img/fail.png",
  26. duration: 2000,
  27. mask: false
  28. });
  29. })
  30. },
  31. unbindCarBtn: function(e) {
  32. console.log(e);
  33. var that = this;
  34. var carNum = e.currentTarget.dataset.car;
  35. that.unbindCar(carNum);
  36. },
  37. unbindCar: function(carNum) {
  38. var that = this;
  39. var postData =
  40. app.globalData.parkVendor == 1 ? {
  41. etcpToken: app.globalData.etcpToken,
  42. carNumber: carNum
  43. } : {
  44. carNumber: carNum
  45. };
  46. Http.post({
  47. url: config.api.unbindCar,
  48. data: postData
  49. })
  50. .then(res => {
  51. console.log(res);
  52. that.initUsrCarList();
  53. wx.showModal({
  54. title: "提示",
  55. showCancel: false,
  56. content: "解绑车牌成功!",
  57. success: function() {}
  58. });
  59. })
  60. .catch(error => {
  61. wx.showModal({
  62. title: "提示",
  63. showCancel: false,
  64. content: "解绑车牌失败!",
  65. });
  66. });
  67. },
  68. bindCar: function(carNum) {
  69. var that = this;
  70. // ETCP
  71. var etcpData = {
  72. etcpToken: app.globalData.etcpToken,
  73. carNumber: carNum
  74. };
  75. var tjdData = {
  76. carNumber: carNum
  77. };
  78. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  79. Http.post({
  80. url: config.api.bindCar,
  81. data: postData
  82. })
  83. .then(res => {
  84. console.log(res);
  85. that.setData({
  86. addCar: null
  87. });
  88. that.initUsrCarList();
  89. wx.showModal({
  90. title: "提示",
  91. showCancel: false,
  92. content: "绑车牌成功!",
  93. success: function() {}
  94. });
  95. })
  96. .catch(error => {
  97. console.log(error);
  98. wx.showModal({
  99. title: "提示",
  100. showCancel: false,
  101. content: error.data.message,
  102. success: function() {}
  103. });
  104. });
  105. },
  106. jumpToAdd: function() {
  107. wx.navigateTo({
  108. url: `/pages/addPark/addPark?flags=managepalte`
  109. });
  110. },
  111. onShow: function(options) {
  112. var that = this;
  113. that.initUsrCarList();
  114. if (that.data.addCar) {
  115. // 绑车牌
  116. if (app.globalData.carLogin) {
  117. that.bindCar(that.data.addCar);
  118. } else {
  119. that.bindCar(that.data.addCar);
  120. }
  121. that.setData({
  122. addCar: null
  123. });
  124. }
  125. },
  126. })