C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

363 řádky
8.6 KiB

  1. // pages/passCar/passCar.js
  2. let config = require("../../config/config.js");
  3. let Http = require("../../utils/HttpBasics");
  4. const 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. },
  17. /*车牌动态样式 */
  18. changeStyle: function() {
  19. var height = this.data.dataHeight == "150rpx" ? "80rpx" : "150rpx";
  20. var lineHeight = this.data.dataHeight == "150rpx" ? "80rpx" : "150rpx";
  21. var fontWeight = this.data.fontWeight == "600" ? "500" : "600";
  22. this.setData({
  23. dataHeight: height,
  24. dataLineHeight: lineHeight,
  25. dataFontWeight: fontWeight
  26. });
  27. },
  28. onLoad: function(options) {
  29. var that = this;
  30. that.getList();
  31. Http.get({
  32. url: config.api.getWeapNote,
  33. data: {
  34. appId: config.weapp.AppId,
  35. }
  36. })
  37. .then(res => {
  38. console.log(res.data.weapNote);
  39. let weapNote = JSON.parse(res.data.weapNote);
  40. console.log(weapNote.carpage);
  41. that.setData({
  42. desc: weapNote.carpage.desc,
  43. title: weapNote.carpage.title
  44. })
  45. })
  46. },
  47. onShow: function(options) {
  48. var that = this;
  49. console.log("车牌号");
  50. if (that.data.addCar) {
  51. // 绑车牌
  52. if (app.globalData.carLogin) {
  53. that.bindCar(that.data.addCar);
  54. } else {
  55. that.bindCar(that.data.addCar);
  56. }
  57. that.setData({
  58. addCar: null
  59. });
  60. }
  61. },
  62. //我的停车券的显示与消失
  63. showquan: function() {
  64. let that = this;
  65. if (that.data.tcq == 1) {
  66. that.setData({
  67. tcq: 2
  68. });
  69. } else if (that.data.tcq == 2) {
  70. that.setData({
  71. tcq: 1
  72. });
  73. }
  74. },
  75. jumpToAdd: function() {
  76. wx.navigateTo({
  77. url: "/pages/addPark/addPark"
  78. });
  79. },
  80. passc: function() {
  81. wx.navigateTo({
  82. url: '/pages/ques/ques',
  83. })
  84. },
  85. //券绑定车牌
  86. bindCoupon: function(e) {
  87. var that = this;
  88. if (that.data.couponList.length > 0) {
  89. console.log("00000000000000");
  90. console.log(e.currentTarget.dataset.checkbind);
  91. /**
  92. * 如果1 已经绑定
  93. * 0 没有绑定
  94. */
  95. for (let car of that.data.carList) {
  96. if (car.stopFee.parkingFee) {
  97. that.data.payList.push(car);
  98. }
  99. }
  100. var etcpData = {
  101. etcpToken: app.globalData.etcpToken,
  102. carNumber: that.data.payList[0].carNumber
  103. ? that.data.payList[0].carNumber
  104. : "",
  105. couponOrderId: that.data.couponList[0].id
  106. };
  107. console.log(etcpData);
  108. // 停简单
  109. var tjdData = {
  110. carNumber: that.data.payList[0].carNumber
  111. };
  112. var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  113. Http.post({
  114. url: config.api.getCarCoupon,
  115. data: postCouponData
  116. })
  117. .then(res => {
  118. that.setData({
  119. flag: "1"
  120. });
  121. // that.initUsrCarList()
  122. wx.showModal({
  123. title: "提示",
  124. showCancel: false,
  125. content: "车牌绑定优免券成功!",
  126. success: function(res) {}
  127. });
  128. })
  129. .catch(error => {
  130. console.log(error);
  131. if (error.code == 2056) {
  132. that.setData({
  133. flags: "alreadybind"
  134. });
  135. }
  136. });
  137. } else {
  138. console.log("1111111111111111111");
  139. that.setData({
  140. flags: "alreadybind"
  141. });
  142. console.log(that.data.flags);
  143. }
  144. },
  145. //获取名下停车券列表
  146. getList() {
  147. var that = this;
  148. Http.get({
  149. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  150. data: {
  151. pageNum: 1,
  152. pageSize: 8,
  153. couponOrderStatus: 0
  154. }
  155. }).then(res => {
  156. that.init();
  157. that.setData({
  158. couponList: res.data.list
  159. });
  160. setTimeout(function() {
  161. wx.hideLoading();
  162. }, 1200);
  163. });
  164. },
  165. bindCar: function(carNum) {
  166. var that = this;
  167. // ETCP
  168. var etcpData = {
  169. etcpToken: app.globalData.etcpToken,
  170. carNumber: carNum
  171. };
  172. var tjdData = {
  173. carNumber: carNum
  174. };
  175. var postData = app.globalData.parkVendor == 1 ? etcpData : tjdData;
  176. Http.post({
  177. url: config.api.bindCar,
  178. data: postData
  179. })
  180. .then(res => {
  181. console.log(res);
  182. that.setData({
  183. addCar: null
  184. });
  185. that.initUsrCarList();
  186. wx.showModal({
  187. title: "提示",
  188. showCancel: false,
  189. content: "绑车牌成功!",
  190. success: function() {}
  191. });
  192. })
  193. .catch(error => {
  194. console.log(error);
  195. wx.showModal({
  196. title: "提示",
  197. showCancel: false,
  198. content: error.data.message,
  199. success: function() {}
  200. });
  201. });
  202. },
  203. unbindCar: function(carNum) {
  204. var that = this;
  205. var postData =
  206. app.globalData.parkVendor == 1
  207. ? {
  208. etcpToken: app.globalData.etcpToken,
  209. carNumber: carNum
  210. }
  211. : {
  212. carNumber: carNum
  213. };
  214. Http.post({
  215. url: config.api.unbindCar,
  216. data: postData
  217. })
  218. .then(res => {
  219. console.log(res);
  220. that.initUsrCarList();
  221. wx.showModal({
  222. title: "提示",
  223. showCancel: false,
  224. content: "解绑车牌成功!",
  225. success: function() {}
  226. });
  227. })
  228. .catch(error => {
  229. wx.showModal({
  230. title: "提示",
  231. showCancel: false,
  232. content: "解绑车牌失败!",
  233. success: function() {}
  234. });
  235. });
  236. },
  237. unbindCarBtn: function(e) {
  238. console.log(e);
  239. var that = this;
  240. var carNum = e.currentTarget.dataset.car;
  241. that.unbindCar(carNum);
  242. },
  243. getStopFeeItem: function(carItem, i) {
  244. var that = this;
  245. var postData =
  246. app.globalData.parkVendor == 1
  247. ? {
  248. etcpToken: app.globalData.etcpToken,
  249. carNumber: carItem.carNumber
  250. }
  251. : {
  252. carNumber: carItem.carNumber,
  253. outCarId: carItem.outCarId
  254. };
  255. var stopFee = "carList[" + i + "].stopFee";
  256. var extraData = "carList[" + i + "].extraData";
  257. console.log(extraData);
  258. var extraDataStr = { params: { CarNumber: carItem.carNumber } };
  259. that.setData({
  260. extraData: extraDataStr
  261. });
  262. Http.post({
  263. url: config.api.getCarStopFee,
  264. data: postData
  265. })
  266. .then(res => {
  267. /**
  268. * 停车费用
  269. */
  270. that.setData({
  271. [stopFee]: res.data,
  272. [extraData]: extraDataStr,
  273. buttonBox: res.data.parkingFee
  274. }),
  275. console.log("res>>>" + JSON.stringify(that.data.buttonBox));
  276. })
  277. .catch(error => {
  278. console.log(error);
  279. });
  280. },
  281. getStopFee: function() {
  282. var that = this;
  283. // carLogin
  284. for (var i = 0; i < that.data.carList.length; i++) {
  285. that.getStopFeeItem(that.data.carList[i], i);
  286. }
  287. // console.log(JSON.stringify(getStopFeeItem))
  288. },
  289. initPark: function() {
  290. var that = this;
  291. // 车场信息获取
  292. Http.get({
  293. url: config.api.getParkInfo,
  294. data: {}
  295. }).then(res => {
  296. that.setData({
  297. park: res.data
  298. });
  299. });
  300. },
  301. initUsrCarList: function() {
  302. var that = this;
  303. // 绑定车获取
  304. Http.get({
  305. url: config.api.getUserCarList,
  306. data: {}
  307. }).then(res => {
  308. that.setData({
  309. carList: res.data
  310. });
  311. console.log("aaaa" + JSON.stringify(that.data.carList));
  312. });
  313. },
  314. init: function() {
  315. var that = this;
  316. app.parkInitCallback = token => {
  317. that.initPark();
  318. that.initUsrCarList();
  319. if (!app.globalData.carLogin) {
  320. // 共同登录
  321. Http.post({
  322. url: config.api.carInit,
  323. data: {
  324. phone: app.globalData.phone
  325. }
  326. }).then(res => {
  327. app.globalData.carLogin = true;
  328. app.globalData.parkVendor = res.data.vendor;
  329. if (res.data.token != "undefined") {
  330. app.globalData.etcpToken = res.data.token;
  331. console.log("etcpToken", app.globalData.etcpToken);
  332. }
  333. // 获取 停车费
  334. that.getStopFee();
  335. });
  336. }
  337. };
  338. if (app.globalData.token && app.globalData.token != null) {
  339. app.parkInitCallback(app.globalData.token);
  340. }
  341. },
  342. // 用户点击右上角分享
  343. onShareAppMessage: function () {
  344. return {
  345. title: this.data.title,
  346. desc: this.data.desc,
  347. success: function (res) {
  348. wx.showToast({
  349. title: "分享成功",
  350. duration: 1000,
  351. icon: "success"
  352. });
  353. }
  354. }}
  355. });