index.vue 18 KB

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