wallet-transfer.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <template>
  2. <cwg-page-wrapper class="create-page" :isHeaderFixed="true">
  3. <cwg-header :title="t('wallet.item62')" />
  4. <uni-loading v-if="loading" />
  5. <view class="container" v-else>
  6. <view class="row">
  7. <view class="col-lg-12 col-sm-12">
  8. <view class="card">
  9. <view class="border-0 card-header">
  10. <uni-forms ref="formRef" :model="form" :rules="rules" label-position="top"
  11. validate-trigger="submit">
  12. <view class="row">
  13. <view class="col-lg-6">
  14. <h5 class="mb-3" v-t="'wallet.item63'"></h5>
  15. <uni-forms-item name="walletbalance">
  16. <uni-easyinput v-model="walletbalanceDisplay" disabled
  17. class="disabled-input" />
  18. </uni-forms-item>
  19. </view>
  20. <view class="col-lg-6">
  21. <h5 class="mb-3" v-t="'Custom.Transfer.IntoAccount'"></h5>
  22. <uni-forms-item name="login">
  23. <cwg-combox v-model:value="form.login" :clearable="false"
  24. :options="toOptionsDisplay" :placeholder="t('placeholder.choose')" />
  25. </uni-forms-item>
  26. </view>
  27. <view class="col-lg-6 mb-3">
  28. <h5 class="mb-3" v-t="'Label.Amount'"></h5>
  29. <view class="card-row amount-box">
  30. <uni-forms-item name="amount" :error-message="amountErrorMessage"
  31. class="amount-input">
  32. <uni-easyinput v-model="form.amount"
  33. :placeholder="t('placeholder.input')" @blur="validateAmount" />
  34. </uni-forms-item>
  35. <view class="btn btn-gray waves-effect waves-light" v-t="'State.All'"
  36. @click="setAllAmount"></view>
  37. </view>
  38. </view>
  39. <button @click="toTransfer" class="btn btn-dark waves-effect waves-light"><i
  40. class="fi fi-rs-check"></i> <text v-t="'Btn.Submit'"></text></button>
  41. </view>
  42. </uni-forms>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- 失败弹窗 -->
  49. <cwg-error-popup v-model:visible="dialogError" @confirm="closeDia" :responseMessage="RES" />
  50. <!-- 成功弹窗 -->
  51. <cwg-success-popup v-model:visible="dialogSuccess" @confirm="closeDia" />
  52. <!-- 等待弹窗 -->
  53. <cwg-wait-popup v-model:visible="dialogCheckWait" type="center" :mask-click="false" :showFooters="false" />
  54. </cwg-page-wrapper>
  55. </template>
  56. <script setup lang="ts">
  57. import { ref, reactive, computed, onMounted, watch } from 'vue'
  58. import { useI18n } from 'vue-i18n'
  59. import { customApi } from '@/service/custom'
  60. import { drawApi } from '@/service/draw'
  61. import Config from '@/config/index'
  62. const { Code } = Config
  63. const { t, locale } = useI18n()
  64. import { useFilters } from '@/composables/useFilters'
  65. const { numberDecimal } = useFilters()
  66. const loading = ref(false)
  67. const flag = ref(false)
  68. const RES = ref('')
  69. const walletbalance = ref('0')
  70. const toOptions = ref([])
  71. const form = reactive({
  72. currency: 'USD',
  73. login: null,
  74. amount: ''
  75. })
  76. const currencyOptions = [{ text: 'USD', value: 'USD' }]
  77. const walletbalanceDisplay = computed(() => `$ ${walletbalance.value}`)
  78. const groupTypeName = (type) => {
  79. if (type == '1') return t("AccountType.ClassicAccount")
  80. if (type == '2') return t("AccountType.SeniorAccount")
  81. if (type == '5') return t("AccountType.SpeedAccount")
  82. if (type == '6') return t("AccountType.SpeedAccount")
  83. if (type == '7') return t("AccountType.StandardAccount")
  84. if (type == '8') return t("AccountType.CentAccount")
  85. return ''
  86. }
  87. // 单位类型
  88. function groupCurrency(type) {
  89. const map = { GBP: ': £', USD: ': $', EUR: ': €', USC: ': ¢' }
  90. return map[type] || ': $'
  91. }
  92. const toOptionsDisplay = computed(() => {
  93. return toOptions.value.map(item => ({
  94. text: `${item.login} - ${groupTypeName(item.type)} - ${t('Custom.Deposit.AvailableBalance')}${groupCurrency(item.currency)}${numberDecimal(item.balance)}`,
  95. value: item.login
  96. }))
  97. })
  98. const dialogCheck = ref(false)
  99. const dialogVisible = ref(false)
  100. const dialogCheckWait = ref(false)
  101. const dialogSuccess = computed(() => dialogCheck.value && dialogVisible.value)
  102. const dialogError = computed(() => dialogCheck.value && !dialogVisible.value)
  103. const rules = computed(() => ({
  104. login: {
  105. rules: [{ required: true, errorMessage: t('vaildate.select.empty') }]
  106. },
  107. currency: {
  108. rules: [{ required: true, errorMessage: t('vaildate.select.empty') }]
  109. },
  110. amount: {
  111. rules: [
  112. { required: true, errorMessage: t('vaildate.amount.format') },
  113. {
  114. validateFunction: (rule, value, data, callback) => {
  115. if (!value) {
  116. callback(t('vaildate.amount.format'))
  117. } else if (!/^[0-9]+([.]{1}[0-9]{1,2})?$/.test(value)) {
  118. callback(t('vaildate.amount.format'))
  119. }
  120. return true
  121. }
  122. }
  123. ]
  124. }
  125. }));
  126. watch(locale, () => {
  127. formRef.value?.clearValidate()
  128. amountErrorMessage.value = ''
  129. })
  130. const amountErrorMessage = ref('')
  131. const setAllAmount = () => {
  132. form.amount = Number(walletbalance.value)
  133. validateAmount()
  134. }
  135. function validateAmount() {
  136. const value = form.amount
  137. if (!value) {
  138. amountErrorMessage.value = t('vaildate.amount.format')
  139. return false
  140. } else if (!/^[0-9]+([.]{1}[0-9]{1,2})?$/.test(value)) {
  141. amountErrorMessage.value = t('vaildate.amount.format')
  142. }
  143. amountErrorMessage.value = ''
  144. return true
  145. }
  146. const formRef = ref(null)
  147. const closeDia = () => {
  148. if (formRef.value) {
  149. form.amount = ''
  150. form.login = null
  151. amountErrorMessage.value = ''
  152. formRef.value.clearValidate()
  153. }
  154. dialogCheck.value = false
  155. dialogVisible.value = false
  156. }
  157. const toTransfer = async () => {
  158. try {
  159. await formRef.value.validate()
  160. if (walletbalance.value == '0' || Number(walletbalance.value) < Number(form.amount)) {
  161. uni.showToast({ title: t('wallet.item64'), icon: 'none' })
  162. return
  163. }
  164. if (flag.value) return
  165. flag.value = true
  166. dialogCheckWait.value = true
  167. let res = await customApi.walletTransferApply({ ...form })
  168. if (res.code == Code.StatusOK) {
  169. dialogCheck.value = true
  170. dialogVisible.value = true
  171. flag.value = false
  172. getWalletList() // refresh balance after success
  173. uni.$emit('updatePayment')
  174. } else {
  175. RES.value = res.msg
  176. dialogCheck.value = true
  177. dialogVisible.value = false
  178. flag.value = false
  179. }
  180. dialogCheckWait.value = false
  181. } catch (e) {
  182. if (e.code == 400) {
  183. dialogCheckWait.value = false
  184. RES.value = e.msg
  185. dialogCheck.value = true
  186. dialogVisible.value = false
  187. flag.value = false
  188. }
  189. }
  190. }
  191. const getToDateList = async () => {
  192. try {
  193. let res = await customApi.CustomDropdown({})
  194. if (res.code == Code.StatusOK) {
  195. toOptions.value = res.data || []
  196. } else {
  197. uni.showToast({ title: res.msg, icon: 'none' })
  198. }
  199. } catch (e) {
  200. console.log(e)
  201. }
  202. }
  203. const getWalletList = async () => {
  204. try {
  205. let res = await drawApi.walletbalance({})
  206. if (res.code == Code.StatusOK) {
  207. walletbalance.value = res.data != null ? res.data : '0'
  208. } else {
  209. uni.showToast({ title: res.msg, icon: 'none' })
  210. }
  211. } catch (e) {
  212. console.log(e)
  213. }
  214. }
  215. onMounted(() => {
  216. getToDateList()
  217. getWalletList()
  218. })
  219. </script>
  220. <style scoped lang="scss">
  221. @import "@/uni.scss";
  222. .amount-box {
  223. display: flex;
  224. align-items: center;
  225. gap: px2rpx(12);
  226. .amount-input {
  227. flex: 1;
  228. }
  229. .btn {
  230. margin-bottom: px2rpx(22);
  231. }
  232. }
  233. .transfer-page {
  234. width: 100%;
  235. padding-bottom: px2rpx(20);
  236. .main-content {
  237. text-align: left;
  238. .box {
  239. padding-top: px2rpx(5);
  240. color: #303133;
  241. .b-card {
  242. border: 1px solid var(--bs-border-color);
  243. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  244. margin-bottom: px2rpx(10);
  245. border-radius: px2rpx(6);
  246. box-shadow: 0 px2rpx(1) px2rpx(6) 0 rgba(0, 0, 0, 0.05);
  247. &:hover {
  248. box-shadow: 0 px2rpx(2) px2rpx(8) 0 rgba(0, 0, 0, 0.1);
  249. }
  250. .card-top {
  251. padding: px2rpx(15) px2rpx(20);
  252. .card-row {
  253. margin-bottom: px2rpx(30);
  254. &:last-child {
  255. margin-bottom: 0;
  256. }
  257. }
  258. .card-tit {
  259. margin-bottom: px2rpx(0) !important;
  260. }
  261. .tit {
  262. font-size: px2rpx(16);
  263. font-weight: 600;
  264. margin-bottom: px2rpx(16);
  265. display: flex;
  266. align-items: center;
  267. color: var(--bs-heading-color);
  268. position: relative;
  269. padding-left: 20px;
  270. &:after {
  271. content: '';
  272. position: absolute;
  273. left: 0;
  274. top: 50%;
  275. transform: translateY(-50%);
  276. width: 0;
  277. height: 0;
  278. border-top: 6px solid transparent;
  279. border-bottom: 6px solid transparent;
  280. border-left: 8px solid currentColor;
  281. }
  282. .iconfont {
  283. margin-right: px2rpx(8);
  284. color: var(--color-primary);
  285. font-size: px2rpx(18);
  286. }
  287. }
  288. .title-wrapper {
  289. display: flex;
  290. justify-content: space-between;
  291. align-items: center;
  292. }
  293. }
  294. }
  295. }
  296. .box-step2 {
  297. .form-row {
  298. display: flex;
  299. flex-wrap: wrap;
  300. margin-bottom: px2rpx(12);
  301. gap: px2rpx(12);
  302. &:last-child {
  303. margin-bottom: 0;
  304. }
  305. .form-col {
  306. flex: 1;
  307. min-width: px2rpx(140);
  308. @media screen and (max-width: 991px) {
  309. flex: 0 0 100%;
  310. width: 100%;
  311. }
  312. }
  313. .form-col-full {
  314. width: 100%;
  315. padding: 0 px2rpx(5);
  316. }
  317. }
  318. .tips {
  319. line-height: 1.8;
  320. font-size: px2rpx(12);
  321. color: var(--bs-heading-color);
  322. background-color: rgba(var(--bs-body-bg-rgb), 1) !important;
  323. padding: px2rpx(12);
  324. border-radius: px2rpx(4);
  325. border-left: px2rpx(2) solid #cf1322;
  326. .title {
  327. font-weight: 600;
  328. margin-bottom: px2rpx(6);
  329. color: var(--bs-heading-color);
  330. }
  331. }
  332. }
  333. }
  334. .picker-select {
  335. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  336. border: 1px solid #dcdfe6;
  337. border-radius: px2rpx(4);
  338. padding: px2rpx(12) px2rpx(14);
  339. font-size: px2rpx(14);
  340. color: #606266;
  341. line-height: 1.4;
  342. width: 100%;
  343. box-sizing: border-box;
  344. &:hover {
  345. border-color: #409eff;
  346. }
  347. &.picker-disabled {
  348. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  349. color: #c0c4cc;
  350. cursor: not-allowed;
  351. }
  352. }
  353. .disabled-input {
  354. // background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  355. // border: 1px solid #dcdfe6;
  356. border-radius: px2rpx(4);
  357. // padding: px2rpx(12) px2rpx(14);
  358. font-size: px2rpx(14);
  359. color: #606266;
  360. width: 100%;
  361. box-sizing: border-box;
  362. }
  363. .m-input {
  364. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  365. border: 1px solid #dcdfe6;
  366. border-radius: px2rpx(4);
  367. padding: px2rpx(12) px2rpx(14);
  368. font-size: px2rpx(14);
  369. width: 100%;
  370. box-sizing: border-box;
  371. &:focus {
  372. border-color: #409eff;
  373. outline: none;
  374. box-shadow: 0 0 0 px2rpx(1) rgba(64, 158, 255, 0.2);
  375. }
  376. }
  377. .popup-content {
  378. padding: px2rpx(30) px2rpx(20);
  379. text-align: center;
  380. min-width: px2rpx(250);
  381. max-width: 80%;
  382. margin: 0 auto;
  383. @media screen and (max-width: 991px) {
  384. min-width: 80%;
  385. max-width: 90%;
  386. margin: 0 px2rpx(10);
  387. }
  388. position: relative;
  389. .icon {
  390. .iconfont {
  391. font-size: px2rpx(60);
  392. display: block;
  393. margin: 0 auto;
  394. }
  395. .icon-chenggong {
  396. color: #67c23a;
  397. }
  398. .icon-jingshi {
  399. color: #f56c6c;
  400. }
  401. .icon-dengdai {
  402. color: #e6a23c;
  403. }
  404. }
  405. .des1 {
  406. font-weight: 600;
  407. font-size: px2rpx(16);
  408. margin: px2rpx(20) 0 px2rpx(15);
  409. color: #303133;
  410. line-height: 1.4;
  411. padding: 0 px2rpx(10);
  412. }
  413. .dialog-footer {
  414. display: flex;
  415. justify-content: center;
  416. gap: px2rpx(10);
  417. margin-top: px2rpx(10);
  418. @media (max-width: 750rpx) {
  419. flex-direction: column;
  420. align-items: center;
  421. gap: px2rpx(6);
  422. }
  423. button {
  424. min-width: px2rpx(90);
  425. padding: 0 px2rpx(12);
  426. border-radius: px2rpx(4);
  427. font-size: px2rpx(14);
  428. transition: all 0.3s ease;
  429. cursor: pointer;
  430. &[type="primary"] {
  431. background-color: #409eff;
  432. color: var(--bs-emphasis-color);
  433. border: none;
  434. &:hover {
  435. background-color: #66b1ff;
  436. transform: translateY(px2rpx(-1));
  437. box-shadow: 0 px2rpx(2) px2rpx(6) 0 rgba(64, 158, 255, 0.3);
  438. }
  439. &:active {
  440. background-color: #3a8ee6;
  441. transform: translateY(0);
  442. }
  443. }
  444. &:not([type="primary"]) {
  445. background-color: rgba(var(--bs-body-bg-rgb), var(--bs-bg-opacity)) !important;
  446. border: 1px solid #dcdfe6;
  447. color: #606266;
  448. &:hover {
  449. border-color: #409eff;
  450. color: #409eff;
  451. transform: translateY(px2rpx(-1));
  452. }
  453. &:active {
  454. transform: translateY(0);
  455. }
  456. }
  457. }
  458. }
  459. }
  460. .wait-popup {
  461. .des1 {
  462. margin-top: px2rpx(10);
  463. }
  464. .icon {
  465. .iconfont {
  466. animation: spin 1s linear infinite;
  467. }
  468. }
  469. }
  470. }
  471. // 动画
  472. @keyframes popupFadeIn {
  473. from {
  474. opacity: 0;
  475. transform: scale(0.9);
  476. }
  477. to {
  478. opacity: 1;
  479. transform: scale(1);
  480. }
  481. }
  482. @keyframes fadeIn {
  483. from {
  484. opacity: 0;
  485. transform: translateY(px2rpx(10));
  486. }
  487. to {
  488. opacity: 1;
  489. transform: translateY(0);
  490. }
  491. }
  492. @keyframes pulse {
  493. 0% {
  494. transform: scale(1);
  495. }
  496. 50% {
  497. transform: scale(1.05);
  498. }
  499. 100% {
  500. transform: scale(1);
  501. }
  502. }
  503. @keyframes spin {
  504. from {
  505. transform: rotate(0deg);
  506. }
  507. to {
  508. transform: rotate(360deg);
  509. }
  510. }
  511. // 表单错误信息样式
  512. .uni-forms-item__error {
  513. font-size: px2rpx(12);
  514. color: #f56c6c;
  515. margin-top: px2rpx(4);
  516. }
  517. // 适配不同屏幕尺寸(媒体查询中的 750rpx 保持不变)
  518. @media (max-width: 750rpx) {
  519. .transfer-page {
  520. .main-content {
  521. padding: px2rpx(8);
  522. .box {
  523. .b-card {
  524. .card-top {
  525. padding: px2rpx(12) px2rpx(16);
  526. .tit {
  527. font-size: px2rpx(14);
  528. .iconfont {
  529. font-size: px2rpx(16);
  530. }
  531. }
  532. }
  533. }
  534. }
  535. }
  536. .s-btn {
  537. font-size: px2rpx(14);
  538. padding: px2rpx(10) px2rpx(16);
  539. }
  540. .popup-content {
  541. padding: px2rpx(20) px2rpx(16);
  542. .icon {
  543. .iconfont {
  544. font-size: px2rpx(50);
  545. }
  546. }
  547. .des1 {
  548. font-size: px2rpx(14);
  549. margin: px2rpx(15) 0 px2rpx(10);
  550. }
  551. .dialog-footer {
  552. button {
  553. min-width: px2rpx(80);
  554. font-size: px2rpx(13);
  555. }
  556. }
  557. }
  558. }
  559. }
  560. </style>