C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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