|
@@ -1,13 +1,17 @@
|
|
|
+import popup from "$utils/tool/popup";
|
|
|
+import request, {InstructionsMessageType} from "$utils/request";
|
|
|
export default <LibMixins>{
|
|
|
|
|
|
data(){
|
|
|
return {
|
|
|
inputPayItem:{
|
|
|
integral:'其他余额',
|
|
|
+ crid:0,
|
|
|
format:false,
|
|
|
input:true,
|
|
|
value:''
|
|
|
},
|
|
|
+ authorization:true,
|
|
|
paySelect:0,
|
|
|
payOrder:['weChat','alipay'],
|
|
|
}
|
|
@@ -32,8 +36,127 @@ export default <LibMixins>{
|
|
|
this.paySelect = index;
|
|
|
}
|
|
|
|
|
|
+ },
|
|
|
+
|
|
|
+ payOrderInfoVerify(callback){
|
|
|
+
|
|
|
+ this.setWaitPattern();
|
|
|
+ if (!this.authorization) return popup.$toast('请同意充值服务协议');
|
|
|
+
|
|
|
+ return this.triggerPayOrder(callback);
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ payOrderInfo(obj){
|
|
|
+
|
|
|
+ let item = this.payList[this.paySelect] || undefined;
|
|
|
+
|
|
|
+ if (!item) {
|
|
|
+ popup.$toast('未知错误');
|
|
|
+ return obj.none();
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.$request({
|
|
|
+ url:'Pay/create_pay_order',
|
|
|
+ token:true,
|
|
|
+ data:{
|
|
|
+ crid: item.crid,
|
|
|
+ custom_amount: item.value || '',
|
|
|
+ pay_type: obj.data.type
|
|
|
+ },
|
|
|
+ message:InstructionsMessageType.other,
|
|
|
+ failMessage:true
|
|
|
+ }).then((data)=>{
|
|
|
+
|
|
|
+ if (data.isSuccess) {
|
|
|
+ window.open(data.data);
|
|
|
+ this.setWaitPattern();
|
|
|
+ }
|
|
|
+
|
|
|
+ return obj.none();
|
|
|
+
|
|
|
+ }).catch(obj.none);
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ // 设置等待模式
|
|
|
+ setWaitPattern(){
|
|
|
+
|
|
|
+ // 开启验证弹窗
|
|
|
+ this.openConfirm();
|
|
|
+
|
|
|
+ let nowTime = Math.floor(new Date().getTime() / 1000);
|
|
|
+
|
|
|
+ // 设置终止时间
|
|
|
+ this.pattern = setInterval(()=>{
|
|
|
+
|
|
|
+ let diff = Math.floor(new Date().getTime()/1000) - nowTime;
|
|
|
+
|
|
|
+ // 如果满足任意一种主动释放 本次循环
|
|
|
+ if (document.hidden === true || document.hidden === undefined || diff <= 300) {
|
|
|
+ clearInterval(this.pattern);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (document.hidden === true) {
|
|
|
+ this.checkPayStatus();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ },1000);
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ // 打开弹窗
|
|
|
+ openConfirm(){
|
|
|
+ popup.$confirm({
|
|
|
+ title:'是否支付完成?',
|
|
|
+ confirmText:'支付完成',
|
|
|
+ cancelText:'未完成',
|
|
|
+ confirm:()=> this.checkPayStatus()
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 查看是否 支付成功
|
|
|
+ checkPayStatus(){
|
|
|
+
|
|
|
+ // 防止未清除掉
|
|
|
+ clearInterval(this.pattern);
|
|
|
+
|
|
|
+ // 关闭弹窗
|
|
|
+ popup.closeConfirm();
|
|
|
+
|
|
|
+ return this.$request({
|
|
|
+ url:'user/get_user_info',
|
|
|
+ token:true,
|
|
|
+ failMessage:true,
|
|
|
+ loading:'验证中',
|
|
|
+ message: InstructionsMessageType.other
|
|
|
+ }).then((data)=>{
|
|
|
+
|
|
|
+ if (data.isSuccess) {
|
|
|
+ if (data.data.integral !== this.user.integral) {
|
|
|
+
|
|
|
+ this.user = data.data;
|
|
|
+
|
|
|
+ popup.$toast('支付成功');
|
|
|
+ } else {
|
|
|
+ popup.$toast('支付未成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.openConfirm();
|
|
|
+
|
|
|
+ }).catch(()=> this.openConfirm());
|
|
|
}
|
|
|
|
|
|
+ },
|
|
|
+
|
|
|
+ created() {
|
|
|
+ this.$store.dispatch('initializationPayPromise');
|
|
|
+ },
|
|
|
+
|
|
|
+ beforeUnmount() {
|
|
|
+ clearInterval(this.pattern);
|
|
|
}
|
|
|
|
|
|
}
|