cash-out.vue 9.06 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
    </van-cell-group>
    <div class="detail">
leiqingsong's avatar
leiqingsong committed
7
      <p class="cash-out-title">提现金额</p>
leiqingsong's avatar
leiqingsong committed
8 9 10 11 12
      <van-field
        v-model="money"
        type="number"
        label="¥"
        class="money"
全球's avatar
全球 committed
13
        :maxlength="maxValue"
leiqingsong's avatar
leiqingsong committed
14
        center
leiqingsong's avatar
leiqingsong committed
15
        @blur="onFillMoneyBlur"
16
        @input="inputClick"
leiqingsong's avatar
leiqingsong committed
17
      />
18 19 20 21
      <div class="remain">
        <span style="color: #666666"
          >可提现金额{{ remainMoney.toFixed(2) }}</span
        >
leiqingsong's avatar
leiqingsong committed
22
        <span v-if="remainMoney > 0" class="all" @click="allIn">全部提现</span>
23 24 25 26
      </div>
      <div class="real">
        <p class="real-item">
          <span>实际到账</span>
全球's avatar
全球 committed
27
          <span>{{ account.toFixed(2) }}</span>
28 29 30
        </p>
        <p class="real-item">
          <span>税款</span>
全球's avatar
全球 committed
31
          <span>{{ rate.toFixed(2) }}</span>
32 33 34 35
        </p>
        <p class="explain">
          <span>扣税说明</span>
          <img
36
            @click="taxtClick"
37 38 39 40 41
            class="explain-img"
            src="@/assets/images/explain.png"
            alt="解释"
          />
        </p>
leiqingsong's avatar
leiqingsong committed
42
        <p v-if="showExplain" class="explain">
leiqingsong's avatar
leiqingsong committed
43
          <span>{{ this.textName }}</span>
44
        </p>
45 46
      </div>
    </div>
leiqingsong's avatar
leiqingsong committed
47 48 49 50 51
    <div style="padding: 10px 16px">
      <van-button type="primary" size="large" @click="onCashOut"
        >提现</van-button
      >
    </div>
52 53 54 55 56 57
    <base-dialog
      base-dialog-title="提现"
      base-dialog-btn="提交"
      :base-dialog-show="validCodeDialogShow"
      :base-dialog-show-close="true"
      @onClick="onSubmit"
全球's avatar
全球 committed
58
      @onClose="onCloseDialog"
59 60
    >
      <div slot="content">
leiqingsong's avatar
leiqingsong committed
61
        <p class="content-text">请输入手机号{{ userPhone }}的动态验证码</p>
62 63 64 65 66
        <van-field
          v-model="validCode"
          type="number"
          class="validCodeInput"
          placeholder="请输入"
leiqingsong's avatar
leiqingsong committed
67
          center
68 69 70 71 72 73
        >
          <img
            slot="left-icon"
            class="valid-code"
            src="@/assets/images/验证码.png"
          />
全球's avatar
全球 committed
74
          <van-button
leiqingsong's avatar
leiqingsong committed
75 76 77 78 79
            slot="button"
            size="small"
            type="primary"
            class="verify-code"
            @click="sendVerification"
全球's avatar
全球 committed
80
          >
leiqingsong's avatar
leiqingsong committed
81 82
            <span v-if="!canSend">{{ time }}秒后重新发送</span>
            <span v-else>发送验证码</span>
全球's avatar
全球 committed
83
          </van-button>
84 85 86 87 88 89 90 91
        </van-field>
      </div>
    </base-dialog>
    <base-dialog
      :base-dialog-title="resultDialogTitle"
      :base-dialog-show="resultDialog"
      @onClick="onSuccess"
    >
leiqingsong's avatar
leiqingsong committed
92
      <div slot="content" style="text-align: center">
93
        <img :src="resultDialogImg" style="width: 70px; height: 76px" alt />
leiqingsong's avatar
leiqingsong committed
94
        <p style="margin: 0; font-size: 14px; color: #999999">
95 96 97 98 99
          {{ resultDialogTip }}
        </p>
      </div>
      <div></div>
    </base-dialog>
100 101 102 103
  </div>
</template>

