index.vue 17 KB

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