index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view>
  3. <view class="pay-view fx-h fx-ac fx-bc" v-if="isShow">
  4. <view class="bg"></view>
  5. <view class="pay-body">
  6. <view class="pay-inner fx-h fx-bc fx-ac">
  7. <image src="../../static/img/wating.png" mode="widthFix" class="alipay-icon"></image>
  8. <view class="pay-txt">如果您支付成功,点击已支付,如果支付取消,请点击重新支付!</view>
  9. <view class="fx-r" style="width: 100%;">
  10. <view class="btn1" @tap="tapClick">已支付</view>
  11. <view class="btn2" @tap="hide">取消</view>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <style>
  19. .pay-view{ position:fixed;top: 0px;left: 0px; width: 100%;height: 100%;z-index: 99;}
  20. .pay-view .bg{ position: absolute;top: 0;left: 0;width: 100%;height: 100%;background: rgba(0,0,0,0.6);}
  21. .alipay-icon{width: 80px;}
  22. .pay-view .pay-body{ border-radius: 10px;background: #fff;width: 90%;z-index: 9;}
  23. .pay-view .pay-inner{padding: 20px;}
  24. .pay-view .pay-txt{font-size: 14px;color: #303033;padding: 20px 0;}
  25. .pay-view .btn1{text-align: center;line-height: 30px;background: #FA4171;border-radius:2px;color: #fff;height: 30px; width: 47%;}
  26. .pay-view .btn2{margin-left: 5%;text-align: center;line-height: 30px;background: #f1f1f1;border-radius:2px;color: #000;height: 30px; width: 47%;}
  27. .pay-view .btn2:hover{opacity: .8;}
  28. </style>
  29. <script>
  30. import {mapState,mapMutations} from 'vuex';
  31. export default {
  32. computed: mapState(['user']),
  33. name: 'ui-pay',
  34. props: {
  35. },
  36. data() {
  37. return {
  38. isShow : false,
  39. orderId : "",
  40. interval : 0,
  41. fn : null
  42. }
  43. },
  44. mounted() {
  45. },
  46. methods: {
  47. show:function(orderId,fn){
  48. this.isShow = true;
  49. this.fn = fn;
  50. this.orderId = orderId;
  51. if(this.interval > 0) {
  52. clearInterval(this.interval);
  53. }
  54. this.interval = setInterval(()=>{
  55. this
  56. .request
  57. .post("checkPay",{orderId : this.orderId})
  58. .then(res=>{
  59. if(res.code == 200){
  60. clearInterval(this.interval);
  61. if(this.fn == null) {
  62. uni.redirectTo({
  63. url:"/pages/user/buy/order_ok"
  64. });
  65. } else {
  66. this.fn();
  67. }
  68. }
  69. })
  70. .catch(err=>{});
  71. },1000);
  72. },
  73. hide:function(){
  74. this.isShow = false;
  75. if(this.interval > 0) {
  76. clearInterval(this.interval);
  77. this.interval = 0;
  78. }
  79. },
  80. tapClick:function(){
  81. uni.showLoading({ title:"获取支付状态.."});
  82. this
  83. .request
  84. .post("checkPay",{orderId : this.orderId})
  85. .then(res=>{
  86. uni.hideLoading();
  87. if(res.code == 200) {
  88. clearInterval(this.interval);
  89. if(this.fn == null) {
  90. uni.redirectTo({
  91. url:"/pages/user/buy/order_ok"
  92. });
  93. } else {
  94. this.fn();
  95. }
  96. } else {
  97. uni.showToast({
  98. 'title' : "未支付成功,请稍等",
  99. duration : 1500,
  100. icon:'none'
  101. });
  102. }
  103. })
  104. .catch(err=>{
  105. console.log(err);
  106. uni.hideLoading();
  107. uni.showModal({ title: '系统提示', content: "获取失败:" + err, showCancel: false});
  108. });
  109. }
  110. }
  111. };
  112. </script>