wallet-transfer.vue 19 KB

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