vaultody.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <cwg-page-wrapper>
  3. <view class="page">
  4. <u-form ref="formRef" :rules="rules" :model="form" class="payment-form">
  5. <cwg-input v-model:value="form.blockchain" fkey="blockchain" type="select" :required="true"
  6. :columns="blockchainList" :label="t('Blockchain.addP2')" rulesKey="blockchain"
  7. @change="handleChange" />
  8. <cwg-input v-if="text1" v-model:value="text1" fkey="text1" type="text" :label="t('Blockchain1.p2')"
  9. :readonly="true" :disabled="true" />
  10. </u-form>
  11. <QrCode v-if="text1" :text="text1"></QrCode>
  12. <view class="fixed-btn">
  13. <view v-if="!text1" class="cwg-button ok-button">
  14. <u-button type="primary" block @click="getVaultodyAddress">{{
  15. t("Blockchain1.p3")
  16. }}</u-button>
  17. </view>
  18. <view v-else class="cwg-button ok-button">
  19. <u-button type="primary" block @click="cardCopy">{{
  20. t("Blockchain1.p4")
  21. }}</u-button>
  22. </view>
  23. </view>
  24. </view>
  25. </cwg-page-wrapper>
  26. </template>
  27. <script setup lang="ts">
  28. import { ref, onMounted, computed } from "vue";
  29. import { showToast } from "@/utils/toast";
  30. import { useI18n } from "vue-i18n";
  31. import { ucardApi } from "@/api/ucard";
  32. import useUserStore from "@/stores/use-user-store";
  33. import QrCode from "@/components/QrCode.vue";
  34. import { Validators } from "@/utils/validators";
  35. const { t } = useI18n();
  36. const userStore = useUserStore();
  37. const userInfo = computed(() => userStore.userInfo);
  38. const formRef = ref();
  39. const form = ref<{
  40. emailCode: string;
  41. cardNumber?: string;
  42. password?: string;
  43. country?: string;
  44. email?: string;
  45. }>({
  46. blockchain: "",
  47. });
  48. const text1 = ref("");
  49. const blockchainList = ref([]);
  50. // 表单验证规则
  51. const rules = {
  52. blockchain: [Validators.required(t("Blockchain.addP2"))],
  53. address: [Validators.required(t("WalletApply.p2"))],
  54. amount: [
  55. Validators.required(t("global.validator.v15"))
  56. ],
  57. };
  58. // 初始化表单
  59. function initForm() {
  60. if (userInfo.value) {
  61. const a = { uniqueId: userInfo.value.uniqueId, country: userInfo.value.country, email: userInfo.value.email }
  62. if (userInfo.value) {
  63. form.value = {
  64. ...a,
  65. };
  66. }
  67. }
  68. }
  69. //生成支付地址
  70. async function getVaultodyAddress() {
  71. try {
  72. await formRef.value?.validate();
  73. let res = await ucardApi.getVaultodyAddress({
  74. ...form.value,
  75. });
  76. if (res.code == 200) {
  77. text1.value = res.data;
  78. } else {
  79. text1.value = "";
  80. showToast(res.msg);
  81. }
  82. } catch (error) {
  83. console.log(error, 1111);
  84. }
  85. }
  86. //获取区块链
  87. async function getBlockchainDropdown() {
  88. let res = await ucardApi.getBlockchainDropdown({
  89. ...form.value,
  90. });
  91. if (res.code == 200) {
  92. res.data.map((item: any) => {
  93. item.text = item.alias;
  94. item.value = item.blockchain;
  95. });
  96. blockchainList.value = res.data;
  97. } else {
  98. blockchainList.value = []
  99. showToast(res.msg);
  100. }
  101. }
  102. // 表单字段变化
  103. function handleChange(value: any) {
  104. if (value.key === "emailCode") {
  105. form.value.emailCode = value.value;
  106. }
  107. }
  108. // 复制 CVV
  109. function cardCopy() {
  110. let title = t("card.Msg.m8");
  111. uni.setClipboardData({
  112. data: text1.value,
  113. success: () => {
  114. uni.showToast({
  115. title,
  116. });
  117. },
  118. });
  119. }
  120. onMounted(() => {
  121. initForm();
  122. getBlockchainDropdown();
  123. });
  124. </script>
  125. <style lang="scss" scoped>
  126. @import "@/uni.scss";
  127. .no-button {
  128. width: 100%;
  129. margin: px2rpx(12) 0;
  130. .u-button {
  131. background-color: #ffbdc8 !important;
  132. }
  133. }
  134. .ok-button {
  135. margin: px2rpx(4) 0;
  136. /* background-color: #EA002A; */
  137. }
  138. .code-input-label {
  139. font-size: var(--font-size-16);
  140. line-height: px2rpx(44);
  141. letter-spacing: px2rpx(1);
  142. color: #474747;
  143. }
  144. .code-input-wrapper {
  145. position: relative;
  146. display: flex;
  147. align-items: center;
  148. }
  149. .code-input {
  150. flex: 1;
  151. }
  152. .get-code-btn {
  153. min-width: px2rpx(100);
  154. margin-bottom: px2rpx(12);
  155. margin-left: px2rpx(10);
  156. .cwg-button .u-button {
  157. border-radius: px2rpx(8);
  158. }
  159. }
  160. .submit-section {
  161. margin: px2rpx(20) 0;
  162. }
  163. .submit-btn {
  164. width: 100%;
  165. }
  166. </style>