index.vue 18 KB

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