cash-out.vue 6.92 KB
Newer Older
1 2
<template>
  <div class="cash-out">
leiqingsong's avatar
leiqingsong committed
3
    <van-cell-group style="margin-bottom: 10px">
leiqingsong's avatar
leiqingsong committed
4
      <van-cell is-link title="所属银行" :value="bank" @click="jumpToBank" />
5 6 7
    </van-cell-group>
    <div class="detail">
      <p style="font-size: 24px">提现金额</p>
leiqingsong's avatar
leiqingsong committed
8 9 10 11 12 13 14
      <van-field
        v-model="money"
        type="number"
        label="¥"
        class="money"
        @blur="onFillMoneyBlur"
      />
15 16 17 18
      <div class="remain">
        <span style="color: #666666"
          >可提现金额{{ remainMoney.toFixed(2) }}</span
        >
leiqingsong's avatar
leiqingsong committed
19
        <span v-if="remainMoney > 0" class="all" @click="allIn">全部提现</span>
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
      </div>
      <div class="real">
        <p class="real-item">
          <span>实际到账</span>
          <span>94.19</span>
        </p>
        <p class="real-item">
          <span>税款</span>
          <span>6.34</span>
        </p>
        <p class="explain">
          <span>扣税说明</span>
          <img
            class="explain-img"
            src="@/assets/images/explain.png"
            alt="解释"
          />
        </p>
      </div>
    </div>
leiqingsong's avatar
leiqingsong committed
40 41 42 43 44
    <div style="padding: 10px 16px">
      <van-button type="primary" size="large" @click="onCashOut"
        >提现</van-button
      >
    </div>
45 46 47 48 49 50
    <base-dialog
      base-dialog-title="提现"
      base-dialog-btn="提交"
      :base-dialog-show="validCodeDialogShow"
      :base-dialog-show-close="true"
      @onClick="onSubmit"
全球's avatar
全球 committed
51
      @onClose="onCloseDialog"
52 53
    >
      <div slot="content">
leiqingsong's avatar
leiqingsong committed
54
        <p class="content-text">请输入手机号{{ userPhone }}的动态验证码</p>
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        <van-field
          v-model="validCode"
          type="number"
          class="validCodeInput"
          placeholder="请输入"
        >
          <img
            slot="left-icon"
            class="valid-code"
            src="@/assets/images/验证码.png"
          />
        </van-field>
      </div>
    </base-dialog>
    <base-dialog
      :base-dialog-title="resultDialogTitle"
      :base-dialog-show="resultDialog"
      @onClick="onSuccess"
    >
      <div slot="content" style="text-align:center">
        <img :src="resultDialogImg" style="width: 70px; height: 76px" alt />
        <p style="margin:0;font-size:14px;color:#999999">
          {{ resultDialogTip }}
        </p>
      </div>
      <div></div>
    </base-dialog>
82 83 84 85
  </div>
</template>

