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.

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