敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

379 lines
11 KiB

1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="wallet-page">
  3. <!-- 导航栏 -->
  4. <navbar title="钱包" leftClick @leftClick="$utils.navigateBack" bgColor="#019245" color="#fff" />
  5. <!-- 总余额展示区 -->
  6. <view class="balance-card" :style="{ backgroundImage: 'url(/static/image/红烧肉.webp)' }">
  7. <view class="balance-info">
  8. <view class="balance-title">总余额</view>
  9. <view class="balance-amount">{{ walletData.balance.toFixed(2) }}</view>
  10. <view class="balance-actions">
  11. <view class="action-btn recharge-btn" v-if="!isRecharge" @tap="navigateToRecharge">
  12. <text>去充值</text>
  13. <text class="arrow">></text>
  14. </view>
  15. <view class="action-btn" v-else />
  16. <view class="action-btn detail-btn" @tap="navigateToDetail">
  17. <text>资产明细</text>
  18. <text class="arrow">></text>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 提现表单 -->
  24. <view class="withdraw-section">
  25. <view class="section-title">{{ isRecharge ? '我要充值' : '我要提现' }}</view>
  26. <!-- 提现金额输入框 -->
  27. <view class="input-item">
  28. <text class="currency-symbol">¥</text>
  29. <input v-if="!isRecharge" class="amount-input" type="digit" v-model="withdrawAmount" placeholder="请输入提现金额"
  30. @blur="validateAmount" />
  31. <input v-else class="amount-input" type="digit" v-model="rechargeAmount" placeholder="请输入充值金额"
  32. @blur="validateAmount" />
  33. </view>
  34. <!-- 真实姓名输入框 -->
  35. <view class="input-item" v-if="!isRecharge">
  36. <input class="name-input" type="nickname" v-model="realName" placeholder="请输入真实姓名"
  37. @blur="validateName" />
  38. </view>
  39. <!-- 提现说明 -->
  40. <view class="withdraw-notes" v-if="!isRecharge">
  41. <view class="notes-title">提现说明</view>
  42. <view class="notes-list">
  43. <view class="note-item" v-for="(rule, index) in walletData.withdrawRules" :key="index">
  44. <text>{{ index + 1 }}{{ rule }}</text>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <!-- 提现按钮 -->
  50. <view class="submit-btn-wrapper">
  51. <button class="submit-btn" @tap="submitWithdraw" :disabled="!isFormValid">
  52. {{ isRecharge ? '立即充值' : '立即提现' }}
  53. </button>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import navbar from '@/components/base/navbar.vue'
  59. import { walletData } from '@/static/js/mockWallet.js'
  60. export default {
  61. components: {
  62. navbar
  63. },
  64. data() {
  65. return {
  66. walletData: null,
  67. withdrawAmount: '',
  68. rechargeAmount: '',
  69. realName: '',
  70. amountError: '',
  71. nameError: '',
  72. isFormValid: true,
  73. isRecharge: false
  74. }
  75. },
  76. onLoad() {
  77. this.walletData = walletData
  78. },
  79. methods: {
  80. // 导航到充值页面
  81. navigateToRecharge() {
  82. this.isRecharge = true
  83. },
  84. // 导航到资产明细页面
  85. navigateToDetail() {
  86. this.$utils.navigateTo('/pages_order/mine/assets')
  87. },
  88. // 验证提现金额
  89. validateAmount() {
  90. if (!this.withdrawAmount) {
  91. this.amountError = '请输入提现金额'
  92. return false
  93. }
  94. const amount = parseFloat(this.withdrawAmount)
  95. if (isNaN(amount) || amount <= 0) {
  96. this.amountError = '请输入有效的提现金额'
  97. return false
  98. }
  99. if (amount > this.walletData.balance) {
  100. this.amountError = '提现金额不能大于余额'
  101. return false
  102. }
  103. if (amount > 200) {
  104. this.amountError = '单笔提现不能超过200元'
  105. return false
  106. }
  107. this.amountError = ''
  108. return true
  109. },
  110. // 验证真实姓名
  111. validateName() {
  112. if (!this.realName) {
  113. this.nameError = '请输入真实姓名'
  114. return false
  115. }
  116. if (this.realName.length < 2) {
  117. this.nameError = '请输入有效的姓名'
  118. return false
  119. }
  120. this.nameError = ''
  121. return true
  122. },
  123. // 提交提现申请
  124. submitWithdraw() {
  125. if (this.isRecharge) {
  126. return this.recharge()
  127. }
  128. // 再次验证表单
  129. if (!this.validateAmount() || !this.validateName()) {
  130. console.log(2);
  131. // 显示具体错误
  132. if (this.amountError) {
  133. console.log(3);
  134. uni.showToast({
  135. title: this.amountError,
  136. icon: 'error'
  137. })
  138. return
  139. }
  140. if (this.nameError) {
  141. uni.showToast({
  142. title: this.nameError,
  143. icon: 'error'
  144. })
  145. return
  146. }
  147. return
  148. }
  149. // 如果在isFormVaild为false的情况下进入函数 则为多次点击 直接返回
  150. if (this.isFormValid) {
  151. this.isFormValid = false
  152. }else return
  153. // 显示提交中状态
  154. uni.showLoading({
  155. title: '提交中...'
  156. })
  157. // 模拟提交过程
  158. setTimeout(() => {
  159. uni.hideLoading()
  160. uni.showToast({
  161. title: '提现申请已提交',
  162. icon: 'success'
  163. })
  164. // 模拟余额变更
  165. this.walletData.balance -= parseFloat(this.withdrawAmount)
  166. // 清空表单
  167. this.withdrawAmount = ''
  168. this.realName = ''
  169. this.isFormValid = true
  170. }, 1500)
  171. },
  172. recharge() {
  173. uni.showModal({
  174. title: '确认充值',
  175. content: '充值金额为' + this.rechargeAmount + '元',
  176. confirmColor: '#019245',
  177. success: (res) => {
  178. // 这里编写函数逻辑
  179. if (res.confirm) {
  180. uni.showLoading({
  181. title: '充值中...'
  182. })
  183. // 执行重置逻辑
  184. // 模拟重置时间
  185. setTimeout(() => {
  186. uni.hideLoading()
  187. uni.showToast({
  188. title: '充值成功',
  189. icon: 'success'
  190. })
  191. // 模拟余额变更
  192. this.walletData.balance += parseFloat(this.rechargeAmount)
  193. // 重置表单
  194. this.rechargeAmount = ''
  195. this.isRecharge = false
  196. }, 1500)
  197. }
  198. },
  199. fail: (err) => {
  200. console.log(err);
  201. }
  202. })
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .wallet-page {
  209. }
  210. .balance-card {
  211. width: 96%;
  212. height: 280rpx;
  213. background-size: cover;
  214. background-position: center;
  215. padding: 30rpx;
  216. box-sizing: border-box;
  217. position: relative;
  218. margin: 20rpx auto;
  219. border-radius: 20rpx;
  220. .balance-info {
  221. position: relative;
  222. z-index: 2;
  223. color: #fff;
  224. }
  225. .balance-title {
  226. font-size: 28rpx;
  227. margin-bottom: 10rpx;
  228. }
  229. .balance-amount {
  230. font-size: 56rpx;
  231. font-weight: bold;
  232. margin-bottom: 20rpx;
  233. }
  234. .balance-actions {
  235. display: flex;
  236. justify-content: space-between;
  237. // justify-content: center;
  238. align-items: center;
  239. .action-btn {
  240. padding: 10rpx 24rpx;
  241. font-size: 24rpx;
  242. border-radius: 30rpx;
  243. display: flex;
  244. align-items: center;
  245. }
  246. .recharge-btn {
  247. background-color: #fff;
  248. color: $uni-color;
  249. border: none;
  250. min-width: 120rpx;
  251. height: 60rpx;
  252. justify-content: center;
  253. font-size: 24rpx;
  254. font-weight: normal;
  255. gap: 4rpx;
  256. // line-height: 1;
  257. padding: 0 20rpx;
  258. }
  259. .detail-btn {
  260. .arrow {
  261. margin-left: 10rpx;
  262. }
  263. }
  264. }
  265. }
  266. .withdraw-section {
  267. padding: 30rpx;
  268. // background-color: #fff;
  269. .section-title {
  270. font-size: 32rpx;
  271. color: #333;
  272. margin-bottom: 30rpx;
  273. font-weight: bold;
  274. }
  275. .input-item {
  276. display: flex;
  277. align-items: center;
  278. padding: 24rpx 20rpx;
  279. margin-bottom: 20rpx;
  280. background-color: #e7e7e7;
  281. border-radius: 20rpx;
  282. .currency-symbol {
  283. color: #FF0000;
  284. margin-right: 20rpx;
  285. }
  286. .amount-input,
  287. .name-input {
  288. flex: 1;
  289. font-size: 28rpx;
  290. height: 60rpx;
  291. }
  292. .name-input {
  293. padding-left: 40rpx;
  294. }
  295. }
  296. .withdraw-notes {
  297. margin-top: 40rpx;
  298. .notes-title {
  299. font-size: 28rpx;
  300. color: #333;
  301. margin-bottom: 20rpx;
  302. }
  303. .notes-list {
  304. .note-item {
  305. font-size: 26rpx;
  306. color: #666;
  307. line-height: 1.6;
  308. margin-bottom: 10rpx;
  309. }
  310. }
  311. }
  312. }
  313. .submit-btn-wrapper {
  314. padding: 40rpx 30rpx;
  315. .submit-btn {
  316. width: 100%;
  317. height: 88rpx;
  318. background-color: $uni-color;
  319. color: #fff;
  320. font-size: 32rpx;
  321. border-radius: 44rpx;
  322. display: flex;
  323. align-items: center;
  324. justify-content: center;
  325. border: none;
  326. &:disabled {
  327. background-color: #ccc;
  328. color: rgba(255, 255, 255, 0.6);
  329. }
  330. }
  331. }
  332. </style>