index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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. console.log('kaiszf++++')
  339. rechargeWechat({
  340. price: that.rechar_id == 0 ? that.money : that.numberPic,
  341. recharge_id: that.rechar_id,
  342. return_url: 'http://ygs.hqgjsmc.com/pages/index/index',
  343. type: 'alipay'
  344. }).then(res => {
  345. console.log('成功返回')
  346. uni.hideLoading();
  347. console.log(res.data.config.jsConfig.expend.pay_info,'zhif')
  348. plus.runtime.openURL('alipays://platformapi/startapp?saId=10000007&qrcode=' + res.data.config.jsConfig.expend.pay_info,function(res) {
  349. console.log(res,'没有调起')
  350. // uni.hideLoading();
  351. });
  352. // uni.requestPayment({
  353. // orderInfo: {
  354. // ...res.data.config,
  355. // timeStamp: res.data.config.timestamp
  356. // },
  357. // provider: 'wxpay',
  358. // success(res) {
  359. // return that.$util.Tips(
  360. // {
  361. // title: '支付成功',
  362. // icon: 'success'
  363. // },
  364. // {
  365. // tab: 5,
  366. // url: '/pages/users/user_money/index'
  367. // }
  368. // );
  369. // },
  370. // fail: function(rej) {
  371. // console.log(rej);
  372. // return that.$util.Tips({
  373. // title: '支付失败'
  374. // });
  375. // },
  376. // complete: function(res) {
  377. // if (res.errMsg == 'requestPayment:cancel')
  378. // return that.$util.Tips({
  379. // title: '取消支付'
  380. // });
  381. // }
  382. // });
  383. }).catch(err => {
  384. console.log('shibai')
  385. })
  386. // #endif
  387. }
  388. }
  389. }
  390. };
  391. </script>
  392. <style lang="scss">
  393. page {
  394. height: 100%;
  395. background: #ffffff;
  396. }
  397. .top_box {
  398. padding: 20rpx 26rpx 20rpx 47rpx;
  399. display: flex;
  400. align-items: center;
  401. justify-content: space-between;
  402. .yue-tit {
  403. font-size: 28rpx;
  404. font-family: PingFang SC;
  405. font-weight: 500;
  406. color: #333333;
  407. }
  408. .yue-num {
  409. font-size: 30rpx;
  410. font-family: PingFang SC;
  411. font-weight: bold;
  412. color: #ff6f0f;
  413. }
  414. }
  415. .line_box {
  416. width: 100%;
  417. height: 20rpx;
  418. background: #f8f8f8;
  419. }
  420. .cz_box {
  421. padding: 40rpx 20rpx 20rpx;
  422. .cz_wrap {
  423. display: flex;
  424. align-items: center;
  425. justify-content: space-between;
  426. padding-bottom: 20rpx;
  427. border-bottom: 1px solid #e6e6e6;
  428. .cz_tit {
  429. font-size: 32rpx;
  430. font-family: PingFang SC;
  431. font-weight: 500;
  432. }
  433. .cz_input {
  434. text-align: right;
  435. font-size: 32rpx;
  436. font-family: PingFang SC;
  437. font-weight: 500;
  438. // color: #BFBFBF;
  439. }
  440. }
  441. .zc_list_box {
  442. display: flex;
  443. flex-wrap: wrap;
  444. .zc_list_price {
  445. width: 202rpx;
  446. height: 60rpx;
  447. background: #f0f0f0;
  448. border-radius: 8rpx;
  449. margin-top: 36rpx;
  450. margin-right: 50rpx;
  451. display: flex;
  452. align-items: center;
  453. justify-content: center;
  454. &:nth-child(3n) {
  455. margin-right: 0;
  456. }
  457. }
  458. .seletPrice {
  459. background: linear-gradient(143.2747deg, #ff6a00, #ee0979);
  460. color: #ffffff;
  461. }
  462. }
  463. }
  464. .recha-box {
  465. padding: 50rpx 30rpx 0;
  466. display: flex;
  467. flex-wrap: wrap;
  468. .recha-frame {
  469. width: 210rpx;
  470. height: 181rpx;
  471. border: 1px solid #dbdede;
  472. border-radius: 20rpx;
  473. display: flex;
  474. align-items: center;
  475. flex-direction: column;
  476. justify-content: center;
  477. margin-right: 30rpx;
  478. margin-bottom: 30rpx;
  479. &:nth-child(3n) {
  480. margin-right: 0;
  481. }
  482. .recha-top {
  483. display: flex;
  484. align-items: center;
  485. .recha-img {
  486. width: 64rpx;
  487. height: 62rpx;
  488. }
  489. .recha-tit {
  490. margin-left: 10rpx;
  491. font-size: 36rpx;
  492. font-family: PingFang SC;
  493. font-weight: bold;
  494. color: #333333;
  495. }
  496. }
  497. .recha-song {
  498. margin-top: 20rpx;
  499. font-size: $font-base;
  500. font-family: PingFang SC;
  501. font-weight: bold;
  502. color: #ff9900;
  503. }
  504. }
  505. .select-frame {
  506. border: 1px solid #ef041f;
  507. }
  508. }
  509. .rechar-box {
  510. padding: 30rpx 20rpx 0;
  511. .rechar-title {
  512. font-size: 32rpx;
  513. font-family: PingFang SC;
  514. font-weight: bold;
  515. color: #333333;
  516. margin-bottom: 10rpx;
  517. }
  518. .rechar-text {
  519. font-size: 28rpx;
  520. font-family: PingFang SC;
  521. font-weight: bold;
  522. color: #333333;
  523. }
  524. }
  525. .cz-type {
  526. margin-top: 22rpx;
  527. display: flex;
  528. justify-content: space-between;
  529. padding: 32rpx;
  530. align-items: center;
  531. .type-left {
  532. display: flex;
  533. align-items: center;
  534. .icon {
  535. height: 38rpx;
  536. image {
  537. width: 48rpx;
  538. height: 38rpx;
  539. }
  540. }
  541. .iconweixin {
  542. color: #36cb59;
  543. }
  544. .tit {
  545. margin-left: 12rpx;
  546. font-size: 30rpx;
  547. color: #333333;
  548. }
  549. }
  550. .type-right {
  551. image {
  552. width: 36rpx;
  553. height: 36rpx;
  554. }
  555. }
  556. }
  557. .add-btn {
  558. &.modified {
  559. }
  560. &.up {
  561. color: #fff;
  562. }
  563. margin: 100rpx auto 0;
  564. display: flex;
  565. align-items: center;
  566. justify-content: center;
  567. width: 604rpx;
  568. height: 90rpx;
  569. // border: 2rpx solid #F21F5D;
  570. border-radius: 10rpx;
  571. font-size: 36rpx;
  572. font-family: PingFang SC;
  573. font-weight: 500;
  574. color: #fff;
  575. line-height: 90rpx;
  576. text-align: center;
  577. background-color: #ff4c4c;
  578. }
  579. .row-box {
  580. margin-top: 30rpx;
  581. padding: 20rpx 30rpx;
  582. background: #fff;
  583. .title {
  584. font-size: $font-base + 2rpx;
  585. color: $font-color-dark;
  586. }
  587. .row {
  588. display: flex;
  589. align-items: center;
  590. position: relative;
  591. height: 80rpx;
  592. .tit {
  593. flex-shrink: 0;
  594. width: 40rpx;
  595. font-size: 30rpx;
  596. color: $font-color-dark;
  597. }
  598. .input {
  599. flex: 1;
  600. font-size: 30rpx;
  601. color: $font-color-dark;
  602. }
  603. .iconlocation {
  604. font-size: 36rpx;
  605. color: $font-color-light;
  606. }
  607. .buttom {
  608. color: $font-color;
  609. font-size: $font-base;
  610. }
  611. }
  612. }
  613. .list {
  614. padding-left: 30rpx;
  615. margin-top: 30rpx;
  616. background-color: #ffffff;
  617. .box {
  618. display: flex;
  619. align-items: center;
  620. width: 100%;
  621. height: 120rpx;
  622. border-bottom: 1px solid $border-color-light;
  623. padding-right: 25rpx;
  624. .icon {
  625. font-size: 48rpx;
  626. padding-right: 20rpx;
  627. display: flex;
  628. }
  629. .yongjing {
  630. width: 48rpx;
  631. height: 48rpx;
  632. }
  633. .iconweixin1 {
  634. color: #18bf16;
  635. }
  636. .iconzhifubao {
  637. color: #08aaec;
  638. }
  639. .title-box {
  640. flex-grow: 1;
  641. text-align: left;
  642. .title {
  643. font-size: $font-base + 2rpx;
  644. color: $font-color-base;
  645. }
  646. .node {
  647. font-size: $font-sm;
  648. color: $font-color-light;
  649. }
  650. }
  651. }
  652. }
  653. /deep/ .uni-radio-input {
  654. width: 45rpx;
  655. height: 45rpx;
  656. }
  657. .active-bg {
  658. background: #999 !important;
  659. color: #ffffff !important;
  660. }
  661. .iconzhifubao {
  662. color: #08aaec;
  663. }
  664. </style>