index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="withdrawal-main">
  3. <view class="withdrawal-item">
  4. <label class="withdrawal-label">提现到账</label>
  5. <view class="withdrawal-item-right" @click="openSheet">
  6. <view class="withdrawal-text">{{ w_key }}</view>
  7. <up-icon name="arrow-right"></up-icon>
  8. </view>
  9. </view>
  10. <view v-if="w_key === '支付宝账户'">
  11. <view class="withdrawal-item">
  12. <label class="withdrawal-label">支付宝账户名</label>
  13. </view>
  14. <view class="price-box">
  15. <input class="price-input2" placeholder="请输入支付宝账户名" border="none" v-model="priceData.name"
  16. />
  17. </view>
  18. <view class="withdrawal-item">
  19. <label class="withdrawal-label">支付宝账号</label>
  20. </view>
  21. <view class="price-box">
  22. <input class="price-input2" placeholder="请输入支付宝账号" border="none" v-model="priceData.code"
  23. />
  24. </view>
  25. </view>
  26. <view class="withdrawal-item">
  27. <label class="withdrawal-label">提现金额</label>
  28. </view>
  29. <view class="price-box">
  30. <up-icon name="rmb" size="28" color="rgba(0, 0, 0, 1)"></up-icon>
  31. <input class="price-input" placeholder="请输入提现金额" border="none" v-model="priceData.price" @change="change" />
  32. </view>
  33. <view class="withdrawal-item">
  34. <label class="withdrawal-label">可提现余额 <up-icon name="rmb"></up-icon>{{ maxPrice }}</label>
  35. <view class="withdrawal-item-right" @click="onMaxChange">
  36. <view class="withdrawal-text">全部提现</view>
  37. </view>
  38. </view>
  39. <view style="margin-top: 45px;">
  40. <up-button type="primary" text="确定提现" @click="onSubmit"></up-button>
  41. </view>
  42. <up-action-sheet :show="show" @close="close" @select="select" :actions="actions">
  43. </up-action-sheet>
  44. </view>
  45. </template>
  46. <script setup>
  47. import { ref } from 'vue';
  48. import { getVolunteerAccountInfo,getAccountInfo,submitAmountApply} from "@/api/mine";
  49. import {
  50. onShow,
  51. } from "@dcloudio/uni-app";
  52. const actions = [
  53. {
  54. name: '支付宝账户',
  55. }
  56. ]
  57. const userType = uni.getStorageSync('userType') //读取本地存储
  58. const w_key = ref('支付宝账户');
  59. const show = ref(false);
  60. const maxPrice = ref(0);
  61. const priceData = ref({
  62. // price: '0.01',
  63. // name: '搁置',
  64. // code: '18696601943'
  65. price: '',
  66. name: '',
  67. code: ''
  68. })
  69. const change = (e) => {
  70. console.log('change', e);
  71. const regex = /^\d*\.?\d*$/;
  72. if (!regex.test(e.detail.value)) {
  73. priceData.value.price = priceData.value.price.replace(/[^\d.]/g, '');
  74. }
  75. };
  76. const openSheet = (index) => {
  77. show.value = true;
  78. }
  79. const close = () => {
  80. show.value = false;
  81. }
  82. const select = (row) => {
  83. w_key.value = row.name
  84. console.log('select', index);
  85. }
  86. const errors = (e) => {
  87. uni.showToast({
  88. title: e,
  89. icon: 'none',
  90. })
  91. }
  92. const handleCheck = ()=> {
  93. const is =priceData.value.price && priceData.value.price>0&&priceData.value.name && priceData.value.code;
  94. if(is){
  95. return true
  96. }
  97. !priceData.value.price && errors('请输入提现金额');
  98. priceData.value.price<=0 && errors('请输入正确的金额');
  99. !priceData.value.name&& errors('请输入账户名');
  100. !priceData.value.code&& errors('请输入账号');
  101. return false
  102. }
  103. const onSubmit = () => {
  104. console.log("TCL: priceData", priceData.value)
  105. // init();
  106. const type = handleCheck();
  107. type && submitAmountApply({
  108. takeAmount:priceData.value.price,
  109. alipayName:priceData.value.name,
  110. alipayAccountNo:priceData.value.code,
  111. payType:'2'
  112. }).then(res => {
  113. if(res.code === 200){
  114. uni.showToast({
  115. title: '提交成功',
  116. icon: 'success'
  117. })
  118. setTimeout(() => {
  119. uni.redirectTo({ url: `/pages_mine/pages/wallet/index` });
  120. }, 800)
  121. }
  122. })
  123. }
  124. const onMaxChange = () => {
  125. priceData.value.price = maxPrice.value;
  126. }
  127. const init = async() => {
  128. try {
  129. uni.showLoading({
  130. title: '数据加载中...'
  131. });
  132. if(userType === 2){
  133. const res = await getVolunteerAccountInfo();
  134. maxPrice.value = res.data.balance;
  135. }
  136. if(userType === 1){
  137. const res = await getAccountInfo();
  138. maxPrice.value = res.data.balance;
  139. }
  140. } catch (error) {
  141. console.log('error', error);
  142. uni.showToast({
  143. title: error.msg,
  144. icon: 'error',
  145. });
  146. } finally {
  147. uni.hideLoading();
  148. }
  149. }
  150. onShow(()=>{
  151. init();
  152. })
  153. </script>
  154. <style lang="scss" scoped>
  155. .withdrawal-main {
  156. position: fixed;
  157. top: 0px;
  158. left: 0px;
  159. right: 0px;
  160. bottom: 0px;
  161. background-color: #fff;
  162. padding: 0 12px;
  163. .withdrawal-item {
  164. display: flex;
  165. align-items: center;
  166. justify-content: space-between;
  167. padding: 12px 0;
  168. .withdrawal-label {
  169. font-size: 14px;
  170. font-weight: 500;
  171. line-height: 20.27px;
  172. color: rgba(153, 153, 153, 1);
  173. display: flex;
  174. align-items: center;
  175. }
  176. .withdrawal-item-right {
  177. display: flex;
  178. align-items: center;
  179. .withdrawal-text {
  180. font-size: 16px;
  181. font-weight: 700;
  182. line-height: 23.17px;
  183. color: rgba(0, 0, 0, 1);
  184. margin-right: 6px;
  185. }
  186. }
  187. }
  188. .price-box {
  189. display: flex;
  190. .price-input {
  191. flex: 1;
  192. height: 58px;
  193. padding: 0 12px;
  194. font-size: 28px;
  195. }
  196. .price-input2 {
  197. flex: 1;
  198. height: 38px;
  199. padding: 0 12px;
  200. font-size: 16px;
  201. }
  202. }
  203. }
  204. </style>