withdraw.vue 12 KB

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