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