C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

332 行
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.init();
  29. that.getList();
  30. },
  31. onShow: function(options) {
  32. var that = this;
  33. console.log("车牌号");
  34. if (that.data.addCar) {
  35. // 绑车牌
  36. if (app.globalData.carLogin) {
  37. that.bindCar(that.data.addCar);
  38. } else {
  39. that.bindCar(that.data.addCar);
  40. }
  41. that.setData({
  42. addCar: null
  43. });
  44. }
  45. },
  46. //我的停车券的显示与消失
  47. showquan: function() {
  48. let that = this;
  49. if (that.data.tcq == 1) {
  50. that.setData({
  51. tcq: 2
  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. //券绑定车牌
  70. bindCoupon: function(e) {
  71. var that = this;
  72. if (that.data.couponList.length > 0) {
  73. console.log("00000000000000");
  74. console.log(e.currentTarget.dataset.checkbind);
  75. /**
  76. * 如果1 已经绑定
  77. * 0 没有绑定
  78. */
  79. for (let car of that.data.carList) {
  80. if (car.stopFee.parkingFee) {
  81. that.data.payList.push(car);
  82. }
  83. }
  84. var etcpData = {
  85. etcpToken: app.globalData.etcpToken,
  86. carNumber: that.data.payList[0].carNumber
  87. ? that.data.payList[0].carNumber
  88. : "",
  89. couponOrderId: that.data.couponList[0].id
  90. };
  91. console.log(etcpData);
  92. // 停简单
  93. var tjdData = {
  94. carNumber: that.data.payList[0].carNumber
  95. };
  96. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  97. Http.post({
  98. url: config.api.getCarCoupon,
  99. data: postCouponData
  100. })
  101. .then(res => {
  102. that.setData({
  103. flag: "1"
  104. });
  105. // that.initUsrCarList()
  106. wx.showModal({
  107. title: "提示",
  108. showCancel: false,
  109. content: "车牌绑定优免券成功!",
  110. success: function(res) {}
  111. });
  112. })
  113. .catch(error => {
  114. console.log(error);
  115. if (error.code == 2056) {
  116. that.setData({
  117. flags: "alreadybind"
  118. });
  119. }
  120. });
  121. } else {
  122. console.log("1111111111111111111");
  123. that.setData({
  124. flags: "alreadybind"
  125. });
  126. console.log(that.data.flags);
  127. }
  128. },
  129. //获取名下停车券列表
  130. getList() {
  131. var that = this;
  132. Http.get({
  133. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  134. data: {
  135. pageNum: 1,
  136. pageSize: 8,
  137. couponOrderStatus: 0
  138. }
  139. }).then(res => {
  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.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. });