index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <Container
  3. title="挑战"
  4. :scrollStyle="{
  5. padding: 0,
  6. }"
  7. :showBack="false"
  8. >
  9. <view>
  10. <view class="bg">
  11. <div class="setting" @click="toRule">规则</div>
  12. </view>
  13. </view>
  14. <template #stick>
  15. <button class="btn" @click="toAdd">立即报名!参与挑战!</button>
  16. </template>
  17. </Container>
  18. </template>
  19. <script setup>
  20. import Container from "../../components/Container/Container.vue";
  21. import { request } from "../../utils/request";
  22. import { router } from "../../utils/router";
  23. import { onShow } from "@dcloudio/uni-app";
  24. import { ref, getCurrentInstance } from "vue";
  25. import ext from "../../ext.json";
  26. const instance = getCurrentInstance();
  27. const isPay = ref(true);
  28. const p = ref(0);
  29. onShow(async () => {
  30. const res = request(
  31. "api/question_bank/question_reception/challenge_registration_log/detail"
  32. );
  33. if (res.data) return;
  34. isPay.value = false;
  35. request(
  36. "api/question_bank/question_reception/recharge_package/list",
  37. {
  38. package_type: 2,
  39. },
  40. "post"
  41. ).then(async (res) => {
  42. p.value = res.data.data[0].id;
  43. });
  44. });
  45. const toRule = () => {
  46. router.push({
  47. url: "/pages/challenge/rule",
  48. });
  49. };
  50. const toAdd = async () => {
  51. if (isPay.value) {
  52. router.push({
  53. url: "/pages/challenge/addContant",
  54. });
  55. return;
  56. }
  57. uni.login({
  58. provider: instance.proxy.$mpPlatform.substring(3),
  59. success: async ({ code }) => {
  60. const package_id = p.value;
  61. // 先调用新增订单再支付
  62. const order = await request(
  63. "api/question_bank/question_reception/orders/add",
  64. {
  65. package_id,
  66. }
  67. );
  68. const e = await request(
  69. "api/question_bank/question_reception/orders/wechat_pay",
  70. {
  71. code,
  72. order_id: order.data.order_id,
  73. app_id: ext.extAppid,
  74. }
  75. );
  76. uni.requestPayment({
  77. provider: "wxpay",
  78. timeStamp: e.data.timeStamp, //时间戳
  79. nonceStr: e.data.nonceStr, //随机字符串
  80. package: e.data.package, //prepay_id
  81. signType: e.data.signType, //签名算法MD5
  82. paySign: e.data.paySign, //签名,
  83. success(res) {
  84. console.log(res);
  85. router.push({
  86. url: "/pages/challenge/addContant",
  87. });
  88. },
  89. fail(err) {
  90. console.log(err);
  91. },
  92. });
  93. },
  94. });
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. .bg {
  99. width: 100%;
  100. height: 1734rpx;
  101. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/IFolqhKEbaTWdBgII6gjvqMKrf8WUbbgEpoeRH5t.png");
  102. background-size: cover;
  103. padding: 32rpx;
  104. box-sizing: border-box;
  105. position: relative;
  106. .setting {
  107. position: absolute;
  108. right: 0;
  109. top: 200rpx;
  110. background: rgba(0, 0, 0, 0.5);
  111. border-radius: 500rpx 0rpx 0rpx 500rpx;
  112. font-weight: 500;
  113. font-size: 24rpx;
  114. color: #ffffff;
  115. padding: 8rpx;
  116. }
  117. }
  118. .btn {
  119. width: 660rpx;
  120. position: absolute;
  121. bottom: 3%;
  122. left: 50%;
  123. transform: translateX(-50%);
  124. }
  125. </style>