pay-button.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <!-- pay 支付按钮 -->
  3. <div class="pay-wrapper">
  4. <slot name="balance"></slot>
  5. <div class="pay-btn">
  6. <div class="iframe-pay"
  7. v-show="currentCurrencyInfo.currencyCode == 'USD'">
  8. <div class="token-pay"
  9. @click="clickPayUSD">
  10. Pay ${{finalAmountData.rechargeAmountValue > 0 && USDepositStatus != 'SUCCESS' ? finalAmountData.rechargeAmountValue : finalAmountData.orderAmountValue}}
  11. </div>
  12. <!-- <iframe
  13. class="iframe-pay"
  14. ref="iframe"
  15. :src="`${payConfig.paypalHtml}?paypalClientId=${payConfig.paypalClientId}&amount=${props.finalAmountData.finalAmountValue}`"></iframe> -->
  16. </div>
  17. <div class="token-pay"
  18. :class="{ disabled: Number(currentCurrencyInfo.balance) < Number(payConfig.amount) }"
  19. v-if="currentCurrencyInfo.currencyCode != 'USD'"
  20. @click="balancePay">
  21. Pay {{payConfig.amount || 0}} {{currentCurrencyInfo.tokenSymbol}}
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { onMounted, ref, defineProps, defineEmits, watch, defineExpose } from "vue";
  28. import { PlayType } from '@/types';
  29. import {payTaskLuckdropWithBalance} from "@/http/publishApi"
  30. import Report from "@/log-center/log"
  31. import {setChromeStorage, getChromeStorage} from "@/uilts/chromeExtension"
  32. const props = defineProps({
  33. finalAmountData: {
  34. type: Object,
  35. default: () => {
  36. return {
  37. balance: "",
  38. feeAmountValue: 0,
  39. feeDesc: 0,
  40. orderAmountValue: 0,
  41. rechargeAmountValue: 0
  42. }
  43. },
  44. },
  45. payConfig: {
  46. type: Object,
  47. default: () => {
  48. return {
  49. paypalClientId: '',
  50. paypalHtml: 'https://d1mcov78iir8kk.cloudfront.net/website/paypal_1.html'
  51. }
  52. }
  53. },
  54. currentCurrencyInfo: {
  55. type: Object,
  56. default: () => {
  57. }
  58. },
  59. USDepositStatus: {
  60. type: String,
  61. default: 'DEFAULT'
  62. },
  63. bizType: {
  64. type: String,
  65. default: PlayType.treasure
  66. }
  67. });
  68. let iframe = ref(null);
  69. let payIng = false;
  70. watch(
  71. () => props.finalAmountData.finalAmountValue,
  72. (newVal) => {
  73. // iframe.value.contentWindow.postMessage({
  74. // actionType: "setAmount", amount: newVal
  75. // },
  76. // "*"
  77. // );
  78. },
  79. {
  80. deep: true
  81. }
  82. );
  83. const emits = defineEmits(["payFinish"]);
  84. const balancePay = () => {
  85. Report.reportLog({
  86. pageSource: Report.pageSource.previewPage,
  87. businessType: Report.businessType.buttonClick,
  88. objectType: Report.objectType.confirmButton
  89. }, {
  90. type: Report.getCurrentBizType(props.bizType)
  91. });
  92. if(payIng) {
  93. return;
  94. }
  95. payIng = true;
  96. payTaskLuckdropWithBalance({
  97. params: {
  98. currencyCode: props.currentCurrencyInfo.currencyCode,
  99. postId: props.payConfig.postId
  100. }
  101. }).then(res => {
  102. if(res.code == 0) {
  103. emits("payFinish", {...res.data});
  104. }
  105. payIng = false;
  106. }).catch(() => {
  107. payIng = false;
  108. })
  109. }
  110. const clickPayUSD = () => {
  111. if(props.finalAmountData.rechargeAmountValue > 0 && props.USDepositStatus != 'SUCCESS') {
  112. setTimeout(() => {
  113. emits("showDepositMask", {});
  114. }, 1000)
  115. chrome.tabs.getCurrent(tab =>{
  116. let achPayInfo = {
  117. amountValue: props.finalAmountData.rechargeAmountValue,
  118. tab: tab
  119. };
  120. let guideUrl = chrome.runtime.getURL('/iframe/ach-cashier.html');
  121. setChromeStorage({ achPayInfo : JSON.stringify(achPayInfo)});
  122. chrome.tabs.create({
  123. url: guideUrl
  124. });
  125. })
  126. } else {
  127. balancePay();
  128. }
  129. }
  130. onMounted(() => {
  131. // window.addEventListener("message", function (event) {
  132. // if (event.data && event.data.actionType) {
  133. // switch (event.data.actionType) {
  134. // case "payCallBack":
  135. // console.log(
  136. // "payCallBack",
  137. // event.data.orderData,
  138. // event.data.transaction
  139. // );
  140. // emits("payFinish", {...event.data, payNetwork: 'pay'});
  141. // break;
  142. // }
  143. // }
  144. // });
  145. });
  146. defineExpose({
  147. balancePay
  148. })
  149. </script>
  150. <style lang="scss" scoped>
  151. .pay-wrapper {
  152. width: 100%;
  153. height: 80px;
  154. background-color: #fff;
  155. position: absolute;
  156. left: 0;
  157. bottom: 0;
  158. box-shadow: 0px -1px 0px #ECECEC;
  159. border-bottom-right-radius: 16px;
  160. padding: 12px 30px;
  161. box-sizing: border-box;
  162. display: flex;
  163. align-items: center;
  164. justify-content: flex-end;
  165. border-bottom-left-radius: 16px;
  166. z-index: 999;
  167. .pay-msg {
  168. text-align: right;
  169. margin-right: 25px;
  170. .row {
  171. font-weight: 600;
  172. font-size: 16px;
  173. color: #1D9BF0;
  174. display: flex;
  175. align-items: center;
  176. justify-content: flex-end;
  177. margin-bottom: 6px;
  178. span {
  179. display: inline-block;
  180. color: #000000;
  181. margin-left: 6px;
  182. }
  183. .icon {
  184. width: 14px;
  185. margin-left:6px;
  186. }
  187. .desc {
  188. margin-right:6px
  189. }
  190. }
  191. .msg {
  192. font-size: 13px;
  193. color: #898989;
  194. }
  195. }
  196. .pay-btn {
  197. height: 48px;
  198. .token-pay {
  199. height: 100%;
  200. background: #1D9BF0;
  201. border-radius: 10000px;
  202. display: flex;
  203. align-items: center;
  204. justify-content: center;
  205. font-weight: 600;
  206. font-size: 18px;
  207. color: #fff;
  208. padding: 0 30px;
  209. word-break: break-all;
  210. cursor: pointer;
  211. &.disabled {
  212. background: #DEDEDE;
  213. }
  214. }
  215. .iframe-pay {
  216. width: 100%;
  217. height: 100%;
  218. }
  219. iframe {
  220. border: medium none;
  221. width: 100%;
  222. height: 100%;
  223. }
  224. }
  225. }
  226. </style>