lock.uvue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <script setup lang='ts'>
  2. import { wechatPay, wechatPayRequest } from '@/services/user'
  3. import { ref } from 'vue'
  4. const props = defineProps({
  5. record: {
  6. type: Object,
  7. default: () => ({})
  8. }
  9. })
  10. const visible = ref(false)
  11. function handleOpen() {
  12. visible.value = true
  13. }
  14. const handlePay = async () => {
  15. console.log(props.record)
  16. try {
  17. const { prepayId, outTradeNo } = await wechatPay({
  18. subjectId: props.record.subjectId,
  19. })
  20. const { signature } = await wechatPayRequest({
  21. prepayId, outTradeNo
  22. })
  23. console.log(signature)
  24. uni.requestPayment({
  25. provider: "wxpay",
  26. timeStamp: String(new Date().getTime().toString()),
  27. nonceStr: outTradeNo,
  28. package: prepayId,
  29. paySign: signature,
  30. signType: "MD5",
  31. success: (res) => {
  32. console.log('res: ', res)
  33. uni.showToast({
  34. title: "支付成功",
  35. icon: 'success'
  36. });
  37. },
  38. fail: (err) => {
  39. console.error("err", err);
  40. uni.hideLoading();
  41. uni.showToast({
  42. title: "支付失败",
  43. icon: 'error'
  44. });
  45. }
  46. });
  47. } catch (err: any) {
  48. uni.showToast({
  49. title: err.message,
  50. icon: 'error'
  51. });
  52. }
  53. }
  54. </script>
  55. <template>
  56. <view class="absolute top-0 left-0 w-full h-full flex items-center justify-center bg1" @tap.stop="handleOpen">
  57. <cl-image src="https://oss.xiaoxiongcode.com/static/home/lock.png" mode="widthFix" width="30%" height="auto" />
  58. </view>
  59. <cl-popup v-model="visible" showClose :size="400" :show-header="false" direction="center">
  60. <view class="p-[40px] ">
  61. <cl-text class="text-center" color="#000" :size="20"> 小朋友,快叫爸爸妈妈帮忙,解锁更多精彩内容吧! </cl-text>
  62. <cl-button class="mt-4" size="large" type="warn" block @tap="handlePay"> 前往购课 </cl-button>
  63. </view>
  64. </cl-popup>
  65. </template>
  66. <style lang="scss" scoped>
  67. .bg1 {
  68. background-color: rgba(255, 255, 255, 0.5);
  69. }
  70. </style>