C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

346 行
8.2 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. couponFreeId: that.data.couponList[0].couponFreeId ? that.data.couponList[0].couponFreeId : '',
  99. merchantId: that.data.couponList[0].merchantId ? that.data.couponList[0].merchantId : '',
  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. })
  124. .catch(error => {
  125. console.log(error);
  126. if (error.code == 2056) {
  127. that.setData({
  128. flags: 'alreadybind'
  129. })
  130. }
  131. })
  132. }else{
  133. console.log('1111111111111111111')
  134. that.setData({
  135. flags: 'alreadybind'
  136. })
  137. console.log(that.data.flags)
  138. }
  139. },
  140. //获取名下停车券列表
  141. getList() {
  142. var that = this;
  143. Http.get({
  144. url: config.api.couponOrderCarList + "?type=5&couponOrderStatus=0",
  145. data: {
  146. pageNum: 1,
  147. pageSize: 8,
  148. couponOrderStatus: 0
  149. }
  150. }).then(res => {
  151. that.init();
  152. that.setData({
  153. couponList: res.data.list
  154. })
  155. setTimeout(function () {
  156. wx.hideLoading();
  157. }, 1200);
  158. });
  159. },
  160. bindCar: function (carNum) {
  161. var that = this
  162. // ETCP
  163. var etcpData = {
  164. etcpToken: app.globalData.etcpToken,
  165. carNumber: carNum,
  166. }
  167. var tjdData = {
  168. carNumber: carNum,
  169. }
  170. var postData = (app.globalData.parkVendor == 1) ? etcpData : tjdData
  171. Http.post({
  172. url: config.api.bindCar,
  173. data: postData,
  174. })
  175. .then(res => {
  176. console.log(res)
  177. that.setData({
  178. addCar: null
  179. })
  180. that.initUsrCarList()
  181. wx.showModal({
  182. title: '提示',
  183. showCancel: false,
  184. content: "绑车牌成功!",
  185. success: function () { }
  186. })
  187. })
  188. .catch(error => {
  189. console.log(error)
  190. wx.showModal({
  191. title: '提示',
  192. showCancel: false,
  193. content: error.data.message,
  194. success: function () { }
  195. })
  196. })
  197. },
  198. unbindCar: function (carNum) {
  199. var that = this
  200. var postData =
  201. (app.globalData.parkVendor == 1) ? {
  202. etcpToken: app.globalData.etcpToken,
  203. carNumber: carNum,
  204. } : {
  205. carNumber: carNum,
  206. }
  207. Http.post({
  208. url: config.api.unbindCar,
  209. data: postData,
  210. })
  211. .then(res => {
  212. console.log(res)
  213. that.initUsrCarList()
  214. wx.showModal({
  215. title: '提示',
  216. showCancel: false,
  217. content: "解绑车牌成功!",
  218. success: function () { }
  219. })
  220. })
  221. .catch(error => {
  222. wx.showModal({
  223. title: '提示',
  224. showCancel: false,
  225. content: "解绑车牌失败!",
  226. success: function () { }
  227. })
  228. })
  229. },
  230. unbindCarBtn: function (e) {
  231. console.log(e)
  232. var that = this
  233. var carNum = e.currentTarget.dataset.car
  234. that.unbindCar(carNum)
  235. },
  236. getStopFeeItem: function (carItem, i) {
  237. var that = this;
  238. var postData =
  239. (app.globalData.parkVendor == 1) ? {
  240. etcpToken: app.globalData.etcpToken,
  241. carNumber: carItem.carNumber,
  242. } : {
  243. carNumber: carItem.carNumber,
  244. outCarId: carItem.outCarId,
  245. }
  246. var stopFee = 'carList[' + i + '].stopFee'
  247. var extraData = 'carList[' + i + '].extraData';
  248. console.log(extraData);
  249. var extraDataStr = { params: { CarNumber: carItem.carNumber } };
  250. that.setData({
  251. extraData: extraDataStr
  252. })
  253. Http.post({
  254. url: config.api.getCarStopFee,
  255. data: postData
  256. })
  257. .then(res => {
  258. /**
  259. * 停车费用
  260. */
  261. that.setData({
  262. [stopFee]: res.data,
  263. [extraData]: extraDataStr,
  264. buttonBox: res.data.parkingFee
  265. }),
  266. console.log('res>>>' + JSON.stringify(that.data.buttonBox))
  267. })
  268. .catch(error => {
  269. console.log(error)
  270. })
  271. },
  272. getStopFee: function () {
  273. var that = this
  274. // carLogin
  275. for (var i = 0; i < that.data.carList.length; i++) {
  276. that.getStopFeeItem(that.data.carList[i], i)
  277. }
  278. // console.log(JSON.stringify(getStopFeeItem))
  279. },
  280. initPark: function () {
  281. var that = this
  282. // 车场信息获取
  283. Http.get({
  284. url: config.api.getParkInfo,
  285. data: {}
  286. })
  287. .then(res => {
  288. that.setData({
  289. park: res.data,
  290. })
  291. })
  292. },
  293. initUsrCarList: function () {
  294. var that = this
  295. // 绑定车获取
  296. Http.get({
  297. url: config.api.getUserCarList,
  298. data: {}
  299. }).then(res => {
  300. that.setData({
  301. carList: res.data
  302. })
  303. console.log('aaaa' + JSON.stringify(that.data.carList) );
  304. })
  305. },
  306. init: function () {
  307. var that = this
  308. app.parkInitCallback = token => {
  309. that.initPark()
  310. that.initUsrCarList()
  311. if (!app.globalData.carLogin) {
  312. // 共同登录
  313. Http.post({
  314. url: config.api.carInit,
  315. data: {
  316. phone: app.globalData.phone
  317. }
  318. }).then(res => {
  319. app.globalData.carLogin = true
  320. app.globalData.parkVendor = res.data.vendor
  321. if (res.data.token != "undefined") {
  322. app.globalData.etcpToken = res.data.token
  323. console.log("etcpToken", app.globalData.etcpToken)
  324. }
  325. // 获取 停车费
  326. that.getStopFee()
  327. })
  328. }
  329. }
  330. if (app.globalData.token && app.globalData.token != null) {
  331. app.parkInitCallback(app.globalData.token)
  332. }
  333. }
  334. })