wallet-transfer.vue 19 KB

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