// index.js
// 获取应用实例
//获取应用实例
// const log = require('../../utils/log')
const { getCache, setCache, CacheKeys } = require('../../utils/cache')
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: 560, //通知公告用到
    length: '',//通知公告
    swiperCurrent: 0,
    midbolear: '',
    per_money: '',
    img: app.globalData.imgUrl,
    new_user_coupons: [],
    scanCodeErr: false,//扫码失败弹框
    isScan: 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
    })
    // this.reloadMap()
  },
  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: []
    })
    if (!this.data.isScan) {
      app.login().then(res => {
        console.log('YYYYYYYYYYYYY')
        that.location()
        that.getUser()
        that.userState()
      })
    }
    that.setData({
      isScan: false
    })
  },
  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
    }
    console.log(id, 'idididid')
    let isCache = getCache('ads:' + id)

    if (isCache) {
      if (isCache == '') return
      if (isCache instanceof Object && isCache.hasOwnProperty('header')) {
  

        that.setData({
          ads: isCache.header
        })
      }
      if (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 => {
      console.log(res)
      if (res.status == 200 && res.data != '') {
        setCache('ads:' + id, 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)
    })
  },
  reloadMap(classname = 'bottom-bt') {
    // 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;
    //     th.setData({ mapHeight: 'calc(100vh - ' + height + 'px)' });
    //   }
    // }).exec();
  },
  //点击广告页
  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') {
        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
      });
    }
  },
  //通知公告
  getNotice(id) {
    let data = {
      'area_id': id
    }

    let isCache = getCache('Notice:' + id)
    if (isCache) {
      if (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 => {
      console.log(res)
      if (200 == res.status && res.data.id) {
        setCache('Notice:' + id, res.data)
        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;
    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)
  },
  //定位当前位置
  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) {
        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'
        })
      }
      // 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;
          data.width = 1
          data.strokeWidth =1
          console.log(data, '区域')
          let id = data.id
          this.getNotice(id)
          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)
              })
          }
          if (res.status == 423) {
            my.getLocation({
              success: function (res) {
                my.alert({
                  title: '提示',
                  content: '您附近暂无运营区域~',
                })
                var setting = {
                  is_deposit: 1
                }
                that.setData({
                  setting
                })
              },
              fail: function (err) {
                that.setData({
                  location: true
                })
              }
            })
          }
          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, 'lkkkkk')
        // 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
    }
    let isCache = getCache('BAN_STOP:' + id)
    if (isCache) {
      that.setData({
        markers: that.data.markers.concat(isCache.centres),
        polygons: that.data.polygons1.concat(isCache.polygons),
      })
      return
    }
    app.request('/parking/stop-sites', data1, 'GET').then(res => {
      console.log(res)
      if (res.status == 200) {
        var data = res.data
        setCache('BAN_STOP:' + id, 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 && 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;
    app.request("/user/status", "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 (err) {
        console.log(err, '用户授权失败')
        if (err.error == 11) {

          my.showAuthGuide({
            authType: 'LBS',
            success: (res) => {

            },
            fail: (error) => {
              my.alert({ content: '获取位置授权失败' });
            },
          });

        }
        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
    if (data.id == 2 && !that.data.latitude && !that.data.longitude) {
      that.setData({
        background: true,
        location: true
      })
      return
    }
    if (data.id == 2 && !setting) {
      my.alert({
        title: '提示',
        content: '您附近暂无运营区，暂不可用车'
      })

      return
    }
    if (data.id == 2 && setting) {
      if (!userStatus) {
        my.navigateTo({
          url: '/pages/authorization/authorization',
        })
      }
      else {
        that.jiance1();
      }
    } else {
      my.navigateTo({
        url: data.url,
      })
    }



    // 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 == 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',
    })
  },

})

















