index.vue 17 KB

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