You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
265 lines
8.7 KiB
265 lines
8.7 KiB
import { config, getUserInfo } from "../../api/user"
|
|
import { zconfig, loginToken, getBaseInfo, getPopupInfo } from "../../api/ztb"
|
|
import { pconfig } from "../../api/payment"
|
|
import { mconfig } from "../../api/moment"
|
|
const util = require('../../utils/util')
|
|
const wxqqmap = require('../../libs/qqmap-wx-jssdk.min')
|
|
const event = require('../../utils/event')
|
|
const storage = require('../../utils/storage')
|
|
const app = getApp()
|
|
const qqwxmap = new wxqqmap({
|
|
key: 'GAMBZ-CBGCK-GB6J3-A6PJX-F6ZHH-IWFUD' // 必填,这里最好填自己申请的的
|
|
// key: 'NGOBZ-UL7ED-WJ34D-PMWW7-LBDI2-J5FYK'
|
|
})
|
|
|
|
Page({
|
|
data: {
|
|
cityName: '',
|
|
TabList: [
|
|
{ index: 0, value: 'article', badge: 0, name: '首页' },
|
|
{ index: 1, value: 'mall', badge: 0, name: '行情' },
|
|
{ index: 2, value: 'agent', badge: 0, name: '交易' },
|
|
{ index: 3, value: 'home', badge: 0, name: '我的' }
|
|
],
|
|
pageIndex: 0,
|
|
safeBottom: app.globalData.safeBottom,
|
|
inited: false,
|
|
path: null,
|
|
landInfo: null,
|
|
visible: false
|
|
},
|
|
/************************************** 初始化流程 ********************************************/
|
|
onLoad: function (options) {
|
|
if (options.url) {
|
|
this.data.path = options.url
|
|
if (options.key && options.value) {
|
|
this.data.path += '?' + options.key + '=' + options.value
|
|
}
|
|
}
|
|
event.on('EventMessage', this, this.onEvent)
|
|
this.data.inited = true
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
const fheght = (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight) - 100
|
|
this.setData({ fragment: fheght, safeBottom: app.globalData.safeBottom })
|
|
var authorization = app.globalData.token || storage.get('Authorization')
|
|
if (authorization) {
|
|
app.globalData.token = authorization
|
|
config.header = { 'Authorization': 'QNT ' + app.globalData.token }
|
|
getUserInfo().then(result => {
|
|
this.toIndex()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
})
|
|
} else {
|
|
this.toIndex()
|
|
}
|
|
},
|
|
alertMessage: function(content){
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
this.wuxDialog.open({
|
|
resetOnClose: true,
|
|
title: '温馨提示',
|
|
content,
|
|
buttons: [{
|
|
text: '确定',
|
|
type: 'primary',
|
|
onTap(e) {
|
|
}
|
|
}]
|
|
})
|
|
},
|
|
defaultIndex: function () {
|
|
this.locationing()
|
|
this.onResume()
|
|
if (this.data.path) {
|
|
wx.navigateTo({ url: this.data.path })
|
|
}
|
|
getPopupInfo().then(result => {
|
|
if (result.data) {
|
|
this.setData({ landInfo: result.data })
|
|
}
|
|
})
|
|
},
|
|
locationing: function() {
|
|
var that = this
|
|
wx.getLocation({
|
|
type: 'gcj02',
|
|
success (res) {
|
|
app.nowLocation = res
|
|
qqwxmap.reverseGeocoder({
|
|
location: res,
|
|
success: function (res) {
|
|
app.nowLocation.cityName = res.result.address_component.city.replace('市', '')
|
|
app.nowLocation.cityCode = res.result.ad_info.city_code
|
|
app.nowCity = { cityName: app.nowLocation.cityName, cityCode: app.nowLocation.cityCode }
|
|
that.setData({ cityName: app.nowLocation.cityName })
|
|
that.locate = true
|
|
},
|
|
fail: function (res) {
|
|
that.locate = true
|
|
}
|
|
})
|
|
},
|
|
fail (e){
|
|
that.locate = true
|
|
if (e && (e.errCode == 2 || e.errCode == 404)) {
|
|
that.alertMessage('位置信息获取失败,请检查手机“位置信息”是否未开启')
|
|
} else if (e && ((e.errMsg.indexOf('getLocation:fail auth deny') != -1) || (e.errMsg.indexOf('system permission denied') != -1))) {
|
|
wx.getSetting({
|
|
success(res){
|
|
if(res && (res.authSetting["scope.userLocation"] !== undefined && res.authSetting["scope.userLocation"] !==true)){
|
|
that.detectSettings()
|
|
} else {
|
|
that.alertMessage('位置信息获取失败,请检查微信是否有定位权限')
|
|
}
|
|
}
|
|
})
|
|
} else if (e && e.errMsg.indexOf('getLocation:fail connect ETIMEDOUT') != -1) {
|
|
that.alertMessage('位置信息获取失败,请检查网络是否连接')
|
|
}
|
|
}
|
|
})
|
|
},
|
|
detectSettings: function(){
|
|
var that = this
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
this.wuxDialog.open({
|
|
resetOnClose: true,
|
|
title: '温馨提示',
|
|
content: '小程序没有定位权限,无法进行送餐服务,请前往设置微信小程序的定位权限。',
|
|
buttons: [{
|
|
text: '前往设置',
|
|
type: 'primary',
|
|
onTap(e) {
|
|
wx.openSetting({
|
|
success(result){
|
|
if(result && (result.authSetting["scope.userLocation"] !== undefined && result.authSetting["scope.userLocation"] ===true)){
|
|
// 成功设置
|
|
that.locationing()
|
|
} else {
|
|
that.detectSettings()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}]
|
|
})
|
|
Dialog.alert({ title: '温馨提示', message: '小程序没有定位权限,无法进行送餐服务,请前往设置微信小程序的定位权限。', confirmButtonText: '前往设置' }).then(() => {
|
|
wx.openSetting({
|
|
success(result){
|
|
if(result && (result.authSetting["scope.userLocation"] !== undefined && result.authSetting["scope.userLocation"] ===true)){
|
|
// 成功设置
|
|
that.locationing()
|
|
} else {
|
|
that.detectSettings()
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
toIndex: function () {
|
|
if (!app.globalData.token) {
|
|
wx.hideLoading()
|
|
this.defaultIndex()
|
|
return
|
|
}
|
|
loginToken({loginToken: app.globalData.token}).then(result => {
|
|
zconfig.header = { 'Authorization': 'QNT ' + result.data.token }
|
|
pconfig.header = { 'Authorization': 'QNT ' + result.data.token }
|
|
mconfig.header = { 'Authorization': 'QNT ' + result.data.token }
|
|
getBaseInfo().then(result => {
|
|
app.globalData.userInfo = result.data
|
|
wx.hideLoading()
|
|
if(!app.globalData.userInfo.identityTag){
|
|
wx.navigateTo({ url: '/pages/home/tab1/index' })
|
|
}
|
|
this.defaultIndex()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.defaultIndex()
|
|
})
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.defaultIndex()
|
|
})
|
|
},
|
|
onResume: function () {
|
|
var pageView = this.selectComponent('#' + this.data.TabList[this.data.pageIndex].value)
|
|
if (pageView && this.data.inited) {
|
|
pageView.onRestart()
|
|
}
|
|
},
|
|
//事件处理函数
|
|
onNavChange: function (e) {
|
|
// 处理用户的登录校验
|
|
this.setData({ pageIndex: Number(e.currentTarget.dataset.tab) })
|
|
this.onResume()
|
|
},
|
|
onAgentClick: function({detail}){
|
|
if(detail.what == 1) {
|
|
this.setData({ pageIndex: 2 })
|
|
this.onResume()
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
if (this.data.inited) {
|
|
this.onResume()
|
|
}
|
|
// 如果定位完成,但是还是没有获取城市信息,那么就要进行城市选择
|
|
if(this.locate && util.isEmpty(this.data.cityName)){
|
|
|
|
}
|
|
if(app.globalData.userInfo && !app.globalData.userInfo.identityTag){
|
|
wx.navigateTo({ url: '/pages/home/tab1/index' })
|
|
}
|
|
},
|
|
onEvent: function (message) {
|
|
if(message.what == 250){
|
|
this.setData({ pageIndex: 0 })
|
|
}
|
|
},
|
|
stopTouchMove: function (e) {
|
|
return false
|
|
},
|
|
// 弹出框的处理;
|
|
onClose: function () {
|
|
this.setData({ visible: false, landInfo: null })
|
|
},
|
|
onImageLoad: function () {
|
|
this.setData({ visible: true })
|
|
},
|
|
onImageClick: function () {
|
|
if (this.data.landInfo.redirectInfo.targetView == 'showH5') {
|
|
util.navigateTo('/pages/html/html/index?link=' + this.data.landInfo.redirectInfo.params.id + '?title=' + this.data.landInfo.title)
|
|
return
|
|
}
|
|
util.navigateTarget(this.data.landInfo.redirectInfo)
|
|
this.setData({ visible: false, landInfo: null })
|
|
},
|
|
toRule: function () {
|
|
if (this.data.landInfo.ruleRedirectInfo.targetView == 'showH5') {
|
|
util.navigateTo('/pages/html/html/index?link=' + this.data.landInfo.ruleRedirectInfo.params.id + '?title=' + this.data.landInfo.title)
|
|
return
|
|
}
|
|
util.navigateTarget(this.data.landInfo.ruleRedirectInfo)
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
},
|
|
onShareAppMessage: function () {
|
|
return {
|
|
title: '纸通宝--废纸交易、最新情报、最优资讯',
|
|
path: '/pages/index/index'
|
|
}
|
|
},
|
|
// 分享至朋友圈
|
|
onShareTimeline() {
|
|
return {
|
|
title: '纸通宝--废纸交易、最新情报、最优资讯',
|
|
path: '/pages/index/index'
|
|
}
|
|
},
|
|
})
|