user_payment.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <view>
  3. <view class="user-payment">
  4. <!-- 充值 -->
  5. <form report-submit="true">
  6. <view class="payment bg-white">
  7. <view class="md normal flex" style="padding: 66rpx 66rpx 0">
  8. 充值金额
  9. </view>
  10. <view class="input flex">
  11. <text style="font-size: 46rpx">¥</text>
  12. <input :placeholder="placeholder" type="digit" @focus="setPlaceholder"
  13. @blur="setPlaceholderStatus" :value="number" @input="onInput" />
  14. </view>
  15. <view class="tip muted m-t-20 flex">
  16. 提示:当前余额为
  17. <text class="primary">¥{{wallet.user_money || 0}}</text>
  18. </view>
  19. </view>
  20. <button size="lg" class="btn white br60" @tap="rechargeRights">
  21. 立即充值
  22. </button>
  23. </form>
  24. <!-- 推荐充值 -->
  25. <view class="fast-payment-container" v-if="rechargeObj.length">
  26. <view class="title bold normal flex">推荐充值</view>
  27. <view class="fast-pay flex flex-wrap">
  28. <view v-for="(item, index) in rechargeObj" :key="index"
  29. class="fast-pay-item bg-white flex-col col-center row-center" @tap="temRecharge(item.id)">
  30. <view class="hot-recharge white" v-if="item.is_recommend">热门充值</view>
  31. <view class="price bold">
  32. <price-format weight="bold" :firstSize="42" :price="item.money"></price-format>
  33. <text class="xxl" style="font-weight: 400">元</text>
  34. </view>
  35. <view class="preferential primary xs">{{item.tips}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 充值成功 -->
  41. <u-popup class="pay-popup" v-model="showPopup" closeable round mode="center">
  42. <view class="content bg-white">
  43. <image class="img-icon" src="/static/images/icon_success.png"></image>
  44. <view class="xxl bold m-t-10">充值成功</view>
  45. <view v-if="rechargeInfo.give_growth" class="lg" style="margin-top: 50rpx">恭喜您获得 <text
  46. v-if="rechargeInfo.give_growth">+ <text
  47. class="primary">{{rechargeInfo.give_growth}}</text>成长值</text></view>
  48. <button class="br60 btn" type="primary" size="md" @tap="onShowPopup">好的,谢谢</button>
  49. </view>
  50. </u-popup>
  51. <loading-view id="van-toast" v-if="showLoading" backgroundColor="rgba(0, 0, 0, 0)"></loading-view>
  52. <float-tab></float-tab>
  53. </view>
  54. </template>
  55. <script>
  56. // +----------------------------------------------------------------------
  57. // | likeshop开源商城系统
  58. // +----------------------------------------------------------------------
  59. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  60. // | gitee下载:https://gitee.com/likeshop_gitee
  61. // | github下载:https://github.com/likeshop-github
  62. // | 访问官网:https://www.likeshop.cn
  63. // | 访问社区:https://home.likeshop.cn
  64. // | 访问手册:http://doc.likeshop.cn
  65. // | 微信公众号:likeshop技术社区
  66. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  67. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  68. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  69. // | likeshop团队版权所有并拥有最终解释权
  70. // +----------------------------------------------------------------------
  71. // | author: likeshop.cn.team
  72. // +----------------------------------------------------------------------
  73. import {
  74. rechargeTemplate,
  75. recharge,
  76. getWallet
  77. } from '@/api/user';
  78. import {
  79. prepay
  80. } from '@/api/app';
  81. import {
  82. wxpay
  83. } from '@/utils/pay';
  84. export default {
  85. data() {
  86. return {
  87. navRecharge: ['账户充值', '佣金转入'],
  88. active: 0,
  89. number: '',
  90. placeholder: "0.00",
  91. rechargeObj: [],
  92. showPopup: false,
  93. rechargeInfo: {},
  94. wallet: {},
  95. showLoading: false
  96. };
  97. },
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. onLoad: function(options) {
  102. this.rechargeTemplateFun();
  103. this.getWalletFun();
  104. },
  105. onUnload() {
  106. uni.$off('payment')
  107. },
  108. methods: {
  109. onShowPopup() {
  110. this.showPopup = !this.showPopup
  111. },
  112. setPlaceholderStatus: function(event) {
  113. if (event.detail.value.length == 0) {
  114. this.placeholder = '0.00'
  115. }
  116. },
  117. setPlaceholder: function() {
  118. this.placeholder = ''
  119. },
  120. getWalletFun() {
  121. getWallet().then(res => {
  122. if (res.code == 1) {
  123. this.wallet = res.data
  124. }
  125. });
  126. },
  127. rechargeTemplateFun() {
  128. rechargeTemplate().then(res => {
  129. if (res.code == 1) {
  130. this.rechargeObj = res.data
  131. }
  132. });
  133. },
  134. rechargeRights() {
  135. const {
  136. number
  137. } = this;
  138. this.rechargeFun({
  139. money: Number(number)
  140. });
  141. },
  142. temRecharge(id) {
  143. this.rechargeFun({
  144. id
  145. });
  146. },
  147. rechargeFun(obj) {
  148. if (!obj.id && obj.money == 0) {
  149. return this.$toast({
  150. title: '请输入金额'
  151. })
  152. }
  153. this.showLoading = true
  154. recharge(obj).then(({ code, data, msg }) => {
  155. if (code != 1) throw new Error(msg)
  156. this.rechargeInfo = data
  157. uni.$on('payment', params => {
  158. setTimeout(() => {
  159. if (params.result) {
  160. this.$toast({ title: "支付成功" })
  161. this.onShowPopup();
  162. this.getWalletFun();
  163. } else {
  164. this.$toast({ title: "支付失败" })
  165. }
  166. }, 500)
  167. })
  168. uni.navigateTo({
  169. url: `/pages/payment/payment?from=${'recharge'}&order_id=${data.id}`
  170. })
  171. }).catch(err => {
  172. console.log(err)
  173. }).finally(() => {
  174. this.showLoading = false
  175. })
  176. },
  177. checkInputText: function(text) {
  178. var reg = /^(\.*)(\d+)(\.?)(\d{0,2}).*$/g;
  179. if (reg.test(text)) {
  180. //正则匹配通过,提取有效文本
  181. text = text.replace(reg, '$2$3$4');
  182. } else {
  183. //正则匹配不通过,直接清空
  184. text = '';
  185. }
  186. return text; //返回符合要求的文本(为数字且最多有带2位小数)
  187. },
  188. onInput(e) {
  189. let number = e.detail.value;
  190. number = this.checkInputText(number);
  191. this.number = number
  192. }
  193. }
  194. };
  195. </script>
  196. <style lang="scss">
  197. .user-payment {
  198. padding: 20rpx 30rpx;
  199. .payment {
  200. text-align: center;
  201. border-radius: 20rpx;
  202. overflow: hidden;
  203. padding-bottom: 74rpx;
  204. .nav {
  205. margin: 20rpx 95rpx 80rpx;
  206. .item {
  207. flex: 1;
  208. .line {
  209. width: 110rpx;
  210. height: 2px;
  211. }
  212. }
  213. }
  214. .line {
  215. width: 110rpx;
  216. height: 2px;
  217. }
  218. .input {
  219. margin-left: 66rpx;
  220. margin-top: 35rpx;
  221. margin-right: 30rpx;
  222. input {
  223. height: 94rpx;
  224. text-align: left;
  225. font-size: 66rpx;
  226. margin-left: 30rpx;
  227. }
  228. border-bottom: $-solid-border;
  229. }
  230. .tip {
  231. margin: 25rpx 66rpx;
  232. }
  233. }
  234. .btn {
  235. background: linear-gradient(79deg, rgba(249, 95, 47, 1) 0%, rgba(255, 44, 60, 1) 100%);
  236. margin: 70rpx 0 30rpx;
  237. }
  238. .fast-payment-container {
  239. margin-top: 72rpx;
  240. .title {
  241. font-size: 38rpx;
  242. line-height: 53rpx;
  243. }
  244. .fast-pay {
  245. margin-top: 40rpx;
  246. .fast-pay-item {
  247. position: relative;
  248. width: 214rpx;
  249. height: 150rpx;
  250. border-radius: 10rpx;
  251. margin-bottom: 16rpx;
  252. &:not(:nth-of-type(3n)) {
  253. margin-right: 24rpx;
  254. }
  255. .hot-recharge {
  256. position: absolute;
  257. padding: 2rpx 10rpx;
  258. height: 30rpx;
  259. background: linear-gradient(180deg, #FF2C3C 0%, #F95F2F 100%);
  260. border-radius: 0 20rpx 0 20rpx;
  261. font-size: 20rpx;
  262. top: 0;
  263. right: 0;
  264. }
  265. .price {
  266. font-size: 42rpx;
  267. line-height: 50rpx;
  268. }
  269. .preferential {
  270. line-height: 32rpx;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. .pay-popup {
  277. .content {
  278. padding: 40rpx 0;
  279. text-align: center;
  280. width: 560rpx;
  281. border-radius: 20rpx;
  282. }
  283. .img-icon {
  284. width: 112rpx;
  285. height: 112rpx;
  286. display: inline-block;
  287. }
  288. .btn {
  289. margin: 80rpx 60rpx 0;
  290. }
  291. }
  292. </style>