C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

480 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. 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. that.getParkStatus();
  207. if (!app.globalData.carLogin) {
  208. /**
  209. * 判断是否授权手机号
  210. */
  211. Http.post({
  212. url: config.api.checkPhoneStatus,
  213. data: {}
  214. })
  215. .then(res => {
  216. console.log(res);
  217. Http.post({
  218. url: config.api.carInit,
  219. data: {
  220. phone: app.globalData.phone
  221. }
  222. }).then(res => {
  223. console.log(res);
  224. app.globalData.carLogin = true;
  225. app.globalData.parkVendor = res.data.vendor;
  226. if (res.data.token) {
  227. app.globalData.etcpToken = res.data.token;
  228. }
  229. /**
  230. * 获得停车费用
  231. */
  232. that.initUsrCarList("flags");
  233. console.log(app.globalData.etcpToken);
  234. });
  235. })
  236. .catch(err => {
  237. console.log(err);
  238. if (err.code == 11005) {
  239. // 用户手机未授权
  240. /**
  241. * 将值传到用户手机号授权的页面
  242. *
  243. */
  244. wx.redirectTo({
  245. url: "/pages/getphoneInfo/index"
  246. });
  247. } else if (err.code == 11006) {
  248. // 用户手机已加密
  249. wx.redirectTo({
  250. url: "/pages/phoneinput/phoneinput"
  251. });
  252. }
  253. })
  254. }
  255. };
  256. if (app.globalData.token && app.globalData.token != null) {
  257. app.parkInitCallback(app.globalData.token);
  258. }
  259. },
  260. /**
  261. * 绑定车牌
  262. */
  263. // bindCar: function(carNum) {
  264. // var that = this;
  265. // // ETCP
  266. // var etcpData = {
  267. // etcpToken: app.globalData.etcpToken,
  268. // carNumber: carNum
  269. // };
  270. // var tjdData = {
  271. // carNumber: carNum
  272. // };
  273. // var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  274. // Http.post({
  275. // url: config.api.bindCar,
  276. // data: postData
  277. // })
  278. // .then(res => {
  279. // console.log(res);
  280. // // that.initUsrCarList();
  281. // wx.showModal({
  282. // title: "提示",
  283. // showCancel: false,
  284. // content: "绑车牌成功!",
  285. // success: function() {}
  286. // });
  287. // })
  288. // .catch(error => {
  289. // console.log(error);
  290. // wx.showModal({
  291. // title: "提示",
  292. // showCancel: false,
  293. // content: error.message,
  294. // success: function() {}
  295. // });
  296. // });
  297. // },
  298. bindCar: function (carNum) {
  299. var that = this;
  300. // ETCP
  301. var etcpData = {
  302. etcpToken: app.globalData.etcpToken,
  303. carNumber: carNum
  304. };
  305. var tjdData = {
  306. carNumber: carNum
  307. };
  308. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  309. Http.post({
  310. url: config.api.bindCar,
  311. data: postData
  312. })
  313. .then(res => {
  314. console.log(res);
  315. that.setData({
  316. addCar: null
  317. });
  318. that.initUsrCarList();
  319. wx.showModal({
  320. title: "提示",
  321. showCancel: false,
  322. content: "绑车牌成功!",
  323. success: function () { }
  324. });
  325. })
  326. .catch(error => {
  327. console.log(error);
  328. wx.showModal({
  329. title: "提示",
  330. showCancel: false,
  331. content: error.data.message,
  332. success: function () { }
  333. });
  334. });
  335. },
  336. /**
  337. * 车场信息获取
  338. */
  339. initPark: function() {
  340. var that = this;
  341. Http.get({
  342. url: config.api.getParkInfo,
  343. data: {}
  344. }).then(res => {
  345. that.setData({
  346. park: res.data
  347. });
  348. });
  349. },
  350. /**
  351. * 车场状态获取
  352. */
  353. getParkStatus: function() {
  354. var that = this;
  355. Http.get({
  356. url: config.api.getParkStatus,
  357. })
  358. .then(res => {
  359. console.log(res);
  360. });
  361. },
  362. /**
  363. * 绑定车获取
  364. */
  365. initUsrCarList: function(flag) {
  366. console.log(flag);
  367. var that = this;
  368. Http.get({
  369. url: config.api.getUserCarList,
  370. data: {}
  371. }).then(res => {
  372. console.log(res)
  373. that.setData({
  374. carList: res.data
  375. });
  376. /**
  377. * flag ==flags
  378. * 表示从首页onShow进来的
  379. */
  380. if (flag == "flags" && res.data.length > 0) {
  381. var listCardNum = res.data[0].carNumber;
  382. console.log(listCardNum);
  383. that.setData({
  384. listCardNum: listCardNum
  385. })
  386. /**
  387. * 获得停车费用
  388. */
  389. that.getStopFee(listCardNum);
  390. }
  391. })
  392. },
  393. /**
  394. * 获得停车费用修改
  395. */
  396. getStopFee: function(carNumber) {
  397. var that = this;
  398. var postData =
  399. app.globalData.parkVendor == 1 ? {
  400. etcpToken: app.globalData.etcpToken,
  401. carNumber: carNumber
  402. } : {
  403. carNumber: carNumber,
  404. outCarId: outCarId
  405. };
  406. Http.post({
  407. url: config.api.getCarStopFee,
  408. data: postData
  409. })
  410. .then(res => {
  411. var extraDataStr = {
  412. params: {
  413. token: app.globalData.etcpToken,
  414. syncId: res.data.orderId,
  415. payType: 6, // 小程序支付
  416. CarNumber: carNumber,
  417. returnUrl: "https://admin.malls.iformall.com/api/carCallback/etcpPaidCallback",
  418. source: "FUMAO-001",
  419. actionId: "1" //操作ID,1:小程序支付
  420. }
  421. };
  422. that.setData({
  423. extraData: extraDataStr
  424. });
  425. that.setData({
  426. stopFees: res.data
  427. })
  428. that.setData({
  429. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  430. })
  431. })
  432. .catch(error => {
  433. console.log(error);
  434. wx.showModal({
  435. title: '提示',
  436. content: error.message,
  437. showCancel: false
  438. })
  439. that.setData({
  440. stopFees: {}
  441. })
  442. });
  443. },
  444. /**
  445. * 下拉刷新
  446. */
  447. onPullDownRefresh: function(e) {
  448. let that = this;
  449. that.initUsrCarList("flags");
  450. wx.stopPullDownRefresh();
  451. },
  452. // 用户点击右上角分享
  453. onShareAppMessage: function() {
  454. return {
  455. title: this.data.title,
  456. desc: this.data.desc,
  457. success: function(res) {
  458. wx.showToast({
  459. title: "分享成功",
  460. duration: 1000,
  461. icon: "success"
  462. });
  463. }
  464. }
  465. }
  466. });