index.vue 11 KB

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