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.

391 rivejä
8.3 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. },
  23. /**
  24. * 车牌轮播滑动
  25. */
  26. onSlideChangeEnd: function (e) {
  27. var that = this;
  28. /**
  29. * 获得当前的车牌号码
  30. */
  31. var listCardNum = (that.data.carList)[e.detail.current].carNumber;
  32. console.log(listCardNum);
  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. onShow: function (options) {
  47. var that = this;
  48. that.getList();
  49. that.init();
  50. /**
  51. * 只有用户选择了优惠券
  52. * 才会进行券和车牌的绑定
  53. */
  54. if (wx.getStorageSync("chosed") && that.data.quanid) {
  55. that.bindCoupon(that.data.quanid);
  56. wx.setStorage({
  57. key: 'chosed',
  58. data: '',
  59. })
  60. }
  61. },
  62. onLoad: function (options) {
  63. var that = this;
  64. /**
  65. * 获得分享小程序的
  66. * title
  67. * desc
  68. */
  69. Http.get({
  70. url: config.api.getWeapNote,
  71. data: {
  72. appId: config.weapp.AppId,
  73. }
  74. })
  75. .then(res => {
  76. let weapNote = JSON.parse(res.data.weapNote);
  77. that.setData({
  78. desc: weapNote.carpage.desc,
  79. title: weapNote.carpage.title
  80. })
  81. });
  82. },
  83. jumpToAdd: function () {
  84. wx.navigateTo({
  85. url: "/pages/addPark/addPark"
  86. });
  87. },
  88. passc: function () {
  89. wx.navigateTo({
  90. url: '/pages/ques/ques',
  91. })
  92. },
  93. /**
  94. * 券绑定车牌
  95. */
  96. bindCoupon: function (quanid) {
  97. var that = this;
  98. /**
  99. * etcp
  100. */
  101. var etcpData = {
  102. etcpToken: app.globalData.etcpToken,
  103. carNumber: that.data.listCardNum,
  104. /**
  105. * 待解决
  106. */
  107. couponOrderId: quanid
  108. };
  109. console.log(etcpData);
  110. /**
  111. * 停简单
  112. */
  113. var tjdData = {
  114. carNumber: that.data.listCardNum
  115. };
  116. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  117. Http.post({
  118. url: config.api.getCarCoupon,
  119. data: postCouponData
  120. })
  121. .then(res => {
  122. that.initUsrCarList();
  123. })
  124. .catch(error => {
  125. wx.showModal({
  126. content: error.message,
  127. showCancel: false,
  128. confirmText: "确定",
  129. })
  130. console.log(error);
  131. })
  132. },
  133. /**
  134. * 选择优惠券
  135. */
  136. gotoquan: function () {
  137. let that = this;
  138. console.log(that.data.quanid);
  139. if (that.data.quanid){
  140. wx.navigateTo({
  141. url: `/pages/passCar/choicecoupon/choicecoupon?quanid=${that.data.quanid}`,
  142. })
  143. }else{
  144. wx.navigateTo({
  145. url: '/pages/passCar/choicecoupon/choicecoupon',
  146. })
  147. }
  148. },
  149. //获取名下停车券列表
  150. getList() {
  151. var that = this;
  152. Http.get({
  153. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  154. data: {
  155. pageNum: 1,
  156. pageSize: 8,
  157. couponOrderStatus: 0
  158. }
  159. }).then(res => {
  160. console.log(res);
  161. that.setData({
  162. couponList: res.data.list
  163. });
  164. });
  165. },
  166. /**
  167. * 共同登录
  168. */
  169. init: function (carNumber) {
  170. var that = this;
  171. app.parkInitCallback = token => {
  172. that.initPark();
  173. if (!app.globalData.carLogin) {
  174. /**
  175. * 判断是否授权手机号
  176. */
  177. Http.post({
  178. url: config.api.checkPhoneStatus,
  179. data: {}
  180. })
  181. .then(res => {
  182. console.log(res);
  183. Http.post({
  184. url: config.api.carInit,
  185. data: {
  186. phone: app.globalData.phone
  187. }
  188. }).then(res => {
  189. console.log(res);
  190. app.globalData.carLogin = true;
  191. app.globalData.parkVendor = res.data.vendor;
  192. if (res.data.token) {
  193. app.globalData.etcpToken = res.data.token;
  194. }
  195. /**
  196. * 获得停车费用
  197. */
  198. that.initUsrCarList("flags");
  199. console.log(app.globalData.etcpToken);
  200. });
  201. })
  202. .catch(err => {
  203. console.log(err);
  204. if (err.code == 11005) {
  205. // 用户手机未授权
  206. /**
  207. * 将值传到用户手机号授权的页面
  208. *
  209. */
  210. wx.redirectTo({
  211. url: "/pages/getphoneInfo/index"
  212. });
  213. } else if (err.code == 11006) {
  214. // 用户手机已加密
  215. wx.redirectTo({
  216. url: "/pages/phoneinput/phoneinput"
  217. });
  218. }
  219. })
  220. }
  221. };
  222. if (app.globalData.token && app.globalData.token != null) {
  223. app.parkInitCallback(app.globalData.token);
  224. }
  225. },
  226. /**
  227. * 绑定车牌
  228. */
  229. bindCar: function (carNum) {
  230. var that = this;
  231. // ETCP
  232. var etcpData = {
  233. etcpToken: app.globalData.etcpToken,
  234. carNumber: carNum
  235. };
  236. var tjdData = {
  237. carNumber: carNum
  238. };
  239. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  240. Http.post({
  241. url: config.api.bindCar,
  242. data: postData
  243. })
  244. .then(res => {
  245. console.log(res);
  246. // that.initUsrCarList();
  247. wx.showModal({
  248. title: "提示",
  249. showCancel: false,
  250. content: "绑车牌成功!",
  251. success: function () { }
  252. });
  253. })
  254. .catch(error => {
  255. console.log(error);
  256. wx.showModal({
  257. title: "提示",
  258. showCancel: false,
  259. content: error.message,
  260. success: function () { }
  261. });
  262. });
  263. },
  264. /**
  265. * 车场信息获取
  266. */
  267. initPark: function () {
  268. var that = this;
  269. Http.get({
  270. url: config.api.getParkInfo,
  271. data: {}
  272. }).then(res => {
  273. that.setData({
  274. park: res.data
  275. });
  276. });
  277. },
  278. /**
  279. * 绑定车获取
  280. */
  281. initUsrCarList: function (flag) {
  282. console.log(flag);
  283. var that = this;
  284. Http.get({
  285. url: config.api.getUserCarList,
  286. data: {}
  287. }).then(res => {
  288. console.log(res)
  289. that.setData({
  290. carList: res.data
  291. });
  292. /**
  293. * flag ==flags
  294. * 表示从首页onShow进来的
  295. */
  296. if (flag == "flags" && res.data.length > 0) {
  297. var listCardNum = res.data[0].carNumber;
  298. console.log(listCardNum);
  299. that.setData({
  300. listCardNum: listCardNum
  301. })
  302. /**
  303. * 获得停车费用
  304. */
  305. that.getStopFee(listCardNum);
  306. }
  307. })
  308. },
  309. /**
  310. * 获得停车费用修改
  311. */
  312. getStopFee: function (carNumber) {
  313. var that = this;
  314. var postData =
  315. app.globalData.parkVendor == 1 ? {
  316. etcpToken: app.globalData.etcpToken,
  317. carNumber: carNumber
  318. } : {
  319. carNumber: carNumber,
  320. outCarId: outCarId
  321. };
  322. var extraDataStr = {
  323. params: {
  324. CarNumber: carNumber
  325. }
  326. };
  327. that.setData({
  328. extraData: extraDataStr
  329. });
  330. Http.post({
  331. url: config.api.getCarStopFee,
  332. data: postData
  333. })
  334. .then(res => {
  335. that.setData({
  336. stopFees: res.data
  337. })
  338. that.setData({
  339. timecha: Util.timecha(res.data.exitTime, res.data.entranceTime)
  340. })
  341. })
  342. .catch(error => {
  343. console.log(error);
  344. wx.showModal({
  345. title: '提示',
  346. content: error.message,
  347. showCancel: false
  348. })
  349. that.setData({
  350. stopFees: {}
  351. })
  352. });
  353. },
  354. /**
  355. * 下拉刷新
  356. */
  357. onPullDownRefresh: function (e) {
  358. let that = this;
  359. that.initUsrCarList("flags");
  360. wx.stopPullDownRefresh();
  361. },
  362. // 用户点击右上角分享
  363. onShareAppMessage: function () {
  364. return {
  365. title: this.data.title,
  366. desc: this.data.desc,
  367. success: function (res) {
  368. wx.showToast({
  369. title: "分享成功",
  370. duration: 1000,
  371. icon: "success"
  372. });
  373. }
  374. }
  375. }
  376. });