Payment.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import type { PaymentData } from "@/interfaces";
  4. import { useMainStore } from "@/stores/main";
  5. const mainStore = useMainStore();
  6. let isLoading = ref(false);
  7. const credit = ref(1);
  8. function increment() {
  9. credit.value++;
  10. }
  11. function decrement() {
  12. if (credit.value > 1) {
  13. credit.value--;
  14. }
  15. }
  16. const epayment = ref("ecpay");
  17. async function ecpay() {
  18. isLoading.value = true;
  19. const data: PaymentData = {
  20. item: `Credit 60 X${credit.value}`,
  21. amount: 500 * credit.value,
  22. };
  23. if (data.amount <= 0) {
  24. return;
  25. }
  26. const originalHTML = await mainStore.Payment(data, "zh");
  27. let formHTML = originalHTML?.replace(
  28. '<script type="text/javascript">document.getElementById("data_set").submit();</scr',
  29. ""
  30. );
  31. formHTML = formHTML?.replace("ipt>", "");
  32. const payFormElement = document.getElementById("pay-form");
  33. payFormElement!.innerHTML = formHTML!;
  34. const ecpayForm: HTMLFormElement = <HTMLFormElement>(
  35. document.getElementById("data_set")
  36. );
  37. ecpayForm.submit();
  38. setTimeout(() => {
  39. isLoading.value = false;
  40. }, 3000);
  41. }
  42. </script>
  43. <template>
  44. <div class="d-flex align-center flex-wrap">
  45. <div class="payment-item me-6 mt-3">
  46. <span>分鐘數:</span>
  47. <v-btn
  48. density="compact"
  49. icon="remove"
  50. color="grey"
  51. class="mx-2"
  52. @click="decrement"
  53. ></v-btn>
  54. <span class="px-2">{{ credit }}</span>
  55. <v-btn
  56. density="compact"
  57. icon="add"
  58. color="grey"
  59. class="mx-2"
  60. @click="increment"
  61. ></v-btn>
  62. <span class="ms-2">NT${{ 500 * credit }}</span>
  63. </div>
  64. <v-btn
  65. @click="ecpay"
  66. variant="flat"
  67. color="primary"
  68. class="px-4 mt-3"
  69. prepend-icon="add"
  70. :loading="isLoading"
  71. >我要加值</v-btn
  72. >
  73. </div>
  74. <div id="pay-form"></div>
  75. </template>
  76. <style lang="scss" scoped>
  77. .payment-item {
  78. .v-btn {
  79. border: 1px solid #a6a6a6;
  80. }
  81. }
  82. </style>