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.

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