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.

345 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. }
  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. // payButton:function(){
  75. // if (that.data.couponList.length>0){
  76. // console.log('>>>'+that.data.couponList.length)
  77. // that.bindCoupon(e);
  78. // }
  79. // },
  80. //券绑定车牌
  81. bindCoupon: function (e) {
  82. var that = this;
  83. if (that.data.couponList.length>0){
  84. console.log('00000000000000')
  85. console.log(e.currentTarget.dataset.checkbind);
  86. /**
  87. * 如果1 已经绑定
  88. * 0 没有绑定
  89. */
  90. for (let car of that.data.carList) {
  91. if (car.stopFee.parkingFee) {
  92. that.data.payList.push(car)
  93. }
  94. }
  95. var etcpData = {
  96. etcpToken: app.globalData.etcpToken,
  97. carNumber: that.data.payList[0].carNumber ? that.data.payList[0].carNumber : '',
  98. couponOrderId: that.data.couponList[0].id,
  99. }
  100. console.log(etcpData)
  101. // 停简单
  102. var tjdData = {
  103. carNumber: that.data.payList[0].carNumber,
  104. }
  105. var postCouponData = (app.globalData.parkVendor == 1) ? etcpData : tjdData;
  106. Http.post({
  107. url: config.api.getCarCoupon,
  108. data: postCouponData,
  109. })
  110. .then(res => {
  111. that.setData({
  112. flag: '1'
  113. });
  114. // that.initUsrCarList()
  115. wx.showModal({
  116. title: '提示',
  117. showCancel: false,
  118. content: "车牌绑定优免券成功!",
  119. success: function (res) {
  120. }
  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. etcpToken: app.globalData.etcpToken,
  202. carNumber: carNum,
  203. } : {
  204. carNumber: carNum,
  205. }
  206. Http.post({
  207. url: config.api.unbindCar,
  208. data: postData,
  209. })
  210. .then(res => {
  211. console.log(res)
  212. that.initUsrCarList()
  213. wx.showModal({
  214. title: '提示',
  215. showCancel: false,
  216. content: "解绑车牌成功!",
  217. success: function () { }
  218. })
  219. })
  220. .catch(error => {
  221. wx.showModal({
  222. title: '提示',
  223. showCancel: false,
  224. content: "解绑车牌失败!",
  225. success: function () { }
  226. })
  227. })
  228. },
  229. unbindCarBtn: function (e) {
  230. console.log(e)
  231. var that = this
  232. var carNum = e.currentTarget.dataset.car
  233. that.unbindCar(carNum)
  234. },
  235. getStopFeeItem: function (carItem, i) {
  236. var that = this;
  237. var postData =
  238. (app.globalData.parkVendor == 1) ? {
  239. etcpToken: app.globalData.etcpToken,
  240. carNumber: carItem.carNumber,
  241. } : {
  242. carNumber: carItem.carNumber,
  243. outCarId: carItem.outCarId,
  244. }
  245. var stopFee = 'carList[' + i + '].stopFee'
  246. var extraData = 'carList[' + i + '].extraData';
  247. console.log(extraData);
  248. var extraDataStr = { params: { CarNumber: carItem.carNumber } };
  249. that.setData({
  250. extraData: extraDataStr
  251. })
  252. Http.post({
  253. url: config.api.getCarStopFee,
  254. data: postData
  255. })
  256. .then(res => {
  257. /**
  258. * 停车费用
  259. */
  260. that.setData({
  261. [stopFee]: res.data,
  262. [extraData]: extraDataStr,
  263. buttonBox: res.data.parkingFee
  264. }),
  265. console.log('res>>>' + JSON.stringify(that.data.buttonBox))
  266. })
  267. .catch(error => {
  268. console.log(error)
  269. })
  270. },
  271. getStopFee: function () {
  272. var that = this
  273. // carLogin
  274. for (var i = 0; i < that.data.carList.length; i++) {
  275. that.getStopFeeItem(that.data.carList[i], i)
  276. }
  277. // console.log(JSON.stringify(getStopFeeItem))
  278. },
  279. initPark: function () {
  280. var that = this
  281. // 车场信息获取
  282. Http.get({
  283. url: config.api.getParkInfo,
  284. data: {}
  285. })
  286. .then(res => {
  287. that.setData({
  288. park: res.data,
  289. })
  290. })
  291. },
  292. initUsrCarList: function () {
  293. var that = this
  294. // 绑定车获取
  295. Http.get({
  296. url: config.api.getUserCarList,
  297. data: {}
  298. }).then(res => {
  299. that.setData({
  300. carList: res.data
  301. })
  302. console.log('aaaa' + JSON.stringify(that.data.carList) );
  303. })
  304. },
  305. init: function () {
  306. var that = this
  307. app.parkInitCallback = token => {
  308. that.initPark()
  309. that.initUsrCarList()
  310. if (!app.globalData.carLogin) {
  311. // 共同登录
  312. Http.post({
  313. url: config.api.carInit,
  314. data: {
  315. phone: app.globalData.phone
  316. }
  317. }).then(res => {
  318. app.globalData.carLogin = true
  319. app.globalData.parkVendor = res.data.vendor
  320. if (res.data.token != "undefined") {
  321. app.globalData.etcpToken = res.data.token
  322. console.log("etcpToken", app.globalData.etcpToken)
  323. }
  324. // 获取 停车费
  325. that.getStopFee()
  326. })
  327. }
  328. }
  329. if (app.globalData.token && app.globalData.token != null) {
  330. app.parkInitCallback(app.globalData.token)
  331. }
  332. }
  333. })