index.vue 12 KB

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