index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <view>
  3. <form @submit="submitSub" :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" @click="navRecharges(index)">{{$t(item)}}</view>
  13. </view>
  14. <view class='tip picList' v-if='!active' >
  15. <view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic == index ? 'pic-box-color-active' : ''"
  16. v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)" v-if="item.price">
  17. <view class="pic-number-pic">
  18. {{ item.price }}<span class="pic-number"> {{$t(`元`)}}</span>
  19. </view>
  20. <view class="pic-number">{{$t(`赠送`)}}:{{ item.give_money }} {{$t(`元`)}} </view>
  21. </view>
  22. <view class="pic-box pic-box-color acea-row row-center-wrapper" :class="activePic == picList.length ? 'pic-box-color-active' : ''"
  23. @click="picCharge(picList.length)">
  24. <input type="number" :placeholder="$t(`其他`)" v-model="money" class="pic-box-money pic-number-pic" :class="activePic == picList.length ? 'pic-box-color-active' : ''" />
  25. </view>
  26. <view class="tips-box">
  27. <view class="tips mt-30">{{$t(`注意事项`)}}:</view>
  28. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  29. {{ $t(item) }}
  30. </view>
  31. </view>
  32. </view>
  33. <view class="tip" v-else>
  34. <view class='input'><text>{{$t(`¥`)}}</text><input placeholder="0.00" type='number' placeholder-class='placeholder' :value="number" name="number"></input></view>
  35. <view class="tips-title">
  36. <view style="font-weight: bold; font-size: 26rpx;">{{$t(`提示`)}}:</view>
  37. <view style="margin-top: 10rpx;">{{$t(`当前可转入佣金为`)}} <text class='font-color'>{{$t(`¥`)}}{{userinfo.commissionCount || 0}}</text>{{$t(`冻结佣金为`)}}<text class='font-color'>{{$t(`¥`)}}{{userinfo.broken_commission}}</text></view>
  38. </view>
  39. <view class="tips-box">
  40. <view class="tips mt-30">{{$t(`注意事项`)}}:</view>
  41. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  42. {{ $t(item) }}
  43. </view>
  44. </view>
  45. </view>
  46. <button class='but bg-color' formType="submit"> {{active ? $t(`立即转入`): $t(`立即充值`) }}</button>
  47. </view>
  48. </form>
  49. <!-- #ifdef MP -->
  50. <!-- <authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  51. <!-- #endif -->
  52. <!-- #ifndef MP -->
  53. <home></home>
  54. <!-- #endif -->
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. getUserInfo,
  60. rechargeRoutine,
  61. rechargeWechat,
  62. getRechargeApi
  63. } from '@/api/user.js';
  64. import {
  65. toLogin
  66. } from '@/libs/login.js';
  67. import {
  68. mapGetters
  69. } from "vuex";
  70. // #ifdef MP
  71. import authorize from '@/components/Authorize';
  72. // #endif
  73. import home from '@/components/home';
  74. import colors from "@/mixins/color";
  75. export default {
  76. components: {
  77. // #ifdef MP
  78. authorize,
  79. // #endif
  80. home
  81. },
  82. mixins:[colors],
  83. data() {
  84. let that = this;
  85. return {
  86. now_money: 0,
  87. navRecharge: [this.$t(`账户充值`), this.$t(`佣金转入`)],
  88. active: 0,
  89. number: '',
  90. userinfo: {},
  91. placeholder: "0.00",
  92. from: '',
  93. isAuto: false, //没有授权的不会自动授权
  94. isShowAuth: false, //是否隐藏授权
  95. picList: [],
  96. activePic: 0,
  97. money: "",
  98. numberPic:'',
  99. rechar_id:0,
  100. rechargeAttention:[]
  101. };
  102. },
  103. computed: mapGetters(['isLogin']),
  104. watch:{
  105. isLogin:{
  106. handler:function(newV,oldV){
  107. if(newV){
  108. this.getUserInfo();
  109. this.getRecharge();
  110. }
  111. },
  112. deep:true
  113. }
  114. },
  115. onLoad(options) {
  116. // #ifdef H5
  117. this.from = this.$wechat.isWeixin() ? "weixin" : "weixinh5"
  118. // #endif
  119. if (this.isLogin) {
  120. this.getUserInfo();
  121. this.getRecharge();
  122. } else {
  123. toLogin();
  124. }
  125. },
  126. methods: {
  127. /**
  128. * 选择金额
  129. */
  130. picCharge(idx, item) {
  131. this.activePic = idx;
  132. if (item === undefined) {
  133. this.rechar_id = 0;
  134. this.numberPic = "";
  135. } else {
  136. this.money = "";
  137. this.rechar_id = item.id;
  138. this.numberPic = item.price;
  139. }
  140. },
  141. /**
  142. * 充值额度选择
  143. */
  144. getRecharge() {
  145. getRechargeApi()
  146. .then(res => {
  147. this.picList = res.data.recharge_quota;
  148. if (this.picList[0]) {
  149. this.rechar_id = this.picList[0].id;
  150. this.numberPic = this.picList[0].price;
  151. }
  152. this.rechargeAttention = res.data.recharge_attention || [];
  153. })
  154. .catch(res => {
  155. this.$util.Tips({
  156. title: res
  157. })
  158. });
  159. },
  160. onLoadFun: function() {
  161. this.getUserInfo();
  162. this.getRecharge();
  163. },
  164. // 授权关闭
  165. authColse: function(e) {
  166. this.isShowAuth = e
  167. },
  168. navRecharges: function(index) {
  169. this.active = index;
  170. },
  171. /**
  172. * 获取用户信息
  173. */
  174. getUserInfo: function() {
  175. let that = this;
  176. getUserInfo().then(res => {
  177. that.$set(that, 'userinfo', res.data);
  178. })
  179. },
  180. /*
  181. * 用户充值
  182. */
  183. submitSub: function(e) {
  184. let that = this
  185. let value = e.detail.value.number;
  186. // 转入余额
  187. if (that.active) {
  188. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  189. return that.$util.Tips({
  190. title: that.$t(`请输入金额`)
  191. });
  192. }
  193. uni.showModal({
  194. title: that.$t(`转入余额`),
  195. content: that.$t(`转入余额后无法再次转出,确认是否转入余额`),
  196. success(res) {
  197. if (res.confirm) {
  198. // #ifdef MP || APP-PLUS
  199. rechargeRoutine({
  200. price: parseFloat(value),
  201. type: 1
  202. })
  203. // #endif
  204. // #ifdef H5
  205. rechargeWechat({
  206. price: parseFloat(value),
  207. from: that.from,
  208. type: 1
  209. })
  210. // #endif
  211. .then(res => {
  212. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
  213. return that.$util.Tips({
  214. title: that.$t(`转入成功`),
  215. icon: 'success'
  216. }, {
  217. tab: 5,
  218. url: '/pages/users/user_money/index'
  219. });
  220. }).catch(err => {
  221. return that.$util.Tips({
  222. title: err
  223. })
  224. });
  225. } else if (res.cancel) {
  226. return that.$util.Tips({
  227. title: that.$t(`已取消`)
  228. });
  229. }
  230. },
  231. })
  232. } else {
  233. uni.showLoading({
  234. title: that.$t(`正在支付`),
  235. })
  236. // #ifdef MP || APP-PLUS
  237. let money = parseFloat(this.money);
  238. if( this.rechar_id == 0){
  239. if(Number.isNaN(money)){
  240. return that.$util.Tips({title: that.$t(`充值金额必须为数字`)});
  241. }
  242. if(money <= 0){
  243. return that.$util.Tips({title: that.$t(`充值金额不能为0`)});
  244. }
  245. }else{
  246. money = this.numberPic
  247. }
  248. rechargeRoutine({
  249. price: money,
  250. type: 0,
  251. rechar_id: this.rechar_id
  252. }).then(res => {
  253. uni.hideLoading();
  254. let jsConfig = res.data;
  255. // #ifdef MP
  256. let mp_pay_name=''
  257. if(uni.requestOrderPayment){
  258. mp_pay_name='requestOrderPayment'
  259. }else{
  260. mp_pay_name='requestPayment'
  261. }
  262. uni[mp_pay_name]({
  263. // #endif
  264. // #ifdef APP-PLUS
  265. uni.requestPayment({
  266. // #endif
  267. // #ifdef MP
  268. timeStamp: jsConfig.timestamp,
  269. nonceStr: jsConfig.nonceStr,
  270. package: jsConfig.package,
  271. signType: jsConfig.signType,
  272. paySign: jsConfig.paySign,
  273. // #endif
  274. // #ifdef APP-PLUS
  275. provider: 'wxpay',
  276. orderInfo: jsConfig,
  277. // #endif
  278. success: function(res) {
  279. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  280. return that.$util.Tips({
  281. title: that.$t(`支付成功`),
  282. icon: 'success'
  283. }, {
  284. tab: 5,
  285. url: '/pages/users/user_money/index'
  286. });
  287. },
  288. fail: function() {
  289. return that.$util.Tips({
  290. title: that.$t(`支付失败`)
  291. });
  292. },
  293. complete: function(res) {
  294. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  295. title: that.$t(`取消支付`)
  296. });
  297. }
  298. })
  299. }).catch(err => {
  300. uni.hideLoading();
  301. return that.$util.Tips({
  302. title: err
  303. })
  304. });
  305. // #endif
  306. // #ifdef H5
  307. rechargeWechat({
  308. price: that.rechar_id == 0 ? that.money : that.numberPic,
  309. from: that.from,
  310. rechar_id: that.rechar_id
  311. }).then(res => {
  312. let data = res.data;
  313. if (data.type == "weixinh5") {
  314. location.replace(data.data.mweb_url);
  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. } else {
  323. that.$wechat.pay(data.data)
  324. .finally(() => {
  325. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  326. return that.$util.Tips({
  327. title: that.$t(`支付成功`),
  328. icon: 'success'
  329. }, {
  330. tab: 5,
  331. url: '/pages/users/user_money/index'
  332. });
  333. })
  334. .catch(function() {
  335. return that.$util.Tips({
  336. title: that.$t(`支付失败`)
  337. });
  338. });
  339. }
  340. }).catch(err=>{
  341. uni.hideLoading();
  342. return that.$util.Tips({
  343. title: err
  344. })
  345. })
  346. // #endif
  347. }
  348. }
  349. }
  350. }
  351. </script>
  352. <style lang="scss">
  353. page {
  354. width: 100%;
  355. height: 100%;
  356. background-color: #fff;
  357. }
  358. .bgcolor{
  359. background-color: var(--view-theme)
  360. }
  361. .payment {
  362. position: relative;
  363. top: -60rpx;
  364. width: 100%;
  365. background-color: #fff;
  366. border-radius: 10rpx;
  367. padding-top: 25rpx;
  368. border-top-right-radius: 39rpx;
  369. border-top-left-radius: 39rpx;
  370. }
  371. .payment .nav {
  372. height: 75rpx;
  373. line-height: 75rpx;
  374. padding: 0 100rpx;
  375. }
  376. .payment .nav .item {
  377. font-size: 30rpx;
  378. color: #333;
  379. }
  380. .payment .nav .item.on {
  381. font-weight: bold;
  382. border-bottom: 4rpx solid var(--view-theme);
  383. }
  384. .payment .input {
  385. display: flex;
  386. align-items: center;
  387. justify-content: center;
  388. border-bottom: 1px dashed #dddddd;
  389. margin: 60rpx auto 0 auto;
  390. padding-bottom: 20rpx;
  391. font-size: 56rpx;
  392. color: #333333;
  393. flex-wrap: nowrap;
  394. }
  395. .payment .input text {
  396. padding-left: 106rpx;
  397. }
  398. .payment .input input {
  399. padding-right: 106rpx;
  400. width: 300rpx;
  401. height: 94rpx;
  402. text-align: center;
  403. font-size: 70rpx;
  404. }
  405. .payment .placeholder {
  406. color: #d0d0d0;
  407. height: 100%;
  408. line-height: 94rpx;
  409. }
  410. .payment .tip {
  411. font-size: 26rpx;
  412. color: #888888;
  413. padding: 0 30rpx;
  414. margin-top: 25rpx;
  415. }
  416. .payment .but {
  417. color: #fff;
  418. font-size: 30rpx;
  419. width: 700rpx;
  420. height: 86rpx;
  421. border-radius: 50rpx;
  422. margin: 46rpx auto 0 auto;
  423. line-height: 86rpx;
  424. }
  425. .payment-top {
  426. width: 100%;
  427. height: 350rpx;
  428. background-color: var(--view-theme);
  429. .name {
  430. font-size: 26rpx;
  431. color: rgba(255, 255, 255, 0.8);
  432. margin-top: -38rpx;
  433. margin-bottom: 30rpx;
  434. }
  435. .pic {
  436. font-size: 32rpx;
  437. color: #fff;
  438. .num {
  439. font-size: 56rpx;
  440. }
  441. }
  442. .pic-font {
  443. font-size: 78rpx;
  444. color: #fff;
  445. }
  446. }
  447. .picList {
  448. display: flex;
  449. flex-wrap: wrap;
  450. margin: 30rpx 0;
  451. .pic-box {
  452. width: 32%;
  453. height: auto;
  454. border-radius: 20rpx;
  455. margin-top: 21rpx;
  456. padding: 20rpx 0;
  457. margin-right: 12rpx;
  458. &:nth-child(3n) {
  459. margin-right: 0;
  460. }
  461. }
  462. .pic-box-color {
  463. background-color: #f4f4f4;
  464. color: #656565;
  465. }
  466. .pic-number {
  467. font-size: 22rpx;
  468. }
  469. .pic-number-pic {
  470. font-size: 38rpx;
  471. margin-right: 10rpx;
  472. text-align: center;
  473. }
  474. .pic-box-color-active {
  475. background-color: var(--view-theme) !important;
  476. color: #fff !important;
  477. }
  478. }
  479. .tips-box{
  480. .tips {
  481. font-size: 28rpx;
  482. color: #333333;
  483. font-weight: 800;
  484. margin-bottom: 14rpx;
  485. margin-top: 20rpx;
  486. }
  487. .tips-samll {
  488. font-size: 24rpx;
  489. color: #333333;
  490. margin-bottom: 14rpx;
  491. }
  492. .tip-box {
  493. margin-top: 30rpx;
  494. }
  495. }
  496. .tips-title{
  497. margin-top: 20rpx;
  498. font-size: 24rpx;
  499. color: #333;
  500. }
  501. </style>