index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <template>
  2. <view :style="viewColor">
  3. <form @submit="submitSub" report-submit='true'>
  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)">
  17. <view class="pic-number-pic">
  18. {{ item.data.price }}<span class="pic-number"> 元</span>
  19. </view>
  20. <view class="pic-number">赠送:{{ item.data.give }} 元</view>
  21. </view>
  22. <view class="pic-box pic-box-color acea-row row-center-wrapper" :class="rechar_id == 0 ? 'pic-box-color-active' : ''"
  23. @click="picCharge(picList.length)">
  24. <input type="digit" :placeholder="otherValue" v-model="money" class="pic-box-money pic-number-pic" :class="rechar_id == 0 ? '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 placeholder="0.00" type='number' placeholder-class='placeholder' :value="number"
  35. name="number"></input></view>
  36. <view class="tips-title">
  37. <view style="font-weight: bold; font-size: 26rpx;">提示:</view>
  38. <view style="margin-top: 10rpx;">当前佣金为 <text class='t-color'>¥{{userinfo.brokerage_price || 0}}</text></view>
  39. </view>
  40. <view class="tips-box">
  41. <view class="tips mt-30">注意事项:</view>
  42. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  43. {{ item }}
  44. </view>
  45. </view>
  46. </view>
  47. <button class='but' formType="submit"> {{active ? '立即转入': '立即充值' }}</button>
  48. </view>
  49. </form>
  50. <payment :payMode="payMode" :order_id="rechar_id" :pay_close="pay_close" :is-call="true" @onChangeFun="onChangeFun"
  51. :totalPrice="totalPrice"></payment>
  52. </view>
  53. </template>
  54. <script>
  55. // +----------------------------------------------------------------------
  56. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  57. // +----------------------------------------------------------------------
  58. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  59. // +----------------------------------------------------------------------
  60. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  61. // +----------------------------------------------------------------------
  62. // | Author: CRMEB Team <admin@crmeb.com>
  63. // +----------------------------------------------------------------------
  64. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  65. import {
  66. spreadInfo,
  67. rechargeRoutine,
  68. rechargeWechat,
  69. getRechargeApi,
  70. rechargeBrokerage
  71. } from '@/api/user.js';
  72. import { mapGetters } from "vuex";
  73. import payment from '@/components/payment';
  74. import { openPaySubscribe } from '@/utils/SubscribeMessage.js';
  75. export default {
  76. components: {
  77. payment
  78. },
  79. data() {
  80. let that = this;
  81. return {
  82. otherValue: '其他',
  83. now_money: 0,
  84. navRecharge: ['账户充值', '佣金转入'],
  85. active: 0,
  86. number: '',
  87. from: '',
  88. userinfo: {},
  89. placeholder: "0.00",
  90. picList: [],
  91. activePic: 0,
  92. money: "",
  93. numberPic: '',
  94. rechar_id: '0',
  95. rechargeAttention: [],
  96. delta: 1,
  97. statusBarHeight: statusBarHeight,
  98. pay_close: false,
  99. totalPrice: '0',
  100. payMode: [{
  101. name: '微信支付',
  102. icon: 'icon-weixinzhifu',
  103. // #ifdef H5
  104. value: this.$wechat.isWeixin() ? 'weixin' : 'h5',
  105. // #endif
  106. // #ifdef MP
  107. value: 'routine',
  108. // #endif
  109. // #ifdef APP-PLUS
  110. value: 'weixin',
  111. // #endif
  112. title: '微信快捷支付',
  113. payStatus: true
  114. }
  115. // #ifdef H5 ||APP-PLUS
  116. ,
  117. {
  118. name: '支付宝支付',
  119. icon: 'icon-zhifubao',
  120. // #ifdef H5 || APP-PLUS
  121. value: 'alipay',
  122. // #endif
  123. // #ifdef MP
  124. value: 'alipayQr',
  125. // #endif
  126. title: '支付宝支付',
  127. payStatus: true
  128. }
  129. // #endif
  130. ],
  131. };
  132. },
  133. computed: mapGetters(['viewColor','isLogin']),
  134. onLoad(options) {
  135. this.delta = options.delta || 1;
  136. if (this.isLogin) {
  137. this.getUserInfo();
  138. this.getRecharge();
  139. } else {
  140. toLogin()
  141. }
  142. },
  143. onUnload: function () {
  144. uni.navigateBack({
  145. delta: this.delta
  146. })
  147. },
  148. methods: {
  149. goBack: function() {
  150. uni.navigateBack();
  151. },
  152. /**
  153. * 选择金额
  154. */
  155. picCharge(idx, item) {
  156. this.activePic = idx;
  157. if (item === undefined) {
  158. this.rechar_id = '0';
  159. this.numberPic = "";
  160. this.otherValue = ''
  161. } else {
  162. this.otherValue = '其他'
  163. this.money = "";
  164. this.rechar_id = item.id.toString();
  165. this.numberPic = item.data.price;
  166. }
  167. },
  168. /**
  169. * 充值额度选择
  170. */
  171. getRecharge() {
  172. getRechargeApi()
  173. .then(res => {
  174. this.picList = res.data.recharge_quota;
  175. if (this.picList[0]) {
  176. this.rechar_id = this.picList[0].id.toString();
  177. this.numberPic = this.picList[0].data.price;
  178. }
  179. this.rechargeAttention = res.data.recharge_attention || [];
  180. })
  181. .catch(res => {
  182. this.$dialog.toast({
  183. mes: res
  184. });
  185. });
  186. },
  187. navRecharges: function(index) {
  188. this.active = index;
  189. },
  190. /**
  191. * 获取用户信息
  192. */
  193. getUserInfo: function() {
  194. let that = this;
  195. spreadInfo().then(res => {
  196. that.$set(that, 'userinfo', res.data);
  197. })
  198. },
  199. payClose: function() {
  200. this.pay_close = false;
  201. },
  202. payCheck: function(type) {
  203. this.createOrder(type);
  204. },
  205. /*
  206. * 用户充值
  207. */
  208. submitSub: function(e) {
  209. let that = this
  210. let value = e.detail.value.number;
  211. // 转入余额
  212. if (that.active) {
  213. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  214. return that.$util.Tips({
  215. title: '请输入金额'
  216. });
  217. }
  218. if(parseFloat(value) > that.userinfo.brokerage_price){
  219. return that.$util.Tips({
  220. title: '剩余可用佣金不足' + parseFloat(value)
  221. });
  222. }
  223. uni.showModal({
  224. title: '转入余额',
  225. content: '转入余额后无法再次转出,确认是否转入余额',
  226. success(res) {
  227. if (res.confirm) {
  228. rechargeBrokerage({
  229. brokerage: parseFloat(value),
  230. }).then(res => {
  231. that.$util.Tips({
  232. title: '转入成功',
  233. icon: 'success'
  234. });
  235. uni.navigateTo({
  236. url: '/pages/users/user_money/index'
  237. });
  238. }).catch(err => {
  239. return that.$util.Tips({
  240. title: err
  241. })
  242. });
  243. } else if (res.cancel) {
  244. return that.$util.Tips({
  245. title: '已取消'
  246. });
  247. }
  248. },
  249. })
  250. } else {
  251. if (this.rechar_id == 0) {
  252. if (parseFloat(that.money)=== 0) {
  253. return that.$util.Tips({
  254. title: '充值金额金额不能为0!'
  255. });
  256. }
  257. if (!that.money) {
  258. return that.$util.Tips({
  259. title: '请填写充值金额!'
  260. });
  261. }
  262. if (!Number(that.money)) {
  263. return that.$util.Tips({
  264. title: '请填写正确的金额!'
  265. });
  266. }
  267. }
  268. this.pay_close = true
  269. }
  270. },
  271. createOrder(type) {
  272. let that = this;
  273. let query = {
  274. price: that.rechar_id == 0 ? that.money : that.numberPic,
  275. recharge_id: that.rechar_id,
  276. type: type,
  277. // #ifdef H5
  278. return_url: location.port ? location.protocol + '//' + location.hostname + ':' + location.port +
  279. '/pages/users/user_payment/index' : location.protocol + '//' + location.hostname +
  280. '/pages/users/user_payment/index'
  281. // #endif
  282. };
  283. // #ifdef MP
  284. // openPaySubscribe().then(() => {
  285. rechargeWechat(query).then(res => {
  286. that.callPay(res);
  287. }).catch(err => {
  288. uni.showToast({
  289. title: err,
  290. icon: 'none'
  291. });
  292. });
  293. // });
  294. // #endif
  295. // #ifndef MP
  296. rechargeWechat(query).then(res => {
  297. that.callPay(res);
  298. }).catch(err => {
  299. uni.showToast({
  300. title: err,
  301. icon: 'none'
  302. });
  303. });
  304. // #endif
  305. },
  306. // 调用支付
  307. callPay(res) {
  308. let that = this, status = res.data.type,
  309. orderId = res.data.recharge_id,
  310. callback_key = res.data.pay_key,
  311. jsConfig = res.data.config,
  312. goPages = '/pages/users/user_payment/index';
  313. switch (status) {
  314. case 'ORDER_EXIST':
  315. case 'EXTEND_ORDER':
  316. case 'PAY_ERROR':
  317. case 'error':
  318. uni.hideLoading();
  319. return that.$util.Tips({
  320. title: res.message
  321. }, {
  322. tab: 5,
  323. url: goPages
  324. });
  325. break;
  326. case 'success':
  327. uni.hideLoading();
  328. if (that.seckillId)
  329. return that.$util.Tips({
  330. title: res.message,
  331. icon: 'success'
  332. }, {
  333. tab: 4,
  334. url: goPages
  335. });
  336. return that.$util.Tips({
  337. title: res.message,
  338. icon: 'success'
  339. }, {
  340. tab: 5,
  341. url: goPages
  342. });
  343. break;
  344. case 'alipay':
  345. case "alipayQr":
  346. uni.hideLoading();
  347. that.$emit('onChangeFun', {
  348. action: 'payClose'
  349. });
  350. uni.navigateTo({
  351. url: '/pages/order_pay_back/index?keyCode='+callback_key+'&url='+jsConfig+'&type=10'
  352. })
  353. return;
  354. break;
  355. // #ifndef MP
  356. case "wechat":
  357. case "weixin":
  358. case "weixinApp":
  359. jsConfig.timeStamp = jsConfig.timestamp;
  360. // #ifndef APP-PLUS
  361. that.$wechat.pay(jsConfig).then(res => {
  362. return that.$util.Tips({
  363. title: res.message,
  364. icon: 'success'
  365. }, {
  366. tab: 4,
  367. url: goPages
  368. });
  369. }).catch(res => {
  370. if (res.errMsg == 'chooseWXPay:cancel') return that.$util.Tips({
  371. title: '取消支付'
  372. }, {
  373. tab: 5,
  374. url: goPages
  375. });
  376. })
  377. // #endif
  378. // #ifdef APP-PLUS
  379. let mp_pay_name=''
  380. if(uni.requestOrderPayment){
  381. mp_pay_name='requestOrderPayment'
  382. }else{
  383. mp_pay_name='requestPayment'
  384. }
  385. uni[mp_pay_name]({
  386. provider: 'wxpay',
  387. orderInfo: jsConfig,
  388. success: (e) => {
  389. let url = '/pages/users/user_payment/index';
  390. return that.$util.Tips({
  391. title: '支付成功',
  392. icon: 'success'
  393. }, {
  394. tab: 4,
  395. url: url
  396. });
  397. },
  398. fail: (e) => {
  399. uni.showModal({
  400. content: "支付失败",
  401. showCancel: false,
  402. success: function(res) {
  403. let url = '/pages/users/user_payment/index';
  404. uni.redirectTo({
  405. url: url
  406. })
  407. }
  408. })
  409. },
  410. complete: () => {
  411. uni.hideLoading();
  412. },
  413. });
  414. // #endif
  415. break;
  416. // #endif
  417. // #ifdef MP
  418. case "routine":
  419. jsConfig.timeStamp = jsConfig.timestamp;
  420. let mp_pay_name=''
  421. if(uni.requestOrderPayment){
  422. mp_pay_name='requestOrderPayment'
  423. }else{
  424. mp_pay_name='requestPayment'
  425. }
  426. uni[mp_pay_name]({
  427. ...jsConfig,
  428. success: function(res) {
  429. uni.hideLoading();
  430. that.getUserInfo();
  431. that.getRecharge();
  432. return that.$util.Tips({
  433. title: '支付成功',
  434. icon: 'success'
  435. }, {
  436. tab: 5,
  437. url: goPages
  438. });
  439. },
  440. fail: function(e) {
  441. uni.hideLoading();
  442. return that.$util.Tips({
  443. title: '取消支付'
  444. }, {
  445. tab: 5,
  446. url: goPages
  447. });
  448. },
  449. })
  450. break;
  451. // #endif
  452. case "balance":
  453. uni.hideLoading();
  454. //余额不足
  455. return that.$util.Tips({
  456. title: res.message
  457. }, {
  458. tab: 5,
  459. url: goPages
  460. });
  461. break;
  462. // #ifdef H5
  463. case 'h5':
  464. let host = window.location.protocol + "//" + window.location.host;
  465. let url = `${host}/pages/users/user_payment/index`
  466. let eUrl = encodeURIComponent(url)
  467. let jsurl = jsConfig.mweb_url || jsConfig.h5_url
  468. let locations = `${jsurl}&redirect_url=${eUrl}`
  469. setTimeout(() => {
  470. location.href = locations;
  471. }, 100);
  472. break;
  473. // #endif
  474. // #ifdef APP-PLUS
  475. case 'alipayApp':
  476. uni.requestPayment({
  477. provider: 'alipay',
  478. orderInfo: jsConfig,
  479. success: (e) => {
  480. return that.$util.Tips({
  481. title: '支付成功',
  482. icon: 'success'
  483. }, {
  484. tab: 5,
  485. url: goPages
  486. });
  487. },
  488. fail: (e) => {
  489. uni.showModal({
  490. content: "支付失败",
  491. showCancel: false,
  492. success: function(res) {
  493. uni.redirectTo({
  494. url: goPages
  495. })
  496. }
  497. })
  498. },
  499. complete: () => {
  500. uni.hideLoading();
  501. },
  502. });
  503. break;
  504. // #endif
  505. }
  506. },
  507. onChangeFun: function(e) {
  508. let opt = e;
  509. let action = opt.action || null;
  510. let value = opt.value != undefined ? opt.value : null;
  511. action && this[action] && this[action](value);
  512. },
  513. }
  514. }
  515. </script>
  516. <style lang="scss" scoped>
  517. page {
  518. width: 100%;
  519. height: 100%;
  520. background-color: #fff;
  521. }
  522. .payment {
  523. position: relative;
  524. top: -60rpx;
  525. width: 100%;
  526. padding-bottom: 50rpx;
  527. background-color: #fff;
  528. border-radius: 10rpx;
  529. padding-top: 25rpx;
  530. border-top-right-radius: 40rpx;
  531. border-top-left-radius: 40rpx;
  532. }
  533. .payment .nav {
  534. height: 75rpx;
  535. line-height: 75rpx;
  536. padding: 0 100rpx;
  537. }
  538. .payment .nav .item {
  539. font-size: 30rpx;
  540. color: #333;
  541. }
  542. .payment .nav .item.on {
  543. font-weight: bold;
  544. border-bottom: 4rpx solid var(--view-theme);
  545. }
  546. .t-color{color:var(--view-theme);}
  547. .payment .input {
  548. display: flex;
  549. align-items: center;
  550. justify-content: center;
  551. border-bottom: 1px dashed #dddddd;
  552. margin: 60rpx auto 0 auto;
  553. padding-bottom: 20rpx;
  554. font-size: 56rpx;
  555. color: #333333;
  556. flex-wrap: nowrap;
  557. }
  558. .payment .input text {
  559. padding-left: 106rpx;
  560. }
  561. .payment .input input {
  562. padding-right: 106rpx;
  563. width: 300rpx;
  564. height: 94rpx;
  565. text-align: center;
  566. font-size: 70rpx;
  567. }
  568. .payment .placeholder {
  569. color: #d0d0d0;
  570. height: 100%;
  571. line-height: 94rpx;
  572. }
  573. .payment .tip {
  574. font-size: 26rpx;
  575. color: #888888;
  576. padding: 0 30rpx;
  577. margin-top: 25rpx;
  578. }
  579. .payment .but {
  580. color: #fff;
  581. font-size: 30rpx;
  582. width: 700rpx;
  583. height: 86rpx;
  584. border-radius: 50rpx;
  585. margin: 46rpx auto 0 auto;
  586. line-height: 86rpx;
  587. background-color: var(--view-theme);
  588. }
  589. .container{
  590. position: relative;
  591. background-color: var(--view-theme);
  592. border-radius: 0 0 40rpx 40rpx;
  593. .fixed-head{
  594. position: absolute;
  595. left: 0;
  596. top: 20px;
  597. width: 100%;
  598. z-index: 10;
  599. .icon-xiangzuo {
  600. margin-right: 40rpx;
  601. margin-left: 20rpx;
  602. font-size: 40rpx;
  603. color: #fff;
  604. }
  605. }
  606. }
  607. .payment-top {
  608. width: 100%;
  609. height: 350rpx;
  610. position: relative;
  611. background-color: var(--view-theme);
  612. .name {
  613. font-size: 26rpx;
  614. color: rgba(255, 255, 255, 0.8);
  615. margin-top: -38rpx;
  616. margin-bottom: 30rpx;
  617. }
  618. .pic {
  619. font-size: 32rpx;
  620. color: #fff;
  621. }
  622. .pic-font {
  623. font-size: 78rpx;
  624. color: #fff;
  625. }
  626. }
  627. .picList {
  628. display: flex;
  629. flex-wrap: wrap;
  630. margin: 30rpx 0;
  631. .pic-box {
  632. width: 32%;
  633. height: auto;
  634. border-radius: 20rpx;
  635. margin-top: 21rpx;
  636. padding: 20rpx 0;
  637. margin-right: 12rpx;
  638. &:nth-child(3n) {
  639. margin-right: 0;
  640. }
  641. }
  642. .pic-box-color {
  643. background-color: #f4f4f4;
  644. color: #656565;
  645. }
  646. .pic-number {
  647. font-size: 22rpx;
  648. }
  649. .pic-number-pic {
  650. font-size: 38rpx;
  651. margin-right: 10rpx;
  652. text-align: center;
  653. }
  654. .pic-box-color-active {
  655. background-color: var(--view-theme);
  656. color: #fff;
  657. }
  658. }
  659. .tips-box {
  660. .tips {
  661. font-size: 28rpx;
  662. color: #333333;
  663. font-weight: 800;
  664. margin-bottom: 14rpx;
  665. margin-top: 20rpx;
  666. }
  667. .tips-samll {
  668. font-size: 24rpx;
  669. color: #333333;
  670. margin-bottom: 14rpx;
  671. }
  672. }
  673. .tips-title {
  674. margin-top: 20rpx;
  675. font-size: 24rpx;
  676. color: #333;
  677. }
  678. </style>