withdraw.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view class="container">
  3. <!-- 内容区域 -->
  4. <scroll-view class="content" scroll-y>
  5. <!-- 提现至 -->
  6. <view class="withdraw-to-section">
  7. <view class="section-label">提现至</view>
  8. <view class="bank-info" @click="goSelectBank">
  9. <text>{{ bankCardInfo.bankName || '请选择银行卡' }}</text>
  10. <text class="card-tail" v-if="bankCardInfo.cardNumber">({{ getCardTail(bankCardInfo.cardNumber) }})</text>
  11. <image class="w36 h36" src="@/static/image/icon_my_more.png" mode=""></image>
  12. </view>
  13. </view>
  14. <!-- 提现金额 -->
  15. <view class="amount-section">
  16. <view class="section-label">提现金额</view>
  17. <view class="amount-input-wrapper">
  18. <view class="align-end" style="flex:1">
  19. <text class="currency">¥</text>
  20. <input
  21. class="amount-input"
  22. v-model="withdrawAmount"
  23. type="digit"
  24. placeholder="0.00"
  25. @input="onAmountInput"
  26. />
  27. </view>
  28. <text class="withdraw-all" @click="withdrawAll">全部提现</text>
  29. </view>
  30. <view class="amount-footer">
  31. <text class="available-amount">可提现金额: ¥ {{ availableAmount || '0.00' }}</text>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. <!-- 底部按钮和提示 -->
  36. <view class="bottom-bar">
  37. <view class="submit-btn" @click="handleSubmit">确认提现</view>
  38. <view class="tips">提现申请发起后,预计在3个工作日到账</view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import { submitWithdraw, getWithdrawInfo } from '@/api-js/withdraw'
  44. import { getBankCardInfo } from '@/api-js/bankCard'
  45. export default {
  46. data() {
  47. return {
  48. withdrawAmount: '320.00',
  49. availableAmount: '320.00',
  50. bankCardInfo: {}
  51. }
  52. },
  53. onLoad() {
  54. this.loadData()
  55. },
  56. methods: {
  57. async loadData() {
  58. try {
  59. uni.showLoading({ title: '加载中...' })
  60. const [bankRes, withdrawRes] = await Promise.all([
  61. getBankCardInfo(),
  62. getWithdrawInfo()
  63. ])
  64. uni.hideLoading()
  65. if (bankRes.code === 200 && bankRes.data) {
  66. this.bankCardInfo = bankRes.data
  67. }
  68. if (withdrawRes.code === 200 && withdrawRes.data) {
  69. this.availableAmount = (withdrawRes.data.availableAmount || 0).toFixed(2)
  70. this.withdrawAmount = this.availableAmount
  71. } else {
  72. // 示例数据
  73. this.availableAmount = '320.00'
  74. this.withdrawAmount = '320.00'
  75. }
  76. if (!this.bankCardInfo.id) {
  77. // 示例数据
  78. this.bankCardInfo = {
  79. bankName: '中国工商银行',
  80. cardNumber: '8869'
  81. }
  82. }
  83. } catch (e) {
  84. uni.hideLoading()
  85. console.error('加载数据失败', e)
  86. this.availableAmount = '320.00'
  87. this.withdrawAmount = '320.00'
  88. this.bankCardInfo = {
  89. bankName: '中国工商银行',
  90. cardNumber: '8869'
  91. }
  92. }
  93. },
  94. getCardTail(cardNumber) {
  95. if (!cardNumber) return ''
  96. if (cardNumber.length < 4) return cardNumber
  97. return cardNumber.substring(cardNumber.length - 4)
  98. },
  99. onAmountInput(e) {
  100. let value = e.detail.value
  101. // 限制只能输入数字和小数点
  102. value = value.replace(/[^\d.]/g, '')
  103. // 限制小数点后两位
  104. if (value.indexOf('.') > -1) {
  105. const parts = value.split('.')
  106. if (parts[1] && parts[1].length > 2) {
  107. value = parts[0] + '.' + parts[1].substring(0, 2)
  108. }
  109. }
  110. // 限制不能超过可提现金额
  111. const amount = parseFloat(value) || 0
  112. const available = parseFloat(this.availableAmount) || 0
  113. if (amount > available) {
  114. value = this.availableAmount
  115. }
  116. this.withdrawAmount = value
  117. },
  118. withdrawAll() {
  119. this.withdrawAmount = this.availableAmount
  120. },
  121. goBack() {
  122. uni.navigateBack()
  123. },
  124. goSelectBank() {
  125. uni.navigateTo({
  126. url: '/pages_user/bankCard'
  127. })
  128. },
  129. async handleSubmit() {
  130. // 验证银行卡
  131. if (!this.bankCardInfo.id) {
  132. uni.showToast({
  133. icon: 'none',
  134. title: '请先添加银行卡'
  135. })
  136. setTimeout(() => {
  137. this.goSelectBank()
  138. }, 1500)
  139. return
  140. }
  141. // 验证金额
  142. const amount = parseFloat(this.withdrawAmount) || 0
  143. if (amount <= 0) {
  144. uni.showToast({
  145. icon: 'none',
  146. title: '请输入提现金额'
  147. })
  148. return
  149. }
  150. const available = parseFloat(this.availableAmount) || 0
  151. if (amount > available) {
  152. uni.showToast({
  153. icon: 'none',
  154. title: '提现金额不能超过可提现金额'
  155. })
  156. return
  157. }
  158. try {
  159. uni.showLoading({ title: '提交中...' })
  160. const res = await submitWithdraw({
  161. amount: this.withdrawAmount,
  162. bankCardId: this.bankCardInfo.id
  163. })
  164. uni.hideLoading()
  165. if (res.code === 200) {
  166. uni.navigateTo({
  167. url: '/pages_user/withdrawSuccess'
  168. })
  169. } else {
  170. uni.showToast({
  171. icon: 'none',
  172. title: res.msg || '提现失败'
  173. })
  174. }
  175. } catch (e) {
  176. uni.hideLoading()
  177. uni.showToast({
  178. icon: 'none',
  179. title: '提现失败'
  180. })
  181. }
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .container {
  188. min-height: 100vh;
  189. background: #f5f5f5;
  190. display: flex;
  191. flex-direction: column;
  192. }
  193. .navbar {
  194. display: flex;
  195. align-items: center;
  196. justify-content: space-between;
  197. padding: 20rpx 24rpx;
  198. background: #fff;
  199. border-bottom: 1rpx solid #f0f0f0;
  200. .nav-left {
  201. width: 60rpx;
  202. .back-icon {
  203. font-size: 36rpx;
  204. color: #333;
  205. font-weight: bold;
  206. }
  207. }
  208. .nav-title {
  209. flex: 1;
  210. text-align: center;
  211. font-size: 36rpx;
  212. font-weight: bold;
  213. color: #333;
  214. }
  215. .nav-right {
  216. display: flex;
  217. align-items: center;
  218. gap: 24rpx;
  219. width: 60rpx;
  220. justify-content: flex-end;
  221. .more-icon {
  222. font-size: 32rpx;
  223. color: #333;
  224. }
  225. .eye-icon {
  226. font-size: 32rpx;
  227. color: #333;
  228. }
  229. }
  230. }
  231. .content {
  232. flex: 1;
  233. padding-bottom: 200rpx;
  234. }
  235. .withdraw-to-section {
  236. background: #fff;
  237. padding: 32rpx;
  238. // margin: 24rpx;
  239. //border-radius: 16rpx;
  240. display: flex;
  241. align-items: center;
  242. justify-content: space-between;
  243. .section-label {
  244. font-family: PingFang SC, PingFang SC;
  245. font-weight: 400;
  246. font-size: 28rpx;
  247. color: #666666;
  248. }
  249. .bank-info {
  250. flex: 1;
  251. display: flex;
  252. align-items: center;
  253. justify-content: flex-end;
  254. margin-left: 24rpx;
  255. font-size: 28rpx;
  256. color: #333;
  257. .card-tail {
  258. margin: 0 8rpx;
  259. }
  260. .arrow-right {
  261. font-size: 32rpx;
  262. color: #999;
  263. margin-left: 8rpx;
  264. margin-bottom: 10rpx;
  265. }
  266. }
  267. }
  268. .amount-section {
  269. background: #fff;
  270. padding: 32rpx;
  271. //margin: 0 24rpx 24rpx;
  272. ///border-radius: 16rpx;
  273. .section-label {
  274. font-size: 28rpx;
  275. color: #333;
  276. font-weight: 500;
  277. margin-bottom: 24rpx;
  278. }
  279. .amount-input-wrapper {
  280. display: flex;
  281. align-items: flex-end;
  282. margin-bottom: 24rpx;
  283. .currency {
  284. font-family: PingFang SC, PingFang SC;
  285. font-weight: 600;
  286. font-size: 28rpx;
  287. color: #333333;
  288. margin-right: 8rpx;
  289. }
  290. .amount-input {
  291. flex: 1;
  292. font-size: 56rpx;
  293. font-weight: bold;
  294. color: #333;
  295. height: 80rpx;
  296. line-height: 80rpx;
  297. }
  298. .withdraw-all {
  299. font-family: PingFang SC, PingFang SC;
  300. font-weight: 400;
  301. font-size: 28rpx;
  302. color: #388BFF;
  303. }
  304. }
  305. .amount-footer {
  306. display: flex;
  307. align-items: center;
  308. justify-content: space-between;
  309. .available-amount {
  310. font-family: PingFang SC, PingFang SC;
  311. font-weight: 400;
  312. font-size: 24rpx;
  313. color: #999999;
  314. }
  315. }
  316. }
  317. .bottom-bar {
  318. position: fixed;
  319. bottom: 0;
  320. left: 0;
  321. right: 0;
  322. background: #fff;
  323. padding: 24rpx;
  324. border-top: 1rpx solid #f0f0f0;
  325. z-index: 100;
  326. .submit-btn {
  327. width: 100%;
  328. height: 88rpx;
  329. background: #388BFF;
  330. border-radius: 44rpx;
  331. display: flex;
  332. align-items: center;
  333. justify-content: center;
  334. font-size: 32rpx;
  335. font-weight: bold;
  336. color: #fff;
  337. margin-bottom: 16rpx;
  338. }
  339. .tips {
  340. text-align: center;
  341. font-size: 24rpx;
  342. color: #999;
  343. line-height: 1.5;
  344. }
  345. }
  346. </style>