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.

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