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.

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