top-up.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <!-- 充值 -->
  2. <template>
  3. <view class="draw-money-wrap u-p-b-30">
  4. <view class="head-box">
  5. <shopro-navbar :background="{ background: navBackground }" :backTextStyle="{ color: '#fff' }" backText="充值"
  6. backIconColor="#fff"></shopro-navbar>
  7. <!-- 账户 -->
  8. <view class="wallet-num-box u-flex u-col-center u-row-between">
  9. <view class="">
  10. <view class="num-title">账户余额(元)</view>
  11. <view class="wallet-num">{{ userInfo.money || '0.00' }}</view>
  12. </view>
  13. <button class="u-reset-button log-btn"
  14. @tap="$Router.push({ path: '/pages/user/wallet/top-up-log' })">充值记录</button>
  15. </view>
  16. </view>
  17. <!-- 充值输入卡片-->
  18. <view class="draw-card">
  19. <view class="card-title">充值金额</view>
  20. <view class="input-box u-flex u-col-center">
  21. <view calss="unit">¥</view>
  22. <input class="u-flex-1 u-p-l-10" type="digit" @focus="onTopupFous" @input="onTopupInput" v-model="money"
  23. placeholder-style="font-size: 30rpx; font-weight: 500;color:#C2C7CF;" placeholder="请输入充值金额" />
  24. </view>
  25. <!-- 快捷充值 -->
  26. <view class="top-up-content u-p-b-30" v-if="initRecharge.moneys.length">
  27. <view class="card-title">快捷充值</view>
  28. <view class="u-flex u-flex-wrap">
  29. <view class="top-up-card u-flex u-row-center u-col-center u-m-b-30 u-m-r-30"
  30. :class="{'top-up-active':curMoneyCard === index}" v-for="(item,index) in initRecharge.moneys"
  31. :key="index" @tap="selectCard(index)">
  32. <view class="top-up-value">
  33. {{item.money}}
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <button class="u-reset-button save-btn" :style="{opacity:!money ? 0.7 : 1 }" :disabled="!money"
  39. @tap="confirmTopup">确认充值</button>
  40. </view>
  41. <!-- 充值说明 -->
  42. <view class="draw-notice">
  43. <view class="title">充值说明</view>
  44. <view class="draw-list">1.充值为在线支付,即时到账,不支持退款;</view>
  45. <view class="draw-list">
  46. 2.充值后金额会自动进入您的余额账户,请注意查收。
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import { mapState, mapActions, mapGetters } from 'vuex';
  53. import FormValidate from '@/shopro/validate/form';
  54. import wechat from '@/shopro/wechat/wechat';
  55. export default {
  56. components: {},
  57. data() {
  58. return {
  59. money: '', //提现金额
  60. showModal: false,
  61. curMoneyCard: '',
  62. navBackground: 'none'
  63. };
  64. },
  65. computed: {
  66. ...mapGetters(['userInfo', 'initRecharge'])
  67. },
  68. async onLoad() {},
  69. onPageScroll(e) {
  70. this.navBackground = e.scrollTop > 50 ?
  71. `url(${this.$IMG_URL}/imgs/user/draw_money_head_bg.png) no-repeat top / 100% auto` : 'none';
  72. },
  73. methods: {
  74. // 充值输入框
  75. onTopupInput(e) {
  76. this.$nextTick(() => {
  77. this.money = this.clearNoNum(e.detail.value)
  78. })
  79. },
  80. // 获取焦点
  81. onTopupFous() {
  82. this.curMoneyCard = ''
  83. },
  84. // 选择充值卡片
  85. selectCard(index) {
  86. this.curMoneyCard = index
  87. this.money = this.initRecharge.moneys[index].money
  88. },
  89. confirmTopup() {
  90. const that = this;
  91. if (this.money <= 0) {
  92. this.$u.toast('请选择或输入充值金额');
  93. return;
  94. }
  95. that.$http(
  96. 'money.recharge', {
  97. recharge_money: that.money
  98. },
  99. '确认中...'
  100. ).then(res => {
  101. if (res.code === 1) {
  102. that.money = '';
  103. that.$Router.push({
  104. path: `/pages/order/payment/method`,
  105. query: {
  106. orderId: res.data.id,
  107. orderType: 'recharge'
  108. }
  109. });
  110. } else {
  111. that.$u.toast(res.msg);
  112. }
  113. });
  114. },
  115. // 校验金额
  116. clearNoNum(val) {
  117. if (val == ".") {
  118. val = "0.";
  119. }
  120. val = val.replace(/[^\d.]/g, "");
  121. //必须保证第一个为数字而不是.
  122. val = val.replace(/^\./g, "");
  123. //保证只有出现一个.而没有多个.
  124. val = val.replace(/\.{2,}/g, ".");
  125. //保证.只出现一次,而不能出现两次以上
  126. val = val
  127. .replace(".", "$#$")
  128. .replace(/\./g, "")
  129. .replace("$#$", ".");
  130. //只能输入两位小数
  131. val = val.replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
  132. if (val.indexOf(".") < 0 && val != "") {
  133. //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
  134. val = parseFloat(val);
  135. }
  136. return val
  137. }
  138. }
  139. };
  140. </script>
  141. <style lang="scss">
  142. .head-box {
  143. background: url($IMG_URL+'/imgs/user/draw_money_head_bg.png') no-repeat;
  144. background-size: 100% auto;
  145. min-height: 400rpx;
  146. padding-bottom: var(--status-bar-height);
  147. // 可提现
  148. .wallet-num-box {
  149. padding: 20rpx 40rpx 0;
  150. .num-title {
  151. font-size: 26rpx;
  152. font-weight: 500;
  153. color: #ffffff;
  154. margin-bottom: 20rpx;
  155. }
  156. .wallet-num {
  157. font-size: 60rpx;
  158. font-weight: 500;
  159. color: #ffffff;
  160. }
  161. .log-btn {
  162. width: 170rpx;
  163. height: 60rpx;
  164. line-height: 60rpx;
  165. background: rgba(255, 255, 255, 0.1);
  166. border: 1rpx solid #eeeeee;
  167. border-radius: 30rpx;
  168. padding: 0;
  169. font-size: 26rpx;
  170. font-weight: 500;
  171. color: #ffffff;
  172. }
  173. }
  174. }
  175. // 提现输入卡片
  176. .draw-card {
  177. background-color: #fff;
  178. border-radius: 20rpx;
  179. width: 690rpx;
  180. min-height: 400rpx;
  181. margin: -70rpx auto 30rpx;
  182. padding: 30rpx;
  183. .card-title {
  184. font-size: 30rpx;
  185. font-weight: 500;
  186. color: #333333;
  187. margin-bottom: 30rpx;
  188. }
  189. .input-box {
  190. width: 624rpx;
  191. border-bottom: 1rpx solid #eee;
  192. height: 100rpx;
  193. margin-bottom: 40rpx;
  194. .unit {
  195. font-size: 48rpx;
  196. color: #333;
  197. }
  198. }
  199. .save-btn {
  200. width: 616rpx;
  201. height: 86rpx;
  202. line-height: 86rpx;
  203. background: linear-gradient(-90deg, #a36fff, #5336ff);
  204. box-shadow: 0px 7rpx 11rpx 2rpx rgba(124, 103, 214, 0.34);
  205. border-radius: 43rpx;
  206. font-size: 30rpx;
  207. font-weight: 500;
  208. color: #ffffff;
  209. }
  210. // 充值卡片
  211. .top-up-card {
  212. width: 190rpx;
  213. height: 124rpx;
  214. background: #F7F6FB;
  215. border-radius: 12rpx;
  216. transition: all linear 0.2s;
  217. &:nth-of-type(3n) {
  218. margin-right: 0 !important;
  219. }
  220. .top-up-value {
  221. font-size: 36rpx;
  222. font-weight: 500;
  223. color: #999999;
  224. &::after {
  225. content: '元';
  226. font-size: 24rpx;
  227. }
  228. }
  229. }
  230. .top-up-active {
  231. background: #564BBD;
  232. transition: all linear 0.2s;
  233. .top-up-value {
  234. color: #fff
  235. }
  236. }
  237. }
  238. // 提现说明
  239. .draw-notice {
  240. width: 684rpx;
  241. min-height: 180rpx;
  242. background: #ffffff;
  243. border-radius: 20rpx;
  244. padding: 30rpx 35rpx;
  245. margin: 20rpx auto;
  246. .title {
  247. font-size: 30rpx;
  248. font-weight: 500;
  249. color: #333333;
  250. margin-bottom: 30rpx;
  251. }
  252. .draw-list {
  253. font-size: 24rpx;
  254. font-weight: 400;
  255. color: #999999;
  256. margin-bottom: 10rpx;
  257. }
  258. }
  259. </style>