wallet-transfer.vue 20 KB

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