cashout.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <Overlay :show="true">
  3. <div class="wrapper" @click.stop>
  4. <div class="block">
  5. <Form @submit="handleCashout">
  6. <CellGroup inset>
  7. <Field v-model="amount" label="提现金额(元)" type="number" placeholder="请输入提现金额" />
  8. </CellGroup>
  9. <div class="submit-box">
  10. <Button :loading="loading" :disabled="!amount" type="primary" hairline native-type="submit" loading-text="结算中..."> 提现 </Button>
  11. <Button type="default" hairline @click="props.unmount"> 取消 </Button>
  12. </div>
  13. </Form>
  14. </div>
  15. </div>
  16. </Overlay>
  17. </template>
  18. <script lang="ts">
  19. import { Toast } from "vant";
  20. import { CashOutModel } from "@/model/cashOut";
  21. const cashOutModel = new CashOutModel();
  22. const useCashout = () => {
  23. const amount = ref<number>();
  24. const loading = ref(false);
  25. const cashout = async () => {
  26. if (!amount.value) {
  27. Toast.fail("请输入金额");
  28. return false;
  29. }
  30. loading.value = true;
  31. const data = await cashOutModel.cashout(amount.value * 100);
  32. loading.value = false;
  33. if (data.code === 200) {
  34. Toast.success("提现成功");
  35. return true;
  36. } else {
  37. Toast.fail(data.msg);
  38. return false;
  39. }
  40. };
  41. return {
  42. amount,
  43. loading,
  44. cashout,
  45. };
  46. };
  47. </script>
  48. <script lang="ts" setup>
  49. import { Overlay, Field, CellGroup, Form, Button } from "vant";
  50. import { ref } from "vue";
  51. import { useUpdateUserInfo } from "@/hooks";
  52. const props = defineProps<{
  53. unmount: () => void;
  54. callback: () => any;
  55. }>();
  56. const { amount, loading, cashout } = useCashout();
  57. const handleCashout = async () => {
  58. if (await cashout()) {
  59. props.unmount();
  60. useUpdateUserInfo();
  61. props.callback();
  62. }
  63. };
  64. </script>
  65. <style scoped lang="scss">
  66. .wrapper {
  67. display: flex;
  68. align-items: center;
  69. justify-content: center;
  70. height: 100%;
  71. }
  72. .block {
  73. width: 300px;
  74. background-color: #fff;
  75. padding: 20px;
  76. border-radius: 10px;
  77. }
  78. .user-img {
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. font-size: 20px;
  83. margin-bottom: 10px;
  84. }
  85. .submit-box {
  86. display: flex;
  87. justify-content: space-around;
  88. align-items: center;
  89. margin-top: 10px;
  90. }
  91. </style>