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

450 行
9.8 KiB

  1. let config = require("../../config/config.js");
  2. let Http = require("../../utils/HttpBasics");
  3. let Util = require("../../utils/util");
  4. let 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. stopFees: {},
  22. },
  23. /**
  24. * 车牌轮播滑动
  25. */
  26. onSlideChangeEnd: function(e) {
  27. var that = this;
  28. /**
  29. * 获得当前的车牌号码
  30. */
  31. var listCardNum = (that.data.carList)[e.detail.current].carNumber;
  32. console.log(listCardNum);
  33. that.setData({
  34. listCardNum: listCardNum
  35. });
  36. /**
  37. * 获得停车费用
  38. */
  39. that.getStopFee(listCardNum);
  40. },
  41. gotomange: function() {
  42. wx.navigateTo({
  43. url: '/pages/managelicenseplate/managelicenseplate',
  44. })
  45. },
  46. showquan: function() {
  47. wx.navigateTo({
  48. url: '/pages/passCar/couponList/couponList',
  49. })
  50. },
  51. /**
  52. * 待完成
  53. */
  54. gotodetail: function(e) {
  55. console.log(e.target.dataset.rule);
  56. wx.navigateTo({
  57. url: `/pages/payrule/payrule?rule=${e.target.dataset.rule}`,
  58. })
  59. },
  60. onShow: function(options) {
  61. var that = this;
  62. that.getList();
  63. that.init();
  64. /**
  65. * 只有用户选择了优惠券
  66. * 才会进行券和车牌的绑定
  67. */
  68. if (wx.getStorageSync("chosed") && that.data.quanid) {
  69. that.bindCoupon(that.data.quanid);
  70. wx.setStorage({
  71. key: 'chosed',
  72. data: '',
  73. })
  74. };
  75. that.initUsrCarList();
  76. if (that.data.addCar) {
  77. // 绑车牌
  78. if (app.globalData.carLogin) {
  79. that.bindCar(that.data.addCar);
  80. } else {
  81. that.bindCar(that.data.addCar);
  82. }
  83. that.setData({
  84. addCar: null
  85. });
  86. }
  87. },
  88. onLoad: function(options) {
  89. var that = this;
  90. /**
  91. * 获得分享小程序的
  92. * title
  93. * desc
  94. */
  95. Http.get({
  96. url: config.api.getWeapNote,
  97. data: {
  98. appId: config.weapp.AppId,
  99. }
  100. })
  101. .then(res => {
  102. let weapNote = JSON.parse(res.data.weapNote);
  103. that.setData({
  104. desc: weapNote.carpage.desc,
  105. title: weapNote.carpage.title
  106. })
  107. });
  108. },
  109. jumpToAdd: function() {
  110. wx.navigateTo({
  111. url: `/pages/addPark/addPark?flags=managepalte`
  112. });
  113. },
  114. passc: function() {
  115. wx.navigateTo({
  116. url: '/pages/ques/ques',
  117. })
  118. },
  119. /**
  120. * 券绑定车牌
  121. */
  122. bindCoupon: function(quanid) {
  123. var that = this;
  124. /**
  125. * etcp
  126. */
  127. var etcpData = {
  128. etcpToken: app.globalData.etcpToken,
  129. carNumber: that.data.listCardNum,
  130. couponOrderId: quanid
  131. };
  132. console.log(etcpData);
  133. /**
  134. * 停简单
  135. */
  136. var tjdData = {
  137. carNumber: that.data.listCardNum
  138. };
  139. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  140. Http.post({
  141. url: config.api.getCarCoupon,
  142. data: postCouponData
  143. })
  144. .then(res => {
  145. that.initUsrCarList();
  146. })
  147. .catch(error => {
  148. wx.showModal({
  149. content: error.message,
  150. showCancel: false,
  151. confirmText: "确定",
  152. })
  153. console.log(error);
  154. })
  155. },
  156. /**
  157. * 选择优惠券
  158. */
  159. gotoquan: function() {
  160. let that = this;
  161. console.log(that.data.quanid);
  162. if (that.data.quanid) {
  163. wx.navigateTo({
  164. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  165. })
  166. } else {
  167. wx.navigateTo({
  168. url: '/pages/passCar/choicecoupon/choicecoupon',
  169. })
  170. }
  171. },
  172. //获取名下停车券列表
  173. getList() {
  174. var that = this;
  175. Http.get({
  176. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  177. data: {
  178. pageNum: 1,
  179. pageSize: 8,
  180. couponOrderStatus: 0
  181. }
  182. }).then(res => {
  183. console.log(res);
  184. that.setData({
  185. couponList: res.data.list
  186. });
  187. });
  188. },
  189. /**
  190. * 共同登录
  191. */
  192. init: function(carNumber) {
  193. var that = this;
  194. app.parkInitCallback = token => {
  195. that.initPark();
  196. if (!app.globalData.carLogin) {
  197. /**
  198. * 判断是否授权手机号
  199. */
  200. Http.post({
  201. url: config.api.checkPhoneStatus,
  202. data: {}
  203. })
  204. .then(res => {
  205. console.log(res);
  206. Http.post({
  207. url: config.api.carInit,
  208. data: {
  209. phone: app.globalData.phone
  210. }
  211. }).then(res => {
  212. console.log(res);
  213. app.globalData.carLogin = true;
  214. app.globalData.parkVendor = res.data.vendor;
  215. if (res.data.token) {
  216. app.globalData.etcpToken = res.data.token;
  217. }
  218. /**
  219. * 获得停车费用
  220. */
  221. that.initUsrCarList("flags");
  222. console.log(app.globalData.etcpToken);
  223. });
  224. })
  225. .catch(err => {
  226. console.log(err);
  227. if (err.code == 11005) {
  228. // 用户手机未授权
  229. /**
  230. * 将值传到用户手机号授权的页面
  231. *
  232. */
  233. wx.redirectTo({
  234. url: "/pages/getphoneInfo/index"
  235. });
  236. } else if (err.code == 11006) {
  237. // 用户手机已加密
  238. wx.redirectTo({
  239. url: "/pages/phoneinput/phoneinput"
  240. });
  241. }
  242. })
  243. }
  244. };
  245. if (app.globalData.token && app.globalData.token != null) {
  246. app.parkInitCallback(app.globalData.token);
  247. }
  248. },
  249. /**
  250. * 绑定车牌
  251. */
  252. // bindCar: function(carNum) {
  253. // var that = this;
  254. // // ETCP
  255. // var etcpData = {
  256. // etcpToken: app.globalData.etcpToken,
  257. // carNumber: carNum
  258. // };
  259. // var tjdData = {
  260. // carNumber: carNum
  261. // };
  262. // var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  263. // Http.post({
  264. // url: config.api.bindCar,
  265. // data: postData
  266. // })
  267. // .then(res => {
  268. // console.log(res);
  269. // // that.initUsrCarList();
  270. // wx.showModal({
  271. // title: "提示",
  272. // showCancel: false,
  273. // content: "绑车牌成功!",
  274. // success: function() {}
  275. // });
  276. // })
  277. // .catch(error => {
  278. // console.log(error);
  279. // wx.showModal({
  280. // title: "提示",
  281. // showCancel: false,
  282. // content: error.message,
  283. // success: function() {}
  284. // });
  285. // });
  286. // },
  287. bindCar: function (carNum) {
  288. var that = this;
  289. // ETCP
  290. var etcpData = {
  291. etcpToken: app.globalData.etcpToken,
  292. carNumber: carNum
  293. };
  294. var tjdData = {
  295. carNumber: carNum
  296. };
  297. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  298. Http.post({
  299. url: config.api.bindCar,
  300. data: postData
  301. })
  302. .then(res => {
  303. console.log(res);
  304. that.setData({
  305. addCar: null
  306. });
  307. that.initUsrCarList();
  308. wx.showModal({
  309. title: "提示",
  310. showCancel: false,
  311. content: "绑车牌成功!",
  312. success: function () { }
  313. });
  314. })
  315. .catch(error => {
  316. console.log(error);
  317. wx.showModal({
  318. title: "提示",
  319. showCancel: false,
  320. content: error.data.message,
  321. success: function () { }
  322. });
  323. });
  324. },
  325. /**
  326. * 车场信息获取
  327. */
  328. initPark: function() {
  329. var that = this;
  330. Http.get({
  331. url: config.api.getParkInfo,
  332. data: {}
  333. }).then(res => {
  334. that.setData({
  335. park: res.data
  336. });
  337. });
  338. },
  339. /**
  340. * 绑定车获取
  341. */
  342. initUsrCarList: function(flag) {
  343. console.log(flag);
  344. var that = this;
  345. Http.get({
  346. url: config.api.getUserCarList,
  347. data: {}
  348. }).then(res => {
  349. console.log(res)
  350. that.setData({
  351. carList: res.data
  352. });
  353. /**
  354. * flag ==flags
  355. * 表示从首页onShow进来的
  356. */
  357. if (flag == "flags" && res.data.length > 0) {
  358. var listCardNum = res.data[0].carNumber;
  359. console.log(listCardNum);
  360. that.setData({
  361. listCardNum: listCardNum
  362. })
  363. /**
  364. * 获得停车费用
  365. */
  366. that.getStopFee(listCardNum);
  367. }
  368. })
  369. },
  370. /**
  371. * 获得停车费用修改
  372. */
  373. getStopFee: function(carNumber) {
  374. var that = this;
  375. var postData =
  376. app.globalData.parkVendor == 1 ? {
  377. etcpToken: app.globalData.etcpToken,
  378. carNumber: carNumber
  379. } : {
  380. carNumber: carNumber,
  381. outCarId: outCarId
  382. };
  383. var extraDataStr = {
  384. params: {
  385. CarNumber: carNumber
  386. }
  387. };
  388. that.setData({
  389. extraData: extraDataStr
  390. });
  391. Http.post({
  392. url: config.api.getCarStopFee,
  393. data: postData
  394. })
  395. .then(res => {
  396. that.setData({
  397. stopFees: res.data
  398. })
  399. that.setData({
  400. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  401. })
  402. })
  403. .catch(error => {
  404. console.log(error);
  405. wx.showModal({
  406. title: '提示',
  407. content: error.message,
  408. showCancel: false
  409. })
  410. that.setData({
  411. stopFees: {}
  412. })
  413. });
  414. },
  415. /**
  416. * 下拉刷新
  417. */
  418. onPullDownRefresh: function(e) {
  419. let that = this;
  420. that.initUsrCarList("flags");
  421. wx.stopPullDownRefresh();
  422. },
  423. // 用户点击右上角分享
  424. onShareAppMessage: function() {
  425. return {
  426. title: this.data.title,
  427. desc: this.data.desc,
  428. success: function(res) {
  429. wx.showToast({
  430. title: "分享成功",
  431. duration: 1000,
  432. icon: "success"
  433. });
  434. }
  435. }
  436. }
  437. });