index.vue 18 KB

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