pay-button.vue 6.2 KB

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