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.

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