wallet-transfer.vue 18 KB

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