C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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