C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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