edit.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="withdrawal-container">
  3. <view class="balance-info">
  4. <text class="balance-label">可用服务点数:</text>
  5. <text class="balance-amount">{{ user.wallet }}</text>
  6. </view>
  7. <view class="input-section">
  8. <text class="input-label">兑现数量(1个兑现1元人民币):</text>
  9. <input
  10. v-model.number="total_fee"
  11. type="number"
  12. class="amount-input"
  13. placeholder="请输入兑现数量"
  14. />
  15. </view>
  16. <button
  17. class="submit-btn"
  18. :class="{ 'submit-btn-disabled': !isValidAmount }"
  19. :disabled="!isValidAmount"
  20. @click="createOrder('wxpay')"
  21. >
  22. 发起兑现
  23. </button>
  24. <text v-if="errorMessage" class="error-message">{{ errorMessage }}</text>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. user: {},
  32. total_fee: null,
  33. errorMessage: ''
  34. }
  35. },
  36. computed: {
  37. isValidAmount() {
  38. return this.total_fee && this.total_fee > 0 && this.total_fee <= this.user.wallet
  39. }
  40. },
  41. onLoad() {
  42. this.user = this.getUser()
  43. },
  44. methods: {
  45. createOrder(provider) {
  46. uni.showModal({
  47. content: '功能正在开发中...',
  48. showCancel: false
  49. });
  50. return;
  51. if (!this.isValidAmount) {
  52. this.errorMessage = '请输入有效的兑现数量'
  53. return
  54. }
  55. this.errorMessage = ''
  56. uni.showLoading({ title: '处理中...' })
  57. this.http.request({
  58. url: '/level-one-server/app/WalletManage/topdownSave',
  59. data: {
  60. amount: this.total_fee * 100, // Convert to cents
  61. goodsName: '服务点兑现'
  62. },
  63. success: res => {
  64. uni.hideLoading()
  65. this.user.wallet -= this.total_fee
  66. uni.setStorageSync('info', this.user)
  67. uni.showToast({
  68. title: '兑现成功!',
  69. icon: 'success'
  70. })
  71. setTimeout(() => {
  72. uni.navigateBack({ delta: 1 })
  73. }, 1500)
  74. },
  75. fail: err => {
  76. uni.hideLoading()
  77. this.errorMessage = '兑现失败,请稍后重试'
  78. console.error('Withdrawal failed:', err)
  79. }
  80. })
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss">
  86. .withdrawal-container {
  87. padding: 30px;
  88. background-color: #f8f8f8;
  89. min-height: 100vh;
  90. }
  91. .balance-info {
  92. background-color: #007AFF;
  93. padding: 20px;
  94. border-radius: 10px;
  95. margin-bottom: 20px;
  96. }
  97. .balance-label {
  98. font-size: 16px;
  99. color: rgba(255, 255, 255, 0.8);
  100. }
  101. .balance-amount {
  102. font-size: 24px;
  103. font-weight: bold;
  104. color: #fff;
  105. }
  106. .input-section {
  107. background-color: #fff;
  108. padding: 15px;
  109. border-radius: 10px;
  110. margin-bottom: 20px;
  111. }
  112. .input-label {
  113. font-size: 16px;
  114. color: #333;
  115. margin-bottom: 10px;
  116. }
  117. .amount-input {
  118. border: 1px solid #ddd;
  119. border-radius: 5px;
  120. padding: 10px;
  121. font-size: 16px;
  122. width: 100%;
  123. box-sizing: border-box;
  124. height: 40px;
  125. }
  126. .submit-btn {
  127. background: linear-gradient(to right, #4facfe 0%, #00f2fe 100%);
  128. color: #fff;
  129. padding: 15px;
  130. border-radius: 25px;
  131. font-size: 18px;
  132. font-weight: bold;
  133. width: 100%;
  134. border: none;
  135. margin-top: 20px;
  136. box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  137. transition: all 0.3s ease;
  138. &:active {
  139. transform: translateY(2px);
  140. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  141. }
  142. &:disabled {
  143. background: #ccc;
  144. box-shadow: none;
  145. }
  146. }
  147. .submit-btn-disabled {
  148. opacity: 0.7;
  149. cursor: not-allowed;
  150. }
  151. .error-message {
  152. color: #ff4d4f;
  153. font-size: 14px;
  154. margin-top: 10px;
  155. text-align: center;
  156. }
  157. </style>