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