PurchaseModal.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <ion-modal :is-open="show" :initial-breakpoint="0.7" :breakpoints="[0.7]" :handle="false" @didDismiss="dismiss">
  3. <ion-content class="ion-padding">
  4. <div class="news-title text-white text-lg AlimamaShuHeiTi relative">
  5. <span class="z-[1] relative">購買金豆</span>
  6. <img class="w-[78px] h-[16px] absolute bottom-0 left-0 z-0" src="@/assets/png-xiantiao1.png" alt="" />
  7. </div>
  8. <div class="money text-xs text-white mt-[5px]">帳戶餘額:{{ balance }}金豆</div>
  9. <div class="choose-list flex flex-wrap justify-between overflow-auto" style="height: 350px">
  10. <!-- <div class="choose-btn flex flex-col items-center justify-center">
  11. <div class="val text-white">
  12. <span class="text-[16px]">¥</span>
  13. <span class="text-[26px]">19.9</span>
  14. </div>
  15. <div class="sub text-xs text-white">1990金豆+<span class="text-[#FFEF00]">送888金豆</span></div>
  16. <div class="btn-tag">首充福利</div>
  17. </div> -->
  18. <div
  19. v-for="(item, i) in products"
  20. :key="item.id"
  21. class="choose-btn flex flex-col items-center justify-center"
  22. :class="{ active: selected === i }"
  23. @click="selected = i"
  24. >
  25. <div class="val text-white">
  26. <!-- <span class="text-[16px]">¥</span> -->
  27. <span class="text-[16px]">{{ item.pricing.price }}</span>
  28. </div>
  29. <div class="sub text-xs text-[#FFEF00]">
  30. {{ item.title }}
  31. <!-- <span class="text-[#FFEF00]">送888金豆</span> -->
  32. </div>
  33. <!-- <div class="btn-tag">粉丝福利</div> -->
  34. </div>
  35. </div>
  36. <div class="tips text-[10px] text-[#61657A] text-center py-4">
  37. 虛擬商品購買後不可退換,青少年請在家長陪同下購買
  38. </div>
  39. <div class="btn">
  40. <van-button class="AlimamaShuHeiTi" type="primary" block round @click="buy">立即支付</van-button>
  41. </div>
  42. </ion-content>
  43. </ion-modal>
  44. </template>
  45. <script setup>
  46. import { IonModal, IonContent } from '@ionic/vue'
  47. import { ref } from 'vue'
  48. import { useIAPStore } from '@/stores/IAP'
  49. import { storeToRefs } from 'pinia'
  50. import uri from 'fast-uri'
  51. import { useUserStore } from '@/stores/user'
  52. const props = defineProps({
  53. show: {
  54. type: Boolean,
  55. default: false
  56. }
  57. })
  58. const emit = defineEmits(['update:show'])
  59. function dismiss() {
  60. emit('update:show', false)
  61. }
  62. const userStore = useUserStore()
  63. const { user, balance } = storeToRefs(userStore)
  64. const { getBalance } = userStore
  65. const { products } = storeToRefs(useIAPStore())
  66. const selected = ref(0)
  67. function buy() {
  68. const { store, ProductType, Platform } = CdvPurchase
  69. store.when().finished(() => {
  70. getBalance()
  71. })
  72. store.validator = uri.resolve(import.meta.env.VITE_HTTP_BASE_URL, '/api/userBalances/recharge/' + user.id)
  73. // store.validator = 'http://192.168.6.215:3333/api/userBalances/recharge/1'
  74. console.log(products.value[selected.value].id)
  75. const product = store.get(products.value[selected.value].id, Platform.GOOGLE_PLAY)
  76. const myTransaction = store.findInLocalReceipts(product)
  77. console.log('myTransaction', myTransaction)
  78. console.log('product', product)
  79. product.getOffer().order()
  80. }
  81. </script>
  82. <style lang="less" scoped>
  83. .buy-page {
  84. --van-popup-background: #20223c;
  85. padding: 21px 18px;
  86. }
  87. .choose-btn {
  88. width: calc(50vw - 27px);
  89. height: 88px;
  90. background: #2d3059;
  91. border-radius: 8px;
  92. border: 1px solid #525686;
  93. margin-top: 18px;
  94. display: inline-flex;
  95. position: relative;
  96. .btn-tag {
  97. font-size: 12px;
  98. color: #ffffff;
  99. line-height: 18px;
  100. position: absolute;
  101. top: 0;
  102. left: 0;
  103. width: 62px;
  104. height: 18px;
  105. background: #7f82af;
  106. border-radius: 8px 0px 8px 0px;
  107. text-align: center;
  108. }
  109. &.active {
  110. background: #2d3059 linear-gradient(318deg, rgba(255, 87, 186, 0.1) 0%, rgba(255, 87, 186, 0.2) 100%);
  111. border-radius: 8px;
  112. border: 2px solid #ff57ba;
  113. .sub {
  114. span {
  115. color: #fff !important;
  116. }
  117. }
  118. .btn-tag {
  119. background: #2d3059 linear-gradient(-318deg, #ff3b20, #ff57ba);
  120. left: -2px;
  121. top: -1px;
  122. }
  123. }
  124. }
  125. </style>