建材商城系统20241014
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.

349 lines
7.6 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. <template>
  2. <view class="purse">
  3. <navbar title="立即提现" leftClick @leftClick="$utils.navigateBack"
  4. bgColor="#DC2828"
  5. color="#fff"
  6. />
  7. <!-- 水洗店 -->
  8. <view class="userShop">
  9. <userShopCommission purse />
  10. </view>
  11. <view class="from-body">
  12. <view>我要提现</view>
  13. <view class="from-line">
  14. <input
  15. placeholder="请输入提现金额"
  16. v-model="withdrawAmount"
  17. type="digit"
  18. @input="onAmountInput"
  19. />
  20. </view>
  21. <view class="tips" v-if="userInfo.price">
  22. 可提现金额¥{{userInfo.price}}
  23. </view>
  24. <!-- 快捷金额选择 -->
  25. <view class="quick-amounts" v-if="userInfo.price && parseFloat(userInfo.price) > 0">
  26. <view class="quick-label">快捷选择</view>
  27. <view class="amount-buttons">
  28. <view
  29. class="amount-btn"
  30. v-for="amount in quickAmounts"
  31. :key="amount"
  32. :class="{'disabled': amount > parseFloat(userInfo.price)}"
  33. @click="selectQuickAmount(amount)"
  34. >
  35. ¥{{amount}}
  36. </view>
  37. <view
  38. class="amount-btn all"
  39. @click="selectAllAmount"
  40. >
  41. 全部
  42. </view>
  43. </view>
  44. </view>
  45. <!-- <view class="from-line">
  46. <input placeholder="请输入姓名" />
  47. </view>
  48. <view class="from-line">
  49. <input placeholder="请输入开户行" />
  50. </view>
  51. <view class="from-line">
  52. <input placeholder="请输入银行卡卡号" />
  53. </view> -->
  54. <view class="mt56">提现说明</view>
  55. <view style="line-height: 45rpx; font-size: 24rpx;color: #666666;" v-html="notice">
  56. </view>
  57. <!-- <p>1本次提现必须通过银行卡提现暂不支持其他途径</p>
  58. <p>2如若遇到24小时提现未到账请联系客服</p> -->
  59. </view>
  60. <view class="b-fiexd">
  61. <view
  62. class="button-submit"
  63. :class="{'disabled': isSubmitting || !withdrawAmount}"
  64. @click="submitWithdraw"
  65. >
  66. {{isSubmitting ? '提交中...' : '提交'}}
  67. </view>
  68. </view>
  69. <!-- <quick-order-entry
  70. ref="quickOrderEntry"
  71. /> -->
  72. </view>
  73. </template>
  74. <script>
  75. import userShopCommission from '@/components/userShop/userShopCommission.vue'
  76. export default {
  77. components: {
  78. userShopCommission,
  79. },
  80. data() {
  81. return {
  82. notice: '',
  83. withdrawAmount: '', // 提现金额
  84. isSubmitting: false, // 是否正在提交
  85. quickAmounts: [10, 50, 100, 200, 500], // 快捷金额选项
  86. }
  87. },
  88. computed: {
  89. userInfo() {
  90. return this.$store.state.userInfo || {};
  91. }
  92. },
  93. onLoad() {
  94. this.$store.commit('getUserInfo');
  95. },
  96. methods: {
  97. // 选择快捷金额
  98. selectQuickAmount(amount) {
  99. if (amount > parseFloat(this.userInfo.price)) return;
  100. this.withdrawAmount = amount.toString();
  101. },
  102. // 选择全部金额
  103. selectAllAmount() {
  104. if (this.userInfo.price) {
  105. this.withdrawAmount = parseFloat(this.userInfo.price).toString();
  106. }
  107. },
  108. // 金额输入处理
  109. onAmountInput(e) {
  110. let value = e.detail.value;
  111. // 只允许输入数字和小数点
  112. value = value.replace(/[^\d.]/g, '');
  113. // 只允许一个小数点
  114. const pointIndex = value.indexOf('.');
  115. if (pointIndex !== -1) {
  116. value = value.substring(0, pointIndex + 1) + value.substring(pointIndex + 1).replace(/\./g, '');
  117. }
  118. // 最多保留2位小数
  119. if (pointIndex !== -1 && value.length > pointIndex + 3) {
  120. value = value.substring(0, pointIndex + 3);
  121. }
  122. this.withdrawAmount = value;
  123. },
  124. // 验证提现金额
  125. validateAmount() {
  126. if (!this.withdrawAmount) {
  127. uni.showToast({
  128. title: '请输入提现金额',
  129. icon: 'none'
  130. });
  131. return false;
  132. }
  133. const amount = parseFloat(this.withdrawAmount);
  134. if (isNaN(amount) || amount <= 0) {
  135. uni.showToast({
  136. title: '请输入正确的提现金额',
  137. icon: 'none'
  138. });
  139. return false;
  140. }
  141. // 检查提现金额是否超过可用余额
  142. if (this.userInfo.price && amount > parseFloat(this.userInfo.price)) {
  143. uni.showToast({
  144. title: '提现金额不能超过可用余额',
  145. icon: 'none'
  146. });
  147. return false;
  148. }
  149. // 检查最小提现金额(假设最小提现1元)
  150. if (amount < 1) {
  151. uni.showToast({
  152. title: '最小提现金额为1元',
  153. icon: 'none'
  154. });
  155. return false;
  156. }
  157. return true;
  158. },
  159. // 提交提现申请
  160. submitWithdraw() {
  161. if (this.isSubmitting) return;
  162. // 验证提现金额
  163. if (!this.validateAmount()) return;
  164. // 确认提现
  165. uni.showModal({
  166. title: '确认提现',
  167. content: `确定要提现 ¥${this.withdrawAmount} 元吗?`,
  168. success: (res) => {
  169. if (res.confirm) {
  170. this.doWithdraw();
  171. }
  172. }
  173. });
  174. },
  175. // 执行提现操作
  176. doWithdraw() {
  177. this.isSubmitting = true;
  178. const params = {
  179. money: parseFloat(this.withdrawAmount)
  180. };
  181. this.$api('openMoney', params, res => {
  182. this.isSubmitting = false;
  183. if (res.code === 200) {
  184. uni.showToast({
  185. title: '提现申请提交成功',
  186. icon: 'success',
  187. duration: 2000,
  188. success: () => {
  189. // 清空输入框
  190. this.withdrawAmount = '';
  191. // 刷新用户信息
  192. this.$store.commit('getUserInfo');
  193. // 延迟返回上一页或跳转到提现记录页面
  194. setTimeout(() => {
  195. uni.navigateBack();
  196. }, 2000);
  197. }
  198. });
  199. } else {
  200. uni.showModal({
  201. title: '提现失败',
  202. content: res.message || '提现申请提交失败,请重试',
  203. showCancel: false
  204. });
  205. }
  206. }, err => {
  207. this.isSubmitting = false;
  208. console.error('提现请求失败', err);
  209. uni.showModal({
  210. title: '网络错误',
  211. content: '网络连接失败,请检查网络后重试',
  212. showCancel: false
  213. });
  214. });
  215. }
  216. }
  217. }
  218. </script>
  219. <style scoped lang="scss">
  220. .purse{
  221. min-height: 100vh;
  222. background-color: #ffffff;
  223. .from-body {
  224. padding: 40rpx 20rpx;
  225. font-size: 28rpx;
  226. font-family: PingFang SC, PingFang SC-Bold;
  227. font-weight: 700;
  228. text-align: left;
  229. color: #333333;
  230. line-height: 40px;
  231. padding-bottom: 160rpx;
  232. .from-line {
  233. margin-top: 40rpx;
  234. }
  235. input {
  236. width: 612rpx;
  237. height: 90rpx;
  238. line-height: 90rpx;
  239. background: #F5F5F5;
  240. border-radius: 46rpx;
  241. padding: 0 50rpx;
  242. font-size: 28rpx;
  243. font-family: PingFang SC, PingFang SC-Regular;
  244. font-weight: 400;
  245. text-align: left;
  246. color: #333;
  247. }
  248. .tips {
  249. margin-top: 20rpx;
  250. font-size: 24rpx;
  251. color: #999;
  252. font-weight: 400;
  253. }
  254. .quick-amounts {
  255. margin-top: 30rpx;
  256. .quick-label {
  257. font-size: 26rpx;
  258. color: #666;
  259. margin-bottom: 20rpx;
  260. font-weight: 400;
  261. }
  262. .amount-buttons {
  263. display: flex;
  264. flex-wrap: wrap;
  265. gap: 20rpx;
  266. .amount-btn {
  267. padding: 16rpx 32rpx;
  268. background: #f5f5f5;
  269. border-radius: 30rpx;
  270. font-size: 26rpx;
  271. color: #333;
  272. text-align: center;
  273. border: 1rpx solid transparent;
  274. transition: all 0.3s;
  275. &:active {
  276. transform: scale(0.95);
  277. }
  278. &.disabled {
  279. opacity: 0.5;
  280. color: #999;
  281. }
  282. &.all {
  283. background: $uni-color;
  284. color: #fff;
  285. }
  286. }
  287. }
  288. }
  289. }
  290. .button-submit {
  291. width: 596rpx;
  292. height: 90rpx;
  293. line-height: 90rpx;
  294. background: $uni-color;
  295. border-radius: 46rpx;
  296. margin: 20rpx auto;
  297. font-size: 28rpx;
  298. font-family: PingFang SC, PingFang SC-Regular;
  299. font-weight: 400;
  300. text-align: center;
  301. color: #ffffff;
  302. transition: opacity 0.3s;
  303. &.disabled {
  304. opacity: 0.6;
  305. background: #ccc;
  306. }
  307. }
  308. }
  309. </style>