yurong/App.vue

202 lines
5.1 KiB
Vue

<script>
export default {
globalData: {
address: '',
openId: null,
token: null,
location: {},//地址
system: {},//系统配置
userInfo: {},//用户信息.
onAddress: {},
onGoodCart: [],//购物车列表
onCoupon: {},//当前优惠券
addressDetail:{},//地址信息
shoppings:[],//购物车列表
},
onLaunch: function() {
//// uni.setStorageSync('token','ab814477-8302-42d7-ad3a-a1f778d549d3')
//let userInfo = uni.getStorageSync('userInfo')
//let token = uni.getStorageSync('token')
//this.globalData.token = token
//this.globalData.userInfo = userInfo
//this.getSystem()
//// #ifdef MP-WEIXIN
//this.overShare()
//// #endif
//if (userInfo&&userInfo.id&&token) {
// this.getUserInfo()
// uni.switchTab({
// url: '/pages/index/index'
// })
//} else {
//}
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
methods: {
// #ifdef MP-WEIXIN
overShare() {
//监听路由切换
wx.onAppRoute(function(res) {
let pages = getCurrentPages(),
view = pages[pages.length - 1]
if (view) {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
}
})
},
// #endif
getSystem() {//获取系统配置
this.axiosFromToken('POST','common/service',{},'加载中').then(res => {
this.globalData.system = res.data
uni.setStorageSync('system',res.data)
console.log(res.constructor().constructor(),'系统配置')
})
},
//获取用户信息
getUserInfo() {
this.axiosFromToken('POST', 'user/userinfo', {
token: this.globalData.token
}).then(res => {
if (res.code == 1) {
console.log('用户信息', res.data);
this.globalData.userInfo = res.data
uni.setStorageSync('userInfo', res.data)
} else {
this.$tools.showtt(res.msg)
}
})
},
getAddress() {//获取位置信息
// #ifdef H5
// //开发状态
this.globalData.location.latitude = '36.667123'
this.globalData.location.longitude = '117.076244'
this.globalData.onAddress = '济南市'
// #endif
let that = this
// #ifdef APP
return new Promise((resolve,reject)=>{
uni.getLocation({
type: 'gcj02',
geocode: true,
success(res) {
that.globalData.location = res
that.globalData.onAddress = res.address.city
resolve(res.address.city)
},
fail(err) {
reject(err)
}
})
})
// #endif
// #ifdef MP-WEIXIN
return new Promise((resolve,reject)=>{
if (that.globalData.location && that.globalData.location.Address && that.globalData.location.latitude && that.globalData.location.longitude) {
resolve()
} else {
var myAmapFun = new that.$vm.$amapwx.AMapWX({key:'32744ba7c2805fac5edc9f7bafc1e1ae'});
uni.showLoading({
title: '加载中',
})
myAmapFun.getRegeo({
success: function(data){
uni.hideLoading()
//获取用户所在地
that.globalData.location = data[0]
let address = data[0].regeocodeData.addressComponent
if (typeof address.city == "string") {
data[0].Address = address.city
} else {
data[0].Address = address.province
}
data[0].Address = data[0].Address.substring(0, data[0].Address.length - 1)
// data[0].Address = '济南市'
that.globalData.onAddress = data[0].Address
resolve(data[0].Address)
},
fail: function(info){
//失败回调
uni.hideLoading()
if (info.errMsg == "getLocation:fail auth deny") {
that.showtt('请同意授权位置信息')
}
console.log(info)
},
})
}
})
// #endif
},
payFn(provider,parmas) {//拉起支付
console.log(parmas,'支付参数')
return new Promise((resolve,reject)=>{
uni.requestPayment({
provider,
// #ifdef MP-WEIXIN
...parmas,
// #endif
// #ifndef MP-WEIXIN
orderInfo: parmas,
// #endif
success: (res) => {
uni.showToast({
icon: 'success',
title: '支付成功'
})
resolve(res)
},
fail: (err) => {
uni.showToast({
icon: 'error',
title: '支付失败'
})
reject(err)
// console.log('fail:', err, this);
}
});
})
}
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "/common/style_scss.scss";
/* #ifdef MP-WEIXIN */
/* 自定义swpier指示器样式 */
wx-swiper .wx-swiper-dot {
width: 12rpx;
height: 6rpx;
background: #fff;
border-radius: 2rpx;
}
wx-swiper .wx-swiper-dot-active {
width: 12rpx;
height: 6rpx;
background: #d4bc03;
border-radius: 2rpx;
}
/* #endif */
</style>