123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892 |
- // index.js
- // 获取应用实例
- //获取应用实例
- const app = getApp();
- var token = my.getStorageSync({ 'key': 'token' }).data;
- const util = require('../../utils/utils.js');
- const { content } = require('/utils/dataTransition.js');
- var mytime = null;
- let testToken = ''
- Page({
- data: {
- cardBottom: [
- {
- id: 1,
- name: '故障上报',
- icon: 'icon-banshou',
- url: '/pages/breakdown/breakdown'
- },
- {
- id: 2,
- name: '输码用车',
- icon: 'icon-17-saoma',
- url: '/pages/inputcode/inputcode'
- },
- {
- id: 3,
- name: '计费规则',
- icon: 'icon-wenhao',
- url: '/pages/charge_rule/charge_rule'
- },
- {
- id: 4,
- name: '个人中心',
- icon: 'icon-wode',
- url: '/pages/mine/mine'
- }
- ],
- adFrame: false,//首页中间广告弹框
- markers: [], //显示单车、停车的P
- polygons: [], //区域
- longitude: '', //113.786111
- latitude: '', //34.78304
- height1: '', //兼容自定义导航栏的高度
- id: '', //停车区域的ID
- stopP: false, //判断是否显示停车区域
- polygons1: [], //可骑行区域 先用这个变量代表
- controls: [], //地图上当前定位的箭头
- background: false, //弹窗的背景颜色
- realname: false, //当前是否已经实名
- deposit: false, //当前是否交押金
- userStatus: '', //用户的一些状态 是否交押金等 0
- scanfail: false, //扫码失败弹窗
- is_pay_order: false, //检测当前是否有订单未支付
- is_ride_order: false,//是否有骑行中订单
- is_punishment: false,//有违章订单
- code: '', //点击立即用车 把编号赋值给code
- over: false, //关闭图标
- over1: false, //扫码失败关闭图标
- location: '', //是否有位置权限
- screenHeight: '', //屏幕可视高度
- box_no: '', //中控编号
- abnormal: '', //提示账号异常
- mid: [],//顶部广告
- ads: [],//首页中间广告
- currentSwiper: 0,
- center_currentSwiper: 0,
- bike_no: undefined,
- stopShow: false,
- stop_info: [],
- notice: [], //公告内容
- animationData: {},
- tabbar_index: 0,
- zoom: 18,
- versions: false, //版本过低弹窗
- chooseSize: false,
- animationData1: {},
- arrowDown: '',
- stop_type: '',
- marqueePace: 0.6, //滚动速度
- marqueeDistance: 520, //初始滚动距离 用到
- size: 26, //用到
- marqueeWidth: 520, //用到
- length: '',
- swiperCurrent: 0,
- midbolear: '',
- per_money: '',
- img: app.globalData.imgUrl,
- new_user_coupons: [],
- scanCodeErr: false,//扫码失败弹框
- },
- onLoad: function (query) {
- var that = this;
- console.log(my.getStorageSync({ 'key': 'token' }).data, 'yyyyyyyyyyyyyyy')
- my.setNavigationBar({
- title: app.globalData.title
- })
- this.setData({
- height1: app.globalData.statusBarHeight,
- screenHeight: app.globalData.screenHeight
- })
- },
- onShow: function () {
- var that = this;
- my.setNavigationBar({
- title: app.globalData.title
- })
- token = my.getStorageSync({ 'key': 'token' }).data
- this.setData({
- show: false,
- midbolear: my.getStorageSync({ 'key': 'midTimes' }).data,
- polygons: []
- })
- app.login().then(res => {
- console.log('YYYYYYYYYYYYY')
- that.location()
- that.getUser()
- })
- // that.location();
- // testToken = setInterval(function () {
- // let token=my.getStorageSync({'key':'token'}).data
- // if (token) {
- // console.log('0000')
- // clearInterval(testToken)
- // } else {
- // console.log(token,'1')
- // }
- // }, 1000)
- my.hideBackHome();
- },
- detail: function () {
- var that = this;
- if (that.data.mid[0].type == 'url') {
- my.navigateTo({
- url: '/' + that.data.mid[0].detail
- })
- }
- },
- //广告列表
- adsList: function (id) {
- var that = this;
- var area_id = ''
- if (id != undefined) {
- area_id = id
- } else {
- area_id = 0
- }
- app.request("/ads?area_id=" + area_id + "&position[]=mid&position[]=header&position[]=footer", '', "GET").then(res => {
- console.log(res)
- if (res.status == 200 && res.data != '') {
- if (res.data.header) {
- console.log(res.data, 'ppppppppppppppppppppppppp')
- 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) {
- // console.log(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') {
- 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
- });
- }
- },
- //定位当前位置
- posi: 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({
- longitude: res.longitude,
- latitude: res.latitude
- })
- },
- fail: function (err) {
- my.hideLoading()
- console.log(err, '定位失败打印')
- my.showToast({
- content: '定位失败',
- icon: 'none'
- })
- }
- })
- }, 1000),
- //点击扫描二维码
- sweepCode: util.throttle(function () {
- let that = this
- console.log('点击扫码,‘iooooo')
- if (!that.data.latitude && !that.data.longitude) {
- that.setData({
- background: true,
- location: true
- })
- } else {
- that.sweep_code()
- }
- }, 1500),
- //骑行区禁停区车辆
- home: function () {
- //请求首页接口和一些设置。
- console.log('测试')
- var that = this;
- if (that.data.longitude != '' && that.data.latitude != '') {
- //116.411027
- var data = {
- 'lat': that.data.latitude,
- 'lng': that.data.longitude
- }
- app.request("/pages/home?include=setting", data, "POST").then(res => {
- console.log(res)
- if (res.status == 200) {
- var data = res.data;
- console.log(data, '区域')
- let id = data.id
- that.userState()
- if (data.points != []) {
- that.setData({
- id: data.id,
- polygons1: that.data.polygons.concat(data),
- setting: data.setting,
- per_money: Number(data.setting.starting_price),
- polygons: []
- })
- if (!data.id) return
- that.adsList(data.id),
- that.ban_stop(data.id), that.setData({
- polygons: that.data.polygons.concat(data)
- })
- }
- clearInterval(mytime)
- my.setStorageSync({ 'key': 'home', data: data })
- }
- if (data) {
- my.setStorageSync({ 'key': 'setting', data: data.setting })
- } else {
- my.removeStorageSync({ key: 'setting' })
- my.removeStorageSync({ key: 'home' })
- }
- }).catch(err => {
- console.log(err)
- if (err.data.message == "该附近暂无运营区域") {
- my.removeStorageSync({ key: 'setting' })
- my.removeStorageSync({ key: 'home' })
- }
- my.alert({
- title: '提示',
- content: err.data.message,
- })
- })
- }
- },
- //停车区域
- ban_stop: function (id) {
- var that = this;
- var data1 = {
- 'area_id': 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({
- polygons2: data.polygons,
- markers: that.data.markers.concat(data.centres),
- polygons: that.data.polygons1.concat(data.polygons)
- })
- }
- })
- },
- //附近车辆坐标
- nearbyCars: function () {
- //附近的车
- var that = this;
- that.setData({
- markers: []
- })
- var data = {
- "lat": that.data.latitude,
- "lng": that.data.longitude
- }
- app.request("/bikes", data, "POST").then(res => {
- // console.log(res)
- if (res.status == 200) {
- var makers = res.data
- if (makers == '') {
- my.showToast({
- content: '附近暂无车辆',
- icon: 'none'
- })
- that.setData({
- markers: []
- })
- } else {
- that.setData({
- markers: makers
- })
- }
- }
- }).catch(err => {
- console.log(err)
- })
- },
- //点击刷新
- refresh: util.throttle(function () {
- var that = this;
- that.setData({
- polygons: []
- })
- if (this.data.stopP == true) {
- that.stopP(), my.showToast({
- content: '刷新成功',
- icon: 'none'
- })
- } else {
- this.location(),
- my.showToast({
- content: '刷新成功',
- icon: 'none'
- })
- }
- }, 1500),
- // //点击去实名认证
- authentication: util.throttle(function () {
- var state = my.getStorageSync({ 'key': 'userState' }).data
- if (state.is_bind_mobile == 1) {
- my.navigateTo({
- url: '/pages/real_name/real_name?state1=1&index=0',
- })
- } else if (state.is_bind_mobile == 1) {
- my.navigateTo({
- url: '/pages/real_name/real_name?state2=2&index=1',
- })
- }
- this.setData({
- background: false,
- realname: false,
- over: false
- })
- }, 1500),
- //点击扫码开锁
- sweep_code: util.throttle(function () {
- var that = this;
- console.log('ooooooo')
- var userStatus = that.data.userStatus;
- var setting = my.getStorageSync({ 'key': 'setting' }).data
- if (!setting) {
- my.alert({
- title: '提示',
- content: '您附近暂无运营区,暂不可用车'
- })
- } else {
- if (!userStatus) {
- my.navigateTo({
- url: '/pages/authorization/authorization',
- })
- }
- else {
- that.jiance('scan');
- }
- }
- }, 1500),
- //扫码用车检测不可用车条件
- jiance: function (source) {
- var that = this;
- var userStatus = that.data.userStatus;
- var setting = my.getStorageSync({ 'key': 'setting' }).data
- //未绑定手机号
- 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_punishment) {
- my.showToast({
- content: '您当前有违章订单需要处理,请处理后再来用车吧',
- icon: 'none'
- })
- return;
- } else if (userStatus.is_ride_order != false && userStatus.is_ride_order != undefined) {
- my.showToast({
- content: '您有一个正在骑行中的订单',
- icon: 'none'
- })
- return;
- } else {
- //有待支付骑行订单
- if (userStatus.is_pay_order != false && userStatus.is_pay_order != undefined) {
- my.showToast({
- content: '你有未支付订单,请先支付',
- icon: 'none'
- })
- return;
- } else {
- //没有押金没有免押券
- if (userStatus.is_deposit == 0 && that.data.setting.is_deposit != 0 && userStatus.is_coupon_deposit_free == false) {
- console.log('没有押金没有免押券')
- my.navigateTo({
- url: '/pages/ride_zige/ride_zige',
- })
- // my.navigateTo({
- // url: '/pages/inputcode/inputcode',
- // })
- } else {
- that.saoMa()
- }
- }
- }
- }
- },
- //扫码事件
- saoMa: function () {
- let that = this
- this.setData({
- scanCodeErr: false
- })
- my.scan({
- onlyFromCamera: true,
- success: function (res) {
- let scanLength = app.globalData.scanLength
- console.log(res, '扫码结果')
- var index = res.code.lastIndexOf("\=");
- console.log(index, '----------')
- var code = res.code.substring(index + 1, res.code.length);
- console.log(code)
- console.log(app.globalData)
- if (code.length == scanLength) {
- that.getBikeMessage(code)
- // my.navigateTo({
- // url: '/pages/use_bike/use_bike?code=' + code,
- // })
- } else {
- console.log(res, '错误码')
- // my.showModal({
- // title:'提示',
- // content:'非法码,请核对车码',
- // showCancel:false
- // })
- that.setData({
- scanCodeErr: true
- })
- }
- },
- fail: function (err) {
- console.log('tuihui')
- // that.setData({
- // scanCodeErr: true
- // })
- }
- })
- },
- //获取车辆信息
- getBikeMessage: function (code) {
- var that = this;
- app.request('/bike/' + code, '', 'GET').then(res => {
- console.log(res, '车辆信息--------------------')
- my.hideLoading()
- if (res.status == 200) {
- if (res.data.is_link == 0) {
- my.alert({
- title: '提示',
- content: '当前车子已下线请换辆车子骑行吧~',
- success: function (res) {
- my.reLaunch({
- url: '/pages/index/index',
- })
- }
- })
- return;
- } else if (res.data.put_status == 0) {
- my.alert({
- title: '提示',
- content: '当前车子还未投放请换辆车子骑行吧~',
- })
- return;
- } else if (res.data.is_low_battery_power == 0) {
- my.alert({
- title: '提示',
- content: '当前车子电量过低请换辆车子骑行吧~',
- })
- return;
- } else if (res.data.is_trouble == 1) {
- my.alert({
- title: '提示',
- content: '当前车子出现故障请换辆车子骑行吧~',
- })
- return;
- } else if (res.data.is_riding == 1) {
- my.alert({
- title: '提示',
- content: '当前车子正在骑行请换辆车子骑行吧~',
- })
- return;
- } else {
- my.reLaunch({
- url: '/pages/use_bike/use_bike?code=' + code,
- })
- }
- } else {
- my.alert({
- title: '提示',
- content: res.data.message,
- })
- }
- })
- },
- //去支付未支付订单
- go_pay: util.throttle(function () {
- //点击去支付
- this.setData({
- is_pay_order: false,
- })
- var pay_order = ''
- if (this.data.userStatus.is_pay_order !== false && this.data.userStatus.is_pay_order !== undefined) {
- pay_order = this.data.userStatus.is_pay_order
- }
- my.navigateTo({
- url: '/pages/pay/pay?order=' + pay_order,
- })
- }, 1500),
- //点击查看正在进行中的订单
- goUseBike: function () {
- console.log(this.data.is_ride_order, 'this.data.is_ride_order')
- my.navigateTo({
- url: '/pages/use_bike/use_bike?order=' + this.data.is_ride_order,
- })
- },
- //有违章订单
- havePunishment: function () {
- my.navigateTo({
- url: '/pages/weizhang/weizhang',
- })
- },
- onReady: function () {
- },
- kefu: util.throttle(function () {
- my.makePhoneCall({
- number: my.getStorageSync({ 'key': 'home' }).data.customer_service_phone,
- })
- }, 1500),
- //用户状态
- userState: function (id) {
- var that = this;
- var data = {
- 'area_id': id
- }
- app.request("/user/status", data, "GET").then(res => {
- console.log(res)
- if (res.status == 200) {
- console.log(res, 'XYYING================')
- that.setData({
- userStatus: res.data,
- is_pay_order: res.data.is_pay_order,
- is_ride_order: res.data.is_ride_order,
- is_punishment: res.data.is_punishment,
- }), my.setStorageSync({ 'key': 'userState', data: res.data })
- }
- }).catch(err => {
- console.log(err)
- })
- },
- getUser() {
- app.request("/me", '', "GET").then(res => {
- console.log(res)
- 200 == res.status && my.setStorageSync({ 'key': 'userInfo', data: res.data })
- }).catch(err => {
- console.log(err)
- })
- },
- 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),
- location: function () {
- //获取当前经纬度 如果未授权让用户去授权
- console.log('dingwei')
- var that = this;
- my.showLoading({
- content: '定位中...',
- mask: true
- })
- my.getLocation({
- type: 'gcj02',
- success: (res) => {
- console.log('经纬度为:+++++++++++++++++++++' + res.latitude + '++++++++' + res.longitude)
- that.setData({
- longitude: res.longitude,
- latitude: res.latitude,
- show: false
- })
- console.log(res, 'ppp')
- that.home(), that.nearbyCars()
- if (that.data.stopP == false) {
- console.log('false')
- } else {
- that.stop()
- }
- my.hideLoading()
- },
- fail: function () {
- my.hideLoading()
- my.getSetting({
- success: function (res) {
- // console.log(res)
- var statu = res.authSetting;
- if (statu['scope.userLocation'] == false) {
- that.setData({
- background: true,
- location: true
- })
- }
- }
- })
- }
- })
- },
- //底部跳转页面按钮(用户未授权和未实名认证的时候不可以跳转)
- skipPage: function (e) {
- let data = e.target.dataset.id
- let that = this
- console.log(that.data, 'oooooo')
- var userStatus = that.data.userStatus;
- var setting = my.getStorageSync({ 'key': 'setting' }).data
- console.log(!setting, '运营区检测')
- if (!that.data.latitude && !that.data.longitude) {
- that.setData({
- background: true,
- location: true
- })
- } else {
- if (data.id == 2) {
- console.log(that.data.userStatus, '')
- if (!setting) {
- my.alert({
- title: '提示',
- content: '您附近暂无运营区,暂不可用车'
- })
- }
- else {
- if (!userStatus) {
- my.navigateTo({
- url: '/pages/authorization/authorization',
- })
- }
- else {
- that.jiance1();
- }
- }
- } else if (data.id == 3 && !setting) {
- wx.showModal({
- title: '提示',
- content: '您附近暂无运营区,暂不可用车',
- showCancel: false
- })
- } else if (data.id == 4) {
- if (userStatus.is_bind_mobile == 0) {
- my.navigateTo({
- url: '/pages/authorization/authorization',
- })
- } else {
- my.navigateTo({
- url: data.url,
- })
- }
- }
- else {
- if (!userStatus) {
- my.navigateTo({
- url: '/pages/authorization/authorization',
- })
- } else {
- my.navigateTo({
- url: data.url,
- })
- }
- }
- }
- },
- //输码开锁检测
- jiance1: function (source) {
- var that = this;
- let setting = my.getStorageSync({ 'key': 'setting' }).data
- var userStatus = that.data.userStatus;
- //未绑定手机号
- 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 (that.data.userStatus.is_punishment) {
- my.showToast({
- content: '您当前有违章订单需要处理,请处理后再来用车吧',
- icon: 'none'
- })
- return;
- } else if (userStatus.is_ride_order != false && userStatus.is_ride_order != undefined) {
- my.showToast({
- content: '您有一个正在骑行中的订单',
- icon: 'none'
- })
- return;
- }
- else {
- //有待支付骑行订单
- if (userStatus.is_pay_order != false && userStatus.is_pay_order != undefined) {
- my.showToast({
- content: '你有未支付订单,请先支付',
- icon: 'none'
- })
- return;
- } else {
- //没有押金没有免押券
- if (userStatus.is_deposit == 0 && that.data.setting.is_deposit != 0 && userStatus.is_coupon_deposit_free == false) {
- console.log('没有押金没有免押券')
- my.navigateTo({
- url: '/pages/ride_zige/ride_zige',
- })
- } else {
- my.navigateTo({
- url: '/pages/inputcode/inputcode',
- })
- }
- }
- }
- }
- },
- // 客服
- kefu: function () {
- my.makePhoneCall({
- number: my.getStorageSync({ 'key': 'home' }).data.customer_service_phone,
- })
- },
- //附近还车点
- findPark: function () {
- my.navigateTo({
- url: '/pages/parking/parking',
- })
- },
- //关闭中间广告弹框
- closeAdframe: function () {
- this.setData({
- adFrame: false
- })
- },
- onHide: function () {
- console.log('onHide')
- this.setData({
- bike_no: undefined,
- background: false,
- bluetooth: false,
- location: false,
- scanfail: false,
- over1: false
- })
- // clearInterval(mytime)
- },
- // 去输码弹框
- cancelErrFrame: function () {
- this.setData({
- scanCodeErr: false
- })
- },
- goInputCode: function () {
- my.navigateTo({
- url: '/pages/inputcode/inputcode',
- })
- }
- })
|