index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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">我的余额</span>
  6. <view class="pic">
  7. ¥<span class="pic-font">{{ 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)">{{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"> 元</span>
  19. </view>
  20. <view class="pic-number">赠送:{{ item.give_money }} 元</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="其他" 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">注意事项:</view>
  28. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  29. {{ item }}
  30. </view>
  31. </view>
  32. </view>
  33. <view class="tip" v-else>
  34. <view class='input'><text>¥</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;">提示:</view>
  37. <view style="margin-top: 10rpx;">当前可转入佣金为 <text class='font-color'>¥{{userinfo.commissionCount || 0}}</text>,冻结佣金为<text class='font-color'>¥{{userinfo.broken_commission}}</text></view>
  38. </view>
  39. <view class="tips-box">
  40. <view class="tips mt-30">注意事项:</view>
  41. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  42. {{ item }}
  43. </view>
  44. </view>
  45. </view>
  46. <button class='but bg-color' formType="submit"> {{active ? '立即转入': '立即充值' }}</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: ['账户充值', '佣金转入'],
  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: '请输入金额'
  191. });
  192. }
  193. uni.showModal({
  194. title: '转入余额',
  195. content: '转入余额后无法再次转出,确认是否转入余额',
  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: '转入成功',
  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: '已取消'
  228. });
  229. }
  230. },
  231. })
  232. } else {
  233. uni.showLoading({
  234. title: '正在支付',
  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: '充值金额必须为数字'});
  241. }
  242. if(money <= 0){
  243. return that.$util.Tips({title: '充值金额不能为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. uni.requestPayment({
  256. // #ifdef MP
  257. timeStamp: jsConfig.timestamp,
  258. nonceStr: jsConfig.nonceStr,
  259. package: jsConfig.package,
  260. signType: jsConfig.signType,
  261. paySign: jsConfig.paySign,
  262. // #endif
  263. // #ifdef APP-PLUS
  264. provider: 'wxpay',
  265. orderInfo: jsConfig,
  266. // #endif
  267. success: function(res) {
  268. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  269. return that.$util.Tips({
  270. title: '支付成功',
  271. icon: 'success'
  272. }, {
  273. tab: 5,
  274. url: '/pages/users/user_money/index'
  275. });
  276. },
  277. fail: function() {
  278. return that.$util.Tips({
  279. title: '支付失败'
  280. });
  281. },
  282. complete: function(res) {
  283. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  284. title: '取消支付'
  285. });
  286. }
  287. })
  288. }).catch(err => {
  289. uni.hideLoading();
  290. return that.$util.Tips({
  291. title: err
  292. })
  293. });
  294. // #endif
  295. // #ifdef H5
  296. rechargeWechat({
  297. price: that.rechar_id == 0 ? that.money : that.numberPic,
  298. from: that.from,
  299. rechar_id: that.rechar_id
  300. }).then(res => {
  301. let data = res.data;
  302. if (data.type == "weixinh5") {
  303. location.replace(data.data.mweb_url);
  304. return that.$util.Tips({
  305. title: '支付成功',
  306. icon: 'success'
  307. }, {
  308. tab: 5,
  309. url: '/pages/users/user_money/index'
  310. });
  311. } else {
  312. that.$wechat.pay(data.data)
  313. .finally(() => {
  314. that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money));
  315. return that.$util.Tips({
  316. title: '支付成功',
  317. icon: 'success'
  318. }, {
  319. tab: 5,
  320. url: '/pages/users/user_money/index'
  321. });
  322. })
  323. .catch(function() {
  324. return that.$util.Tips({
  325. title: '支付失败'
  326. });
  327. });
  328. }
  329. }).catch(err=>{
  330. uni.hideLoading();
  331. return that.$util.Tips({
  332. title: err
  333. })
  334. })
  335. // #endif
  336. }
  337. }
  338. }
  339. }
  340. </script>
  341. <style lang="scss">
  342. page {
  343. width: 100%;
  344. height: 100%;
  345. background-color: #fff;
  346. }
  347. .bgcolor{
  348. background-color: var(--view-theme)
  349. }
  350. .payment {
  351. position: relative;
  352. top: -60rpx;
  353. width: 100%;
  354. background-color: #fff;
  355. border-radius: 10rpx;
  356. padding-top: 25rpx;
  357. border-top-right-radius: 39rpx;
  358. border-top-left-radius: 39rpx;
  359. }
  360. .payment .nav {
  361. height: 75rpx;
  362. line-height: 75rpx;
  363. padding: 0 100rpx;
  364. }
  365. .payment .nav .item {
  366. font-size: 30rpx;
  367. color: #333;
  368. }
  369. .payment .nav .item.on {
  370. font-weight: bold;
  371. border-bottom: 4rpx solid var(--view-theme);
  372. }
  373. .payment .input {
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. border-bottom: 1px dashed #dddddd;
  378. margin: 60rpx auto 0 auto;
  379. padding-bottom: 20rpx;
  380. font-size: 56rpx;
  381. color: #333333;
  382. flex-wrap: nowrap;
  383. }
  384. .payment .input text {
  385. padding-left: 106rpx;
  386. }
  387. .payment .input input {
  388. padding-right: 106rpx;
  389. width: 300rpx;
  390. height: 94rpx;
  391. text-align: center;
  392. font-size: 70rpx;
  393. }
  394. .payment .placeholder {
  395. color: #d0d0d0;
  396. height: 100%;
  397. line-height: 94rpx;
  398. }
  399. .payment .tip {
  400. font-size: 26rpx;
  401. color: #888888;
  402. padding: 0 30rpx;
  403. margin-top: 25rpx;
  404. }
  405. .payment .but {
  406. color: #fff;
  407. font-size: 30rpx;
  408. width: 700rpx;
  409. height: 86rpx;
  410. border-radius: 50rpx;
  411. margin: 46rpx auto 0 auto;
  412. line-height: 86rpx;
  413. }
  414. .payment-top {
  415. width: 100%;
  416. height: 350rpx;
  417. background-color: var(--view-theme);
  418. .name {
  419. font-size: 26rpx;
  420. color: rgba(255, 255, 255, 0.8);
  421. margin-top: -38rpx;
  422. margin-bottom: 30rpx;
  423. }
  424. .pic {
  425. font-size: 32rpx;
  426. color: #fff;
  427. }
  428. .pic-font {
  429. font-size: 78rpx;
  430. color: #fff;
  431. }
  432. }
  433. .picList {
  434. display: flex;
  435. flex-wrap: wrap;
  436. margin: 30rpx 0;
  437. .pic-box {
  438. width: 32%;
  439. height: auto;
  440. border-radius: 20rpx;
  441. margin-top: 21rpx;
  442. padding: 20rpx 0;
  443. margin-right: 12rpx;
  444. &:nth-child(3n) {
  445. margin-right: 0;
  446. }
  447. }
  448. .pic-box-color {
  449. background-color: #f4f4f4;
  450. color: #656565;
  451. }
  452. .pic-number {
  453. font-size: 22rpx;
  454. }
  455. .pic-number-pic {
  456. font-size: 38rpx;
  457. margin-right: 10rpx;
  458. text-align: center;
  459. }
  460. .pic-box-color-active {
  461. background-color: var(--view-theme) !important;
  462. color: #fff !important;
  463. }
  464. }
  465. .tips-box{
  466. .tips {
  467. font-size: 28rpx;
  468. color: #333333;
  469. font-weight: 800;
  470. margin-bottom: 14rpx;
  471. margin-top: 20rpx;
  472. }
  473. .tips-samll {
  474. font-size: 24rpx;
  475. color: #333333;
  476. margin-bottom: 14rpx;
  477. }
  478. .tip-box {
  479. margin-top: 30rpx;
  480. }
  481. }
  482. .tips-title{
  483. margin-top: 20rpx;
  484. font-size: 24rpx;
  485. color: #333;
  486. }
  487. </style>