withdraw.vue 7.5 KB

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