wallet-transfer.vue 19 KB

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