From 49fcaa3f7665642c1ecbb6e8e62c98fc22bd01a2 Mon Sep 17 00:00:00 2001 From: meo <18801474720@163.com> Date: Sat, 29 Sep 2018 10:47:41 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=81=9C=E8=BD=A6][=E4=BF=AE=E6=94=B9]:?= =?UTF-8?q?=E5=81=9C=E8=BD=A6=E5=8A=9F=E8=83=BD=E9=A2=9D=E5=BA=A6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/coupon/detail/index.js | 137 +++--- pages/getphoneInfo/index.js | 44 +- .../managelicenseplate.wxss | 1 - pages/passCar/passCar.js | 395 +++++++++--------- pages/passCar/passCar.json | 3 +- pages/passCar/passCar.wxml | 87 ++-- pages/passCar/passCar.wxss | 58 +-- pages/user/index.js | 9 +- pages/user/index.wxml | 2 +- project.config.json | 4 +- utils/util.js | 25 +- 11 files changed, 388 insertions(+), 377 deletions(-) diff --git a/pages/coupon/detail/index.js b/pages/coupon/detail/index.js index b1ab5e6..9bfbd25 100644 --- a/pages/coupon/detail/index.js +++ b/pages/coupon/detail/index.js @@ -27,10 +27,6 @@ Page({ onLoad(options) { let that = this; - console.log(options); - console.log("couponChannelId" + options.couponChannelId); - console.log("couponId" + options.couponId); - console.log("传的变量的名字叫couponId"); wx.showLoading({ title: "加载中..." }); @@ -98,70 +94,70 @@ Page({ /** * 拉取车牌列表 */ - init: function () { - var that = this + // init: function () { + // var that = this - app.parkInitCallback = token => { - that.initPark() - that.initUsrCarList() - if (!app.globalData.carLogin) { - // 共同登录 - Http.post({ - url: config.api.carInit, - data: { - phone: app.globalData.phone - } - }).then(res => { - app.globalData.carLogin = true - app.globalData.parkVendor = res.data.vendor - if (res.data.token != "undefined") { - app.globalData.etcpToken = res.data.token - console.log("etcpToken", app.globalData.etcpToken) - } - // 获取 停车费 - that.getStopFee() - }) - } - } - if (app.globalData.token && app.globalData.token != null) { - app.parkInitCallback(app.globalData.token) - } - }, - getStopFee: function () { - var that = this - // carLogin - for (var i = 0; i < that.data.carList.length; i++) { - that.getStopFeeItem(that.data.carList[i], i) - } - // console.log(JSON.stringify(getStopFeeItem)) - }, - initPark: function () { - var that = this - // 车场信息获取 - Http.get({ - url: config.api.getParkInfo, - data: {} - }) - .then(res => { - console.log(res) - that.setData({ - park: res.data, - }) - }) - }, - initUsrCarList: function () { - var that = this - // 绑定车获取 - Http.get({ - url: config.api.getUserCarList, - data: {} - }).then(res => { - console.log('>>>>>>>>>>>>>>>>>1' + JSON.stringify(res)); - that.setData({ - carList: res.data - }) - }) - }, + // app.parkInitCallback = token => { + // that.initPark() + // that.initUsrCarList() + // if (!app.globalData.carLogin) { + // // 共同登录 + // Http.post({ + // url: config.api.carInit, + // data: { + // phone: app.globalData.phone + // } + // }).then(res => { + // app.globalData.carLogin = true + // app.globalData.parkVendor = res.data.vendor + // if (res.data.token != "undefined") { + // app.globalData.etcpToken = res.data.token + // console.log("etcpToken", app.globalData.etcpToken) + // } + // // 获取 停车费 + // that.getStopFee() + // }) + // } + // } + // if (app.globalData.token && app.globalData.token != null) { + // app.parkInitCallback(app.globalData.token) + // } + // }, + // getStopFee: function () { + // var that = this + // // carLogin + // for (var i = 0; i < that.data.carList.length; i++) { + // that.getStopFeeItem(that.data.carList[i], i) + // } + // // console.log(JSON.stringify(getStopFeeItem)) + // }, + // initPark: function () { + // var that = this + // // 车场信息获取 + // Http.get({ + // url: config.api.getParkInfo, + // data: {} + // }) + // .then(res => { + // console.log(res) + // that.setData({ + // park: res.data, + // }) + // }) + // }, + // initUsrCarList: function () { + // var that = this + // // 绑定车获取 + // Http.get({ + // url: config.api.getUserCarList, + // data: {} + // }).then(res => { + // console.log('>>>>>>>>>>>>>>>>>1' + JSON.stringify(res)); + // that.setData({ + // carList: res.data + // }) + // }) + // }, /** * 发起支付 */ @@ -170,12 +166,7 @@ Page({ wx.showLoading({ title: "加载中..." }); - if (that.data.data.type == 6) { - this.initUsrCarList() - // 领取 5.停车券 - // TODO 选取用户下的车牌 - - } else { + if (that.data.data.type == 6) {} else { Http.post({ url: config.api.checkPhoneStatus, data: {} diff --git a/pages/getphoneInfo/index.js b/pages/getphoneInfo/index.js index f97b579..4cc1038 100755 --- a/pages/getphoneInfo/index.js +++ b/pages/getphoneInfo/index.js @@ -7,14 +7,16 @@ Page({ couponChannelId: "", couponId: "" }, - onLoad: function(options) { + onLoad: function (options) { var that = this; console.log(options); - - that.setData({ - couponChannelId: options.couponChannelId, - couponId: options.couponId - }); + if (options.couponChannelId && options.couponId) { + that.setData({ + couponChannelId: options.couponChannelId, + couponId: options.couponId + }); + } + Http.get({ url: config.api.marketicon, @@ -31,8 +33,8 @@ Page({ }) }); }, - - getPhoneNumber: function(e) { + + getPhoneNumber: function (e) { var that = this; var iv = e.detail.iv; var encryptedData = e.detail.encryptedData; @@ -43,7 +45,7 @@ Page({ iv: iv } }).then( - function(res) { + function (res) { console.log(res); console.log("这是用户授权手机号的结果"); console.log(that.data.couponChannelId); @@ -53,18 +55,24 @@ Page({ wx.showToast({ title: res.data.msg, icon: "success", - success: function(res) { - wx.redirectTo({ - url: "/pages/coupon/detail/index?couponChannelId=" + - that.data.couponChannelId + - "&couponId=" + - that.data.couponId + - "&flag=pay" - }); + success: function (res) { + if (that.data.couponChannelId && that.data.couponId) { + wx.redirectTo({ + url: "/pages/coupon/detail/index?couponChannelId=" + + that.data.couponChannelId + + "&couponId=" + + that.data.couponId + + "&flag=pay" + }) + } else { + wx.switchTab({ + url: '/pages/passCar/passCar', + }) + } } }); }, - function(error) { + function (error) { wx.showToast({ title: "请重新授权手机号", icon: "none" diff --git a/pages/managelicenseplate/managelicenseplate.wxss b/pages/managelicenseplate/managelicenseplate.wxss index f41d2cc..0eaa2fb 100644 --- a/pages/managelicenseplate/managelicenseplate.wxss +++ b/pages/managelicenseplate/managelicenseplate.wxss @@ -255,7 +255,6 @@ page { .btn001 { margin: 0 auto; - width: 120rpx; height: 180rpx; line-height: 180rpx; font-size: 32rpx; diff --git a/pages/passCar/passCar.js b/pages/passCar/passCar.js index 024185c..5e34cd1 100644 --- a/pages/passCar/passCar.js +++ b/pages/passCar/passCar.js @@ -1,7 +1,7 @@ -// pages/passCar/passCar.js let config = require("../../config/config.js"); let Http = require("../../utils/HttpBasics"); -const app = getApp(); +let Util = require("../../utils/util"); +let app = getApp(); Page({ data: { park: null, @@ -18,41 +18,39 @@ Page({ interval: 5000, duration: 1000, current: 0, - list: [] + stopFees: {}, }, /** - * 轮播图 + * 车牌轮播滑动 */ - onSlideChangeEnd: function(e) { + onSlideChangeEnd: function (e) { var that = this; - console.log(e); - console.log(e.detail.current); - var listCardNum = (that.data.list)[e.detail.current].memberKeyword; + /** + * 获得当前的车牌号码 + */ + var listCardNum = (that.data.carList)[e.detail.current].carNumber; console.log(listCardNum); that.setData({ listCardNum: listCardNum - }) - console.log(that.data.listCardNum); + }); + /** + * 获得停车费用 + */ + that.getStopFee(listCardNum); }, - gotomange: function() { + gotomange: function () { wx.navigateTo({ url: '/pages/managelicenseplate/managelicenseplate', }) }, - /*车牌动态样式 */ - changeStyle: function() { - var height = this.data.dataHeight == "150rpx" ? "80rpx" : "150rpx"; - var lineHeight = this.data.dataHeight == "150rpx" ? "80rpx" : "150rpx"; - var fontWeight = this.data.fontWeight == "600" ? "500" : "600"; - this.setData({ - dataHeight: height, - dataLineHeight: lineHeight, - dataFontWeight: fontWeight - }); - }, - onLoad: function(options) { + onLoad: function (options) { var that = this; - that.getList(); + /** + * 获得分享小程序的 + * title + * desc + */ + Http.get({ url: config.api.getWeapNote, data: { @@ -60,108 +58,69 @@ Page({ } }) .then(res => { - console.log(res.data.weapNote); let weapNote = JSON.parse(res.data.weapNote); - console.log(weapNote.carpage); that.setData({ desc: weapNote.carpage.desc, title: weapNote.carpage.title }) - }) - }, - - onShow: function(options) { - var that = this; - if (that.data.addCar) { - // 绑车牌 - if (app.globalData.carLogin) { - that.bindCar(that.data.addCar); - } else { - that.bindCar(that.data.addCar); - } - that.setData({ - addCar: null - }); - } - }, - //我的停车券的显示与消失 - showquan: function() { - let that = this; - if (that.data.tcq == 1) { - that.setData({ - tcq: 2 - }); - } else if (that.data.tcq == 2) { - that.setData({ - tcq: 1 }); - } + }, - jumpToAdd: function() { + + + jumpToAdd: function () { wx.navigateTo({ url: "/pages/addPark/addPark" }); }, - passc: function() { + passc: function () { wx.navigateTo({ url: '/pages/ques/ques', }) }, + + //券绑定车牌 - bindCoupon: function(e) { + bindCoupon: function (e) { + console.log(e); var that = this; wx.showLoading({ title: '加载中...', }); if (that.data.couponList.length > 0) { /** - * 如果1 已经绑定 - * 0 没有绑定 + * etcp */ - for (let car of that.data.carList) { - if (car.stopFee.parkingFee) { - that.data.payList.push(car); - } - } var etcpData = { etcpToken: app.globalData.etcpToken, - carNumber: that.data.payList[0].carNumber ? - that.data.payList[0].carNumber : - "", + carNumber: that.data.listCardNum, + /** + * 待解决 + */ couponOrderId: that.data.couponList[0].id }; console.log(etcpData); - // 停简单 + /** + * 停简单 + */ var tjdData = { - carNumber: that.data.payList[0].carNumber + carNumber: that.data.listCardNum }; var postCouponData = app.globalData.parkVendor == 1 ? etcpData : tjdData; - Http.post({ url: config.api.getCarCoupon, data: postCouponData }) .then(res => { - that.setData({ - flag: "1" - }); that.initUsrCarList(); - console.log("loading") wx.hideLoading(); }) .catch(error => { console.log(error); - if (error.code == 2056) { - that.setData({ - flags: "alreadybind" - }); - } - }); + }) } else { + console.log("没有停车券可以绑定") wx.hideLoading(); - that.setData({ - flags: "alreadybind" - }); } }, @@ -176,17 +135,24 @@ Page({ couponOrderStatus: 0 } }).then(res => { - that.init(); + console.log(res); that.setData({ couponList: res.data.list }); - setTimeout(function() { - wx.hideLoading(); - }, 1200); }); }, - bindCar: function(carNum) { + onShow: function (options) { + var that = this; + that.getList(); + that.init(); + }, + + /** + * 绑定车牌 + */ + + bindCar: function (carNum) { var that = this; // ETCP var etcpData = { @@ -203,15 +169,12 @@ Page({ }) .then(res => { console.log(res); - that.setData({ - addCar: null - }); - that.initUsrCarList(); + // that.initUsrCarList(); wx.showModal({ title: "提示", showCancel: false, content: "绑车牌成功!", - success: function() {} + success: function () {} }); }) .catch(error => { @@ -219,69 +182,77 @@ Page({ wx.showModal({ title: "提示", showCancel: false, - content: error.data.message, - success: function() {} + content: error.message, + success: function () {} }); }); }, - // unbindCar: function(carNum) { - // var that = this; - // var postData = - // app.globalData.parkVendor == 1 - // ? { - // etcpToken: app.globalData.etcpToken, - // carNumber: carNum - // } - // : { - // carNumber: carNum - // }; - // Http.post({ - // url: config.api.unbindCar, - // data: postData - // }) - // .then(res => { - // console.log(res); - // that.initUsrCarList(); - // wx.showModal({ - // title: "提示", - // showCancel: false, - // content: "解绑车牌成功!", - // success: function() {} - // }); - // }) - // .catch(error => { - // wx.showModal({ - // title: "提示", - // showCancel: false, - // content: "解绑车牌失败!", - // success: function() {} - // }); - // }); - // }, - // unbindCarBtn: function(e) { - // console.log(e); - // var that = this; - // var carNum = e.currentTarget.dataset.car; - // that.unbindCar(carNum); - // }, - getStopFeeItem: function(carItem, i) { + + + /** + * 车场信息获取 + */ + initPark: function () { + var that = this; + Http.get({ + url: config.api.getParkInfo, + data: {} + }).then(res => { + that.setData({ + park: res.data + }); + }); + }, + + + /** + * 绑定车获取 + */ + initUsrCarList: function (flag) { + console.log(flag); + var that = this; + Http.get({ + url: config.api.getUserCarList, + data: {} + }).then(res => { + console.log(res) + that.setData({ + carList: res.data + }); + /** + * flag ==flags + * 表示从首页onShow进来的 + */ + if (flag == "flags") { + var listCardNum = res.data[0].carNumber; + console.log(listCardNum); + that.setData({ + listCardNum: listCardNum + }) + /** + * 获得停车费用 + */ + that.getStopFee(listCardNum); + } + }) + }, + + /** + * 获得停车费用修改 + */ + getStopFee: function (carNumber) { var that = this; var postData = - app.globalData.parkVendor == 1 ? - { + app.globalData.parkVendor == 1 ? { etcpToken: app.globalData.etcpToken, - carNumber: carItem.carNumber - } : - { - carNumber: carItem.carNumber, - outCarId: carItem.outCarId + carNumber: carNumber + } : { + carNumber: carNumber, + outCarId: outCarId }; - var stopFee = "carList[" + i + "].stopFee"; - var extraData = "carList[" + i + "].extraData"; - console.log(extraData); var extraDataStr = { params: { - CarNumber: carItem.carNumber + CarNumber: carNumber } }; that.setData({ @@ -292,86 +263,100 @@ Page({ data: postData }) .then(res => { - /** - * 停车费用 - */ that.setData({ - [stopFee]: res.data, - [extraData]: extraDataStr, - buttonBox: res.data.parkingFee - }) + stopFees: res.data + }) + that.setData({ + timecha: Util.timecha(res.data.exitTime, res.data.entranceTime) + }) }) .catch(error => { console.log(error); + wx.showModal({ + title: '提示', + content: error.message, + showCancel: false + }) + that.setData({ + stopFees: {} + }) }); }, - getStopFee: function() { - var that = this; - // carLogin - for (var i = 0; i < that.data.carList.length; i++) { - that.getStopFeeItem(that.data.carList[i], i); - } - }, - initPark: function() { - var that = this; - // 车场信息获取 - Http.get({ - url: config.api.getParkInfo, - data: {} - }).then(res => { - console.log(res); - that.setData({ - park: res.data - }); - }); - }, - initUsrCarList: function() { - var that = this; - // 绑定车获取 - Http.get({ - url: config.api.getUserCarList, - data: {} - }).then(res => { - that.setData({ - carList: res.data - }); - }); - }, - init: function() { + /** + * 共同登录 + */ + init: function (carNumber) { var that = this; app.parkInitCallback = token => { that.initPark(); - that.initUsrCarList(); if (!app.globalData.carLogin) { - // 共同登录 + /** + * 判断是否授权手机号 + */ Http.post({ - url: config.api.carInit, - data: { - phone: app.globalData.phone - } - }).then(res => { - app.globalData.carLogin = true; - app.globalData.parkVendor = res.data.vendor; - if (res.data.token != "undefined") { - app.globalData.etcpToken = res.data.token; - console.log("etcpToken", app.globalData.etcpToken); - } - // 获取 停车费 - that.getStopFee(); - }); + url: config.api.checkPhoneStatus, + data: {} + }) + .then(res => { + console.log(res); + Http.post({ + url: config.api.carInit, + data: { + phone: app.globalData.phone + } + }).then(res => { + console.log(res); + app.globalData.carLogin = true; + app.globalData.parkVendor = res.data.vendor; + if (res.data.token) { + app.globalData.etcpToken = res.data.token; + } + /** + * 获得停车费用 + */ + that.initUsrCarList("flags"); + console.log(app.globalData.etcpToken); + }); + }) + .catch(err => { + console.log(err); + if (err.code == 11005) { + // 用户手机未授权 + /** + * 将值传到用户手机号授权的页面 + * + */ + wx.redirectTo({ + url: "/pages/getphoneInfo/index" + }); + } else if (err.code == 11006) { + // 用户手机已加密 + wx.redirectTo({ + url: "/pages/phoneinput/phoneinput" + }); + } + }) } }; if (app.globalData.token && app.globalData.token != null) { app.parkInitCallback(app.globalData.token); } }, + /** + * 下拉刷新 + */ + onPullDownRefresh: function(e) { + let that = this; + that.initUsrCarList("flags"); + wx.stopPullDownRefresh(); + }, // 用户点击右上角分享 - onShareAppMessage: function() { + onShareAppMessage: function () { return { title: this.data.title, desc: this.data.desc, - success: function(res) { + success: function (res) { wx.showToast({ title: "分享成功", duration: 1000, diff --git a/pages/passCar/passCar.json b/pages/passCar/passCar.json index 83aeba7..a02ad69 100644 --- a/pages/passCar/passCar.json +++ b/pages/passCar/passCar.json @@ -1,5 +1,6 @@ { "component": true, "usingComponents": {}, - "navigationBarTitleText": "停车" + "navigationBarTitleText": "停车", + "enablePullDownRefresh": true } \ No newline at end of file diff --git a/pages/passCar/passCar.wxml b/pages/passCar/passCar.wxml index c9172ec..600a5c7 100644 --- a/pages/passCar/passCar.wxml +++ b/pages/passCar/passCar.wxml @@ -1,35 +1,27 @@ - - - - 我的爱车 - 最多可添加3辆 - - - 车辆管理 - - - - - - {{park.addr}} - - 总车位: - + + + + {{park.addr}} - - 停车费: - + + 总车位:{{park.number}}个 + + 停车费: + + + - + - - - + + + {{item.carNumber}} @@ -37,42 +29,47 @@ - + - - - + 入场时间: - {{item.stopFee.entranceTime}} + {{stopFees.entranceTime}} - - 优免券: + + 停车时长: + {{timecha}} + + + 优惠券: 2小时优免券 待缴费用: - {{item.stopFee.parkingFee}} + {{stopFees.remainingFee}} - - + + + - 我的爱车 + 我的爱车 + 车辆入场后,才能绑车牌 @@ -86,6 +83,14 @@ + + + 车辆管理 + + + + + 常见问题 @@ -93,9 +98,10 @@ + - - + \ No newline at end of file diff --git a/pages/passCar/passCar.wxss b/pages/passCar/passCar.wxss index c999ee0..e334774 100644 --- a/pages/passCar/passCar.wxss +++ b/pages/passCar/passCar.wxss @@ -3,7 +3,8 @@ page { background-color: #fff; } - +.top{ +} .headBox { width: 690rpx; margin: 30rpx auto 0; @@ -27,7 +28,7 @@ page { font-size: 32rpx; word-break: break-all; text-align: justify; - font-weight:bold; + font-weight: bold; } ::-webkit-scrollbar { @@ -56,29 +57,33 @@ page { } .price { + width: 690rpx; font-size: 28rpx; color: #999; - width: 100%; - margin-top: 10rpx; - line-height: 40rpx; + margin: 10rpx auto 60rpx; } -.time{ - color: #999!important; + +.time { + color: #999 !important; } -.price .fl{ + +.price .fl { width: 15%; - color: #666; + color: #333; } -.price .fr{ + +.price .fr { width: 85%; color: #999; line-height: 40rpx; font-size: 26rpx; } -.titleName .fr{ + +.titleName .fr { color: #999; font-size: 27rpx; } + .borderBox { width: 750rpx; margin-top: 26rpx; @@ -212,14 +217,16 @@ page { } .passNumberBox { + width: 690rpx; + margin: 50rpx auto 0; position: relative; background-color: white; - /* border-bottom: 1rpx #f8f8f8 solid; */ - margin-top: 60rpx; } -.numberBox{ + +.numberBox { width: 100%; } + .passNumber { width: 400rpx; height: 100rpx; @@ -399,7 +406,7 @@ page { left: 0; top: 0; z-index: 100000000; - border-radius:60rpx; + border-radius: 60rpx; } .active { @@ -407,17 +414,17 @@ page { } .borderBox { - width: 690rpx; - margin: 50rpx auto 0; + width: 750rpx; + border-top: 4rpx #f8f8f8 solid; } .carmanage { position: relative; width: 690rpx; margin: 0 auto; - height: 88rpx; - line-height: 88rpx; - border-bottom: 1rpx solid #eee; + height: 80rpx; + line-height: 82rpx; + /* border-bottom: 1rpx solid #eee; */ } .carmanage .fr { @@ -425,7 +432,6 @@ page { color: #888; letter-spacing: 1.16rpx; text-align: right; - margin-right: 40rpx; } .fl { @@ -457,9 +463,9 @@ page { .mycar { display: inline-block; - margin-left: 20rpx; - font-size: 30rpx; + font-size: 33rpx; color: #333; + line-height: 35rpx; letter-spacing: 1.16rpx; } @@ -555,7 +561,7 @@ button::after { margin: 0 8rpx; width: 32rpx; height: 14rpx; - background: #fff; + background: #ccc; border-radius: 8rpx; transition: all 0.6s; } @@ -581,7 +587,7 @@ button::after { .orderBox .fr { line-height: 60rpx; font-size: 28rpx; - color: #FF4949; + color: #ff4949; } .jians { @@ -590,7 +596,7 @@ button::after { width: 34rpx; height: 34rpx; text-align: center; - background: orange; + background: #ff4949; line-height: 34rpx; color: #fff; border-radius: 6rpx; diff --git a/pages/user/index.js b/pages/user/index.js index 36e4f63..56b3a66 100644 --- a/pages/user/index.js +++ b/pages/user/index.js @@ -6,10 +6,6 @@ Page({ * 页面的初始数据 */ data: { - // user: { - // avatar: - // "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg" - // } flag: 'hidden', score:'0' }, @@ -34,7 +30,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function(options) { - + }, /** @@ -71,7 +67,8 @@ Page({ }).then(res=>{ console.log(res); that.setData({ - score: res.data.score + score: res.data.score, + levelName: res.data.levelName }) }) }, diff --git a/pages/user/index.wxml b/pages/user/index.wxml index 4d0f6ac..6f12379 100644 --- a/pages/user/index.wxml +++ b/pages/user/index.wxml @@ -8,7 +8,7 @@ - 微信用户 + 等级:{{levelName}} {{score}} diff --git a/project.config.json b/project.config.json index de8711f..99c9d33 100644 --- a/project.config.json +++ b/project.config.json @@ -4,14 +4,14 @@ "ignore": [] }, "setting": { - "urlCheck": false, + "urlCheck": true, "es6": true, "postcss": true, "minified": true, "newFeature": true }, "compileType": "miniprogram", - "libVersion": "2.2.5", + "libVersion": "2.0.9", "appid": "wx649b3be73c1afe47", "projectname": "%E5%AF%8C%E8%8C%82%E9%93%BE%E5%AE%A2", "isGameTourist": false, diff --git a/utils/util.js b/utils/util.js index 85b263a..a0be6b4 100644 --- a/utils/util.js +++ b/utils/util.js @@ -96,10 +96,33 @@ function timechuo(startTime) { console.log(month, day, hour, minute, second); return (day+"天"+hour+"小时"+minute+"分钟") } + + +//计算时间差 +function timecha(endTime,startTime) { + var s1 = new Date(endTime.replace(/-/g, "/")); + var s2 = new Date(startTime.replace(/-/g, "/")); + var runTime = parseInt((s1.getTime() - s2.getTime()) / 1000); + var year = Math.floor(runTime / 86400 / 365); + var runTime = runTime % (86400 * 365); + var month = Math.floor(runTime / 86400 / 30); + var runTime = runTime % (86400 * 30); + var day = Math.floor(runTime / 86400); + var runTime = runTime % 86400; + var hour = Math.floor(runTime / 3600); + var runTime = runTime % 3600; + var minute = Math.floor(runTime / 60); + var runTime = runTime % 60; + var second = runTime; + console.log(month, day, hour, minute, second); + return (day+"天"+hour+"小时"+minute+"分钟") +} + module.exports = { formatTime: formatTime, barcode: barc, qrcode: qrc, fmtDate: fmtDate, - timechuo:timechuo + timechuo:timechuo, + timecha:timecha };