C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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