index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <template>
  2. <view class="content">
  3. <view class="top_box">
  4. <text class="yue-tit">当前余额:</text>
  5. <text class="yue-num">¥{{ now_money }}</text>
  6. </view>
  7. <view class="line_box"></view>
  8. <view class="cz_box">
  9. <view class="cz_wrap">
  10. <text class="cz_tit">¥</text>
  11. <input class="cz_input" type="number" v-model="money" @focus="changeNum()" placeholder="请输入充值金额" placeholder-class="placeholder" />
  12. </view>
  13. <view class="zc_list_box">
  14. <view class="zc_list_price" :class="{ seletPrice: seletNum == item.data.price }" @click="seletChange(item, index)" v-for="(item, index) in list" :key="index">
  15. {{ item.data.price }}元
  16. </view>
  17. </view>
  18. </view>
  19. <!-- <view class="line_box"></view> -->
  20. <!-- <view class="row-box">
  21. <view class="title">充值金额</view>
  22. <view class="row">
  23. <text class="tit">¥</text>
  24. <input class="input" type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="placeholder" />
  25. </view>
  26. </view> -->
  27. <!-- <view class="rechar-box">
  28. <view class="rechar-title">注意事项</view>
  29. <view class="rechar-text" v-for="(item, index) in zhuyi" :key="index">
  30. <text>{{ index + 1 }}.{{item}}</text>
  31. </view>
  32. </view> -->
  33. <view class="line_box"></view>
  34. <!-- <view class="cz-type" @click.stop="changePayType('weixin')">
  35. <view class="type-left">
  36. <view class="icon iconfont iconweixin"></view>
  37. <view class="tit">微信充值</view>
  38. </view>
  39. <view class="right" v-show="loaded"><radio value="weixin" color="#EB001C" :checked="type == 'weixin'" /></view>
  40. </view> -->
  41. <view class="cz-type" @click.stop="changePayType('alipay')">
  42. <view class="type-left">
  43. <view class="icon iconfont iconzhifubao"></view>
  44. <view class="tit">支付宝充值</view>
  45. </view>
  46. <view class="right"><radio value="weixin" color="#EB001C" :checked="type == 'alipay'" /></view>
  47. </view>
  48. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? submitSub() : ''">立即充值</button>
  49. </view>
  50. </template>
  51. <script>
  52. // +----------------------------------------------------------------------
  53. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  54. // +----------------------------------------------------------------------
  55. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  56. // +----------------------------------------------------------------------
  57. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  58. // +----------------------------------------------------------------------
  59. // | Author: CRMEB Team <admin@crmeb.com>
  60. // +----------------------------------------------------------------------
  61. import { spreadInfo, rechargeRoutine, rechargeWechat, getRechargeApi, rechargeBrokerage } from '@/api/user.js';
  62. import { mapGetters } from 'vuex';
  63. import authorize from '@/components/Authorize';
  64. export default {
  65. components: {
  66. authorize
  67. },
  68. data() {
  69. let that = this;
  70. return {
  71. type: 'alipay',
  72. otherValue: '其他',
  73. payLoding: false, //是否加载中
  74. now_money: 0,
  75. list: [{ data: { price: '' } }],
  76. seletNum: '300', // 选中
  77. navRecharge: ['账户充值', '佣金转入'],
  78. active: 0,
  79. number: '',
  80. userinfo: {},
  81. placeholder: '0.00',
  82. from: '',
  83. isAuto: false, //没有授权的不会自动授权
  84. isShowAuth: false, //是否隐藏授权
  85. picList: [],
  86. activePic: 0,
  87. money: '',
  88. numberPic: '',
  89. rechar_id: 0,
  90. rechargeAttention: []
  91. };
  92. },
  93. computed: mapGetters(['isLogin', 'viewColor']),
  94. onLoad(options) {
  95. // #ifdef H5
  96. this.from = this.$wechat.isWeixin() ? 'weixin' : 'h5';
  97. // #endif
  98. if (this.isLogin) {
  99. this.getUserInfo();
  100. this.getRecharge();
  101. } else {
  102. this.isAuto = true;
  103. this.isShowAuth = true;
  104. }
  105. },
  106. methods: {
  107. //选择支付方式
  108. changePayType(type) {
  109. this.type = type;
  110. },
  111. /**
  112. * 充值额度选择
  113. */
  114. getRecharge() {
  115. getRechargeApi()
  116. .then(res => {
  117. console.log(res);
  118. this.list = res.data.recharge_quota;
  119. })
  120. .catch(res => {
  121. this.$dialog.toast({
  122. mes: res
  123. });
  124. });
  125. },
  126. onLoadFun: function() {
  127. this.isShowAuth = false;
  128. this.getUserInfo();
  129. this.getRecharge();
  130. },
  131. // 授权关闭
  132. authColse: function(e) {
  133. this.isShowAuth = e;
  134. },
  135. navRecharges: function(index) {
  136. this.active = index;
  137. },
  138. seletChange(item, index) {
  139. this.seletNum = item.data.price;
  140. this.seletMoney = item.data.price;
  141. this.money = item.data.price;
  142. },
  143. changeNum() {
  144. this.seletNum = this.money = '';
  145. console.log(this.seletNum, this.money);
  146. },
  147. /**
  148. * 获取用户信息
  149. */
  150. getUserInfo: function() {
  151. let that = this;
  152. spreadInfo().then(res => {
  153. this.now_money = res.data.now_money;
  154. });
  155. },
  156. /*
  157. * 用户充值
  158. */
  159. submitSub: function(e) {
  160. let that = this;
  161. let value = this.money;
  162. // 转入余额
  163. if (that.active) {
  164. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == '') {
  165. return that.$util.Tips({
  166. title: '请输入金额'
  167. });
  168. }
  169. if (parseFloat(value) > that.userinfo.brokerage_price) {
  170. return that.$util.Tips({
  171. title: '剩余可用佣金不足' + parseFloat(value)
  172. });
  173. }
  174. uni.showModal({
  175. title: '转入余额',
  176. content: '转入余额后无法再次转出,确认是否转入余额',
  177. success(res) {
  178. if (res.confirm) {
  179. rechargeBrokerage({
  180. brokerage: parseFloat(value)
  181. })
  182. .then(res => {
  183. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
  184. return that.$util.Tips(
  185. {
  186. title: '转入成功',
  187. icon: 'success'
  188. },
  189. {
  190. tab: 5,
  191. url: '/pages/users/user_money/index'
  192. }
  193. );
  194. })
  195. .catch(err => {
  196. return that.$util.Tips({
  197. title: err
  198. });
  199. });
  200. } else if (res.cancel) {
  201. return that.$util.Tips({
  202. title: '已取消'
  203. });
  204. }
  205. }
  206. });
  207. } else {
  208. // uni.showLoading({
  209. // title: '正在支付',
  210. // mask: true
  211. // });
  212. if (this.rechar_id == 0) {
  213. if (parseFloat(that.money) === 0) {
  214. return that.$util.Tips({
  215. title: '充值金额金额不能为0!'
  216. });
  217. }
  218. if (!that.money) {
  219. return that.$util.Tips({
  220. title: '请填写充值金额!'
  221. });
  222. }
  223. if (!Number(that.money)) {
  224. return that.$util.Tips({
  225. title: '请填写正确的金额!'
  226. });
  227. }
  228. }
  229. that.payLoding = true;
  230. // #ifdef MP
  231. // let money = parseFloat(this.money);
  232. rechargeWechat({
  233. price: that.rechar_id == 0 ? that.money : that.numberPic,
  234. type: 'routine',
  235. recharge_id: this.rechar_id
  236. })
  237. .then(res => {
  238. uni.hideLoading();
  239. let jsConfig = res.data.config;
  240. uni.requestPayment({
  241. timeStamp: jsConfig.timestamp,
  242. nonceStr: jsConfig.nonceStr,
  243. package: jsConfig.package,
  244. signType: jsConfig.signType,
  245. paySign: jsConfig.paySign,
  246. success: function(res) {
  247. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  248. return that.$util.Tips(
  249. {
  250. title: '支付成功',
  251. icon: 'success'
  252. },
  253. {
  254. tab: 5,
  255. url: '/pages/users/user_money/index'
  256. }
  257. );
  258. },
  259. fail: function() {
  260. return that.$util.Tips({
  261. title: '支付失败'
  262. });
  263. },
  264. complete: function(res) {
  265. if (res.errMsg == 'requestPayment:cancel')
  266. return that.$util.Tips({
  267. title: '取消支付'
  268. });
  269. }
  270. });
  271. })
  272. .catch(err => {
  273. uni.hideLoading();
  274. return that.$util.Tips({
  275. title: err
  276. });
  277. });
  278. // #endif
  279. // #ifdef H5
  280. rechargeWechat({
  281. price: that.rechar_id == 0 ? that.money : that.numberPic,
  282. type: that.type,
  283. recharge_id: that.rechar_id
  284. })
  285. .then(res => {
  286. console.log(res);
  287. that.payLoding = false;
  288. window.location.href = res.data.config.jsConfig.expend.pay_info;
  289. // if (res.data.type == 'h5') {
  290. // let host = window.location.protocol + '//' + window.location.host;
  291. // let url = `${host}/pages/users/user_money/index`;
  292. // let eUrl = encodeURIComponent(url);
  293. // let locations = `${res.data.config.mweb_url}&redirect_url=${eUrl}`;
  294. // setTimeout(() => {
  295. // location.href = locations;
  296. // }, 100);
  297. // } else {
  298. // uni.hideLoading();
  299. // const jsConfig = res.data.config;
  300. // jsConfig.timeStamp = jsConfig.timestamp;
  301. // that.$wechat
  302. // .pay(jsConfig)
  303. // .then(res => {
  304. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  305. // return that.$util.Tips(
  306. // {
  307. // title: '支付成功',
  308. // icon: 'success'
  309. // },
  310. // {
  311. // tab: 5,
  312. // url: '/pages/users/user_money/index'
  313. // }
  314. // );
  315. // })
  316. // .catch(res => {
  317. // if (res.errMsg == 'chooseWXPay:cancel')
  318. // return that.$util.Tips(
  319. // {
  320. // title: '取消支付'
  321. // },
  322. // {
  323. // tab: 5,
  324. // url: goPages + '?status=0'
  325. // }
  326. // );
  327. // });
  328. // }
  329. })
  330. .catch(error => {
  331. that.payLoding = false;
  332. return that.$util.Tips({
  333. title: error
  334. });
  335. });
  336. // #endif
  337. // #ifdef APP-PLUS
  338. rechargeWechat({
  339. price: that.rechar_id == 0 ? that.money : that.numberPic,
  340. recharge_id: that.rechar_id,
  341. type: 'weixin'
  342. }).then(res => {
  343. uni.hideLoading();
  344. uni.requestPayment({
  345. orderInfo: {
  346. ...res.data.config,
  347. timeStamp: res.data.config.timestamp
  348. },
  349. provider: 'wxpay',
  350. success(res) {
  351. return that.$util.Tips(
  352. {
  353. title: '支付成功',
  354. icon: 'success'
  355. },
  356. {
  357. tab: 5,
  358. url: '/pages/users/user_money/index'
  359. }
  360. );
  361. },
  362. fail: function(rej) {
  363. console.log(rej);
  364. return that.$util.Tips({
  365. title: '支付失败'
  366. });
  367. },
  368. complete: function(res) {
  369. if (res.errMsg == 'requestPayment:cancel')
  370. return that.$util.Tips({
  371. title: '取消支付'
  372. });
  373. }
  374. });
  375. });
  376. // #endif
  377. }
  378. }
  379. }
  380. };
  381. </script>
  382. <style lang="scss">
  383. page {
  384. height: 100%;
  385. background: #ffffff;
  386. }
  387. .top_box {
  388. padding: 20rpx 26rpx 20rpx 47rpx;
  389. display: flex;
  390. align-items: center;
  391. justify-content: space-between;
  392. .yue-tit {
  393. font-size: 28rpx;
  394. font-family: PingFang SC;
  395. font-weight: 500;
  396. color: #333333;
  397. }
  398. .yue-num {
  399. font-size: 30rpx;
  400. font-family: PingFang SC;
  401. font-weight: bold;
  402. color: #ff6f0f;
  403. }
  404. }
  405. .line_box {
  406. width: 100%;
  407. height: 20rpx;
  408. background: #f8f8f8;
  409. }
  410. .cz_box {
  411. padding: 40rpx 20rpx 20rpx;
  412. .cz_wrap {
  413. display: flex;
  414. align-items: center;
  415. justify-content: space-between;
  416. padding-bottom: 20rpx;
  417. border-bottom: 1px solid #e6e6e6;
  418. .cz_tit {
  419. font-size: 32rpx;
  420. font-family: PingFang SC;
  421. font-weight: 500;
  422. }
  423. .cz_input {
  424. text-align: right;
  425. font-size: 32rpx;
  426. font-family: PingFang SC;
  427. font-weight: 500;
  428. // color: #BFBFBF;
  429. }
  430. }
  431. .zc_list_box {
  432. display: flex;
  433. flex-wrap: wrap;
  434. .zc_list_price {
  435. width: 202rpx;
  436. height: 60rpx;
  437. background: #f0f0f0;
  438. border-radius: 8rpx;
  439. margin-top: 36rpx;
  440. margin-right: 50rpx;
  441. display: flex;
  442. align-items: center;
  443. justify-content: center;
  444. &:nth-child(3n) {
  445. margin-right: 0;
  446. }
  447. }
  448. .seletPrice {
  449. background: linear-gradient(143.2747deg, #ff6a00, #ee0979);
  450. color: #ffffff;
  451. }
  452. }
  453. }
  454. .recha-box {
  455. padding: 50rpx 30rpx 0;
  456. display: flex;
  457. flex-wrap: wrap;
  458. .recha-frame {
  459. width: 210rpx;
  460. height: 181rpx;
  461. border: 1px solid #dbdede;
  462. border-radius: 20rpx;
  463. display: flex;
  464. align-items: center;
  465. flex-direction: column;
  466. justify-content: center;
  467. margin-right: 30rpx;
  468. margin-bottom: 30rpx;
  469. &:nth-child(3n) {
  470. margin-right: 0;
  471. }
  472. .recha-top {
  473. display: flex;
  474. align-items: center;
  475. .recha-img {
  476. width: 64rpx;
  477. height: 62rpx;
  478. }
  479. .recha-tit {
  480. margin-left: 10rpx;
  481. font-size: 36rpx;
  482. font-family: PingFang SC;
  483. font-weight: bold;
  484. color: #333333;
  485. }
  486. }
  487. .recha-song {
  488. margin-top: 20rpx;
  489. font-size: $font-base;
  490. font-family: PingFang SC;
  491. font-weight: bold;
  492. color: #ff9900;
  493. }
  494. }
  495. .select-frame {
  496. border: 1px solid #ef041f;
  497. }
  498. }
  499. .rechar-box {
  500. padding: 30rpx 20rpx 0;
  501. .rechar-title {
  502. font-size: 32rpx;
  503. font-family: PingFang SC;
  504. font-weight: bold;
  505. color: #333333;
  506. margin-bottom: 10rpx;
  507. }
  508. .rechar-text {
  509. font-size: 28rpx;
  510. font-family: PingFang SC;
  511. font-weight: bold;
  512. color: #333333;
  513. }
  514. }
  515. .cz-type {
  516. margin-top: 22rpx;
  517. display: flex;
  518. justify-content: space-between;
  519. padding: 32rpx;
  520. align-items: center;
  521. .type-left {
  522. display: flex;
  523. align-items: center;
  524. .icon {
  525. height: 38rpx;
  526. image {
  527. width: 48rpx;
  528. height: 38rpx;
  529. }
  530. }
  531. .iconweixin {
  532. color: #36cb59;
  533. }
  534. .tit {
  535. margin-left: 12rpx;
  536. font-size: 30rpx;
  537. color: #333333;
  538. }
  539. }
  540. .type-right {
  541. image {
  542. width: 36rpx;
  543. height: 36rpx;
  544. }
  545. }
  546. }
  547. .add-btn {
  548. &.modified {
  549. }
  550. &.up {
  551. color: #fff;
  552. }
  553. margin: 100rpx auto 0;
  554. display: flex;
  555. align-items: center;
  556. justify-content: center;
  557. width: 604rpx;
  558. height: 90rpx;
  559. // border: 2rpx solid #F21F5D;
  560. border-radius: 10rpx;
  561. font-size: 36rpx;
  562. font-family: PingFang SC;
  563. font-weight: 500;
  564. color: #fff;
  565. line-height: 90rpx;
  566. text-align: center;
  567. background-color: #ff4c4c;
  568. }
  569. .row-box {
  570. margin-top: 30rpx;
  571. padding: 20rpx 30rpx;
  572. background: #fff;
  573. .title {
  574. font-size: $font-base + 2rpx;
  575. color: $font-color-dark;
  576. }
  577. .row {
  578. display: flex;
  579. align-items: center;
  580. position: relative;
  581. height: 80rpx;
  582. .tit {
  583. flex-shrink: 0;
  584. width: 40rpx;
  585. font-size: 30rpx;
  586. color: $font-color-dark;
  587. }
  588. .input {
  589. flex: 1;
  590. font-size: 30rpx;
  591. color: $font-color-dark;
  592. }
  593. .iconlocation {
  594. font-size: 36rpx;
  595. color: $font-color-light;
  596. }
  597. .buttom {
  598. color: $font-color;
  599. font-size: $font-base;
  600. }
  601. }
  602. }
  603. .list {
  604. padding-left: 30rpx;
  605. margin-top: 30rpx;
  606. background-color: #ffffff;
  607. .box {
  608. display: flex;
  609. align-items: center;
  610. width: 100%;
  611. height: 120rpx;
  612. border-bottom: 1px solid $border-color-light;
  613. padding-right: 25rpx;
  614. .icon {
  615. font-size: 48rpx;
  616. padding-right: 20rpx;
  617. display: flex;
  618. }
  619. .yongjing {
  620. width: 48rpx;
  621. height: 48rpx;
  622. }
  623. .iconweixin1 {
  624. color: #18bf16;
  625. }
  626. .iconzhifubao {
  627. color: #08aaec;
  628. }
  629. .title-box {
  630. flex-grow: 1;
  631. text-align: left;
  632. .title {
  633. font-size: $font-base + 2rpx;
  634. color: $font-color-base;
  635. }
  636. .node {
  637. font-size: $font-sm;
  638. color: $font-color-light;
  639. }
  640. }
  641. }
  642. }
  643. /deep/ .uni-radio-input {
  644. width: 45rpx;
  645. height: 45rpx;
  646. }
  647. .active-bg {
  648. background: #999 !important;
  649. color: #ffffff !important;
  650. }
  651. .iconzhifubao {
  652. color: #08aaec;
  653. }
  654. </style>