index.vue 18 KB

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