|
|
@@ -31,6 +31,7 @@
|
|
|
import tkiQrcode from "tki-qrcode"
|
|
|
import tkiBarcode from "@/components/tki-barcode/tki-barcode.vue"
|
|
|
import totp from "@/utils/totp.js"
|
|
|
+ import socket from "@/utils/socket.js"
|
|
|
export default {
|
|
|
components: {
|
|
|
tkiBarcode,
|
|
|
@@ -55,14 +56,67 @@
|
|
|
width: 3,
|
|
|
height: 130,
|
|
|
displayValue: false
|
|
|
- }
|
|
|
+ },
|
|
|
+ //webSocket
|
|
|
+ webSocket:{}
|
|
|
}
|
|
|
},
|
|
|
+ async onLoad(options) {
|
|
|
+ let res = await this.$api.loginUser.detail({
|
|
|
+ id: this.vuex_userId
|
|
|
+ })
|
|
|
+ this.nickName=res.data.nickName
|
|
|
+ // this.avatar =(await this.initAvatat(res.data.avatar)).tempFilePath;
|
|
|
+ //清除缓存
|
|
|
+ await this.clearBillRecordCache()
|
|
|
+ //连接websocket
|
|
|
+ this.onSocketOpen()
|
|
|
+ },
|
|
|
+ async mounted() {
|
|
|
+ //获取用户ID
|
|
|
+ this.id = this.vuex_userId
|
|
|
+ //生成动态密码
|
|
|
+ this.refreshCode();
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ this.handelOut()
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ this.handelOut()
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ handelOut(){
|
|
|
+ uni.hideLoading()
|
|
|
+ this.webSocket.closeSocket()
|
|
|
+ clearInterval(this.timer);
|
|
|
+ clearInterval(this.timerBillRecords);
|
|
|
+ },
|
|
|
+ // 启动webSocket
|
|
|
+ onSocketOpen() {
|
|
|
+ this.webSocket=new socket({
|
|
|
+ sid:this.vuex_userId
|
|
|
+ })
|
|
|
+ this.webSocket.init(()=>{
|
|
|
+ console.log("启动成功");
|
|
|
+ //连接成功,清除轮询
|
|
|
+ clearInterval(this.timerBillRecords)
|
|
|
+ });
|
|
|
+ this.webSocket.error = ()=>{
|
|
|
+ //连接失败就轮询查询订单
|
|
|
+ this.timerBillRecords = setInterval(this.queryBillRecords,5000);
|
|
|
+ }
|
|
|
+ this.webSocket.acceptMessage=(res)=>{
|
|
|
+ console.log(res.content);
|
|
|
+ console.log(res.content==this.$global.socketMessage.payForPaymentCode);
|
|
|
+ //收到商户通知用户去支付
|
|
|
+ if (res.content==this.$global.socketMessage.payForPaymentCode) {
|
|
|
+ this.queryBillRecords()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
refreshCode() {
|
|
|
this.timer = setInterval(() => {
|
|
|
this.secret = totp.getSecret(this.id);
|
|
|
- console.log(this.secret);
|
|
|
}, 1000)
|
|
|
},
|
|
|
async initAvatat(url) {
|
|
|
@@ -78,13 +132,17 @@
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
+ async clearBillRecordCache(){
|
|
|
+ await this.$api.loginUser.clearBillRecordCache({userId:this.vuex_userId})
|
|
|
+ },
|
|
|
async queryBillRecords(){
|
|
|
let resp=await this.$api.loginUser.getBillrecordFromRedis({userId:this.vuex_userId})
|
|
|
if (this.$isEmpty(resp.data)) {
|
|
|
return
|
|
|
}
|
|
|
+ //清除缓存
|
|
|
+ await this.clearBillRecordCache()
|
|
|
if (resp.data.realPayAmount>0) {
|
|
|
- clearInterval(this.timerBillRecords)
|
|
|
//去支付
|
|
|
let params={
|
|
|
orderType:this.$global.orderType.USER_PAY,
|
|
|
@@ -95,47 +153,36 @@
|
|
|
if (!this.$isEmpty(res.data.prePayTn)) {
|
|
|
let prePayTn= JSON.parse(res.data.prePayTn)
|
|
|
this.$mpi.requestPayment(prePayTn).then(()=>{
|
|
|
- this.$dialog.showModal('支付成功',false).then(()=>{
|
|
|
- this.$api.loginUser.clearBillRecordCache({userId:this.vuex_userId})
|
|
|
- uni.navigateBack({
|
|
|
- delta:1
|
|
|
- })
|
|
|
- })
|
|
|
+ //通知商户端付款成功
|
|
|
+ this.sendInfo(resp.data)
|
|
|
+ this.handelResult('支付成功')
|
|
|
}).catch(err=>{
|
|
|
- this.$dialog.showModal('支付失败',false).then(()=>{
|
|
|
- this.$api.loginUser.clearBillRecordCache({userId:this.vuex_userId})
|
|
|
- uni.navigateBack({
|
|
|
- delta:1
|
|
|
- })
|
|
|
- })
|
|
|
+ this.handelResult('支付失败')
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
+ this.handelResult('支付失败')
|
|
|
+
|
|
|
+ }else{
|
|
|
+ this.handelResult('已使用积分抵扣成功')
|
|
|
}
|
|
|
},
|
|
|
+ handelResult(content){
|
|
|
+ this.$dialog.showModal(content,false).then(()=>{
|
|
|
+ this.$api.loginUser.clearBillRecordCache({userId:this.vuex_userId})
|
|
|
+ uni.reLaunch({
|
|
|
+ url:"/pages/mine/mine"
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ sendInfo(data){
|
|
|
+ let msg={
|
|
|
+ sid:data.shopId,
|
|
|
+ content:"账户到账 "+data.payAmount,
|
|
|
+ }
|
|
|
+ this.$api.webSocket.sendInfo(msg)
|
|
|
+ },
|
|
|
},
|
|
|
- async created(option) {
|
|
|
- let res = await this.$api.loginUser.detail({
|
|
|
- id: this.vuex_userId
|
|
|
- })
|
|
|
- this.nickName=res.data.nickName
|
|
|
- // this.avatar =(await this.initAvatat(res.data.avatar)).tempFilePath;
|
|
|
- //清除缓存
|
|
|
- await this.$api.loginUser.clearBillRecordCache({userId:this.vuex_userId})
|
|
|
- //轮询
|
|
|
- this.timerBillRecords = setInterval(this.queryBillRecords,5000);
|
|
|
- },
|
|
|
- async mounted(option) {
|
|
|
- //获取用户ID
|
|
|
- this.id = this.vuex_userId
|
|
|
- //生成动态密码
|
|
|
- this.refreshCode();
|
|
|
- },
|
|
|
- beforeDestroy() {
|
|
|
- clearInterval(this.timer);
|
|
|
- clearInterval(this.timerBillRecords);
|
|
|
- uni.hideLoading()
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
</script>
|
|
|
|