<script>
leiqingsong's avatar
leiqingsong committed
104
import { getWithdrawalAmount } from "@/api/wallet";
leiqingsong's avatar
leiqingsong committed
105
import { getUserBankInfo, sendSms, cashOut, getTaxRate } from "@/api/bank";
106
import BaseDialog from "@/components/BaseDialog.vue";
107
export default {
108
  components: { BaseDialog },
109 110 111
  name: "CashOut",
  data() {
    return {
leiqingsong's avatar
leiqingsong committed
112
      showExplain: false,
leiqingsong's avatar
leiqingsong committed
113
      userPhone: JSON.parse(localStorage.getItem("user")).userId,
114
      bank: "",
leiqingsong's avatar
leiqingsong committed
115
      money: null,
leiqingsong's avatar
leiqingsong committed
116 117
      account: 0,
      rate: 0,
leiqingsong's avatar
leiqingsong committed
118
      remainMoney: 100,
119 120 121 122
      resultDialogTitle: "",
      resultDialogTip: "",
      resultDialogImg: "",
      resultDialog: false,
leiqingsong's avatar
leiqingsong committed
123
      canSend: true,
leiqingsong's avatar
leiqingsong committed
124
      textName: "",
leiqingsong's avatar
leiqingsong committed
125
      validCodeDialogShow: false,
全球's avatar
全球 committed
126
      validCode: null,
全球's avatar
全球 committed
127
      time: 60,
128
      maxValue: 8
129 130
    };
  },
leiqingsong's avatar
leiqingsong committed
131 132
  created() {
    this.getUserInfo();
leiqingsong's avatar
leiqingsong committed
133
    this.canCashOut();
leiqingsong's avatar
leiqingsong committed
134
  },
135
  methods: {
leiqingsong's avatar
leiqingsong committed
136 137
    onFillMoneyBlur(e) {
      if (e.target.value > this.remainMoney) {
leiqingsong's avatar
leiqingsong committed
138 139
        this.$toast.fail("输入超过可提现金额,请重新输入");
        return false;
leiqingsong's avatar
leiqingsong committed
140 141
      }
    },
leiqingsong's avatar
leiqingsong committed
142
    sendVerification() {
leiqingsong's avatar
leiqingsong committed
143 144 145 146 147 148 149 150 151 152
      const params = {
        userId: JSON.parse(localStorage.getItem("user")).userId
      };
      sendSms(params).then(res => {
        if (res.code == 0) {
          this.timeDown();
        } else {
          this.$toast.fail(res.message);
        }
      });
leiqingsong's avatar
leiqingsong committed
153 154 155 156 157 158 159 160 161 162 163
    },
    timeDown() {
      this.canSend = false;
      const timer = setInterval(() => {
        this.time -= 1;
        if (this.time <= 0) {
          clearInterval(timer);
          this.canSend = true;
        }
      }, 1000);
    },
全球's avatar
全球 committed
164

leiqingsong's avatar
leiqingsong committed
165 166 167
    inputClick() {
      this.rate = this.money * 0.02;
      this.account = this.money - this.rate;
168 169 170
      let num = this.money;
      var re = /([0-9]+\.[0-9]{2})[0-9]*/;
      this.money = num.replace(re, "$1");
leiqingsong's avatar
leiqingsong committed
171
    },
leiqingsong's avatar
leiqingsong committed
172 173
    canCashOut() {
      const params = {
leiqingsong's avatar
leiqingsong committed
174
        userId: JSON.parse(localStorage.getItem("user")).userId
leiqingsong's avatar
leiqingsong committed
175 176 177 178 179 180 181 182
      };
      getWithdrawalAmount(params).then(res => {
        if (res.code === 0) {
          this.remainMoney = res.data.currentMoneyCan;
        } else {
          this.remainMoney = 100;
        }
      });
leiqingsong's avatar
leiqingsong committed
183
      getWithdrawalAmount;
leiqingsong's avatar
leiqingsong committed
184
    },
leiqingsong's avatar
leiqingsong committed
185 186 187 188 189
    jumpToBank() {
      console.log("1");
      this.$router.push("/bank");
    },
    // 全部提现
190 191
    allIn() {
      this.money = this.remainMoney;
leiqingsong's avatar
leiqingsong committed
192
    },
leiqingsong's avatar
leiqingsong committed
193
    // 点击提现
leiqingsong's avatar
leiqingsong committed
194
    onCashOut() {
leiqingsong's avatar
leiqingsong committed
195
      if (this.money == 0) {
leiqingsong's avatar
leiqingsong committed
196
        this.$toast.fail("请输入正确金额");
leiqingsong's avatar
leiqingsong committed
197 198
        return;
      }
leiqingsong's avatar
leiqingsong committed
199 200 201 202
      if (!this.money) {
        this.$toast.fail("未输入提现金额");
        return;
      }
leiqingsong's avatar
leiqingsong committed
203
      if (this.money > this.remainMoney) {
leiqingsong's avatar
leiqingsong committed
204 205
        this.$toast.fail("输入超过可提现金额,请重新输入");
        return;
leiqingsong's avatar
leiqingsong committed
206
      }
leiqingsong's avatar
leiqingsong committed
207 208
      this.validCode = null;
      this.validCodeDialogShow = true;
209
    },
leiqingsong's avatar
leiqingsong committed
210
    taxtClick() {
leiqingsong's avatar
leiqingsong committed
211 212 213 214 215 216 217 218 219 220 221
      this.showExplain = !this.showExplain;
      if (this.showExplain) {
        const params = {
          money: 1
        };
        getTaxRate(params).then(res => {
          if (res.code === 0) {
            this.textName = res.data.taxDesc;
          }
        });
      }
leiqingsong's avatar
leiqingsong committed
222
    },
leiqingsong's avatar
leiqingsong committed
223 224
    getUserInfo() {
      const params = {
leiqingsong's avatar
leiqingsong committed
225
        userId: JSON.parse(localStorage.getItem("user")).userId
leiqingsong's avatar
leiqingsong committed
226 227 228
      };
      getUserBankInfo(params).then(res => {
        if (res.code === 0) {
leiqingsong's avatar
leiqingsong committed
229 230 231 232 233
          if (res.data.bankName) {
            this.bank = res.data.bankName;
          } else {
            this.bank = "";
          }
leiqingsong's avatar
leiqingsong committed
234 235 236
        }
      });
    },
leiqingsong's avatar
leiqingsong committed
237 238 239
    onCloseDialog() {
      this.validCodeDialogShow = false;
    },
240
    onSubmit() {
leiqingsong's avatar
leiqingsong committed
241
      if (!this.validCode) {
leiqingsong's avatar
leiqingsong committed
242
        this.$toast.fail("请输入验证码");
leiqingsong's avatar
leiqingsong committed
243 244
        return;
      }
245
      this.validCodeDialogShow = false;
leiqingsong's avatar
leiqingsong committed
246 247
      const params = {
        code: this.validCode,
全球's avatar
全球 committed
248
        money: this.money,
leiqingsong's avatar
leiqingsong committed
249
        userId: JSON.parse(localStorage.getItem("user")).userId
leiqingsong's avatar
leiqingsong committed
250 251 252 253
      };
      cashOut(params)
        .then(res => {
          this.resultDialog = true;
leiqingsong's avatar
leiqingsong committed
254
          if (res.code == 0) {
leiqingsong's avatar
leiqingsong committed
255 256 257 258 259
            this.resultDialogTitle = "提现成功";
            this.resultDialogTip = "提现成功,请及时查收";
            this.resultDialogImg = require("@/assets/images/成功.png");
          } else {
            this.resultDialogTitle = "提现失败";
全球's avatar
全球 committed
260
            this.resultDialogTip = res.message;
leiqingsong's avatar
leiqingsong committed
261 262 263 264 265 266
            this.resultDialogImg = require("@/assets/images/叉号.png");
          }
        })
        .catch(err => {
          this.$toast.fail(err.response.data.error);
        });
267 268 269
    },
    onSuccess() {
      this.resultDialog = false;
270 271 272 273 274 275 276 277
    }
  }
};
</script>

