敢为人鲜小程序前端代码仓库
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.

336 lines
8.7 KiB

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