index.vue 18 KB

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