index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <view>
  3. <form @submit="submitSub" :style="colorStyle">
  4. <view class="payment-top acea-row row-column row-center-wrapper">
  5. <span class="name">我的余额</span>
  6. <view class="pic">
  7. ¥<span class="pic-font">{{ userinfo.now_money || 0 }}</span>
  8. </view>
  9. </view>
  10. <view class="payment">
  11. <view class="nav acea-row row-around row-middle">
  12. <view class="item" :class="active==index?'on':''" v-for="(item,index) in navRecharge" :key="index" @click="navRecharges(index)">{{item}}</view>
  13. </view>
  14. <view class='tip picList' v-if='!active' >
  15. <view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic == index ? 'pic-box-color-active' : ''"
  16. v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)" v-if="item.price">
  17. <view class="pic-number-pic">
  18. {{ item.price }}<span class="pic-number"> 元</span>
  19. </view>
  20. <view class="pic-number">赠送:{{ item.give_money }} 元</view>
  21. </view>
  22. <view class="pic-box pic-box-color acea-row row-center-wrapper" :class="activePic == picList.length ? 'pic-box-color-active' : ''"
  23. @click="picCharge(picList.length)">
  24. <input type="number" placeholder="其他" v-model="money" class="pic-box-money pic-number-pic" :class="activePic == picList.length ? 'pic-box-color-active' : ''" />
  25. </view>
  26. <view class="tips-box">
  27. <view class="tips mt-30">注意事项:</view>
  28. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  29. {{ item }}
  30. </view>
  31. </view>
  32. </view>
  33. <view class="tip" v-else>
  34. <view class='input'><text>¥</text><input @input='inputNum' :maxlength="moneyMaxLeng" placeholder="0.00" type='number' placeholder-class='placeholder' :value="number" name="number"></input></view>
  35. <view class="tips-title">
  36. <view style="font-weight: bold; font-size: 26rpx;">提示:</view>
  37. <view style="margin-top: 10rpx;">当前可转入佣金为 <text class='font-color'>¥{{userinfo.commissionCount || 0}}</text>,冻结佣金为<text class='font-color'>¥{{userinfo.broken_commission}}</text></view>
  38. </view>
  39. <view class="tips-box">
  40. <view class="tips mt-30">注意事项:</view>
  41. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  42. {{ item }}
  43. </view>
  44. </view>
  45. </view>
  46. <button class='but bg-color' formType="submit"> {{active ? '立即转入': '立即充值' }}</button>
  47. </view>
  48. </form>
  49. <home v-if="navigation"></home>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. getUserInfo,
  55. rechargeRoutine,
  56. rechargeWechat,
  57. getRechargeApi
  58. } from '@/api/user.js';
  59. import {
  60. toLogin
  61. } from '@/libs/login.js';
  62. import {
  63. mapGetters
  64. } from "vuex";
  65. import home from '@/components/home';
  66. import colors from "@/mixins/color";
  67. export default {
  68. components: {
  69. home
  70. },
  71. mixins:[colors],
  72. data() {
  73. let that = this;
  74. return {
  75. now_money: 0,
  76. navRecharge: ['账户充值', '佣金转入'],
  77. active: 0,
  78. number: '',
  79. userinfo: {},
  80. placeholder: "0.00",
  81. from: '',
  82. isAuto: false, //没有授权的不会自动授权
  83. isShowAuth: false, //是否隐藏授权
  84. picList: [],
  85. activePic: 0,
  86. money: "",
  87. numberPic:'',
  88. rechar_id:0,
  89. rechargeAttention:[],
  90. moneyMaxLeng:8
  91. };
  92. },
  93. computed: mapGetters(['isLogin']),
  94. watch:{
  95. isLogin:{
  96. handler:function(newV,oldV){
  97. if(newV){
  98. this.getUserInfo();
  99. this.getRecharge();
  100. }
  101. },
  102. deep:true
  103. }
  104. },
  105. onLoad(options) {
  106. // #ifdef H5
  107. this.from = this.$wechat.isWeixin() ? "weixin" : "weixinh5"
  108. // #endif
  109. if (this.isLogin) {
  110. this.getUserInfo();
  111. this.getRecharge();
  112. } else {
  113. toLogin();
  114. }
  115. },
  116. onShow() {
  117. uni.removeStorageSync('form_type_cart');
  118. },
  119. methods: {
  120. inputNum: function(e) {
  121. let val = e.detail.value;
  122. let dot = val.indexOf('.');
  123. if(dot>-1){
  124. this.moneyMaxLeng = dot+3;
  125. }else{
  126. this.moneyMaxLeng = 8
  127. }
  128. },
  129. /**
  130. * 选择金额
  131. */
  132. picCharge(idx, item) {
  133. this.activePic = idx;
  134. if (item === undefined) {
  135. this.rechar_id = 0;
  136. this.numberPic = "";
  137. } else {
  138. this.money = "";
  139. this.rechar_id = item.id;
  140. this.numberPic = item.price;
  141. }
  142. },
  143. /**
  144. * 充值额度选择
  145. */
  146. getRecharge() {
  147. getRechargeApi()
  148. .then(res => {
  149. this.picList = res.data.recharge_quota;
  150. if (this.picList[0]) {
  151. this.rechar_id = this.picList[0].id;
  152. this.numberPic = this.picList[0].price;
  153. }
  154. this.rechargeAttention = res.data.recharge_attention || [];
  155. })
  156. .catch(res => {
  157. this.$util.Tips({
  158. title: res
  159. })
  160. });
  161. },
  162. onLoadFun: function() {
  163. this.getUserInfo();
  164. this.getRecharge();
  165. },
  166. // 授权关闭
  167. authColse: function(e) {
  168. this.isShowAuth = e
  169. },
  170. navRecharges: function(index) {
  171. this.active = index;
  172. },
  173. /**
  174. * 获取用户信息
  175. */
  176. getUserInfo: function() {
  177. let that = this;
  178. getUserInfo().then(res => {
  179. that.$set(that, 'userinfo', res.data);
  180. })
  181. },
  182. /*
  183. * 用户充值
  184. */
  185. submitSub: function(e) {
  186. let that = this
  187. let value = e.detail.value.number;
  188. // 转入余额
  189. if (that.active) {
  190. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  191. return that.$util.Tips({
  192. title: '请输入金额'
  193. });
  194. }
  195. uni.showModal({
  196. title: '转入余额',
  197. content: '转入余额后无法再次转出,确认是否转入余额',
  198. success(res) {
  199. if (res.confirm) {
  200. // #ifdef MP || APP-PLUS
  201. rechargeRoutine({
  202. price: parseFloat(value),
  203. type: 1
  204. })
  205. // #endif
  206. // #ifdef H5
  207. rechargeWechat({
  208. price: parseFloat(value),
  209. from: that.from,
  210. type: 1
  211. })
  212. // #endif
  213. .then(res => {
  214. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
  215. return that.$util.Tips({
  216. title: '转入成功',
  217. icon: 'success'
  218. }, {
  219. tab: 5,
  220. url: '/pages/users/user_money/index'
  221. });
  222. }).catch(err => {
  223. return that.$util.Tips({
  224. title: err
  225. })
  226. });
  227. } else if (res.cancel) {
  228. return that.$util.Tips({
  229. title: '已取消'
  230. });
  231. }
  232. },
  233. })
  234. } else {
  235. uni.showLoading({
  236. title: '正在支付',
  237. })
  238. // #ifdef MP || APP-PLUS
  239. let money = parseFloat(this.money);
  240. if( this.rechar_id == 0){
  241. if(Number.isNaN(money)){
  242. return that.$util.Tips({title: '充值金额必须为数字'});
  243. }
  244. if(money <= 0){
  245. return that.$util.Tips({title: '充值金额不能为0'});
  246. }
  247. }else{
  248. money = this.numberPic
  249. }
  250. rechargeRoutine({
  251. price: money,
  252. type: 0,
  253. rechar_id: this.rechar_id
  254. }).then(res => {
  255. uni.hideLoading();
  256. let jsConfig = res.data;
  257. let mp_pay_name=''
  258. if(uni.requestOrderPayment){
  259. mp_pay_name='requestOrderPayment'
  260. }else{
  261. mp_pay_name='requestPayment'
  262. }
  263. uni[mp_pay_name]({
  264. // #ifdef MP
  265. timeStamp: jsConfig.timestamp,
  266. nonceStr: jsConfig.nonceStr,
  267. package: jsConfig.package,
  268. signType: jsConfig.signType,
  269. paySign: jsConfig.paySign,
  270. // #endif
  271. // #ifdef APP-PLUS
  272. provider: 'wxpay',
  273. orderInfo: jsConfig,
  274. // #endif
  275. success: function(res) {
  276. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  277. return that.$util.Tips({
  278. title: '支付成功',
  279. icon: 'success'
  280. }, {
  281. tab: 5,
  282. url: '/pages/users/user_money/index'
  283. });
  284. },
  285. fail: function() {
  286. return that.$util.Tips({
  287. title: '支付失败'
  288. });
  289. },
  290. complete: function(res) {
  291. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  292. title: '取消支付'
  293. });
  294. }
  295. })
  296. }).catch(err => {
  297. uni.hideLoading();
  298. return that.$util.Tips({
  299. title: err
  300. })
  301. });
  302. // #endif
  303. // #ifdef H5
  304. rechargeWechat({
  305. price: that.rechar_id == 0 ? that.money : that.numberPic,
  306. from: that.from,
  307. rechar_id: that.rechar_id
  308. }).then(res => {
  309. let data = res.data;
  310. if (data.type == "weixinh5") {
  311. location.replace(data.data.mweb_url);
  312. // return that.$util.Tips({
  313. // title: '支付成功',
  314. // icon: 'success'
  315. // }, {
  316. // tab: 5,
  317. // url: '/pages/users/user_money/index'
  318. // });
  319. } else {
  320. that.$wechat.pay(data.data)
  321. .finally(() => {
  322. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  323. return that.$util.Tips({
  324. title: '支付成功',
  325. icon: 'success'
  326. }, {
  327. tab: 5,
  328. url: '/pages/users/user_money/index'
  329. });
  330. })
  331. .catch(function() {
  332. return that.$util.Tips({
  333. title: '支付失败'
  334. });
  335. });
  336. }
  337. }).catch(err=>{
  338. uni.hideLoading();
  339. return that.$util.Tips({
  340. title: err
  341. })
  342. })
  343. // #endif
  344. }
  345. }
  346. }
  347. }
  348. </script>
  349. <style lang="scss">
  350. page {
  351. width: 100%;
  352. height: 100%;
  353. background-color: #fff;
  354. }
  355. .bgcolor{
  356. background-color: var(--view-theme)
  357. }
  358. .payment {
  359. position: relative;
  360. top: -60rpx;
  361. width: 100%;
  362. background-color: #fff;
  363. border-radius: 10rpx;
  364. padding-top: 25rpx;
  365. border-top-right-radius: 39rpx;
  366. border-top-left-radius: 39rpx;
  367. }
  368. .payment .nav {
  369. height: 75rpx;
  370. line-height: 75rpx;
  371. padding: 0 100rpx;
  372. }
  373. .payment .nav .item {
  374. font-size: 30rpx;
  375. color: #333;
  376. }
  377. .payment .nav .item.on {
  378. font-weight: bold;
  379. border-bottom: 4rpx solid var(--view-theme);
  380. }
  381. .payment .input {
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. border-bottom: 1px dashed #dddddd;
  386. margin: 60rpx auto 0 auto;
  387. padding-bottom: 20rpx;
  388. font-size: 56rpx;
  389. color: #333333;
  390. flex-wrap: nowrap;
  391. }
  392. .payment .input text {
  393. padding-left: 106rpx;
  394. }
  395. .payment .input input {
  396. padding-right: 106rpx;
  397. width: 300rpx;
  398. height: 94rpx;
  399. text-align: center;
  400. font-size: 70rpx;
  401. }
  402. .payment .placeholder {
  403. color: #d0d0d0;
  404. height: 100%;
  405. line-height: 94rpx;
  406. }
  407. .payment .tip {
  408. font-size: 26rpx;
  409. color: #888888;
  410. padding: 0 30rpx;
  411. margin-top: 25rpx;
  412. }
  413. .payment .but {
  414. color: #fff;
  415. font-size: 30rpx;
  416. width: 700rpx;
  417. height: 86rpx;
  418. border-radius: 50rpx;
  419. margin: 46rpx auto 0 auto;
  420. line-height: 86rpx;
  421. }
  422. .payment-top {
  423. width: 100%;
  424. height: 350rpx;
  425. background-color: var(--view-theme);
  426. .name {
  427. font-size: 26rpx;
  428. color: rgba(255, 255, 255, 0.8);
  429. margin-top: -38rpx;
  430. margin-bottom: 30rpx;
  431. }
  432. .pic {
  433. font-size: 32rpx;
  434. color: #fff;
  435. }
  436. .pic-font {
  437. font-size: 78rpx;
  438. color: #fff;
  439. }
  440. }
  441. .picList {
  442. display: flex;
  443. flex-wrap: wrap;
  444. margin: 30rpx 0;
  445. .pic-box {
  446. width: 32%;
  447. height: auto;
  448. border-radius: 20rpx;
  449. margin-top: 21rpx;
  450. padding: 20rpx 0;
  451. margin-right: 12rpx;
  452. &:nth-child(3n) {
  453. margin-right: 0;
  454. }
  455. }
  456. .pic-box-color {
  457. background-color: #f4f4f4;
  458. color: #656565;
  459. }
  460. .pic-number {
  461. font-size: 22rpx;
  462. }
  463. .pic-number-pic {
  464. font-size: 38rpx;
  465. margin-right: 10rpx;
  466. text-align: center;
  467. }
  468. .pic-box-color-active {
  469. background-color: var(--view-theme) !important;
  470. color: #fff !important;
  471. }
  472. }
  473. .tips-box{
  474. .tips {
  475. font-size: 28rpx;
  476. color: #333333;
  477. font-weight: 800;
  478. margin-bottom: 14rpx;
  479. margin-top: 20rpx;
  480. }
  481. .tips-samll {
  482. font-size: 24rpx;
  483. color: #333333;
  484. margin-bottom: 14rpx;
  485. }
  486. .tip-box {
  487. margin-top: 30rpx;
  488. }
  489. }
  490. .tips-title{
  491. margin-top: 20rpx;
  492. font-size: 24rpx;
  493. color: #333;
  494. }
  495. </style>