@@ -6,139 +6,30 @@ App({ | |||
var that = this; | |||
that.globalData.sceneAddress = options.scene; | |||
that.getLocation(); | |||
that.userLogin(); | |||
}, | |||
/** | |||
* 获取地址位置信息 | |||
*/ | |||
getLocation: function() { | |||
var that = this | |||
wx.getLocation({ | |||
type: "wgs84", | |||
success: function(res) { | |||
that.globalData.locationInfo = res | |||
console.log("getLocation", res); | |||
}, | |||
fail: error => { | |||
console.log(error); | |||
} | |||
}); | |||
}, | |||
/** | |||
* 用户登录 | |||
*/ | |||
userLogin: function() { | |||
var that = this; | |||
// 登录 | |||
wx.login({ | |||
success: ({ code }) => { | |||
Http.post({ | |||
url: config.api.login, | |||
data: { | |||
appId: config.weapp.AppId, | |||
code: code, | |||
sceneAddress: that.globalData.sceneAddress | |||
} | |||
}) | |||
.then(res => { | |||
console.log("userlogin", res); | |||
that.globalData.token = res.data.token; | |||
Http.setToken(res.data.token); | |||
that.checkUserCarStatus(); | |||
that.getUserInfo(); | |||
if (that.couponChannelListCallback) { | |||
that.couponChannelListCallback(that.globalData.token); | |||
} | |||
if (that.couponListCallback) { | |||
that.couponListCallback(that.globalData.token); | |||
} | |||
if (that.businessListCallback) { | |||
that.businessListCallback(that.globalData.token); | |||
} | |||
return Http.post({ | |||
url: config.api.checkUserStatus, | |||
data: {} | |||
}); | |||
}) | |||
.then(res => { | |||
console.log("checkUserStatus", res); | |||
}) | |||
.catch(err => { | |||
console.log("checkUserStatus:err", err); | |||
if (err.code == 11004) { | |||
// 用户昵称未授权 | |||
wx.redirectTo({ | |||
url: "../getuserinfo/index" | |||
}); | |||
} | |||
}); | |||
} | |||
}); | |||
}, | |||
/** | |||
* 获取用户信息 | |||
*/ | |||
getUserInfo: function() { | |||
// 获取用户信息 | |||
wx.getSetting({ | |||
success: res => { | |||
console.log("getSetting", res); | |||
if (res.authSetting["scope.userInfo"]) { | |||
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 | |||
wx.getUserInfo({ | |||
success: res => { | |||
// 可以将 res 发送给后台解码出 unionId | |||
console.log("getUserInfo", res); | |||
} | |||
}); | |||
} | |||
} | |||
}); | |||
}, | |||
/** | |||
* 检查用户是否有车 | |||
*/ | |||
checkUserCarStatus: function() { | |||
var that = this; | |||
Http.get({ | |||
url: config.api.userCarCount, | |||
data: {} | |||
}).then(res => { | |||
if (res.data > 0) { | |||
// 用户名下有车 | |||
that.globalData.phone = res.data.phone; | |||
that.globalData.supportCar = true; | |||
// 共同登录 | |||
that.userCarLogin(); | |||
} | |||
}); | |||
}, | |||
/** | |||
* car共同登录 | |||
*/ | |||
userCarLogin: function() { | |||
var that = this; | |||
if (!that.globalData.carLogin) { | |||
// 共同登录 | |||
Http.post({ | |||
url: config.api.carInit, | |||
data: { | |||
phone: that.globalData.phone | |||
} | |||
}).then(res => { | |||
that.globalData.carLogin = true; | |||
that.globalData.parkVendor = res.data.vendor; | |||
if (res.data.token != "undefined") { | |||
that.globalData.etcpToken = res.data.token; | |||
console.log("etcpToken", that.globalData.etcpToken); | |||
} | |||
}); | |||
} | |||
}, | |||
}, | |||
globalData: { | |||
// token | |||
token: null, | |||
// 渠道 | |||
sceneAddress: null, | |||
// location info | |||
locationInfo: null, | |||
// 二维码参数 | |||
scene: null, | |||
// 支持智慧停车, 用户名下有车 | |||
@@ -131,7 +131,7 @@ var config = { | |||
}, | |||
weapp: { | |||
AppId: "wx8eb8275b78db4ede" | |||
AppId: "wxb11603577a84a86d" | |||
}, | |||
ErrorCode: { | |||
NICK_NOT_AUTH: 11004, | |||
@@ -22,52 +22,134 @@ Page({ | |||
var scene = decodeURIComponent(options.scene); | |||
}, | |||
onShow:function(){ | |||
let that = this; | |||
if (app.globalData.token && app.globalData.token != null) { | |||
} else { | |||
wx.login({ | |||
success: ({ code }) => { | |||
console.log(code); | |||
Http.post({ | |||
onShow: function() { | |||
this.userLogin() | |||
}, | |||
onGetCode: function(e) { | |||
//子组件传递给父组件的值 | |||
this.setData({ | |||
code: e.detail.val, | |||
page: e.detail.pageNum | |||
}); | |||
}, | |||
/** | |||
* 用户登录 | |||
*/ | |||
userLogin: function() { | |||
var that = this; | |||
// 登录 | |||
wx.login({ | |||
success: ({ | |||
code | |||
}) => { | |||
Http.post({ | |||
url: config.api.login, | |||
data: { | |||
appId: config.weapp.AppId, | |||
code: code, | |||
sceneAddress: app.globalData.sceneAddress | |||
sceneAddress: app.globalData.sceneAddress, | |||
latitude: '' + app.globalData.locationInfo.latitude, | |||
longtitude: '' + app.globalData.locationInfo.longtitude, | |||
} | |||
}).then(res => { | |||
//banner渲染 | |||
}) | |||
.then(res => { | |||
console.log("userlogin:app", res); | |||
app.globalData.token = res.data.token; | |||
Http.setToken(res.data.token); | |||
if (res.code == 200) { | |||
Http.get({ | |||
url: config.api.bannerlist, | |||
data: { | |||
pageNum: 1, | |||
pageSize: 5 | |||
} | |||
}).then(res => { | |||
that.setData({ | |||
list: res.data.list | |||
}); | |||
that.checkUserCarStatus(); | |||
that.getUserInfo(); | |||
if (app.couponChannelListCallback) { | |||
app.couponChannelListCallback(app.globalData.token); | |||
} | |||
if (app.couponListCallback) { | |||
app.couponListCallback(app.globalData.token); | |||
} | |||
if (app.businessListCallback) { | |||
app.businessListCallback(app.globalData.token); | |||
} | |||
return Http.post({ | |||
url: config.api.checkUserStatus, | |||
data: {} | |||
}); | |||
}) | |||
.then(res => { | |||
console.log("checkUserStatus:res", res); | |||
}) | |||
.catch(err => { | |||
console.log("checkUserStatus:err", err); | |||
if (err.code == 11004) { | |||
// 用户昵称未授权 | |||
wx.redirectTo({ | |||
url: "/pages/getuserinfo/index" | |||
}); | |||
} | |||
}); | |||
} | |||
}); | |||
}, | |||
/** | |||
* 检查用户是否有车 | |||
*/ | |||
checkUserCarStatus: function() { | |||
var that = this; | |||
Http.get({ | |||
url: config.api.userCarCount, | |||
data: {} | |||
}).then(res => { | |||
if (res.data > 0) { | |||
// 用户名下有车 | |||
app.globalData.phone = res.data.phone; | |||
app.globalData.supportCar = true; | |||
// 共同登录 | |||
that.userCarLogin(); | |||
} | |||
}); | |||
}, | |||
/** | |||
* car共同登录 | |||
*/ | |||
userCarLogin: function() { | |||
var that = this; | |||
if (!app.globalData.carLogin) { | |||
// 共同登录 | |||
Http.post({ | |||
url: config.api.carInit, | |||
data: { | |||
phone: app.globalData.phone | |||
} | |||
}).then(res => { | |||
app.globalData.carLogin = true; | |||
app.globalData.parkVendor = res.data.vendor; | |||
if (res.data.token != "undefined") { | |||
app.globalData.etcpToken = res.data.token; | |||
console.log("etcpToken", app.globalData.etcpToken); | |||
} | |||
}); | |||
} | |||
}, | |||
onGetCode: function(e) { | |||
//子组件传递给父组件的值 | |||
this.setData({ | |||
code: e.detail.val, | |||
page: e.detail.pageNum | |||
/** | |||
* 获取用户信息 | |||
*/ | |||
getUserInfo: function() { | |||
// 获取用户信息 | |||
wx.getSetting({ | |||
success: res => { | |||
console.log("getSetting", res); | |||
if (res.authSetting["scope.userInfo"]) { | |||
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 | |||
wx.getUserInfo({ | |||
success: res => { | |||
// 可以将 res 发送给后台解码出 unionId | |||
console.log("getUserInfo", res); | |||
} | |||
}); | |||
} | |||
} | |||
}); | |||
}, | |||
//下拉加载更多 | |||
onReachBottom: function() { | |||
let that = this; | |||
@@ -12,8 +12,8 @@ | |||
}, | |||
"compileType": "miniprogram", | |||
"libVersion": "2.2.4", | |||
"appid": "wx8eb8275b78db4ede", | |||
"projectname": "%E5%AF%8C%E8%8C%82%E6%94%AF%E4%BB%98%E6%B5%8B%E8%AF%95", | |||
"appid": "wxb11603577a84a86d", | |||
"projectname": "%E5%AF%8C%E8%8C%82%E9%93%BE%E5%AE%A2%E6%B5%8B%E8%AF%95", | |||
"isGameTourist": false, | |||
"condition": { | |||
"search": { | |||