C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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