C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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