withdrawal.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <v-header scroll title="提现" backgroundColor="#fff">
  3. <view class="withdrawal-container flex">
  4. <view class="withdrawal-header jCenter">
  5. <view class="flex-all-1"></view>
  6. <view class="withdrawal-header-info row aCenter">
  7. <view class="flex-all-1">提现金额</view>
  8. <view @click="triggerRecord" class="withdrawal-record">提现记录</view>
  9. </view>
  10. <view class="withdrawal-input-container row aCenter">
  11. <view class="withdrawal-price-em">¥</view>
  12. <view class="flex-all-1">
  13. <input v-model="price" @blur="blurFormatPrice" type="digit" class="withdrawal-input" />
  14. </view>
  15. </view>
  16. <view class="row withdrawal-footer aCenter">
  17. <view>可提现余额¥{{user.profit || '0.00'}}</view>
  18. <view class="withdrawal-cash" @click="triggerToAll">全部提现</view>
  19. </view>
  20. </view>
  21. <view class="center">
  22. <view @click="triggerSubmit" class="withdrawal-button center">确定提现</view>
  23. </view>
  24. </view>
  25. </v-header>
  26. </template>
  27. <script>
  28. import vHeader from '@/components/v-header/main.vue';
  29. import user from '@/mixins/user';
  30. import toast from '@/utils/tool/toast';
  31. import globalMixins from '@/mixins/global';
  32. import modal from '@/utils/tool/modal';
  33. export default {
  34. name: "withdrawal",
  35. mixins:[globalMixins,user],
  36. data(){
  37. return {
  38. price:''
  39. }
  40. },
  41. methods:{
  42. blurFormatPrice(){
  43. let price = this.price.toString();
  44. if (/\d+.{0,1}\d*/.test(price)) {
  45. let usePrice = price.split('.') || [];
  46. let lastLength = usePrice[1] && usePrice[1].length || 0;
  47. lastLength = lastLength >= 2? 2:0;
  48. if (lastLength) {
  49. usePrice[1] = usePrice[1].substr(0,lastLength);
  50. price = usePrice.join('.');
  51. }
  52. // 不能小于0
  53. price = price <0?0:price;
  54. let maxPrice = parseFloat(this.user.profit) || 0;
  55. price = price >= maxPrice ? this.user.profit : price;
  56. price = parseFloat(price).toString();
  57. this.price = price;
  58. this.beforePrice = price;
  59. } else {
  60. this.price = this.beforePrice;
  61. }
  62. },
  63. triggerRecord(){
  64. return this.$router.navigateTo('withdrawal-record');
  65. },
  66. triggerToAll(){
  67. if (this.price !== this.user.profit) {
  68. this.price = this.user.profit;
  69. }
  70. },
  71. triggerSubmit(){
  72. if (this.cashStatus) return null;
  73. let price = parseFloat(this.price);
  74. if (!price) return toast.info('请输入提现金额');
  75. else if (price <= 0) return toast.info('金额必须大于零');
  76. else if (this.user.withdrawLimit && price < parseFloat(this.user.withdrawLimit)) return toast.info('最少提现'+this.user.withdrawLimit+'元');
  77. else if (price > parseFloat(this.user.profit)) return toast.info('超出提现金额');
  78. modal.confirm({
  79. title:'提现确认',
  80. content:'是否执行提现操作',
  81. confirm:()=>{
  82. return this.$request({
  83. url:'user/profitWithdraw',
  84. token:true,
  85. data:{
  86. money: price
  87. },
  88. loading:'处理中',
  89. message:1,
  90. failMessage:true,
  91. next:({status})=> this.cashStatus = status
  92. }).then((data)=>{
  93. if (data.isSuccess) {
  94. this.updateUserInfo({
  95. profit: (parseFloat(this.user.profit) - price).toFixed(2)
  96. });
  97. this.beforePrice = '';
  98. this.$store.dispatch('updateUserInfoPromise',true);
  99. this.price = '';
  100. }
  101. });
  102. }
  103. });
  104. }
  105. },
  106. components:{
  107. vHeader
  108. },
  109. created(){
  110. this.beforePrice = this.price;
  111. }
  112. }
  113. </script>
  114. <style scoped lang="scss" src="./style.scss"></style>