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.

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