PurchaseModal.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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">{{ $t('mine.buy') }}</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]">{{ $t('wallet.balance', { balance: 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. {{ $t('wallet.tips') }}
  38. </div>
  39. <div class="btn">
  40. <van-button class="AlimamaShuHeiTi" type="primary" block round @click="buy">{{
  41. $t('wallet.pay')
  42. }}</van-button>
  43. </div>
  44. </ion-content>
  45. </ion-modal>
  46. </template>
  47. <script setup>
  48. import { IonModal, IonContent } from '@ionic/vue'
  49. import { ref } from 'vue'
  50. import { useIAPStore } from '@/stores/IAP'
  51. import { storeToRefs } from 'pinia'
  52. import uri from 'fast-uri'
  53. import { useUserStore } from '@/stores/user'
  54. const props = defineProps({
  55. show: {
  56. type: Boolean,
  57. default: false
  58. }
  59. })
  60. const emit = defineEmits(['update:show'])
  61. function dismiss() {
  62. emit('update:show', false)
  63. }
  64. const userStore = useUserStore()
  65. const { user, balance } = storeToRefs(userStore)
  66. const { getBalance } = userStore
  67. const { products } = storeToRefs(useIAPStore())
  68. const selected = ref(0)
  69. function buy() {
  70. const { store, ProductType, Platform } = CdvPurchase
  71. store.when().finished(() => {
  72. emit('update:show', false)
  73. getBalance()
  74. })
  75. store.validator = uri.resolve(import.meta.env.VITE_HTTP_BASE_URL, '/api/userBalances/recharge/' + user.value.id)
  76. // store.validator = 'http://192.168.6.215:3333/api/userBalances/recharge/1'
  77. console.log(products.value[selected.value].id)
  78. const product = store.get(products.value[selected.value].id, Platform.GOOGLE_PLAY)
  79. const myTransaction = store.findInLocalReceipts(product)
  80. console.log('myTransaction', myTransaction)
  81. if (myTransaction) {
  82. myTransaction.verify()
  83. }
  84. console.log('product', product)
  85. product.getOffer().order()
  86. }
  87. </script>
  88. <style lang="less" scoped>
  89. .buy-page {
  90. --van-popup-background: #20223c;
  91. padding: 21px 18px;
  92. }
  93. .choose-btn {
  94. width: calc(50vw - 27px);
  95. height: 88px;
  96. background: #2d3059;
  97. border-radius: 8px;
  98. border: 1px solid #525686;
  99. margin-top: 18px;
  100. display: inline-flex;
  101. position: relative;
  102. .btn-tag {
  103. font-size: 12px;
  104. color: #ffffff;
  105. line-height: 18px;
  106. position: absolute;
  107. top: 0;
  108. left: 0;
  109. width: 62px;
  110. height: 18px;
  111. background: #7f82af;
  112. border-radius: 8px 0px 8px 0px;
  113. text-align: center;
  114. }
  115. &.active {
  116. background: #2d3059 linear-gradient(318deg, rgba(255, 87, 186, 0.1) 0%, rgba(255, 87, 186, 0.2) 100%);
  117. border-radius: 8px;
  118. border: 2px solid #ff57ba;
  119. .sub {
  120. span {
  121. color: #fff !important;
  122. }
  123. }
  124. .btn-tag {
  125. background: #2d3059 linear-gradient(-318deg, #ff3b20, #ff57ba);
  126. left: -2px;
  127. top: -1px;
  128. }
  129. }
  130. }
  131. </style>