123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- const ald = require('./utils/ald-stat.js')
- import { post, get, login } from './utils/http'
- App({
- globalData: {
- navBarData: {
- navBarHeight: 0,
- menuBotton: 0,
- menuRight: 0,
- menuHeight: 0
- },
- userInfo: null,
- couponPopup: false,
- coupon: null,
- systemInfo: {},
- sceneData: {},
- memberRules: '',
- storeData: {},
- showGoods:false,
- toViewIndex:'',
- shareUserID:'',
- isH5:false,
- isSkinPlan:false,
- isTestSkin:false,
- isCardBag:false,
- },
- invite_id:"null",
-
- loginConfig: {
- code: '',
- codeTime: ''
- },
- address:{},
- onLaunch(options) {
-
- let RECORD_WHITE = ['pages/projectDetail/projectDetail','pages/reserveCar/reserveCar','pages/orderBy/orderBy']
- wx.onAppRoute((route) => {
- if(this.globalData.isSkinPlan||this.globalData.isTestSkin){
- if(!RECORD_WHITE.includes(route.path)){
- this.globalData.isSkinPlan = false
- this.globalData.isTestSkin = false
- }
- }
- });
- let WHITE_LIST=['pages/login/login','pages/home/home']
- if(!WHITE_LIST.includes(options.path)){
- if(wx.getStorageSync('userInfo')==''){
- wx.navigateTo({
- url: '/pages/login/login',
- })
- }
- }
- let that = this
- this.getPermission(that);
- that.setNavBarInfo()
-
- if (wx.getStorageSync('token')) {
- get('api/order/check_first', {}, (res) => {
- if (res.data.order_status == 1) {
- wx.setStorageSync('agree', true)
- }
- })
- }
- that.initData()
-
- },
- onShow(opts) {
- this.globalData.sceneData = {
- path: opts.path,
- query: opts.query
- }
- if (!this.globalData.userInfo) {
- this.initData()
- }
- if (opts.path == 'pages/deviceLogin/deviceLogin') {
- return
- }
-
-
-
- },
-
- initData() {
- let that = this
-
- if (wx.getStorageSync('token')) {
- get('api/user', {}, (res) => {
- if (res.data) {
- that.globalData.userInfo = res.data
- wx.setStorageSync('userInfo', res.data)
- }
- })
- }
- return
-
- let storeId = wx.getStorageSync('store_id')
- if (storeId) {
- get(
- 'api/store/info',
- {
- store_id: storeId
- },
- (res) => {
- this.globalData.storeData = res.data
- }
- )
- }
- },
-
- setNavBarInfo() {
-
- const systemInfo = wx.getSystemInfoSync()
- this.globalData.systemInfo = systemInfo
-
- const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
- this.systemInfo = systemInfo
-
- let navBarData = {
- navBarHeight:
- (menuButtonInfo.top - systemInfo.statusBarHeight) * 2 +
- menuButtonInfo.height +
- systemInfo.statusBarHeight,
- menuBotton: menuButtonInfo.top - systemInfo.statusBarHeight,
- menuRight: systemInfo.screenWidth - menuButtonInfo.right,
- menuHeight: menuButtonInfo.height
- }
- this.globalData.navBarData = navBarData
- },
-
- getPermission: function (obj) {
- let that = this
- wx.getLocation({
- success: function (res) {
- that.getStore()
- that.globalData.address = res
-
- },
- fail: function () {
- wx.getSetting({
- success: function (res) {
- var statu = res.authSetting;
- if (!statu['scope.userLocation']) {
- wx.showModal({
- title: '是否授权当前位置',
- content: '需要获取您的地理位置,请确认授权,否则无法定位最近店铺',
- success: function (tip) {
- if (tip.confirm) {
- wx.openSetting({
- success: function (data) {
- if (data.authSetting["scope.userLocation"] === true) {
- wx.showToast({
- title: '授权成功',
- icon: 'success',
- duration: 1000
- })
-
- wx.getLocation({
- success: function (res) {
- that.getStore()
- app.address = res
- },
- })
- } else {
- wx.showToast({
- title: '授权失败',
- icon: 'success',
- duration: 1000
- })
- }
- }
- })
- }
- }
- })
- }
- },
- fail: function (res) {
- wx.showToast({
- title: '调用授权窗口失败',
- icon: 'success',
- duration: 1000
- })
- }
- })
- }
- })
- },
-
- getStore() {
- get(
- 'api/store', {
- page: 1,
- limit: 100,
- keyword: ""
- },
- (res) => {
- let lat1 = this.globalData.address.latitude,
- lng1 = this.globalData.address.longitude,
- storeList = res.data.list,
- distanceList = []
-
- storeList.forEach(item => {
- let distanceInfo = {}
- distanceInfo["id"] = item.id
- distanceInfo["dist"] = this.getDistance(lat1, lng1, item.latitude, item.longitude)
- distanceList.push(distanceInfo)
- })
-
- let _distanceList = distanceList.sort(function (a, b) {
- return a.dist - b.dist
- })
-
-
- wx.setStorageSync('store_id', String(_distanceList[0].id))
- }
- )
- },
-
- getDistance(lat1, lng1, lat2, lng2) {
- lat1 = lat1 || 0;
- lng1 = lng1 || 0;
- lat2 = lat2 || 0;
- lng2 = lng2 || 0;
- var rad1 = lat1 * Math.PI / 180.0;
- var rad2 = lat2 * Math.PI / 180.0;
- var a = rad1 - rad2;
- var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
- var r = 6378137;
- var distance = r * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos(rad2) * Math.pow(Math.sin(b / 2), 2)));
- return distance;
- },
- })
|