index.vue 17 KB

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