C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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