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.

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