<script>
leiqingsong's avatar
leiqingsong committed
86
import { getWithdrawalAmount } from "@/api/wallet";
leiqingsong's avatar
leiqingsong committed
87
import { getUserBankInfo, sendSms, cashOut } from "@/api/bank";
88
import BaseDialog from "@/components/BaseDialog.vue";
89
export default {
90
  components: { BaseDialog },
91 92 93
  name: "CashOut",
  data() {
    return {
leiqingsong's avatar
leiqingsong committed
94
      userPhone: this.$userId,
95
      bank: "",
leiqingsong's avatar
leiqingsong committed
96 97
      money: null,
      remainMoney: 100,
98 99 100 101
      resultDialogTitle: "",
      resultDialogTip: "",
      resultDialogImg: "",
      resultDialog: false,
leiqingsong's avatar
leiqingsong committed
102 103
      validCodeDialogShow: false,
      validCode: null
104 105
    };
  },
leiqingsong's avatar
leiqingsong committed
106 107
  created() {
    this.getUserInfo();
leiqingsong's avatar
leiqingsong committed
108
    this.canCashOut();
leiqingsong's avatar
leiqingsong committed
109
  },
110
  methods: {
leiqingsong's avatar
leiqingsong committed
111 112
    onFillMoneyBlur(e) {
      if (e.target.value > this.remainMoney) {
leiqingsong's avatar
leiqingsong committed
113 114
        this.$toast.fail("输入超过可提现金额,请重新输入");
        return false;
leiqingsong's avatar
leiqingsong committed
115 116 117 118 119 120 121 122 123 124 125 126 127
      }
    },
    canCashOut() {
      const params = {
        userId: this.$userId
      };
      getWithdrawalAmount(params).then(res => {
        if (res.code === 0) {
          this.remainMoney = res.data.currentMoneyCan;
        } else {
          this.remainMoney = 100;
        }
      });
leiqingsong's avatar
leiqingsong committed
128
      getWithdrawalAmount;
leiqingsong's avatar
leiqingsong committed
129
    },
leiqingsong's avatar
leiqingsong committed
130 131 132 133 134
    jumpToBank() {
      console.log("1");
      this.$router.push("/bank");
    },
    // 全部提现
135 136
    allIn() {
      this.money = this.remainMoney;
leiqingsong's avatar
leiqingsong committed
137
    },
leiqingsong's avatar
leiqingsong committed
138
    // 点击提现
leiqingsong's avatar
leiqingsong committed
139 140 141 142 143
    onCashOut() {
      if (!this.money) {
        this.$toast.fail("未输入提现金额");
        return;
      }
leiqingsong's avatar
leiqingsong committed
144
      if (this.money > this.remainMoney) {
leiqingsong's avatar
leiqingsong committed
145 146
        this.$toast.fail("输入超过可提现金额,请重新输入");
        return;
leiqingsong's avatar
leiqingsong committed
147
      }
leiqingsong's avatar
leiqingsong committed
148
      const params = {
leiqingsong's avatar
leiqingsong committed
149
        userId: this.$userId
leiqingsong's avatar
leiqingsong committed
150 151
      };
      sendSms(params).then();
leiqingsong's avatar
leiqingsong committed
152 153
      this.validCode = null;
      this.validCodeDialogShow = true;
154
    },
leiqingsong's avatar
leiqingsong committed
155 156
    getUserInfo() {
      const params = {
leiqingsong's avatar
leiqingsong committed
157
        userId: this.$userId
leiqingsong's avatar
leiqingsong committed
158 159 160
      };
      getUserBankInfo(params).then(res => {
        if (res.code === 0) {
leiqingsong's avatar
leiqingsong committed
161 162 163 164 165
          if (res.data.bankName) {
            this.bank = res.data.bankName;
          } else {
            this.bank = "";
          }
leiqingsong's avatar
leiqingsong committed
166 167 168
        }
      });
    },
全球's avatar
全球 committed
169 170 171
      onCloseDialog(){
          this.validCodeDialogShow = false;
      },
172 173
    onSubmit() {
      this.validCodeDialogShow = false;
leiqingsong's avatar
leiqingsong committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
      const params = {
        code: this.validCode,
        money: this.money
      };
      cashOut(params)
        .then(res => {
          this.resultDialog = true;
          if (res.code === 0) {
            this.resultDialogTitle = "提现成功";
            this.resultDialogTip = "提现成功,请及时查收";
            this.resultDialogImg = require("@/assets/images/成功.png");
          } else {
            this.resultDialogTitle = "提现失败";
            this.resultDialogTip = "提现失败,验证码错误";
            this.resultDialogImg = require("@/assets/images/叉号.png");
          }
        })
        .catch(err => {
          this.$toast.fail(err.response.data.error);
        });
194 195 196
    },
    onSuccess() {
      this.resultDialog = false;
197 198 199 200 201 202 203 204
    }
  }
};
</script>

<style lang="scss" scoped>
.cash-out {
  padding: 10px 0;
leiqingsong's avatar
leiqingsong committed
205
  font-family: PingFang-SC-Medium;
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
  .bank {
    ::v-deep .van-field__control {
      text-align: right;
    }
  }
  .detail {
    height: 380px;
    padding: 10px 16px;
    background-color: #ffffff;

    .money {
      box-sizing: border-box;
      margin: 0 0 10px;
      border-bottom: 1px solid #eeeeee;
      ::v-deep .van-field__label {
        width: 16px;
        height: 21px;
        font-size: 28px;
        line-height: 20px;
        color: #333333;
      }

      ::v-deep .van-field__control {
        font-size: 23px;
        color: #333333;
      }
    }

    .remain {
      padding: 10px 16px;
      font-size: 12px;

      .all {
        padding-left: 20px;
        color: #88c678;
      }
    }

    .real {
      padding: 10px 16px;
      font-size: 14px;
      background-color: #f9f9f9;
      .real-item {
        display: flex;
        flex-wrap: nowrap;
        justify-content: space-between;
        align-items: center;
      }
      .explain {
        position: relative;
        span {
          color: #999999;
        }
        .explain-img {
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
          width: 14px;
          height: 14px;
          margin-left: 8px;
        }
      }
    }
  }
}
271 272 273 274
.content-text {
  width: 185px;
  margin: 25px auto;
  text-align: center;
leiqingsong's avatar
leiqingsong committed
275
  font-family: PingFang-SC-Medium;
276 277 278
  font-size: 14px;
  color: #333333;
}
leiqingsong's avatar
leiqingsong committed
279 280 281 282 283
.validCodeInput {
  width: 245px;
  margin: 10px auto;
  background-color: #f9f9f9;
  border-radius: 20px;
284 285 286 287
  .van-field__left-icon {
    display: flex;
    align-items: center;
  }
leiqingsong's avatar
leiqingsong committed
288 289 290 291 292
  .valid-code {
    width: 16px;
    height: 18px;
  }
}
293
</style>