C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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