yurong/.svn/pristine/8a/8a2bffdbdeb51be10de7c4ae5c3...

204 lines
5.1 KiB
Plaintext

<script>
export default {
globalData: {
address: '',
openId: null,
token: null,
location: {},//地址
system: {},//系统配置
userInfo: {},//用户信息.
onAddress: {},
onGoodCart: [],//购物车列表
onCoupon: {},//当前优惠券
},
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,'系统配置')
})
},
//获取用户信息
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.showToast(res.msg)
}
})
},
getAddress() {//获取位置信息
// #ifdef H5
// //开发状态
this.app.location.latitude = '36.667123'
this.app.location.longitude = '117.076244'
this.app.location.Address = '济南市'
// #endif
// #ifndef H5
let that = this
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 = '济南市'
resolve(data[0].Address)
},
fail: function(info){
//失败回调
uni.hideLoading()
if (info.errMsg == "getLocation:fail auth deny") {
that.showtt('请同意授权位置信息')
}
console.log(info)
},
})
}
})
// #endif
},
createParmas(order_no,paytype=2) {//生成支付参数
return new Promise((resolve,reject)=>{
this.$vm.$tools.axiosFrom('POST','order/orderPayment',{
paytype,
order_no,
openid: uni.getStorageSync('openId')
}).then(res => {
console.log(res,'支付参数')
if (paytype==1) {
this.payFn('alipay',res.data).then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
} else if (paytype==2) {
this.payFn('wxpay',res.data).then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
}
})
})
},
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>