reward.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="answerPopup-box bg">
  3. <!-- 正确 -->
  4. <image class="tipimg" src="/static/images/course_answer_img.png"
  5. mode="aspectFill"></image>
  6. <view class="answerPopup-title">恭喜你,回答正确</view>
  7. <view class="answerPopup-desc">您有一份奖励待领取哦</view>
  8. <view class="answerPopup-btn" @click="handleReceive">领取</view>
  9. <view class="footer-tips">重庆云联融智提供技术支持</view>
  10. </view>
  11. </template>
  12. <script>
  13. import wx from 'jweixin-module';
  14. import { initJssdk } from "@/utils/common.js"
  15. export default {
  16. data() {
  17. return {
  18. mchId:'',
  19. packageInfo: ''
  20. }
  21. },
  22. methods: {
  23. handleReceive() {
  24. this.packageInfo = uni.getStorageSync('receive_package') || ''
  25. this.mchId = uni.getStorageSync('mchId') || ''
  26. this.initWXConfig(this.packageInfo)
  27. },
  28. handleTest(packageVal,appId,mchId) {
  29. const that = this
  30. wx.ready(() => {
  31. // config信息验证后会执行ready方法,所有接口调用都必须在config之后
  32. wx.checkJsApi({
  33. jsApiList: ['requestMerchantTransfer'],
  34. success: function(res) {
  35. if (res.checkResult['requestMerchantTransfer']) {
  36. WeixinJSBridge.invoke('requestMerchantTransfer', {
  37. mchId: mchId || that.mchId,
  38. appId: appId,
  39. package: packageVal,
  40. },
  41. function(res) {
  42. if (res.err_msg === 'requestMerchantTransfer:ok') {
  43. // res.err_msg将在页面展示成功后返回应用时返回success,并不代表付款成功
  44. }
  45. }
  46. );
  47. } else {
  48. alert('你的微信版本过低,请更新至最新版本。');
  49. }
  50. }
  51. });
  52. });
  53. wx.error(function(res){
  54. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
  55. });
  56. },
  57. initWXConfig(packageVal) {
  58. const isWechat = String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  59. if(isWechat) {
  60. let url = window.location.href.split('#')[0]
  61. initJssdk((data)=>{
  62. this.handleTest(packageVal,data.appId,data.mchId)
  63. },url)
  64. } else {
  65. uni.showToast({
  66. title: '请在微信浏览器中打开'
  67. })
  68. }
  69. }
  70. },
  71. onUnload() {
  72. uni.removeStorageSync('receive_package')
  73. uni.removeStorageSync('mchId')
  74. }
  75. }
  76. </script>
  77. <style scoped lang="scss">
  78. @mixin u-flex($flexD, $alignI, $justifyC) {
  79. display: flex;
  80. flex-direction: $flexD;
  81. align-items: $alignI;
  82. justify-content: $justifyC;
  83. }
  84. .footer-tips {
  85. width: 100%;
  86. position: absolute;
  87. left: 0;
  88. bottom: 14rpx;
  89. text-align: center;
  90. font-family: PingFang SC,PingFang SC;
  91. font-weight: 500;
  92. font-size: 12px;
  93. color: #bbb;
  94. }
  95. .answerPopup {
  96. &-box {
  97. width: 100%;
  98. height: 100vh;
  99. background: linear-gradient(180deg, #FFFAF6 50%, #FEECD8 100%);
  100. background-color: #fff;
  101. font-weight: 400;
  102. box-sizing: border-box;
  103. position: relative;
  104. @include u-flex(column, center, center);
  105. font-family: PingFang SC, PingFang SC;
  106. font-weight: 400;
  107. .tipimg {
  108. width: 206rpx;
  109. height: 206rpx;
  110. margin-bottom: 16rpx;
  111. }
  112. }
  113. &-title {
  114. font-weight: 600;
  115. font-size: 36rpx;
  116. color: #222222;
  117. }
  118. &-desc {
  119. margin-top: 30rpx;
  120. font-size: 28rpx;
  121. color: #757575;
  122. }
  123. &-btn {
  124. width: 464rpx;
  125. height: 84rpx;
  126. margin-top: 10vh;
  127. margin-bottom: 16vh;
  128. background: #FF5C03;
  129. border-radius: 42rpx;
  130. font-weight: 500;
  131. font-size: 32rpx;
  132. color: #FFFFFF;
  133. text-align: center;
  134. line-height: 84rpx;
  135. }
  136. }
  137. </style>