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

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