withdraw.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <view class="withdraw-container">
  3. <!-- 顶部余额展示 -->
  4. <view class="balance-box">
  5. <view>
  6. <view class="balance-title">可提现余额</view>
  7. <view class="balance-rmb">
  8. <view style="display: flex; align-items: flex-end">¥</view>
  9. <view class="rmb">{{ appStore.$userInfo.nowMoney }}</view>
  10. </view>
  11. </view>
  12. </view>
  13. <!-- 主要内容区域 -->
  14. <view class="main-content">
  15. <!-- 到账账户 -->
  16. <view class="section">
  17. <view class="section-title">到账账户</view>
  18. <view class="account-item" @click="goToBankManage">
  19. <view class="account-info">
  20. <view class="bank-icon">
  21. <!-- <text class="iconfont icon-qianbao">🏦</text> -->
  22. <text
  23. :style="{
  24. color:
  25. defaultAccount?.accountType === 1 ? '#f2cb51' : '#019FE8',
  26. }"
  27. class="iconfont"
  28. :class="[
  29. defaultAccount?.accountType === 1
  30. ? 'icon-qianbao'
  31. : 'icon-zhifubao',
  32. ]"
  33. ></text>
  34. </view>
  35. <view class="account-details" v-if="defaultAccount">
  36. <text
  37. class="account-number"
  38. v-if="defaultAccount.accountType === 1"
  39. >{{ defaultAccount.bankName }}({{
  40. formatCardNumber(defaultAccount.accountNumber)
  41. }})</text
  42. >
  43. <text class="account-number" v-else
  44. >{{ defaultAccount.accountName }}({{
  45. formatCardNumber(defaultAccount.accountNumber)
  46. }})</text
  47. >
  48. </view>
  49. </view>
  50. <view class="arrow">{{ ">" }}</view>
  51. </view>
  52. </view>
  53. <!-- 提现金额 -->
  54. <view class="section">
  55. <view class="section-title">提现金额</view>
  56. <view class="amount-input-container">
  57. <view class="currency-symbol">¥</view>
  58. <input
  59. class="amount-input"
  60. type="digit"
  61. v-model="withdrawAmount"
  62. placeholder="请输入提现金额"
  63. @input="onAmountInput"
  64. />
  65. <view class="withdraw-all" @click="withdrawAll">全部提现</view>
  66. </view>
  67. <view class="balance-info"
  68. >账户余额{{ appStore.$userInfo.nowMoney }}元</view
  69. >
  70. </view>
  71. <!-- 提交按钮 -->
  72. <view class="submit-section">
  73. <view class="btn-box" @click="submitWithdraw">
  74. <image class="btn" src="/static/images/sb_btn.png"></image>
  75. <text class="btn-text">提交申请</text>
  76. </view>
  77. </view>
  78. </view>
  79. <!-- 协议窗口 -->
  80. <up-parse :content="content"></up-parse>
  81. </view>
  82. </template>
  83. <script setup>
  84. import { ref, computed } from "vue";
  85. import { withdrawToCard } from "@/api/user";
  86. import { onShow } from "@dcloudio/uni-app";
  87. import { useAppStore } from "@/stores/app";
  88. import { getDefaultAccount, getUserInfo, agreementGetoneApi } from "@/api/user";
  89. // 响应式数据
  90. const availableBalance = ref("5733.67");
  91. const withdrawAmount = ref("");
  92. const defaultAccount = ref(null);
  93. const appStore = useAppStore();
  94. const content = ref("");
  95. // 计算属性
  96. const canSubmit = computed(() => {
  97. return withdrawAmount.value && parseFloat(withdrawAmount.value) > 0;
  98. });
  99. // 获取协议
  100. function agreementGetoneFn() {
  101. // 资产说明
  102. agreementGetoneApi({ name: "withraw" }).then((res) => {
  103. content.value = res.data?.content;
  104. });
  105. }
  106. onShow(() => {
  107. agreementGetoneFn();
  108. fetchDefaultAccount();
  109. fetchUserInfo();
  110. });
  111. async function fetchUserInfo() {
  112. try {
  113. const { data } = await getUserInfo();
  114. appStore.UPDATE_USERINFO(data);
  115. } catch (error) {
  116. console.error("getUserInfo", error);
  117. }
  118. }
  119. // 获取默认账户详情
  120. async function fetchDefaultAccount() {
  121. try {
  122. const { data } = await getDefaultAccount();
  123. defaultAccount.value = data;
  124. } catch (error) {
  125. console.error("getDefaultAccount", error);
  126. }
  127. }
  128. const formatCardNumber = (cardNumber) => {
  129. // 显示卡号,只显示后4位,其他用*代替
  130. if (cardNumber.length <= 4) return cardNumber;
  131. const lastFour = cardNumber.slice(-4);
  132. return `****${lastFour}`;
  133. };
  134. // 方法
  135. const onAmountInput = (e) => {
  136. let value = e.detail.value;
  137. // 限制输入格式,只允许数字和小数点
  138. value = value.replace(/[^0-9.]/g, "");
  139. // 限制小数点后两位
  140. if (value.includes(".")) {
  141. const parts = value.split(".");
  142. if (parts[1] && parts[1].length > 2) {
  143. value = parts[0] + "." + parts[1].substring(0, 2);
  144. }
  145. }
  146. withdrawAmount.value = value;
  147. };
  148. const withdrawAll = () => {
  149. withdrawAmount.value = appStore.$userInfo.nowMoney;
  150. };
  151. const goToBankManage = () => {
  152. // 跳转到银行卡管理页面
  153. uni.navigateTo({
  154. url: "/pages/users/bank_card_manage/index",
  155. });
  156. };
  157. const submitWithdraw = () => {
  158. if (!appStore.userInfo.realNameVerified) {
  159. uni.showToast({ title: "请先进行实名认证", icon: "none", duration: 2000 });
  160. uni.navigateTo({ url: "/pages/users/face_detect/index" });
  161. return;
  162. }
  163. if (!canSubmit.value) return;
  164. if (!defaultAccount.value || !defaultAccount.value.id) {
  165. uni.showToast({
  166. title: "请选择提现账户",
  167. icon: "none",
  168. });
  169. return;
  170. }
  171. // 提交提现申请
  172. uni.showModal({
  173. title: "提示",
  174. content: `确认提现 ¥${withdrawAmount.value} 吗?`,
  175. success: async (res) => {
  176. if (res.confirm) {
  177. try {
  178. if (
  179. Number(withdrawAmount.value) > Number(appStore.$userInfo.nowMoney)
  180. ) {
  181. return uni.showToast({
  182. title: "余额不足",
  183. });
  184. }
  185. // 提现方式| alipay=支付宝,bank=银行卡,weixin=微信
  186. const extractType =
  187. defaultAccount.value.accountType === 1 ? "bank" : "alipay";
  188. // 提现金额
  189. const money = withdrawAmount.value;
  190. // // 姓名
  191. const name = defaultAccount.value.accountName;
  192. const alipayParams = {
  193. alipayCode: defaultAccount.value.accountNumber, // 支付宝账号
  194. extractType,
  195. name,
  196. money,
  197. };
  198. const bankParams = {
  199. extractType,
  200. bankName: defaultAccount.value.bankName, // 提现银行名称
  201. cardum: defaultAccount.value.accountNumber, // 银行卡
  202. money,
  203. name,
  204. };
  205. const params =
  206. defaultAccount.value.accountType === 1 ? bankParams : alipayParams;
  207. await withdrawToCard(params);
  208. // fetchUserInfo()
  209. const { data } = await getUserInfo();
  210. appStore.UPDATE_USERINFO(data);
  211. uni.showToast({
  212. title: "提现申请已提交",
  213. icon: "success",
  214. });
  215. setTimeout(() => {
  216. uni.navigateTo({
  217. url: "/pages/users/vault/index",
  218. });
  219. }, 1000);
  220. } catch (error) {
  221. console.error("withdrawToCard", error);
  222. const title = typeof error === "string" ? error : "提现失败";
  223. uni.showToast({
  224. title,
  225. duration: 2000,
  226. });
  227. } finally {
  228. withdrawAmount.value = "";
  229. }
  230. }
  231. },
  232. });
  233. };
  234. </script>
  235. <style lang="scss" scoped>
  236. .withdraw-container {
  237. min-height: 100%;
  238. width: 100%;
  239. background: $uni-bg-primary;
  240. display: flex;
  241. flex-direction: column;
  242. align-items: center;
  243. .balance-box {
  244. height: 300rpx;
  245. padding-left: 60rpx;
  246. color: #000;
  247. display: flex;
  248. align-items: center;
  249. flex-wrap: wrap;
  250. width: 100%;
  251. box-sizing: border-box;
  252. .balance-title {
  253. width: 100%;
  254. font-size: 30rpx;
  255. margin-bottom: 10rpx;
  256. }
  257. .balance-rmb {
  258. width: 100%;
  259. display: flex;
  260. width: 100%;
  261. font-size: 56rpx;
  262. .rmb {
  263. font-size: 56rpx;
  264. margin-left: 10rpx;
  265. }
  266. }
  267. }
  268. .main-content {
  269. width: 100%;
  270. padding: 40rpx 40rpx;
  271. box-sizing: border-box;
  272. background: #fff;
  273. border-radius: 40rpx 40rpx 0 0;
  274. margin-top: -20rpx;
  275. // box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
  276. .section {
  277. margin-bottom: 50rpx;
  278. .section-title {
  279. color: #000;
  280. font-size: 32rpx;
  281. // font-weight: 600;
  282. margin-bottom: 20rpx;
  283. position: relative;
  284. &::before {
  285. content: "";
  286. position: absolute;
  287. left: -16rpx;
  288. top: 50%;
  289. transform: translateY(-50%);
  290. width: 4rpx;
  291. height: 32rpx;
  292. background-color: #f8c007;
  293. border-radius: 3rpx;
  294. }
  295. }
  296. .account-item {
  297. display: flex;
  298. align-items: center;
  299. justify-content: space-between;
  300. padding: 20rpx 24rpx;
  301. background: #f8f9fa;
  302. border-radius: 16rpx;
  303. border: 2rpx solid #e9ecef;
  304. transition: all 0.3s ease;
  305. &:active {
  306. background: #f0f0f0;
  307. transform: scale(0.98);
  308. }
  309. .account-info {
  310. display: flex;
  311. align-items: center;
  312. .bank-icon {
  313. display: flex;
  314. align-items: center;
  315. justify-content: center;
  316. margin-right: 24rpx;
  317. .icon {
  318. font-size: 28rpx;
  319. }
  320. }
  321. .account-details {
  322. .account-number {
  323. color: #333;
  324. font-size: 30rpx;
  325. font-weight: 500;
  326. }
  327. }
  328. }
  329. .arrow {
  330. color: #999;
  331. font-size: 32rpx;
  332. font-weight: 300;
  333. }
  334. }
  335. .amount-input-container {
  336. display: flex;
  337. align-items: center;
  338. background-color: #ededed;
  339. border-radius: 15rpx;
  340. padding: 20rpx 24rpx;
  341. transition: border-color 0.3s ease;
  342. &:focus-within {
  343. border-color: #e9c279;
  344. }
  345. .currency-symbol {
  346. color: #333;
  347. font-size: 32rpx;
  348. // font-weight: 600;
  349. margin-right: 16rpx;
  350. }
  351. .amount-input {
  352. height: 100%;
  353. flex: 1;
  354. display: flex;
  355. align-items: center;
  356. color: #000;
  357. font-size: 28rpx;
  358. &::placeholder {
  359. color: #999;
  360. font-weight: 400;
  361. }
  362. }
  363. .withdraw-all {
  364. color: #e9c279;
  365. font-size: 28rpx;
  366. font-weight: 500;
  367. transition: all 0.3s ease;
  368. &:active {
  369. background: #e9c279;
  370. color: #fff;
  371. }
  372. }
  373. }
  374. .balance-info {
  375. color: #666;
  376. font-size: 24rpx;
  377. margin-top: 16rpx;
  378. padding-left: 8rpx;
  379. }
  380. }
  381. .submit-section {
  382. width: 100%;
  383. display: flex;
  384. justify-content: center;
  385. .btn-box {
  386. height: 100rpx;
  387. display: flex;
  388. justify-content: center;
  389. align-items: center;
  390. margin-bottom: 40rpx;
  391. margin-top: 80rpx;
  392. width: 100%;
  393. box-sizing: border-box;
  394. position: relative;
  395. .btn {
  396. height: 80rpx;
  397. width: 380rpx;
  398. }
  399. .btn-text {
  400. font-size: 30rpx;
  401. color: #000;
  402. position: absolute;
  403. top: 50%;
  404. left: 50%;
  405. transform: translate(-50%, -50%);
  406. }
  407. }
  408. }
  409. .tips-section {
  410. padding: 30rpx 0;
  411. .tips-title {
  412. color: #333;
  413. font-size: 28rpx;
  414. font-weight: 600;
  415. margin-bottom: 16rpx;
  416. }
  417. .tips-item {
  418. color: #666;
  419. font-size: 26rpx;
  420. line-height: 40rpx;
  421. margin-bottom: 8rpx;
  422. }
  423. .tips-note {
  424. color: #999;
  425. font-size: 24rpx;
  426. line-height: 36rpx;
  427. margin-top: 8rpx;
  428. }
  429. }
  430. }
  431. }
  432. </style>