洛阳学员端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.1 KiB

  1. <template>
  2. <view class="">
  3. <web-view :src="$store.state.webViewUrl" @onPostMessage="postMessage" @message="postMessage"></web-view>
  4. <!-- <web-view src="http://192.168.1.44:92/vue/wxStudentCertificate3" @onPostMessage="postMessage" @message="postMessage"></web-view> -->
  5. </view>
  6. </template>
  7. <script>
  8. let polling = null
  9. let timerNum = 0
  10. import { order_info } from '@/config/api.js'
  11. export default {
  12. data() {
  13. return {
  14. iswxPay: false
  15. }
  16. },
  17. onLoad(options) {
  18. this.outTradeNo = options.outTradeNo
  19. this.initWx()
  20. this.order_infoFn()
  21. },
  22. onShow() {
  23. if(this.iswxPay) {
  24. timerNum = 0
  25. this.pollFn()
  26. }
  27. },
  28. onHide() {
  29. clearInterval(polling)
  30. polling = null
  31. },
  32. methods: {
  33. // 监听h5事件
  34. postMessage(res) {
  35. console.log('监听到了')
  36. let item = res.detail.data[0]
  37. console.log(res)
  38. console.log('监听到的发送事件')
  39. console.log(item)
  40. if(item.action=='ysb-wxPay') {
  41. // this.$u.toast('用户点击了微信支付')
  42. this.iswxPay = true
  43. this.wxPay(item)
  44. }else if(item.action=='ysb-paySuccess') {
  45. this.$u.toast('支付成功')
  46. this.iswxPay = false
  47. this.$store.dispatch('getUserInfo')
  48. setTimeout(()=>{
  49. uni.switchTab({
  50. url: '/pages/tabbar/learnCar/index'
  51. })
  52. },800)
  53. }
  54. },
  55. // 轮询定时
  56. pollFn() {
  57. polling = setInterval(async ()=>{
  58. timerNum ++
  59. if(timerNum>10) {
  60. clearInterval(polling)
  61. polling = null
  62. }
  63. await this.order_infoFn()
  64. },1000)
  65. },
  66. // 查询订单状态
  67. async order_infoFn() {
  68. const {data: res} = await order_info({outTradeNo:this.outTradeNo})
  69. if(res.status==10) {
  70. this.$u.toast('支付成功')
  71. clearInterval(polling)
  72. polling = null
  73. setTimeout(()=>{
  74. uni.switchTab({
  75. url: '/pages/tabbar/learnCar/index'
  76. })
  77. },1500)
  78. }
  79. console.log('订单状态')
  80. console.log(res)
  81. },
  82. // "action": "lyxc-wxPay",
  83. // "miniProgramType": 2,
  84. // "miniAppId": "gh_89b377cbc340",
  85. // "path": "/pages/wxPayOnly/wxPayOnly?channelNo=QD202404083509&orderNo=20240423170705024771&inpartNo=820198016000045&merchantName=中原智慧新校园&amount=1&redMsg=&payType=04"
  86. // 跳转到微信支付
  87. wxPay(item) {
  88. console.log(item)
  89. // #ifdef APP-PLUS
  90. this.sweixin ? this.sweixin.launchMiniProgram({
  91. path: item.path, //跳转小程序页面路径 pages/index/index
  92. type: item.miniProgramType, //可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
  93. id: item.miniAppId //小程序的原始id
  94. }) : plus.nativeUI.alert('当前环境不支持微信操作!');
  95. // #endif
  96. },
  97. // 初始化微信支付方法
  98. initWx() {
  99. // #ifdef APP-PLUS
  100. plus.share.getServices((s) => {
  101. var shares = {};
  102. for (var i = 0; i < s.length; i++) {
  103. var t = s[i];
  104. console.log("...........", t);
  105. shares[t.id] = t;
  106. }
  107. var sweixin = shares['weixin'];
  108. this.sweixin = sweixin
  109. }, function(e) {
  110. console.log("获取分享服务列表失败:" + e.message);
  111. });
  112. // #endif
  113. },
  114. }
  115. }
  116. </script>
  117. <style>
  118. </style>