|
@@ -42,25 +42,39 @@
|
|
|
<span class="fyy-h3 color-red" v-html="total"></span>元
|
|
|
</p>
|
|
|
<router-link to="/Pay">
|
|
|
- <van-button type="bigred" @click="pay">支付</van-button>
|
|
|
+ <van-button type="bigred" @click="pay" :loading="paying">支付</van-button>
|
|
|
</router-link>
|
|
|
</div>
|
|
|
+
|
|
|
+ <van-dialog
|
|
|
+ v-model="showAlipay"
|
|
|
+ title="支付宝扫码支付"
|
|
|
+ overlay
|
|
|
+ confirm = "paying = false"
|
|
|
+ >
|
|
|
+ <div ref="qrcodeDiv" class="qrcode"></div>
|
|
|
+ </van-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import remoteApi from '@/api/remoteApi'
|
|
|
+import QRCode from 'qrcodejs2'
|
|
|
+import Cookies from 'js-cookie'
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
+ paying: false,
|
|
|
area:{},
|
|
|
building:{},
|
|
|
room:{},
|
|
|
price:0,
|
|
|
roomId : null,
|
|
|
kwh : 0,
|
|
|
- payType: 'weipay'
|
|
|
+ payType: 'weipay',
|
|
|
+ showAlipay: false,
|
|
|
+ qrCodeUrl: ''
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
@@ -72,16 +86,17 @@ export default {
|
|
|
},
|
|
|
pay() {
|
|
|
var self = this
|
|
|
+ self.paying = true
|
|
|
+
|
|
|
+ self.$toast.loading({
|
|
|
+ message: '处理中...',
|
|
|
+ forbidClick: true,
|
|
|
+ loadingType: 'spinner',
|
|
|
+ duration: 10000
|
|
|
+ });
|
|
|
|
|
|
if(self.payType=='weipay'){
|
|
|
//首先要获取openid
|
|
|
- self.$toast.loading({
|
|
|
- message: '处理中...',
|
|
|
- forbidClick: true,
|
|
|
- loadingType: 'spinner',
|
|
|
- duration: 10000
|
|
|
- });
|
|
|
-
|
|
|
remoteApi.prepareWXPay(self.roomId,self.payType,self.kwh,self.total).then(resp=>{
|
|
|
self.$toast.clear()
|
|
|
|
|
@@ -92,10 +107,50 @@ export default {
|
|
|
|
|
|
var url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`
|
|
|
|
|
|
- alert(url)
|
|
|
window.location.href = url
|
|
|
}
|
|
|
else{
|
|
|
+ self.paying = false
|
|
|
+ self.$toast.fail(resp.message)
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else if(self.payType=='alipay') {
|
|
|
+ remoteApi.prepareAliPay(self.roomId,self.payType,self.kwh,self.total).then(resp=>{
|
|
|
+ if(resp.result){
|
|
|
+ var recordId = resp.data.recordId;
|
|
|
+ return remoteApi.tradePrecreatePay(recordId);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ self.paying = false
|
|
|
+ self.$toast.fail(resp.message)
|
|
|
+ }
|
|
|
+ }).then(resp=>{
|
|
|
+ self.$toast.clear()
|
|
|
+
|
|
|
+ if(resp==null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(resp);
|
|
|
+
|
|
|
+ if(resp.result) {
|
|
|
+ self.showAlipay = true;
|
|
|
+
|
|
|
+ //对话框显示后才能正常获取到$refs.qrcodeDiv
|
|
|
+ self.$nextTick(()=>{
|
|
|
+ var qrcode = new QRCode(self.$refs.qrcodeDiv, {
|
|
|
+ text: resp.data,
|
|
|
+ width: 200,
|
|
|
+ height: 200,
|
|
|
+ colorDark: '#000000',
|
|
|
+ colorLight: '#ffffff',
|
|
|
+ correctLevel: QRCode.CorrectLevel.H
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ self.paying = false
|
|
|
self.$toast.fail(resp.message)
|
|
|
}
|
|
|
});
|
|
@@ -111,6 +166,10 @@ export default {
|
|
|
// 当前页面是否获取到了openid?
|
|
|
this.roomId = this.$route.query.roomId;
|
|
|
|
|
|
+ if(this.roomId==null || this.roomId.length==0){
|
|
|
+ this.roomId = Cookies.get("selectedRoomId");
|
|
|
+ }
|
|
|
+
|
|
|
this.$toast.loading({
|
|
|
message: '加载中...',
|
|
|
forbidClick: true,
|
|
@@ -142,5 +201,6 @@ export default {
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
-<style scoped>
|
|
|
+<style lang="scss" scoped>
|
|
|
+
|
|
|
</style>
|