12
12
</el-descriptions >
13
13
</el-card >
14
14
15
- <!-- 微信支付 -->
15
+ <!-- 支付选择框 -->
16
16
<el-card style =" margin-top : 10px " >
17
17
<!-- 支付宝 -->
18
18
<el-descriptions title =" 选择支付宝支付" >
19
19
</el-descriptions >
20
20
<div class =" pay-channel-container" >
21
- <div class =" box" v-for =" channel in aliPayChannels" :key =" channel.code" >
21
+ <div class =" box" v-for =" channel in aliPayChannels" :key =" channel.code" @click = " submit(channel.code) " >
22
22
<img :src =" icons[channel.code]" >
23
23
<div class =" title" >{{ channel.name }}</div >
24
24
</div >
40
40
</div >
41
41
</div >
42
42
</el-card >
43
+
44
+ <!-- 支付二维码 -->
45
+ <el-dialog :title =" qrCode.title" :visible.sync =" qrCode.visible" width =" 350px" append-to-body
46
+ :close-on-press-escape =" false" >
47
+ <qrcode-vue :value =" qrCode.url" size =" 310" level =" H" />
48
+ </el-dialog >
43
49
</div >
44
50
</template >
45
51
<script >
52
+ import QrcodeVue from ' qrcode.vue'
46
53
import { DICT_TYPE , getDictDatas } from " @/utils/dict" ;
47
- import { getOrder } from ' @/api/pay/order' ;
48
- import { PayOrderStatusEnum } from " @/utils/constants" ;
54
+ import { getOrder , submitOrder } from ' @/api/pay/order' ;
55
+ import { PayChannelEnum , PayOrderStatusEnum } from " @/utils/constants" ;
49
56
50
57
export default {
51
58
name: " PayOrderSubmit" ,
52
59
components: {
60
+ QrcodeVue,
53
61
},
54
62
data () {
55
63
return {
@@ -69,6 +77,12 @@ export default {
69
77
wx_pub: require (" @/assets/images/pay/icon/wx_pub.svg" ),
70
78
mock: require (" @/assets/images/pay/icon/mock.svg" ),
71
79
},
80
+ qrCode: { // 支付二维码
81
+ url: ' ' ,
82
+ title: ' ' ,
83
+ visible: false ,
84
+ },
85
+ interval: undefined , // 定时任务,轮询是否完成支付
72
86
};
73
87
},
74
88
created () {
@@ -94,32 +108,90 @@ export default {
94
108
}
95
109
}
96
110
},
97
- /** 获得请假信息 */
111
+ /** 获得支付信息 */
98
112
getDetail () {
99
113
// 1.1 未传递订单编号
100
114
if (! this .id ) {
101
115
this .$message .error (' 未传递支付单号,无法查看对应的支付信息' );
102
- this .$router . go ( - 1 );
116
+ this .goBackToList ( );
103
117
return ;
104
118
}
105
119
getOrder (this .id ).then (response => {
106
120
// 1.2 无法查询到支付信息
107
121
if (! response .data ) {
108
122
this .$message .error (' 支付订单不存在,请检查!' );
109
- this .$router . go ( - 1 );
123
+ this .goBackToList ( );
110
124
return ;
111
125
}
112
126
// 1.3 订单已支付
113
127
if (response .data .status !== PayOrderStatusEnum .WAITING .status ) {
114
128
this .$message .error (' 支付订单不处于待支付状态,请检查!' );
115
- this .$router . go ( - 1 );
129
+ this .goBackToList ( );
116
130
return ;
117
131
}
118
132
119
133
// 2. 可以展示
120
134
this .payOrder = response .data ;
121
135
});
122
136
},
137
+ /** 提交支付 */
138
+ submit (channelCode ) {
139
+ submitOrder ({
140
+ id: this .id ,
141
+ channelCode: channelCode
142
+ }).then (response => {
143
+ // 不同的支付,调用不同的策略
144
+ if (channelCode === PayChannelEnum .ALIPAY_QR .code ) {
145
+ this .submitAfterAlipayQr (response .data .invokeResponse )
146
+ }
147
+ // 打开轮询任务
148
+ this .createQueryInterval ()
149
+ })
150
+ },
151
+ /** 提交支付后(支付宝扫码支付) */
152
+ submitAfterAlipayQr (invokeResponse ) {
153
+ this .qrCode = {
154
+ title: ' 请使用支付宝“扫一扫”扫码支付' ,
155
+ url: invokeResponse .qrCode ,
156
+ visible: true
157
+ }
158
+ },
159
+ /** 轮询查询任务 */
160
+ createQueryInterval () {
161
+ this .interval = setInterval (() => {
162
+ getOrder (this .id ).then (response => {
163
+ // 已支付
164
+ if (response .data .status === PayOrderStatusEnum .SUCCESS .status ) {
165
+ this .clearQueryInterval ();
166
+ this .$message .success (' 支付成功!' );
167
+ this .goBackToList ();
168
+ }
169
+ // 已取消
170
+ if (response .data .status === PayOrderStatusEnum .CLOSED .status ) {
171
+ this .clearQueryInterval ();
172
+ this .$message .error (' 支付已关闭!' );
173
+ this .goBackToList ();
174
+ }
175
+ })
176
+ }, 1000 * 2 )
177
+ },
178
+ /** 清空查询任务 */
179
+ clearQueryInterval () {
180
+ // 清空各种弹窗
181
+ this .qrCode = {
182
+ title: ' ' ,
183
+ url: ' ' ,
184
+ visible: false
185
+ }
186
+ // 清空任务
187
+ clearInterval (this .interval )
188
+ this .interval = undefined
189
+ },
190
+ /** 回到列表 **/
191
+ goBackToList () {
192
+ this .$tab .closePage ();
193
+ this .$router .go (- 1 );
194
+ }
123
195
}
124
196
};
125
197
</script >
0 commit comments