<style lang="scss" scoped>
.cash-out {
  padding: 10px 0;
leiqingsong's avatar
leiqingsong committed
278
  font-family: PingFang-SC-Medium;
279 280 281 282 283 284 285 286 287 288
  .bank {
    ::v-deep .van-field__control {
      text-align: right;
    }
  }
  .detail {
    height: 380px;
    padding: 10px 16px;
    background-color: #ffffff;

leiqingsong's avatar
leiqingsong committed
289 290 291
    .cash-out-title {
      font-size: 24px;
    }
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
    .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;
        }
      }
    }
  }
}
347 348 349 350
.content-text {
  width: 185px;
  margin: 25px auto;
  text-align: center;
leiqingsong's avatar
leiqingsong committed
351
  font-family: PingFang-SC-Medium;
352 353 354
  font-size: 14px;
  color: #333333;
}
leiqingsong's avatar
leiqingsong committed
355 356 357 358 359
.validCodeInput {
  width: 245px;
  margin: 10px auto;
  background-color: #f9f9f9;
  border-radius: 20px;
360 361 362 363
  .van-field__left-icon {
    display: flex;
    align-items: center;
  }
leiqingsong's avatar
leiqingsong committed
364 365 366 367 368
  .valid-code {
    width: 16px;
    height: 18px;
  }
}
全球's avatar
全球 committed
369 370 371 372 373
.verify-code {
  background-color: transparent;
  border: none;
  color: #88c677;
}
374
</style>