1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699 |
- // const log = require('../../utils/log')
- const {
- getCache,
- setCache,
- CacheKeys
- } = require('../../utils/cache')
- var app = getApp()
- var interval;
- // var inter1;
- var locationTerval;
- var huancheTime;
- // var coundDown; //运动中不可锁车倒计时
- var linshiStop; //临时停车倒计时
- const util = require('../../utils/utils.js');
- var interval;
- //蓝牙操作方法
- var BluetoothOperate = require('../../service/bluetooth.js');
- //const { content } = require('../../service/dataTransition.js');
- let bluetoothOperate = new BluetoothOperate();
- let machineNO = "" //设备编号
- let key = "" //蓝牙密钥
- let operateType = '' //'open'开锁 'close'上锁 'bell'寻铃 'temporaryClose'临时锁车 'temporaryOpen'临时锁车开车
- var mytime = null;
- Page({
- data: {
- marqueeDistance: 520, //初始滚动距离 用到
- marqueeWidth: 560, //通知公告用到
- marqueePace: 0.6, //滚动速度
- length: '', //通知公告
- size: 26, //通知公告用到
- notice: '', //通知公告
- currentSwiper: 0,
- nowBikeStatus: '', //当前车辆的状态
- money: {
- time_money: 0,
- dispatch_money: 0,
- total_money: 0
- }, //骑行费用
- steps: 1, //开锁步骤
- parkStatus: 0, //骑行中:0,临时停车:1,点击结束用车:2
- frame: false, //车辆未开锁弹框
- code: '', //车辆编码
- bikeMessage: '', //车辆信息
- times: '0', //当前骑行时间
- estimate_money: '0', //预计金额
- minute: '', //骑行总时间秒
- data: [],
- box_no: '',
- screenHeight: '',
- change: false,
- timing: 5,
- isShow: false,
- minute1: '',
- parke: true,
- timeout: 15,
- retry: '',
- bikePosition: false,
- battery_power: '--',
- huanche_timeout: 0,
- img: app.globalData.imgUrl,
- title: app.globalData.title,
- stopmMinute: 30, //临时停车时间
- stopMiao: 0,
- chaButton: 0, //0 不显示 1显示
- markers: [],
- polygons: [],
- polygons1: [],
- zoom: 12,
- temporaryTime: '', //临时锁车时间
- background: false, //位置权限弹框
- location: false, //位置权限弹框
- coundDownTime: 5, //运动中不可锁车倒计时
- countTimeShow: false,
- dispatch_money: 0, //调度费
- area_id: '', //区域id
- mapHeight: 'calc(100vh - 300px)',
- isHour: false, //及时判断是否含有小时
- popShow: false,
- centerLon: '', //地图中心点经纬度
- centerLat: '', //地图中心点经纬度
- is_out_area: false, //当前用户是否超出区域
- load_num: 0, //超出区域弹窗提示弹出次数控制控制弹窗弹出次数
- isUseTK: app.globalData.isUseTK, //是否使用头盔
- ifKnowUseTK: true, //是否已点击使用头盔
- is_dev: true, //是否为开发环境是的话隐藏购卡充值
- localSearchStop: app.globalData.localSearchStop, //是否开启使用当前位置查询还车点
- bikeMarker: [], //当前车辆位置的mark
- isUseLinTing: app.globalData.isUseLinTing, //是否使用临时停车
- TKfuwei: true, //头盔是否复位
- TKtipsProp: false, //头盔是否在位提示框
- start_use_bike_time: 0, //开始用车的时间
- noShowRefOpenLock: false,//隐藏为开锁按钮,false不隐藏
- },
- onShow: function () {
- let isLearn = my.getStorageSync({
- 'key': 'videoLearn'
- }).data
- let is_dev = my.getStorageSync({
- 'key': 'userInfo'
- }).data
- let home = my.setStorageSync({
- 'key': 'home'
- }).data
- let that = this
- that.setData({
- polygons1: [],
- polygons: [],
- is_dev: is_dev ? is_dev.is_dev : true,
- markers: [],
- zoom: home &&home.zoom ? home.zoom : 12
- })
- my.setNavigationBar({
- title: app.globalData.title
- })
- clearInterval(locationTerval);
- if (isLearn == false || !isLearn) {
- my.navigateTo({
- url: '/pages/video/video?code=' + this.data.code,
- })
- }
- app.login().then(res => {
- that.userState()
- that.posiLoca()
- that.chushiPosiloc()
- if (that.data.code) {
- that.getBikeMessage()
- }
- })
- if (that.data.order != undefined) {
- console.log(that.data.order, 'that.data.orderthat.data.orderthat.data.order')
- that.chushi()
- }
- // that.reloadMap()
- },
- //初始化位之信息并获取区域
- chushiPosiloc: function () {
- let that = this
- my.showLoading({
- content: '正在定位...',
- })
- my.getLocation({
- type: 'gcj02',
- success: (res) => {
- console.log('经纬度为:+++++++++++2323++++++++++' + res.latitude + '++++++++' + res.longitude)
- var latitude = res.latitude
- var longitude = res.longitude
- my.hideLoading()
- that.setData({
- longitude: longitude,
- latitude: latitude,
- })
- that.home()
- },
- fail: function (err) {
- console.log(err)
- my.hideLoading()
- if (err.error == 11) {
- my.showAuthGuide({
- authType: 'LBS',
- success: (res) => {
- },
- fail: (error) => {
- my.alert({
- content: '获取位置授权失败'
- });
- },
- })
- }
- my.getSetting({
- success: function (res) {
- // console.log(res)
- var statu = res.authSetting;
- if (statu['scope.userLocation'] == false) {
- that.setData({
- background: true,
- location: true
- })
- }
- }
- })
- }
- })
- },
- onLoad: function (options) {
- let that = this
- console.log(options!=={},!app.globalData.scanCode)
-
- if(options.code){
- that.setData({
- code: options.code
- })
- }else if (app.globalData.scanCode) {
- that.setData({
- code: app.globalData.scanCode
- })
- } else if (options.order != undefined) {
- that.setData({
- order: options.order,
- })
- }else if(options!=={} && !app.globalData.scanCode){
- my.reLaunch({
- url:'/pages/index/index'
- })
- }
- },
- getNotice(id) {
- let data = {
- 'area_id': id
- }
- let isCache = getCache('Notice:' + id)
- console.log(isCache, 'isCache')
- if (isCache) {
- if (isCache != null && isCache instanceof Object && !isCache.hasOwnProperty('id')) return
- this.setData({
- notice: isCache
- })
- var length = isCache.description.length * this.data.size; //计算文字的长度
- this.setData({
- length: length
- })
- if (this.data.length > this.data.marqueeWidth) {
- this.noticeRun();
- } else {
- this.setData({
- marqueeDistance: 0
- })
- }
- return
- }
- app.request("/index/an", data, "GET").then(res => {
- if (200 == res.status) {
- setCache('Notice:' + id, res.data)
- if (res.data != null && res.data instanceof Object && !res.data.hasOwnProperty('id')) return
- this.setData({
- notice: res.data
- })
- var length = res.data.description.length * this.data.size; //计算文字的长度
- this.setData({
- length: length
- })
- if (this.data.length > this.data.marqueeWidth) {
- this.noticeRun();
- } else {
- this.setData({
- marqueeDistance: 0
- })
- }
- }
- }).catch(err => {
- // console.log(err)
- })
- },
- noticeRun: function () {
- var that = this;
- clearInterval(mytime);
- mytime = setInterval(function () {
- if (-that.data.marqueeDistance < that.data.length) {
- that.setData({
- marqueeDistance: that.data.marqueeDistance - that.data.marqueePace,
- })
- } else {
- clearInterval(mytime);
- that.setData({
- marqueeDistance: that.data.marqueeWidth
- });
- that.noticeRun();
- }
- }, 10)
- },
- //广告列表
- adsList: function (id) {
- var that = this;
- var area_id = ''
- if (id != undefined) {
- area_id = id
- } else {
- area_id = 0
- }
- let isCache = getCache('ads:' + id)
- if (isCache) {
- if (isCache == '') return
- if (isCache != null && isCache instanceof Object && isCache.hasOwnProperty('header')) {
- that.setData({
- ads: isCache.header
- })
- }
- if (isCache != null && isCache instanceof Object && isCache.hasOwnProperty('mid')) {
- that.setData({
- mid: isCache.mid,
- adFrame: true
- })
- }
- return
- }
- app.request("/ads?area_id=" + area_id + "&position[]=mid&position[]=header&position[]=footer", '', "GET").then(res => {
- if (res.status == 200) {
- setCache('ads:' + id, res.data)
- if (res.data == '') return
- if (res.data.header) {
- that.setData({
- ads: res.data.header
- })
- }
- if (res.data.mid) {
- that.setData({
- mid: res.data.mid,
- adFrame: true
- })
- }
- }
- }).catch(err => {
- // console.log(err)
- })
- },
- //点击广告页
- swiper: util.throttle(function (e) {
- var type = e.currentTarget.dataset.type;
- var index = e.currentTarget.dataset.index;
- var name = e.currentTarget.dataset.name;
- var detail = e.currentTarget.dataset.detail;
- var id = e.currentTarget.dataset.id;
- if (type != 'clilk_null') {
- if (type == 'wxUrl') {
- console.log(e, 'pppp')
- my.navigateTo({
- url: '/' + detail,
- })
- } else if (type == 'phone') {
- my.makePhoneCall({
- number: detail,
- })
- } else if (type == 'toMiniProgram') {
- my.navigateToMiniProgram({
- appId: detail,
- extraData: {
- foo: 'bar'
- },
- // envVersion: 'develop',
- success(res) {
- // 打开成功
- }
- })
- } else {
- my.navigateTo({
- url: '../swiper/swiper?type=' + type + '&url=' + id + '&name=' + name + '&detail=' + detail,
- })
- }
- }
- }, 1000),
- //点击轮播图
- swiperChange: function (e) {
- if (this.data.currentSwiper == 0 && this.data.swiperCurrent > 1) { //卡死时,重置current为正确索引
- this.setData({
- currentSwiper: this.data.swiperCurrent
- });
- } else { //正常轮转时,记录正确页码索引
- this.setData({
- swiperCurrent: e.detail.current
- });
- }
- },
- //用户状态
- userState: function (area_id) {
- var that = this;
- app.request("/user/status", "GET").then(res => {
- console.log(res, 'zhuangtai')
- if (res.status == 200) {
- my.setStorageSync({
- 'key': 'userState',
- data: res.data
- });
- if (res.data.is_ride_order) {
- that.setData({
- order: res.data.is_ride_order,
- })
- that.chushi()
- }
- /**
- * 未支付直接调转支付
- * mead
- */
- if (res.data.is_pay_order) {
- my.navigateTo({
- url: '/pages/pay/pay?order=' + res.data.is_pay_order,
- })
- }
- } else {
- if (this.data.bikeInfo.is_link == 0) {
- my.alert({
- title: '提示',
- content: '当前车子已下线请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.put_status == 0) {
- my.alert({
- title: '提示',
- content: '当前车子还未投放请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.is_low_battery_power == 0) {
- my.alertal({
- title: '提示',
- content: '当前车子电量过低请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.is_trouble == 1) {
- my.alert({
- title: '提示',
- content: '当前车子出现故障请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.is_riding == 1) {
- my.alert({
- title: '提示',
- content: '当前车子正在骑行请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- }
- }
- }).catch(err => {
- console.log(err)
- })
- },
- //骑行区禁停区车辆
- home: function () {
- //请求首页接口和一些设置。
- var that = this;
- if (that.data.longitude != '' && that.data.latitude != '') {
- //116.411027
- var data = {
- 'lat': that.data.latitude,
- 'lng': that.data.longitude,
- 'bike_no': that.data.code
- }
- app.request("/pages/home?include=setting", data, "POST").then(res => {
- console.log(res, '骑行区域')
- if (res.status == 200) {
- var data = res.data;
- that.setData({
- area_id: res.data.id,
- zoom: data.zoom ? data.zoom : 12,
- polygons: that.data.polygons.concat(data),
- })
- my.setStorageSync({
- 'key': 'home',
- data: data
- });
- let area_id = res.data.id
- //原获取全部还车点接口
- if (that.data.localSearchStop == false) that.ban_stop(area_id)
- //根据位置请求区域
- if (that.data.localSearchStop == true) that.searchStopArea(that.data.longitude, that.data.latitude)
-
- that.getNotice(area_id)
- that.adsList(area_id)
- console.log(data, '区域')
-
- }
- console.log(data, 'tdada')
- if (data) {
- my.setStorageSync({
- 'key': 'setting',
- data: data.setting
- });
- } else {
- my.removeStorageSync({
- key: 'setting'
- })
- }
- }).catch(err => {
- console.log(err)
- my.alert({
- title: '提示',
- content: err.data.message,
- })
- })
- }
- },
- regionchange: function (e) {
- if (this.data.localSearchStop == false) return
- if (e.type == 'end') {
- this.searchStopArea(e.longitude, e.latitude)
- }
- },
- //添加定位点,并展示周围还车点
- searchStopArea: function (longitude, latitude) {
- let home = my.getStorageSync({
- 'key': 'home'
- }).data
- if (!home || !home.id) return
- let params = {
- 'lat': latitude,
- 'lng': longitude,
- 'area_id':home.id,
- }
- console.log(this.data.polygons)
- app.request('/parking/nearby-all', params, 'GET').then(res => {
- console.log('根据位置获取区域', res)
- let arr = [home]
- this.setData({
- markers: this.data.bikeMarker.concat(res.data.points),
- polygons: arr.concat(res.data.polygons),
- centerLat:latitude,
- centerLon:longitude
- })
- })
- },
- //停车区域
- ban_stop: function (area_id) {
- var that = this;
- let home = my.getStorageSync({
- 'key': 'home'
- }).data
- that.setData({
- polygons1: that.data.polygons1.concat(home)
- })
- let isCache = getCache('BAN_STOP:' + area_id)
- if (isCache) {
- that.setData({
- markers: that.data.markers.concat(isCache.centres),
- polygons: that.data.polygons1.concat(isCache.polygons),
- })
- return
- }
- var data1 = {
- 'area_id': area_id
- }
- app.request('/parking/stop-sites', data1, 'GET').then(res => {
- console.log(res)
- if (res.status == 200) {
- var data = res.data
- console.log(data)
- that.setData({
- markers: that.data.markers.concat(data.centres),
- polygons: that.data.polygons1.concat(data.polygons),
- })
- }
- })
- },
- //初始化信息
- chushi: function () {
- my.showLoading()
- var that = this;
- var date = Date.parse(new Date()) / 1000;
- app.request('/pages/ride-order?no=' + that.data.order, '', 'GET').then(res => {
- console.log(res, ',---------')
- let setting = my.getStorageSync({
- 'key': 'setting'
- }).data;
- if (res.status == 200) {
- my.hideLoading()
- my.setStorageSync({
- 'key': 'bike_status',
- data: res.data.status
- })
- if (res.data.is_out_area == true) {
- that.setData({
- load_num: that.data.load_num + 1
- })
- }
- this.data.start_use_bike_time = res.data.start_use_bike_time
- if (res.data.is_out_area == true && that.data.load_num == 1) {
- my.showModal({
- title: '提示',
- content: '您当前已超出骑行区域,车辆已经断电,请将车辆骑回运营区,或联系客服进行车辆回电',
- cancelText: '联系客服',
- confirmText: '我知道了',
- complete: (res) => {
- if (res.cancel) {
- my.makePhoneCall({
- number: my.getStorageSync({
- 'key': 'home'
- }).data.customer_service_phone,
- })
- that.setData({
- load_num: 0
- })
- }
- if (res.confirm) {
- that.setData({
- load_num: 0
- })
- }
- }
- })
- }
- if (res.data.start_use_bike_time <= 0) {
- that.setData({
- minute: 0
- })
- } else {
- that.countBikeMoney()
- }
- that.terval()
- my.showToast({
- content: '刷新成功',
- icon: 'none'
- })
- that.setData({
- data: res.data,
- code: res.data.bike_no,
- temporaryTime: res.data.pause_bike_time
- })
- let userStatus = my.getStorageSync({
- 'key': 'userState'
- }).data;
- let setting = my.getStorageSync({
- 'key': 'setting'
- }).data;
- let bike_status = my.getStorageSync({
- 'key': 'bike_status'
- }).data;
- console.log('pppppppp---------------------vyvyvyvy')
- //有正在骑行中的订单的订单
- if (userStatus.is_ride_order != false && bike_status == 1) {
- //骑行中
- console.log('ppppp')
- that.setData({
- steps: 3
- })
- my.setStorageSync({
- 'key': 'nowBikeStatus',
- data: 0
- })
- // that.reloadMap()
- } else if (bike_status == 0 && userStatus.is_ride_order != false) {
- // 临时停车
- that.setData({
- parkStatus: 1,
- steps: 3
- })
- my.setStorageSync({
- 'key': 'nowBikeStatus',
- data: 1
- })
- // that.reloadMap()
- that.stopDownTime()
- }
- app.request('/bike/' + that.data.code, '', 'GET').then(res => {
- console.log(res)
- 200 == res.status && that.setData({
- battery_power: res.data.battery_power,
- box_no: res.data.box_no,
- bikeMessage: res.data,
- })
- })
- if (res.data.status == 0) {
- that.setData({
- bolear: 0
- })
- } else if (res.data.status == 1) {
- that.setData({
- bolear: 1
- })
- } else if (res.data.status == 2) {
- clearInterval(interval),
- // clearInterval(interval1);
- clearInterval(locationTerval);
- my.reLaunch({
- url: '../payment/payment?order=' + res.data.no
- })
- } else {
- my.reLaunch({
- url: '../index/index',
- })
- }
- that.bikeLocation();
- }
- }).catch(err => {
- console.log(err)
- })
- },
- //获取车辆位置信息
- bikeLocation: function (type) {
- var that = this;
- var data = {
- bike_no: that.data.code
- }
- app.request('/order/orderBikePosition', data, 'GET').then(res => {
- if (res.statusCode == 200) {
- if (type == 'getPosition') {
- this.data.markers.map((item, index) => {
- if (item.id == 12345) {
- this.setData({
- ['markers[' + index + '].longitude']: res.data.lng,
- ['markers[' + index + '].latitude']: res.data.lat
- })
- this.data.bikeMarker[0].latitude = res.data.lat
- this.data.bikeMarker[0].longitude = res.data.lng
- }
- })
- } else {
- var array = {}
- array.iconPath = '/img/dianche.png';
- array.width = 28;
- array.height = 28;
- array.zIndex = 1111;
- array.id = 12345;
- array.latitude = res.data.lat;
- array.longitude = res.data.lng;
- this.setData({
- markers:this.data.markers.concat(array)
- })
- this.data.bikeMarker = [array]
- }
- }
- }).catch(err => {
- console.log(err)
- })
- },
- //获取当前位置
- posiLoca: function () {
- var that = this;
- my.showLoading({
- content: '正在定位...',
- icon: 'none'
- })
- // locationTerval = setInterval(function () {
- my.getLocation({
- type: 'gcj02',
- success: (res) => {
- var latitude = res.latitude
- var longitude = res.longitude
- my.hideLoading()
- that.setData({
- longitude: longitude,
- latitude: latitude,
- })
- if (!that.data.centerLon) {
- //第一次进入当前页面时为为中心点坐标赋值
- that.setData({
- centerLon: res.longitude,
- centerLat: res.latitude,
- })
- }
- that.home()
- },
- fail: function (err) {
- my.hideLoading()
- if (err.error == 11) {
- my.showAuthGuide({
- authType: 'LBS',
- success: (res) => {
- },
- fail: (error) => {
- my.alert({
- content: '获取位置授权失败'
- });
- },
- })
- }
- my.getSetting({
- success: function (res) {
- // console.log(res)
- var statu = res.authSetting;
- if (statu['scope.userLocation'] == false) {
- that.setData({
- background: true,
- location: true
- })
- }
- }
- })
- }
- })
- },
- //获取蓝牙秘钥
- getSecretKey(box_no) {
- // if (!box_no) box_no = this._bikeMainId
- // let that = this;
- // if(box_no== my.getStorageSync('box_no')) return;
- return new Promise(function (res, rej) {
- let param = {
- box_no: box_no, //我公司是通过设备编号获取的密钥
- };
- app.request('/blu/get-key', param, 'GET').then(resp => {
- key = resp.data.key
- res(resp.data.key);
- my.setStorageSync({
- 'key': 'box_no',
- data: box_no
- })
- })
- });
- },
- //行车时间计时
- terval: function () {
- var that = this;
- clearInterval(interval)
- clearInterval(huancheTime)
-
- interval = setInterval(function () {
- that.countBikeMoney()
- }, 5000)
- },
- //计算骑行费用
- countBikeMoney: function () {
- var that = this
- var setting = my.getStorageSync({
- 'key': 'setting'
- }).data;
- var total_minute = this.data.minute
- console.log("this.data.start_use_bike_time",this.data.start_use_bike_time)
- let cha = (new Date()).getTime() / 1000 - this.data.start_use_bike_time
- var time = 0
- var _minute = Math.ceil(cha / 60); //分钟
- console.log('骑行总时长分钟', _minute, cha, total_minute, setting.starting_price_time)
- if (_minute == total_minute) return 0; //分钟相等
- if (_minute === 0) {
- time = _minute + 1 - setting.starting_price_time;
- } else {
- time = _minute - setting.starting_price_time;
- }
- var per_money = setting.per_money;
- var per_minute = setting.per_minute;
- // 向上取整
- let money = 0
- if (time <= 0) {
- money = parseFloat(setting.starting_price)
- } else {
- money = Math.ceil(time / per_minute) * per_money + parseFloat(setting.starting_price)
- }
- //将全部分钟分开为小时+分钟用于显示时间
- var hour = Math.floor(_minute / 60);
- var minute = Math.floor(_minute % 60);
- money = money.toFixed(2)
- hour = hour < 10 ? '0' + hour : hour
- minute = minute < 10 && hour > 0 ? '0' + minute : minute
- if (app.globalData.noShowRefOpenLock == true && that.data.noShowRefOpenLock == false && minute >= 3) {
- that.setData({
- noShowRefOpenLock: true
- })
- }
- if (hour > 0) {
- that.setData({
- minute: _minute, // 骑行总分钟
- times: hour + ":" + minute,
- estimate_money: money,
- isHour: true
- })
- } else {
- that.setData({
- minute: _minute,
- times: minute,
- estimate_money: money,
- isHour: false
- })
- }
- },
- //获取车辆信息
- getBikeMessage: function () {
- my.showLoading()
- var that = this;
- app.request('/bike/' + that.data.code, '', 'GET').then(res => {
- machineNO = res.data.box_no
- my.hideLoading()
- if (res.status == 200) {
- that.setData({
- bikeMessage: res.data,
- battery_power: res.data.battery_power,
- steps: 1
- }),
- key = res.data.key
- } else {
- setTimeout(function () {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }, 2000)
- }
- })
- },
- //检测用户是否完成实名认证,是否有待支付订单违章记录等
- jiance: function () {
- let that = this
- var userStatus = my.getStorageSync({
- 'key': 'userState'
- }).data;
- var setting = my.getStorageSync({
- 'key': 'setting'
- }).data;
- console.log(userStatus, '旭颖')
- console.log(setting, '旭颖')
- if (userStatus.is_bind_mobile == 0) {
- my.navigateTo({
- url: '/pages/authorization/authorization',
- })
- //未实名认证
- } else
- if (userStatus.is_card_certified == 0 && setting.is_card == 1) {
- my.navigateTo({
- url: '/pages/real_name/real_name',
- })
- } //是否缴纳押金
- else if (userStatus.is_deposit == 0 && setting.is_deposit != 0 && userStatus.is_coupon_deposit_free == false) {
- my.navigateTo({
- url: '/pages/ride_zige/ride_zige',
- })
- } else if (userStatus.is_ride_order != false) {
- my.alert({
- title: '提示',
- content: '您有一个正在骑行中的订单',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- } else if (userStatus.is_pay_order != false && userStatus.is_pay_order != undefined) {
- my.alert({
- title: '提示',
- content: '您有一个待支付订单,请先支付',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- } else {
- that.setData({
- steps: 2
- })
- // this.reloadMap()
- }
- },
- reloadMap(classname = 'use-bike-bottom') {
- let query = my.createSelectorQuery();
- let th = this;
- query.select('.' + classname).boundingClientRect(function (rect) {
- if (rect != null && rect instanceof Object && rect.hasOwnProperty('height')) {
- let height = rect.height || 300;
- th.setData({
- mapHeight: 'calc(100vh - ' + (height) + 'px)'
- });
- } else {
- let height = 300;
- th.setData({
- mapHeight: 'calc(100vh - ' + height + 'px)'
- });
- }
- }).exec();
- },
- //倒计时
- //临时停车倒计时
- stopDownTime() {
- // let that = this
- // let endTime = Date.parse(new Date()); //date日期类型
- // let startTime
- // if (!that.data.temporaryTime || that.data.temporaryTime == null) {
- // startTime = endTime
- // } else {
- // let data1 = that.data.temporaryTime
- // let data2 = data1.replace(/-/g, '/')
- // let data3 = new Date(data2)
- // startTime = data3.getTime()
- // }
- // let totleTime = 1800
- // clearInterval(linshiStop)
- // console.log(endTime, 'endTime')
- // console.log(startTime, 'startTime')
- // let date3 = endTime - startTime;
- // console.log(date3, 'date3')
- // //计算出相差天数
- // var days = Math.floor(date3 / (24 * 3600 * 1000));
- // //计算出小时数
- // var leave1 = date3 % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
- // var hours = Math.floor(leave1 / (3600 * 1000));
- // //计算相差分钟数
- // var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
- // var minutes = Math.floor(leave2 / (60 * 1000));
- // //计算相差秒数
- // var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
- // var seconds = Math.round(leave3 / 1000);
- // console.log(minutes, 'minutes')
- // let chaTime = totleTime - minutes * 60
- // console.log(chaTime, 'chaTime')
- // linshiStop = setInterval(function () {
- // let test = 30 * 60 * 1000
- // console.log(test, 'test')
- // if (date3 > test) {
- // that.setData({
- // stopMiao: 0,
- // stopmMinute: 0
- // })
- // clearInterval(linshiStop)
- // } else if (chaTime <= 0) {
- // that.setData({
- // stopMiao: 0,
- // stopmMinute: 0
- // })
- // clearInterval(linshiStop)
- // } else {
- // console.log(minutes, 'pppp')
- // chaTime--
- // let fen = parseInt(chaTime / 60);
- // let miao = parseInt(chaTime % 60);
- // that.setData({
- // stopMiao: miao,
- // stopmMinute: fen
- // })
- // }
- // }, 1000)
- },
- //开锁方法
- openBike() {
- var that = this;
- var setting = my.getStorageSync({
- 'key': 'setting'
- }).data;
- my.showLoading({
- content: '开锁中...',
- mask: true
- })
- var data = {
- bike_no: that.data.code,
- lat: that.data.latitude,
- lng: that.data.longitude,
- area_id: my.getStorageSync({
- 'key': 'home'
- }).data.id,
- }
- app.request('/bike/open-lock', data, 'POST').then(res => {
- console.log(res)
- if (res.status == 200) {
- that.setData({
- steps: 3,
- order: res.data.no,
- ifKnowUseTK: false,
- estimate_money: parseFloat(setting.starting_price),
- start_use_bike_time: res.data.start_use_bike_timestamp
- })
- that.terval()
- //蓝牙开锁
- operateType = 'open'
- bluetoothOperate.start(operateType, machineNO, key, (flag) => {
- bluetoothOperate.end((flag) => {});
- });
- my.hideLoading()
- } else {
- // that.setData({
- // steps: 3
- // })
- // that.terval()
- }
- })
- },
- //开锁失败重试开锁
- retryOpenBike: function () {
- var that = this;
- console.log('重试开锁')
- //蓝牙重试开锁
- my.showLoading({
- content: '开锁中...',
- mask: true
- })
- let data = {
- order_no: that.data.order,
- bike_no: that.data.code
- }
- app.request('/order/retry-open-lock', data, 'GET').then(res => {
- console.log(res)
- if (res.status == 200) {
- my.hideLoading()
- if (res.data.status == 1) {
- that.setData({
- frame: false
- })
- my.hideLoading()
- operateType = 'open'
- bluetoothOperate.start(operateType, machineNO, key, (flag) => {
- bluetoothOperate.end((flag) => {});
- });
- my.showToast({
- content: '开锁成功',
- icon: 'none'
- })
- }
- }
- })
- },
- openBikeClick: function () {
- let that = this
- if (this.data.bikeMessage.is_link == 0) {
- my.alert({
- title: '提示',
- content: '当前车子已下线请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.put_status == 0) {
- my.alert({
- title: '提示',
- content: '当前车子还未投放请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.is_low_battery_power == 0) {
- my.alert({
- title: '提示',
- content: '当前车子电量过低请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.is_trouble == 1) {
- my.alert({
- title: '提示',
- content: '当前车子出现故障请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (this.data.bikeMessage.is_riding == 1) {
- my.alert({
- title: '提示',
- content: '当前车子正在骑行请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- }
- that.jiance()
- },
- go_setting: util.throttle(function () {
- //点击去设置位置权限
- this.setData({
- background: false,
- location: false
- })
- my.openSetting({
- success: function (res) {}
- })
- }, 1500),
- //点击已开启位置权限
- open: util.throttle(function () {
- this.setData({
- background: false,
- location: false
- })
- }, 1500),
- //寻铃
- clickBell: util.throttle(function (e) {
- //点击响铃
- var that = this;
- my.showLoading({
- content: '找车中...',
- mask: true
- })
- app.request('/order/retry-bell-lock?order_no=' + that.data.order + '&bike_no=' + that.data.code, '', 'GET').then(res => {
- console.log(res)
- if (res.status == 200) {
- //蓝牙寻铃找车
- operateType = 'bell'
- bluetoothOperate.start(operateType, machineNO, key, (flag) => {
- //flag == true 操作成功
- //flag == false 操作失败
- //end
- bluetoothOperate.end((flag) => {});
- });
- res.data.is_ok == true && my.showToast({
- content: '找车成功',
- icon: 'none',
- duration: 2000
- })
- res.data.is_ok == false && my.showToast({
- content: '找车失败请重试',
- icon: 'none',
- duration: 2000
- })
- }
- })
- }, 1000),
- //立即开锁
- konwOpenBike: util.throttle(function () {
- var that = this;
- // that.jiance()
- if (that.data.deposit == true) return;
- that.openBike()
- }, 1000),
- //临时锁车
- parkBike: function () {
- let that = this
- my.showLoading({
- content: '正在临时锁车',
- })
- var data = {
- bike_no: that.data.code,
- order_no: that.data.order,
- lat: that.data.latitude,
- lng: that.data.longitude
- }
- //代表要临时停车
- app.request('/bike/temporary-close-lock', data, 'POST').then(res => {
- console.log(res)
- if (res.status == 200) {
- my.hideLoading()
- //蓝牙临时锁车
- operateType = 'temporaryClose'
- bluetoothOperate.start(operateType, machineNO, key, (flag) => {
- //flag == true 操作成功
- //flag == false 操作失败
- //end
- bluetoothOperate.end((flag) => {});
- });
- my.showToast({
- content: '停车成功',
- icon: 'none'
- })
- that.setData({
- parkStatus: 1,
- // nowBikeStatus:1
- })
- my.setStorageSync({
- 'key': 'nowBikeStatus',
- data: 1
- })
- that.stopDownTime()
- // that.getBikeMessage()
- } else if (res.status == 450) {
- my.showToast({
- content: '运动中不能关锁,请稍后重试',
- icon: 'none',
- duration: 5000,
- mask: true
- })
- my.hideLoading()
- }
- })
- },
- //结束临时锁车
- openPark: function () {
- let that = this
- my.showLoading({
- content: '解锁中',
- })
- var data = {
- bike_no: that.data.code,
- order_no: that.data.order,
- lat: that.data.latitude,
- lng: that.data.longitude
- }
- // clearInterval(inter1)
- app.request('/bike/temporary-open-lock', data, 'POST').then(res => {
- // that.inter1()
- if (res.status == 200) {
- my.hideLoading()
- // 蓝牙临时开车
- operateType = 'temporaryOpen'
- bluetoothOperate.start(operateType, machineNO, key, (flag) => {
- //flag == true 操作成功
- //flag == false 操作失败
- //end
- bluetoothOperate.end((flag) => {});
- });
- my.showToast({
- content: '开车成功',
- icon: 'none'
- })
- clearInterval(linshiStop)
- my.setStorageSync({
- 'key': 'stopMiao',
- data: 0
- })
- my.setStorageSync({
- 'key': 'stopmMinute',
- data: 30
- })
- that.setData({
- stopMiao: 0,
- stopmMinute: 30,
- parkStatus: 0,
- nowBikeStatus: 0
- })
- my.setStorageSync({
- 'key': 'nowBikeStatus',
- data: 0
- })
- }
- })
- },
- endUseBike: function () {
- let that = this
- this.data.TKfuwei = true
- my.showLoading({
- content: '加载中...'
- })
- var data = {
- bike_no: that.data.code,
- order_no: that.data.order,
- lat: that.data.latitude,
- lng: that.data.longitude
- }
- app.request('/order/expect-order-money', data, 'POST').then(res => {
- console.log(res)
- if (res.status == 200) {
- my.hideLoading()
- let data = res.data.dispatch_money
- res.data.time_money = parseFloat(res.data.time_money)
- let data1 = parseFloat(data)
- if (res.data.is_app_check_helmet_status == true && res.data.helmet_status == 1) {
- this.setData({
- TKtipsProp: true,
- dispatch_money: data1,
- money: res.data,
- })
- } else {
- that.setData({
- dispatch_money: data1,
- money: res.data,
- chaButton: 1,
- parkStatus: 2
- })
- }
- }else{
- my.hideLoading()
- }
- }).catch(res => {
- my.hideLoading()
- })
- },
- //继续还车
- continueHuanche: function () {
- this.data.TKfuwei = false
- this.setData({
- chaButton: 1,
- parkStatus: 2,
- TKtipsProp: false,
- })
- },
- //我知道了
- tkKnow: function () {
- this.setData({
- TKtipsProp: false,
- })
- },
- //确定结束用车
- sureEndUseBike: util.throttle(function () {
- if (this.data.dispatch_money != 0) {
- this.setData({
- popShow: true
- })
- } else {
- this.huanche()
- }
- }, 1000),
- huanche() {
- //还车接口
- my.showLoading({
- content: '结算中...',
- mask: true
- })
- var that = this;
- var data = {
- bike_no: that.data.code,
- order_no: that.data.order,
- lat: that.data.latitude,
- lng: that.data.longitude
- }
- if (this.data.TKfuwei == false) data.forceCloseBike = true
- app.request('/bike/close-lock', data, 'POST').then(res => {
- console.log(res)
- my.hideLoading()
- if (res.status == 200) {
- console.log(res, '结束用车')
- clearInterval(linshiStop);
- clearInterval(interval);
- my.setStorageSync({
- 'key': 'stopMiao',
- data: 0
- })
- my.setStorageSync({
- 'key': 'stopmMinute',
- data: 30
- })
- my.hideNavigationBarLoading(), my.hideLoading()
- my.reLaunch({
- url: '../pay/pay?order=' + res.data.no
- })
- //蓝牙锁车操作 确定结束用车
- if (machineNO && key) {
- operateType = 'close'
- bluetoothOperate.start(operateType, machineNO, key, (flag) => {
- //flag == true 操作成功
- //flag == false 操作失败
- //end
- //订单结束关闭蓝牙
- bluetoothOperate.end((flag) => {});
- });
- }
- } else if (res.status == 450) {
- my.showToast({
- content: '运动中不能关锁,请稍后重试',
- icon: 'none',
- duration: 5000,
- mask: true
- })
- }
- }).catch(err => {
- my.showToast({
- content: '关锁失败,请重试。',
- icon: 'none',
- duration: 5000,
- })
- my.hideLoading()
- })
- },
- //开关头盔锁
- controlToukui: util.throttle(function () {
- var that = this;
- my.showLoading({
- title: '开锁中...',
- mask: true
- })
- let data = {
- order_no: that.data.order,
- bike_no: that.data.code
- }
- // if (app.globalData.req) {
- app.request('/order/retry-open-helmet-lock', data, 'GET', app.globalData.req).then(res => {
- if (res.status == 200) {
- my.hideLoading()
- if (res.data.status == 1) {
- //that.reloadMap()
- my.hideLoading()
- my.showToast({
- content: '头盔锁已开启',
- type: 'none'
- })
- }
- } else {
- // log.warn('重试开锁失败(order/retry-open-lock)' + '用户id' + '--' + wx.getStorageSync('user_ID'))
- my.hideLoading()
- }
- })
- }, 1000),
- //取消锁车
- cancelEndBike: function () {
- let that = this
- that.setData({
- chaButton: 0,
- dispatch_money: 0,
- parkStatus: my.getStorageSync({
- 'key': 'nowBikeStatus'
- }).data
- })
- // that.reloadMap()
- },
- //计价规则
- chargeRule: function () {
- my.navigateTo({
- url: '/pages/charge_rule/charge_rule',
- })
- },
- //骑行须知
- bikeKnow: function () {
- my.navigateTo({
- url: '/pages/ride_rule/ride_rule',
- })
- },
- popHide() {
- //取消继续还车
- this.setData({
- popShow: false
- })
- },
- //骑行优惠券
- bikeCoupon: function () {
- my.navigateTo({
- url: '/pages/buy-card/buy-card',
- })
- },
- //客服
- keFu: function () {
- let phone = my.getStorageSync({
- 'key': 'home'
- })
- my.makePhoneCall({
- number: phone.data.customer_service_phone || '13203706613'
- })
- },
- //车辆为未开锁弹框
- //打开
- frameClose: function () {
- let that = this
- that.setData({
- frame: false
- })
- // that.reloadMap()
- },
- //关闭弹框
- frameShow: function () {
- let that = this
- that.setData({
- frame: true
- })
- that.reloadMap('frame')
- },
- //故障上报
- guzhang: function () {
- this.setData({
- frame: false,
- })
- // this.reloadMap()
- my.navigateTo({
- url: '/pages/breakdown/breakdown',
- })
- },
- //附近还车点
- findPark: function () {
- my.navigateTo({
- url: '/pages/parking/parking',
- })
- },
- onHide: function () {
- console.log('onHide5555')
- // clearInterval(testToken
- clearInterval(mytime)
- clearInterval(interval)
- bluetoothOperate.end((flag) => {});
- },
- onUnload: function () {
- clearInterval(locationTerval)
- bluetoothOperate.end((flag) => {});
- // 停止位置跟踪
- // my.stopLocationUpdate({
- // success: (res) => {
- // console.log("onUnload stopLocationUpdate success", res)
- // },
- // fail: (err) => {
- // console.log("onUnload stopLocationUpdate fail", err)
- // }
- // })
- },
- //返回首页
- backHome() {
- my.reLaunch({
- url: '/pages/index/index',
- })
- },
- //关闭中间广告弹框
- closeAdframe: function () {
- this.setData({
- adFrame: false
- })
- },
- //佩戴头盔提示
- knowToukui() {
- this.setData({
- ifKnowUseTK: true
- })
- },
- //将地图将当前位置展示在屏幕中央,防止用户滑动查看停车区时频繁定位中心点
- // getPosition: function () {
- // this.setData({
- // centerLon: this.data.longitude,
- // centerLat: this.data.latitude,
- // })
- // this.mapCtx.moveToLocation();
- // this.bikeLocation('getPosition');
- // },
- getPosition:util.throttle(function () {
- //点击定位
- //这是一段注
- var that = this;
- my.showLoading({
- content: '定位中'
- })
- my.getLocation({
- type: 'gcj02',
- success: (res) => {
- console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
- my.hideLoading()
- that.setData({
- centerLon: res.longitude,
- centerLat: res.latitude
- })
- this.bikeLocation('getPosition');
- },
- fail: function (err) {
- console.log(err, '用户授权失败')
- if (err.error == 11) {
- my.showAuthGuide({
- authType: 'LBS',
- success: (res) => {
- },
- fail: (error) => {
- my.alert({
- content: '获取位置授权失败'
- });
- },
- });
- }
- my.hideLoading()
- my.showToast({
- content: '定位失败',
- icon: 'none'
- })
- }
- })
- }, 1000),
- })
|