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

596 行
14 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. scroll:true,
  23. canIUse: wx.canIUse("navigator")
  24. },
  25. /**
  26. * 车牌轮播滑动
  27. */
  28. onSlideChangeEnd: function(e) {
  29. var that = this;
  30. /**
  31. * 获得当前的车牌号码
  32. */
  33. var listCardNum = (that.data.carList)[e.detail.current].carNumber;
  34. that.setData({
  35. listCardNum: listCardNum
  36. });
  37. /**
  38. * 获得停车费用
  39. */
  40. if(that.data.scroll){
  41. that.getStopFee(listCardNum);
  42. }
  43. },
  44. gotomange: function() {
  45. wx.navigateTo({
  46. url: '/pages/managelicenseplate/managelicenseplate',
  47. })
  48. },
  49. bindfail:function(res){
  50. console.log(res)
  51. },
  52. gotoetcp:function(){
  53. console.log(this.data.extraData)
  54. // wx.navigateToMiniProgram({
  55. // appId:'wx192b7d2e8dcbefd0',
  56. // extraData: this.data.extraData,
  57. // envVersion:'release',
  58. // path:"pages/main/main",
  59. // })
  60. wx.navigateToMiniProgram({
  61. appId:'wxc07f9d67923d676d',
  62. extraData: this.data.extraData,
  63. envVersion:'release',
  64. path: "pages/main/main",
  65. })
  66. },
  67. showquan: function() {
  68. wx.navigateTo({
  69. url: '/pages/passCar/couponList/couponList',
  70. })
  71. },
  72. gotodetail: function(e) {
  73. wx.showModal({
  74. title: '缴费规则',
  75. content: e.target.dataset.rule,
  76. showCancel: false,
  77. })
  78. },
  79. onShow: function(options) {
  80. var that = this;
  81. if (app.globalData.token) {
  82. that.getList();
  83. that.init();
  84. }else{
  85. that.init();
  86. }
  87. /**
  88. * 只有用户选择了优惠券
  89. * 才会进行券和车牌的绑定
  90. */
  91. if (wx.getStorageSync("chosed") && that.data.quanid) {
  92. that.bindCoupon(that.data.quanid);
  93. wx.setStorage({
  94. key: 'chosed',
  95. data: '',
  96. })
  97. };
  98. if (app.globalData.token) {
  99. that.initUsrCarList();
  100. }
  101. if (that.data.addCar) {
  102. // 绑车牌
  103. if (app.globalData.carLogin) {
  104. that.bindCar(that.data.addCar);
  105. } else {
  106. that.bindCar(that.data.addCar);
  107. }
  108. that.setData({
  109. addCar: null
  110. });
  111. }
  112. },
  113. onLoad: function(options) {
  114. var that = this;
  115. /**
  116. * 获得分享小程序的
  117. * title
  118. * desc
  119. */
  120. Http.get({
  121. url: config.api.getWeapNote,
  122. data: {
  123. appId: config.weapp.AppId,
  124. }
  125. })
  126. .then(res => {
  127. let weapNote = JSON.parse(res.data.weapNote);
  128. that.setData({
  129. desc: weapNote.carpage.desc,
  130. title: weapNote.carpage.title
  131. })
  132. })
  133. .catch(err => {
  134. console.log(err);
  135. })
  136. // 登录
  137. var scene = decodeURIComponent(options.scene);
  138. that.setData({
  139. scene: scene
  140. });
  141. if (app.globalData.token){}else{
  142. app.getLocation();
  143. that.userLogin()
  144. }
  145. },
  146. /**
  147. * 用户登录
  148. */
  149. userLogin: function () {
  150. var that = this;
  151. // 登录
  152. wx.login({
  153. success: ({
  154. code
  155. }) => {
  156. wx.getSystemInfo({
  157. success: function (res) {
  158. that.setData({
  159. systemInfo: JSON.stringify(res)
  160. })
  161. }
  162. })
  163. var usrdata = {
  164. appId: config.weapp.AppId,
  165. code: code,
  166. sceneAddress: app.globalData.sceneAddress,
  167. scene: that.data.scene,
  168. systemInfo: that.data.systemInfo
  169. };
  170. if (app.globalData.locationInfo) {
  171. usrdata = {
  172. appId: config.weapp.AppId,
  173. code: code,
  174. sceneAddress: app.globalData.sceneAddress,
  175. latitude: "" + app.globalData.locationInfo.latitude,
  176. longitude: "" + app.globalData.locationInfo.longitude,
  177. scene: that.data.scene,
  178. systemInfo: that.data.systemInfo
  179. };
  180. }
  181. Http.post({
  182. url: config.api.login,
  183. data: usrdata
  184. })
  185. .then(res => {
  186. app.globalData.token = res.data.token;
  187. Http.setToken(res.data.token);
  188. that.checkUserCarStatus();
  189. that.getUserInfo();
  190. that.getList();
  191. that.init();
  192. that.initUsrCarList();
  193. return Http.post({
  194. url: config.api.checkUserStatus,
  195. data: {}
  196. });
  197. })
  198. .then(res => {
  199. })
  200. .catch(err => {
  201. if (err.code == 11004) {
  202. // 用户昵称未授权
  203. wx.redirectTo({
  204. url: "/pages/getuserinfo/index"
  205. });
  206. }else{
  207. wx.showToast({
  208. title: err.errMsg,
  209. icon: 'none',
  210. duration: 2000,
  211. mask: false
  212. });
  213. }
  214. });
  215. }
  216. });
  217. },
  218. /**
  219. * 检查用户是否有车
  220. */
  221. checkUserCarStatus: function () {
  222. var that = this;
  223. Http.get({
  224. url: config.api.userCarCount,
  225. data: {}
  226. }).then(res => {
  227. if (res.data > 0) {
  228. // 用户名下有车
  229. app.globalData.phone = res.data.phone;
  230. app.globalData.supportCar = true;
  231. // 共同登录
  232. that.userCarLogin();
  233. }
  234. })
  235. .catch(err => {
  236. })
  237. },
  238. /**
  239. * 获取用户信息
  240. */
  241. getUserInfo: function () {
  242. // 获取用户信息
  243. wx.getSetting({
  244. success: res => {
  245. if (res.authSetting["scope.userInfo"]) {
  246. // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  247. wx.getUserInfo({
  248. success: res => {
  249. // 可以将 res 发送给后台解码出 unionId
  250. }
  251. });
  252. }
  253. }
  254. })
  255. },
  256. jumpToAdd: function() {
  257. wx.navigateTo({
  258. url: `/pages/addPark/addPark?flags=managepalte`
  259. });
  260. },
  261. passc: function() {
  262. wx.navigateTo({
  263. url: '/pages/ques/ques',
  264. })
  265. },
  266. /**
  267. * 券绑定车牌
  268. */
  269. bindCoupon: function(quanid) {
  270. var that = this;
  271. /**
  272. * etcp
  273. */
  274. var etcpData = {
  275. etcpToken: app.globalData.etcpToken,
  276. carNumber: that.data.listCardNum,
  277. couponOrderId: quanid
  278. };
  279. /**
  280. * 停简单
  281. */
  282. var tjdData = {
  283. carNumber: that.data.listCardNum
  284. };
  285. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  286. Http.post({
  287. url: config.api.getCarCoupon,
  288. data: postCouponData
  289. })
  290. .then(res => {
  291. that.initUsrCarList();
  292. })
  293. .catch(err => {
  294. wx.showToast({
  295. title: err.message,
  296. icon: 'none',
  297. duration: 2000,
  298. mask: false
  299. });
  300. })
  301. },
  302. /**
  303. * 选择优惠券
  304. */
  305. gotoquan: function() {
  306. let that = this;
  307. if (that.data.quanid) {
  308. wx.navigateTo({
  309. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  310. })
  311. } else {
  312. wx.navigateTo({
  313. url: '/pages/passCar/choicecoupon/choicecoupon',
  314. })
  315. }
  316. },
  317. //获取名下停车券列表
  318. getList() {
  319. var that = this;
  320. Http.get({
  321. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  322. data: {
  323. pageNum: 1,
  324. pageSize: 8,
  325. couponOrderStatus: 0
  326. }
  327. }).then(res => {
  328. that.setData({
  329. couponList: res.data.list
  330. });
  331. })
  332. .catch(err => {
  333. console.log(err)
  334. })
  335. },
  336. /**
  337. * 共同登录
  338. */
  339. init: function(carNumber) {
  340. var that = this;
  341. app.parkInitCallback = token => {
  342. that.initPark();
  343. that.getParkStatus();
  344. if (!app.globalData.carLogin) {
  345. /**
  346. * 判断是否授权手机号
  347. */
  348. Http.post({
  349. url: config.api.checkPhoneStatus,
  350. data: {}
  351. })
  352. .then(res => {
  353. Http.post({
  354. url: config.api.carInit,
  355. data: {
  356. phone: app.globalData.phone
  357. }
  358. }).then(res => {
  359. app.globalData.carLogin = true;
  360. app.globalData.parkVendor = res.data.vendor;
  361. if (res.data.token) {
  362. app.globalData.etcpToken = res.data.token;
  363. }
  364. /**
  365. * 获得停车费用
  366. */
  367. that.initUsrCarList("flags");
  368. });
  369. })
  370. .catch(err => {
  371. if (err.code == 11005) {
  372. // 用户手机未授权
  373. /**
  374. * 将值传到用户手机号授权的页面
  375. *
  376. */
  377. wx.redirectTo({
  378. url: "/pages/getphoneInfo/index"
  379. });
  380. } else if (err.code == 11006) {
  381. // 用户手机已加密
  382. wx.redirectTo({
  383. url: "/pages/phoneinput/phoneinput"
  384. });
  385. }else{
  386. wx.showToast({
  387. title: err.errMsg,
  388. icon: 'none',
  389. duration: 2000,
  390. mask: false
  391. });
  392. }
  393. })
  394. }
  395. };
  396. if (app.globalData.token && app.globalData.token != null) {
  397. app.parkInitCallback(app.globalData.token);
  398. }
  399. },
  400. bindCar: function (carNum) {
  401. var that = this;
  402. // ETCP
  403. var etcpData = {
  404. etcpToken: app.globalData.etcpToken,
  405. carNumber: carNum
  406. };
  407. var tjdData = {
  408. carNumber: carNum
  409. };
  410. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  411. Http.post({
  412. url: config.api.bindCar,
  413. data: postData
  414. })
  415. .then(res => {
  416. that.setData({
  417. addCar: null
  418. });
  419. that.initUsrCarList();
  420. wx.showModal({
  421. title: "提示",
  422. showCancel: false,
  423. content: "绑车牌成功!",
  424. success: function () { }
  425. });
  426. })
  427. .catch(error => {
  428. wx.showModal({
  429. title: "提示",
  430. showCancel: false,
  431. content: error.data.message,
  432. success: function () { }
  433. });
  434. });
  435. },
  436. /**
  437. * 车场信息获取
  438. */
  439. initPark: function() {
  440. var that = this;
  441. Http.get({
  442. url: config.api.getParkInfo,
  443. data: {}
  444. })
  445. .then(res => {
  446. that.setData({
  447. park: res.data
  448. })
  449. })
  450. .catch(err => {
  451. console.log(err);
  452. // wx.showToast({
  453. // title: err.message,
  454. // icon: 'none',
  455. // duration: 2000,
  456. // mask: false
  457. // });
  458. })
  459. },
  460. /**
  461. * 车场状态获取
  462. */
  463. getParkStatus: function() {
  464. var that = this;
  465. Http.get({
  466. url: config.api.getParkStatus,
  467. })
  468. .then(res => {
  469. })
  470. .catch(err => {
  471. })
  472. },
  473. /**
  474. * 绑定车获取
  475. */
  476. initUsrCarList: function(flag) {
  477. var that = this;
  478. Http.get({
  479. url: config.api.getUserCarList,
  480. data: {}
  481. }).then(res => {
  482. that.setData({
  483. carList: res.data
  484. });
  485. /**
  486. * flag ==flags
  487. * 表示从首页onShow进来的
  488. */
  489. if (flag == "flags" && res.data.length > 0) {
  490. var listCardNum = res.data[0].carNumber;
  491. that.setData({
  492. listCardNum: listCardNum
  493. })
  494. /**
  495. * 获得停车费用
  496. */
  497. that.getStopFee(listCardNum);
  498. }
  499. })
  500. .catch(err => {
  501. wx.showToast({
  502. title: err.message,
  503. icon: 'none',
  504. duration: 2000,
  505. mask: false
  506. });
  507. })
  508. },
  509. /**
  510. * 获得停车费用修改
  511. */
  512. getStopFee: function(carNumber) {
  513. let that = this;
  514. let postData =
  515. app.globalData.parkVendor == 1 ? {
  516. etcpToken: app.globalData.etcpToken,
  517. carNumber: carNumber
  518. } : {
  519. carNumber: carNumber,
  520. outCarId: outCarId
  521. };
  522. console.log(postData)
  523. Http.post({
  524. url: config.api.getCarStopFee,
  525. data: postData
  526. })
  527. .then(res => {
  528. var extraDataStr = {
  529. params: {
  530. token: app.globalData.etcpToken,
  531. syncId: res.data.orderId,
  532. payType: 6, // 小程序支付
  533. CarNumber: carNumber,
  534. returnUrl: "https://admin.malls.iformall.com/api/carCallback/etcpPaidCallback",
  535. source: "FUMAO-001",
  536. actionId: "1" //操作ID,1:小程序支付
  537. }
  538. };
  539. that.setData({
  540. extraData: extraDataStr,
  541. stopFees: res.data,
  542. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  543. });
  544. that.setData({
  545. scroll:true
  546. })
  547. })
  548. .catch(error => {
  549. console.log(error)
  550. wx.showModal({
  551. title: '提示',
  552. content: error.message,
  553. showCancel: false
  554. })
  555. that.setData({
  556. stopFees: {},
  557. scroll: true
  558. })
  559. });
  560. },
  561. /**
  562. * 下拉刷新
  563. */
  564. onPullDownRefresh: function(e) {
  565. let that = this;
  566. that.initUsrCarList("flags");
  567. wx.stopPullDownRefresh();
  568. },
  569. // 用户点击右上角分享
  570. onShareAppMessage: function() {
  571. return {
  572. title: this.data.title,
  573. desc: this.data.desc,
  574. success: function(res) {
  575. wx.showToast({
  576. title: "分享成功",
  577. duration: 1000,
  578. icon: "success"
  579. });
  580. }
  581. }
  582. }
  583. });