index.vue 2.6 KB

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