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.

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