index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  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. that.$util.Tips({
  401. title: that.$t(`订单创建成功`)
  402. });
  403. setTimeout(() => {
  404. location.href = res.data.result.jsConfig.mweb_url;
  405. }, 2000);
  406. break;
  407. case 'ALIPAY_PAY':
  408. //#ifdef H5
  409. uni.hideLoading();
  410. that.formContent = res.data.result.jsConfig;
  411. that.$nextTick(() => {
  412. document.getElementById('alipaysubmit').submit();
  413. })
  414. //#endif
  415. // #ifdef MP
  416. uni.navigateTo({
  417. url: `/pages/users/alipay_invoke/index?id=${orderId}&link=${jsConfig.qrCode}`
  418. });
  419. // #endif
  420. // #ifdef APP-PLUS
  421. uni.requestPayment({
  422. provider: 'alipay',
  423. orderInfo: jsConfig,
  424. success: (e) => {
  425. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(this
  426. .number,
  427. that.userinfo
  428. .now_money));
  429. return that.$util.Tips({
  430. title: that.$t(`支付成功`),
  431. icon: 'success'
  432. }, {
  433. tab: 5,
  434. url: '/pages/users/user_money/index'
  435. });
  436. },
  437. fail: (e) => {
  438. return that.$util.Tips({
  439. title: that.$t(`支付失败`)
  440. });
  441. },
  442. complete: () => {
  443. uni.hideLoading();
  444. },
  445. });
  446. // #endif
  447. break;
  448. }
  449. }).catch(err => {
  450. uni.hideLoading();
  451. return that.$util.Tips({
  452. title: err
  453. })
  454. })
  455. },
  456. formpost(url, postData) {
  457. let tempform = document.createElement("form");
  458. tempform.action = url;
  459. tempform.method = "post";
  460. tempform.target = "_self";
  461. tempform.style.display = "none";
  462. for (let x in postData) {
  463. let opt = document.createElement("input");
  464. opt.name = x;
  465. opt.value = postData[x];
  466. tempform.appendChild(opt);
  467. }
  468. document.body.appendChild(tempform);
  469. this.$nextTick(e => {
  470. tempform.submit();
  471. })
  472. },
  473. pay() {
  474. this.pay_close = true;
  475. },
  476. /*
  477. * 用户充值
  478. */
  479. submitSub() {
  480. let that = this
  481. let value = this.number;
  482. // 转入余额
  483. if (that.active) {
  484. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  485. return that.$util.Tips({
  486. title: that.$t(`请输入金额`)
  487. });
  488. }
  489. uni.showModal({
  490. title: that.$t(`转入余额`),
  491. content: that.$t(`转入余额后无法再次转出,确认是否转入余额`),
  492. success(res) {
  493. if (res.confirm) {
  494. recharge({
  495. price: parseFloat(value),
  496. type: 1
  497. })
  498. .then(res => {
  499. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
  500. return that.$util.Tips({
  501. title: that.$t(`转入成功`),
  502. icon: 'success'
  503. }, {
  504. tab: 5,
  505. url: '/pages/users/user_money/index'
  506. });
  507. }).catch(err => {
  508. return that.$util.Tips({
  509. title: err
  510. })
  511. });
  512. } else if (res.cancel) {
  513. return that.$util.Tips({
  514. title: that.$t(`已取消`)
  515. });
  516. }
  517. },
  518. })
  519. } else {
  520. this.pay()
  521. }
  522. }
  523. },
  524. }
  525. </script>
  526. <style lang="scss" scoped>
  527. page {
  528. width: 100%;
  529. height: 100%;
  530. background-color: #fff;
  531. }
  532. .bgcolor {
  533. background-color: var(--view-theme)
  534. }
  535. .payment {
  536. position: relative;
  537. top: -60rpx;
  538. width: 100%;
  539. background-color: #fff;
  540. border-radius: 10rpx;
  541. padding-top: 25rpx;
  542. border-top-right-radius: 39rpx;
  543. border-top-left-radius: 39rpx;
  544. }
  545. .payment .nav {
  546. height: 75rpx;
  547. line-height: 75rpx;
  548. padding: 0 100rpx;
  549. }
  550. .payment .nav .item {
  551. font-size: 30rpx;
  552. color: #333;
  553. }
  554. .payment .nav .item.on {
  555. font-weight: bold;
  556. border-bottom: 4rpx solid var(--view-theme);
  557. }
  558. .payment .input {
  559. display: flex;
  560. align-items: center;
  561. justify-content: center;
  562. border-bottom: 1px dashed #dddddd;
  563. margin: 60rpx auto 0 auto;
  564. padding-bottom: 20rpx;
  565. font-size: 56rpx;
  566. color: #333333;
  567. flex-wrap: nowrap;
  568. }
  569. .payment .input text {
  570. padding-left: 106rpx;
  571. }
  572. .payment .input input {
  573. padding-right: 106rpx;
  574. width: 300rpx;
  575. height: 94rpx;
  576. text-align: center;
  577. font-size: 70rpx;
  578. }
  579. .payment .placeholder {
  580. color: #d0d0d0;
  581. height: 100%;
  582. line-height: 94rpx;
  583. }
  584. .payment .tip {
  585. font-size: 26rpx;
  586. color: #888888;
  587. padding: 0 30rpx;
  588. margin-top: 25rpx;
  589. }
  590. .payment .but {
  591. color: #fff;
  592. font-size: 30rpx;
  593. width: 700rpx;
  594. height: 86rpx;
  595. border-radius: 50rpx;
  596. margin: 46rpx auto 0 auto;
  597. line-height: 86rpx;
  598. }
  599. .payment-top {
  600. width: 100%;
  601. height: 350rpx;
  602. background-color: var(--view-theme);
  603. .name {
  604. font-size: 26rpx;
  605. color: rgba(255, 255, 255, 0.8);
  606. margin-top: -38rpx;
  607. margin-bottom: 30rpx;
  608. }
  609. .pic {
  610. font-size: 32rpx;
  611. color: #fff;
  612. .num {
  613. font-size: 56rpx;
  614. }
  615. }
  616. .pic-font {
  617. font-size: 78rpx;
  618. color: #fff;
  619. }
  620. }
  621. .picList {
  622. display: flex;
  623. flex-wrap: wrap;
  624. margin: 30rpx 0;
  625. .pic-box {
  626. width: 32%;
  627. height: auto;
  628. border-radius: 20rpx;
  629. margin-top: 21rpx;
  630. padding: 20rpx 0;
  631. margin-right: 12rpx;
  632. &:nth-child(3n) {
  633. margin-right: 0;
  634. }
  635. }
  636. .pic-box-color {
  637. background-color: #f4f4f4;
  638. color: #656565;
  639. }
  640. .pic-number {
  641. font-size: 22rpx;
  642. }
  643. .pic-number-pic {
  644. font-size: 38rpx;
  645. margin-right: 10rpx;
  646. text-align: center;
  647. }
  648. .pic-box-color-active {
  649. background-color: var(--view-theme) !important;
  650. color: #fff !important;
  651. }
  652. }
  653. .tips-box {
  654. .tips {
  655. font-size: 28rpx;
  656. color: #333333;
  657. font-weight: 800;
  658. margin-bottom: 14rpx;
  659. margin-top: 20rpx;
  660. }
  661. .tips-samll {
  662. font-size: 24rpx;
  663. color: #333333;
  664. margin-bottom: 14rpx;
  665. }
  666. .tip-box {
  667. margin-top: 30rpx;
  668. }
  669. }
  670. .tips-title {
  671. margin-top: 20rpx;
  672. font-size: 24rpx;
  673. color: #333;
  674. }
  675. </style>