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.
371 lines
12 KiB
371 lines
12 KiB
import { config, getUserInfo } from "../../api/user"
|
|
import { zconfig, loginToken, getBaseInfo, getPopupInfo, hasGetMemberInfo, receiveMember } from "../../api/ztb"
|
|
import { pconfig } from "../../api/payment"
|
|
import { mconfig } from "../../api/moment"
|
|
const util = require('../../utils/util')
|
|
const tdsdk = require('../../libs/tdweapp.js')
|
|
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'})
|
|
|
|
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,
|
|
path: null,
|
|
landInfo: null,
|
|
visible: false,
|
|
inited: false,
|
|
show: false,
|
|
cityList: [],
|
|
historyList: [],
|
|
cityId: null,
|
|
visible2: false
|
|
},
|
|
/************************************** 初始化流程 ********************************************/
|
|
onLoad: function (options) {
|
|
if (options.url) {
|
|
this.data.path = options.url
|
|
if (options.key && options.value) {
|
|
this.data.path += '?' + options.key + '=' + options.value
|
|
}
|
|
}
|
|
var citystring = storage.get('ztb-now-city')
|
|
if(!util.isEmpty(citystring)){
|
|
app.nowCity = JSON.parse(citystring)
|
|
this.data.cityName = app.nowCity.cityName
|
|
}
|
|
var min = new Date()
|
|
min.setHours(0, 0, 0)
|
|
var maxDate = util.formatDate(min, 'Y-M-D')
|
|
min.setFullYear(min.getFullYear() - 1, min.getMonth(), min.getDate())
|
|
var minDate = util.formatDate(min, 'Y-M-D')
|
|
var calendar = maxDate
|
|
event.on('EventMessage', this, this.onEvent)
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
const fheght = (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight) - 100
|
|
this.setData({
|
|
fragment: fheght,
|
|
safeBottom: app.globalData.safeBottom,
|
|
maxDate, minDate, calendar,
|
|
cityName: this.data.cityName,
|
|
customHeight: app.globalData.customHeight,
|
|
customWidth: app.globalData.Custom.left,
|
|
StatusBar: app.globalData.StatusBar || 40,
|
|
})
|
|
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.data.inited = true
|
|
this.locationing()
|
|
if (this.data.path && '/pages/index/index' != this.data.path) {
|
|
util.navigateTo(this.data.path)
|
|
}
|
|
if(!app.globalData.userInfo){
|
|
this.setData({ landInfo: {otherType: 10, picUrl: '/assets/popup/send-member.png'} })
|
|
} else {
|
|
hasGetMemberInfo().then(result => {
|
|
if (result.data && result.data.hasGetMember && !this.data.landInfo) {
|
|
if(result.data.type === 1){
|
|
this.setData({ landInfo: {otherType: 11, picUrl: '/assets/popup/eighty-member.png'} })
|
|
} else {
|
|
this.setData({ landInfo: {otherType: 11, picUrl: '/assets/popup/serve-member.png'} })
|
|
}
|
|
}
|
|
})
|
|
}
|
|
getPopupInfo().then(result => {
|
|
if (result.data && !this.data.landInfo) {
|
|
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.replace('156', '')
|
|
if(!app.nowCity){
|
|
app.nowCity = { cityName: app.nowLocation.cityName, cityCode: app.nowLocation.cityCode }
|
|
that.setData({ cityName: app.nowLocation.cityName })
|
|
}
|
|
event.emit('EventMessage', { what: 444, desc: 'nowCity' })
|
|
that.located = true
|
|
},
|
|
fail: function (res) {
|
|
that.located = true
|
|
}
|
|
})
|
|
},
|
|
fail (e){
|
|
that.located = 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()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}]
|
|
})
|
|
},
|
|
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 fragment = this.selectComponent('#' + this.data.TabList[this.data.pageIndex].value)
|
|
if (fragment) {
|
|
fragment.onRestart()
|
|
}
|
|
},
|
|
//事件处理函数
|
|
onNavChange: function (e) {
|
|
// 处理用户的登录校验
|
|
this.setData({ pageIndex: Number(e.currentTarget.dataset.tab) })
|
|
this.onResume()
|
|
},
|
|
onAgentClick: function({detail}){
|
|
this.setData({ pageIndex: detail.what })
|
|
this.onResume()
|
|
},
|
|
setHeightData: function(){
|
|
const fheght = (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight) - 100
|
|
this.setData({
|
|
fragment: fheght,
|
|
safeBottom: app.globalData.safeBottom,
|
|
cityName: this.data.cityName,
|
|
customHeight: app.globalData.customHeight,
|
|
StatusBar: app.globalData.StatusBar || 40,
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
tdsdk.Page.onShow()
|
|
if(this.data.inited || app.globalData.Custom){
|
|
this.onResume()
|
|
}
|
|
// 如果定位完成,但是还是没有获取城市信息,那么就要进行城市选择
|
|
if(this.located && util.isEmpty(app.nowCity)){
|
|
wx.navigateTo({url: `/pages/home/city-select/index?type=1` })
|
|
}
|
|
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, visible2: false })
|
|
},
|
|
onImageLoad: function () {
|
|
this.setData({ visible: true })
|
|
},
|
|
onPicker: function({detail}){
|
|
if(detail.type == 1){
|
|
this.setData({ show: true })
|
|
} else if(detail.type == 2 && this.data.cityList && this.data.cityList.length){
|
|
this.setData({ visible2: true, cityId: detail.cityId })
|
|
}
|
|
},
|
|
onVisibleChange({detail}) {
|
|
this.setData({ show: detail.visible })
|
|
},
|
|
onConfirm({detail}) {
|
|
this.setData({ calendar: detail.label })
|
|
var fragment = this.selectComponent('#' + this.data.TabList[1].value)
|
|
if(fragment && fragment.onCalendarChange){
|
|
fragment.onCalendarChange(detail.label)
|
|
}
|
|
},
|
|
onImageClick: function () {
|
|
if(!this.data.landInfo){
|
|
return
|
|
}
|
|
if(this.data.landInfo.otherType == 10){
|
|
util.navigateTo('/pages/login/index')
|
|
} else if(this.data.landInfo.otherType == 11){
|
|
wx.showLoading({ title: '领取中', mask: true })
|
|
receiveMember().then(res => {
|
|
wx.hideLoading()
|
|
util.showToast('会员领取成功')
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast('领取会员失败,请下次登录重新领取')
|
|
})
|
|
} else 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)
|
|
} else {
|
|
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)
|
|
},
|
|
onRegionList: function({detail}){
|
|
var hotstring = storage.get('ztb-history-list')
|
|
var historyList = []
|
|
if(!util.isEmpty(hotstring)){
|
|
historyList = JSON.parse(hotstring)
|
|
}
|
|
this.setData({ cityList: detail, historyList })
|
|
},
|
|
clickCity: function(e){
|
|
this.setData({cityId: e.currentTarget.dataset.id, visible2: false })
|
|
var fragment = this.selectComponent('#' + this.data.TabList[2].value)
|
|
if(fragment && fragment.onCityChange){
|
|
fragment.onCityChange({detail: {cityId: e.currentTarget.dataset.id}})
|
|
}
|
|
if(!util.isEmpty(e.currentTarget.dataset.index)){
|
|
var item = this.data.cityList[e.currentTarget.dataset.index]
|
|
var flag = false
|
|
for (let index = 0; index < this.data.historyList.length; index++) {
|
|
if(this.data.historyList[index].cityId == item.cityId){
|
|
flag = true
|
|
break
|
|
}
|
|
}
|
|
if(!flag){
|
|
if(this.data.historyList.length >= 4){
|
|
this.data.historyList.splice(3, 1)
|
|
}
|
|
this.data.historyList.unshift(item)
|
|
storage.put('ztb-history-list', JSON.stringify(this.data.historyList))
|
|
this.setData({ historyList: this.data.historyList })
|
|
}
|
|
}
|
|
},
|
|
clearHistory: function(){
|
|
storage.remove('ztb-history-list')
|
|
this.setData({ historyList: [] })
|
|
},
|
|
onHide: function(){
|
|
tdsdk.Page.onHide()
|
|
},
|
|
onUnload: function(){
|
|
tdsdk.Page.onUnload()
|
|
event.remove('EventMessage', this)
|
|
},
|
|
onShareAppMessage: function () {
|
|
return {
|
|
title: '纸通宝--废纸交易、最新情报、最优资讯',
|
|
path: '/pages/index/index'
|
|
}
|
|
},
|
|
// 分享至朋友圈
|
|
onShareTimeline() {
|
|
return {
|
|
title: '纸通宝--废纸交易、最新情报、最优资讯',
|
|
path: '/pages/index/index'
|
|
}
|
|
}
|
|
})
|