Commit 8f224082 authored by 潘永坪's avatar 潘永坪

扫码支付页面登录修改

parent 50584994
......@@ -6,8 +6,9 @@
//4.setStorageSync与setStorage的区别:如果后续的操作需要使用更新storage后保存的data,则使用setStorageSync使用异步性能更好,使用同步数据更安全
export default {
onLaunch: function(options) {//初始化完成时触发(全局只触发一次
let path=options.path
let openid=uni.getStorageSync("openid")
if(!openid){
if(!openid&&path.indexOf("pages/ourPayment/ourPayment")==-1){//扫码支付页面不需要在此登录
setTimeout(()=>{//解决关联普通二维码扫码首次进入时一直显示登录中
uni.navigateTo({
url: "/pages/login/login"
......
......@@ -6,7 +6,6 @@ if(process.env.NODE_ENV === 'development'){//开发环境
}
const request = (url = '', data = {}, type = 'POST') => {
uni.showLoading({title: '加载中',mask:true})
data.reqId = new Date().getTime() //获取时间戳
return new Promise((resolve, reject) => {
uni.request({
......@@ -15,11 +14,9 @@ const request = (url = '', data = {}, type = 'POST') => {
data:data,
dataType: 'json',
}).then((response) => {
uni.hideLoading()
let [error, res] = response;
resolve(res.data);
}).catch(error => {
uni.hideLoading()
let [err, res] = error;
reject(err)
})
......
......@@ -172,17 +172,66 @@
this.merchantId=option.merchantId
this.companyId=option.companyId
}
if (this.merchantId) { //大商家的有merchantId
this.init()
} else { //小商家没有merchantId
this.initTwo()
if(uni.getStorageSync("openid")){
this.openid=uni.getStorageSync("openid")
if (this.merchantId) { //大商家的有merchantId
this.init()
} else { //小商家没有merchantId
this.initTwo()
}
//#ifdef MP-WEIXIN
this.initCoupon()
//#endif
}else{
this.login()
}
//#ifdef MP-WEIXIN
this.initCoupon()
//#endif
},
methods: {
login(){//---------------------------------------------------------------------登录
let _this=this
uni.getProvider({
service: 'oauth',
success(proRes){
uni.login({
provider:proRes.provider[0],
success: function (res) {
if(res.code){
let source=""
if(proRes.provider[0]=="weixin"){
source=3
}else if(proRes.provider[0]=="alipay"){
source=4
}
let data={
code:res.code,
source,//微信小程序3,支付宝小程序4
}
_this.$request('wechat/wx/getUserInfoByCode',data).then(res => {
if(res.code=='00'){
_this.openid=res.data.openid
uni.setStorageSync('openid',_this.openid)
if (_this.merchantId) { //大商家的有merchantId
_this.init()
} else { //小商家没有merchantId
_this.initTwo()
}
//#ifdef MP-WEIXIN
_this.initCoupon()
//#endif
}else{
uni.removeStorageSync('openid')
}
}).catch((err)=>{
uni.removeStorageSync('openid')
})
}
}
})
}
})
},
getUrlKey(name){//---------------------------------------------------------------获取url
return(new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(decodeURIComponent(this.enterUrl)) || [, ""])[1].replace(/\+/g, '%20') || "";
},
......@@ -223,7 +272,9 @@
"merchantId": this.merchantId,
"companyId": this.companyId,
}
uni.showLoading({title: '加载中',mask:true})
this.$request("scenic/order/findCodePayInfo",data).then((res) => {
uni.hideLoading()
if (res.code =="00") {
this.name = res.data.name
} else {
......@@ -232,13 +283,17 @@
icon:"none"
})
}
}).catch((err)=>{
uni.hideLoading()
})
},
initTwo() { //--------------------------------------------------------------------------初始化获取商家名称,没有merchantId的小商家
let data = {
"id": this.companyId,
}
uni.showLoading({title: '加载中',mask:true})
this.$request("user/company/detail", data).then((res) => {
uni.hideLoading()
if (res.code=="00"){
this.name = res.data.companyVo.companyName
} else {
......@@ -247,6 +302,8 @@
icon:"none"
})
}
}).catch((err)=>{
uni.hideLoading()
})
},
initCoupon() { //-------------------------------------------------------------------------加载优惠券
......@@ -258,7 +315,7 @@
merchantId:this.merchantId, //商户Id
companyId:this.companyId,//公司Id
orderSource:this.orderSource,//订单来源 8扫码支付
openid:uni.getStorageSync("openid")
openid:this.openid
}
this.$request("wechatUser/myPage/usableCouponList",data).then((res) => {
if (res.code == "00") {
......@@ -315,7 +372,7 @@
let data = {
companyId: this.companyId,
merchantId: this.merchantId,
userId:uni.getStorageSync("openid"),
userId:this.openid,
orderMoney: parseFloat(this.buyMoney),
payType: this.payType, //支付类型,
orderSource:this.orderSource,//订单来源 8扫码支付
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment