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.

328 lines
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. },
  14. /*车牌动态样式 */
  15. changeStyle: function () {
  16. var height = this.data.dataHeight == '150rpx' ? '80rpx' : '150rpx';
  17. var lineHeight = this.data.dataHeight == '150rpx' ? '80rpx' : '150rpx';
  18. var fontWeight = this.data.fontWeight == '600' ? '500' : '600';
  19. this.setData({
  20. dataHeight: height,
  21. dataLineHeight: lineHeight,
  22. dataFontWeight: fontWeight
  23. });
  24. },
  25. onLoad: function (options) {
  26. var that = this
  27. that.getList();
  28. },
  29. onShow: function (options) {
  30. var that = this;
  31. console.log("车牌号")
  32. if (that.data.addCar) {
  33. // 绑车牌
  34. if (app.globalData.carLogin) {
  35. that.bindCar(that.data.addCar)
  36. } else {
  37. that.bindCar(that.data.addCar)
  38. }
  39. that.setData({
  40. addCar: null
  41. })
  42. }
  43. },
  44. //我的停车券的显示与消失
  45. showquan: function () {
  46. let that = this;
  47. if (that.data.tcq == 1) {
  48. that.setData({
  49. tcq: 2
  50. })
  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. //券绑定车牌
  74. bindCoupon: function (e) {
  75. var that = this;
  76. console.log(e.currentTarget.dataset.checkbind);
  77. /**
  78. * 如果1 已经绑定
  79. * 0 没有绑定
  80. */
  81. for (let car of that.data.carList) {
  82. if (car.stopFee.parkingFee) {
  83. that.data.payList.push(car)
  84. console.log('bbbb' + 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,
  91. 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. console.log(stopFee)
  248. that.setData({
  249. [stopFee]: res.data,
  250. [extraData]: extraDataStr
  251. })
  252. })
  253. .catch(error => {
  254. console.log(error)
  255. })
  256. },
  257. getStopFee: function () {
  258. var that = this
  259. // carLogin
  260. for (var i = 0; i < that.data.carList.length; i++) {
  261. that.getStopFeeItem(that.data.carList[i], i)
  262. }
  263. // console.log(JSON.stringify(getStopFeeItem))
  264. },
  265. initPark: function () {
  266. var that = this
  267. // 车场信息获取
  268. Http.get({
  269. url: config.api.getParkInfo,
  270. data: {}
  271. })
  272. .then(res => {
  273. that.setData({
  274. park: res.data,
  275. })
  276. })
  277. },
  278. initUsrCarList: function () {
  279. var that = this
  280. // 绑定车获取
  281. Http.get({
  282. url: config.api.getUserCarList,
  283. data: {}
  284. }).then(res => {
  285. that.setData({
  286. carList: res.data
  287. })
  288. console.log('aaaa' + JSON.stringify(that.data.carList) );
  289. })
  290. },
  291. init: function () {
  292. var that = this
  293. app.parkInitCallback = token => {
  294. that.initPark()
  295. that.initUsrCarList()
  296. if (!app.globalData.carLogin) {
  297. // 共同登录
  298. Http.post({
  299. url: config.api.carInit,
  300. data: {
  301. phone: app.globalData.phone
  302. }
  303. }).then(res => {
  304. app.globalData.carLogin = true
  305. app.globalData.parkVendor = res.data.vendor
  306. if (res.data.token != "undefined") {
  307. app.globalData.etcpToken = res.data.token
  308. console.log("etcpToken", app.globalData.etcpToken)
  309. }
  310. // 获取 停车费
  311. that.getStopFee()
  312. })
  313. }
  314. }
  315. if (app.globalData.token && app.globalData.token != null) {
  316. app.parkInitCallback(app.globalData.token)
  317. }
  318. }
  319. })