recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <template>
  2. <view class="content">
  3. <view class="top_box">
  4. <text class="yue-tit">当前余额:</text>
  5. <text class="yue-num">¥{{ now_money | parseFloatNum }}</text>
  6. </view>
  7. <view class="line_box"></view>
  8. <view class="cz_box">
  9. <view class="cz_wrap">
  10. <text class="cz_tit">¥</text>
  11. <input class="cz_input" type="number" v-model="money" @focus="changeNum()" placeholder="请输入充值金额"
  12. placeholder-class="placeholder" />
  13. </view>
  14. <view class="zc_list_box">
  15. <view class="zc_list_price" :class="{ seletPrice: seletNum == item.price }"
  16. @click="seletChange(item, index)" v-for="(item, index) in list" :key="index">
  17. {{ item.price | parseFloatNum }}元
  18. </view>
  19. </view>
  20. </view>
  21. <view class="line_box"></view>
  22. <!-- <view class="cz-type" @click="type = 'weixin'">
  23. <view class="type-left">
  24. <view class="icon iconfont iconweixin"></view>
  25. <view class="tit">微信充值</view>
  26. </view>
  27. <view class="right">
  28. <radio value="weixin" color=" #EB001C" :checked="type == 'weixin'" />
  29. </view>
  30. </view> -->
  31. <!-- #ifdef APP-PLUS -->
  32. <view class="cz-type" @click="type = 'ali'">
  33. <view class="type-left">
  34. <view class="icon iconfont iconzhifubao"></view>
  35. <view class="tit">支付宝充值</view>
  36. </view>
  37. <view class="right">
  38. <radio value="ali" color=" #EB001C" :checked="type == 'ali'" />
  39. </view>
  40. </view>
  41. <!-- #endif -->
  42. <button class="add-btn up" :class="{ 'active-bg': payLoding }"
  43. @click="!payLoding ? confirm() : ''">立即充值</button>
  44. </view>
  45. </template>
  46. <script>
  47. import {
  48. getMoneyStyle
  49. } from '@/utils/rocessor.js';
  50. // #ifdef H5
  51. import {
  52. rechargeWechat,
  53. rechargeAli
  54. } from '@/api/wallet.js';
  55. // #endif
  56. // #ifdef MP
  57. import {
  58. rechargeRoutine,
  59. } from '@/api/wallet.js';
  60. // #endif
  61. // #ifdef APP-PLUS
  62. import {
  63. rechargeAli
  64. } from '@/api/wallet.js';
  65. // #endif
  66. import {
  67. mapState
  68. } from 'vuex';
  69. import {
  70. spreadCommission,
  71. userBalance,
  72. moneyChong
  73. } from '@/api/wallet.js';
  74. export default {
  75. filters: {
  76. getMoneyStyle,
  77. // 去处小数点后的0
  78. parseFloatNum(clock) {
  79. return parseFloat(clock);
  80. }
  81. },
  82. data() {
  83. return {
  84. type: 'weixin',
  85. money: '', //充值金额
  86. payLoding: false, //是否加载中
  87. list: [
  88. '300',
  89. '200',
  90. '150',
  91. '100',
  92. '50'
  93. ],
  94. now_money: '',
  95. seletNum: '300', // 选中
  96. zhuyi: [],
  97. quota: '', // 送的钱
  98. typeText: 0, // 0-微信 1-佣金
  99. };
  100. },
  101. onLoad(options) {
  102. this.loadData();
  103. },
  104. computed: {
  105. // #ifdef H5
  106. ...mapState(['weichatObj', 'userInfo'])
  107. // #endif
  108. // #ifdef MP
  109. ...mapState(['userInfo'])
  110. // #endif
  111. },
  112. methods: {
  113. // 跳转
  114. navTo(url) {
  115. uni.navigateTo({
  116. url: url
  117. });
  118. },
  119. changeNum() {
  120. this.seletNum = this.money = '';
  121. console.log(this.seletNum, this.money);
  122. },
  123. seletChange(item, index) {
  124. this.seletNum = item.price;
  125. this.seletMoney = item.price;
  126. this.money = item.price
  127. },
  128. // 切换选中对象
  129. tabRadio(e) {
  130. this.type = e.detail.value;
  131. if (e.detail.value == 'weixin') {
  132. this.typeText = 0
  133. } else {
  134. this.typeText = 1
  135. }
  136. },
  137. // 充值金额
  138. rechargeXuan(item) {
  139. this.money = item.price;
  140. this.quota = item.quota;
  141. },
  142. loadData() {
  143. moneyChong({}).then(({
  144. data
  145. }) => {
  146. console.log(data, "123456789");
  147. this.list = data.recharge_quota;
  148. });
  149. userBalance({}).then(({
  150. data
  151. }) => {
  152. this.now_money = data.now_money;
  153. });
  154. },
  155. // 提交
  156. confirm() {
  157. let obj = this;
  158. obj.payLoding = true;
  159. if (!obj.money) {
  160. obj.$api.msg('请输入金额');
  161. obj.payLoding = false;
  162. return;
  163. }
  164. // 微信支付
  165. if (obj.type == 'weixin') {
  166. // #ifdef H5
  167. rechargeWechat({
  168. price: this.money,
  169. from: this.type,
  170. }).then(e => {
  171. let da = e.data.data;
  172. obj.weichatObj.chooseWXPay({
  173. timestamp: da.timestamp,
  174. nonceStr: da.nonceStr,
  175. package: da.package,
  176. signType: da.signType,
  177. paySign: da.paySign,
  178. success: function(res) {
  179. uni.showToast({
  180. title: '充值成功',
  181. duration: 2000,
  182. position: 'top',
  183. success: function(res) {
  184. uni.navigateBack()
  185. }
  186. });
  187. }
  188. });
  189. obj.payLoding = false;
  190. })
  191. .catch(e => {
  192. obj.payLoding = false;
  193. console.log(e);
  194. });
  195. // #endif
  196. // #ifdef MP
  197. rechargeRoutine({
  198. price: this.money
  199. })
  200. .then(e => {
  201. let da = e.data;
  202. wx.requestPayment({
  203. timeStamp: da.timestamp,
  204. nonceStr: da.nonceStr,
  205. package: da.package,
  206. signType: da.signType,
  207. paySign: da.paySign,
  208. success: function(res) {
  209. uni.showToast({
  210. title: '充值成功',
  211. duration: 2000,
  212. position: 'top',
  213. success: function(res) {
  214. uni.navigateBack()
  215. }
  216. });
  217. },
  218. })
  219. obj.payLoding = false;
  220. })
  221. .catch(e => {
  222. obj.payLoding = false;
  223. console.log(e);
  224. });
  225. // #endif
  226. }
  227. // #ifdef APP-PLUS
  228. if (obj.type == 'ali') {
  229. rechargeAli({
  230. price: this.money
  231. }).then((data) => {
  232. const url = data.msg;
  233. uni.requestPayment({
  234. provider: 'alipay',
  235. orderInfo: url,
  236. success: res => {
  237. uni.showToast({
  238. title: '支付成功',
  239. duration: 2000
  240. });
  241. obj.paySuccessTo();
  242. },
  243. fail: e => {
  244. console.log(e);
  245. },
  246. complete: () => {}
  247. });
  248. obj.payLoding = false;
  249. return
  250. }).catch()
  251. }
  252. // #endif
  253. },
  254. }
  255. };
  256. </script>
  257. <style lang="scss">
  258. page {
  259. height: 100%;
  260. background: #111111;
  261. }
  262. .top_box {
  263. padding: 20rpx 26rpx 20rpx 47rpx;
  264. display: flex;
  265. align-items: center;
  266. justify-content: space-between;
  267. .yue-tit {
  268. font-size: 28rpx;
  269. font-family: PingFang SC;
  270. font-weight: 500;
  271. color: #ffffff;
  272. }
  273. .yue-num {
  274. font-size: 30rpx;
  275. font-family: PingFang SC;
  276. font-weight: bold;
  277. color: #FDD58A;
  278. }
  279. }
  280. .line_box {
  281. width: 100%;
  282. height: 20rpx;
  283. background: #1B1B1B;
  284. }
  285. .cz_box {
  286. padding: 40rpx 20rpx 20rpx;
  287. .cz_wrap {
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-between;
  291. padding-bottom: 20rpx;
  292. border-bottom: 1px solid #e6e6e6;
  293. .cz_tit {
  294. font-size: 32rpx;
  295. font-family: PingFang SC;
  296. font-weight: 500;
  297. color: #FFFFFF;
  298. }
  299. .cz_input {
  300. text-align: right;
  301. font-size: 32rpx;
  302. font-family: PingFang SC;
  303. font-weight: 500;
  304. color: #FFFFFF;
  305. }
  306. }
  307. .zc_list_box {
  308. display: flex;
  309. flex-wrap: wrap;
  310. .zc_list_price {
  311. color: #ffffff;
  312. width: 202rpx;
  313. height: 60rpx;
  314. background: #111111;
  315. border-radius: 8rpx;
  316. margin-top: 36rpx;
  317. margin-right: 50rpx;
  318. display: flex;
  319. align-items: center;
  320. justify-content: center;
  321. &:nth-child(3n) {
  322. margin-right: 0;
  323. }
  324. }
  325. .seletPrice {
  326. background: $bgBaseBg;
  327. color: #ffffff;
  328. }
  329. }
  330. }
  331. .recha-box {
  332. padding: 50rpx 30rpx 0;
  333. display: flex;
  334. flex-wrap: wrap;
  335. .recha-frame {
  336. width: 210rpx;
  337. height: 181rpx;
  338. border: 1px solid #dbdede;
  339. border-radius: 20rpx;
  340. display: flex;
  341. align-items: center;
  342. flex-direction: column;
  343. justify-content: center;
  344. margin-right: 30rpx;
  345. margin-bottom: 30rpx;
  346. &:nth-child(3n) {
  347. margin-right: 0;
  348. }
  349. .recha-top {
  350. display: flex;
  351. align-items: center;
  352. .recha-img {
  353. width: 64rpx;
  354. height: 62rpx;
  355. }
  356. .recha-tit {
  357. margin-left: 10rpx;
  358. font-size: 36rpx;
  359. font-family: PingFang SC;
  360. font-weight: bold;
  361. color: #333333;
  362. }
  363. }
  364. .recha-song {
  365. margin-top: 20rpx;
  366. font-size: $font-base;
  367. font-family: PingFang SC;
  368. font-weight: bold;
  369. color: #ff9900;
  370. }
  371. }
  372. .select-frame {
  373. border: 1px solid #ef041f;
  374. }
  375. }
  376. .rechar-box {
  377. padding: 30rpx 20rpx 0;
  378. .rechar-title {
  379. font-size: 32rpx;
  380. font-family: PingFang SC;
  381. font-weight: bold;
  382. color: #333333;
  383. margin-bottom: 10rpx;
  384. }
  385. .rechar-text {
  386. font-size: 28rpx;
  387. font-family: PingFang SC;
  388. font-weight: bold;
  389. color: #333333;
  390. }
  391. }
  392. .cz-type {
  393. margin-top: 22rpx;
  394. display: flex;
  395. justify-content: space-between;
  396. padding: 32rpx;
  397. align-items: center;
  398. .type-left {
  399. display: flex;
  400. align-items: center;
  401. .icon {
  402. height: 38rpx;
  403. image {
  404. width: 48rpx;
  405. height: 38rpx;
  406. }
  407. }
  408. .iconweixin {
  409. color: #36cb59;
  410. }
  411. .iconzhifubao {
  412. color: #08aaec;
  413. }
  414. .tit {
  415. margin-left: 12rpx;
  416. font-size: 30rpx;
  417. color: #ffffff;
  418. }
  419. }
  420. .type-right {
  421. image {
  422. width: 36rpx;
  423. height: 36rpx;
  424. }
  425. }
  426. }
  427. .add-btn {
  428. &.modified {}
  429. &.up {
  430. color: #9F570E;
  431. }
  432. margin-top: 100rpx;
  433. display: flex;
  434. align-items: center;
  435. justify-content: center;
  436. width: 604rpx;
  437. height: 90rpx;
  438. // border: 2rpx solid #F21F5D;
  439. border-radius: 10rpx;
  440. font-size: 36rpx;
  441. font-family: PingFang SC;
  442. font-weight: 500;
  443. color: #F21F5D;
  444. line-height: 90rpx;
  445. text-align: center;
  446. background: $bgBaseBg;
  447. }
  448. .row-box {
  449. margin-top: 30rpx;
  450. padding: 20rpx 30rpx;
  451. background: #fff;
  452. .title {
  453. font-size: $font-base + 2rpx;
  454. color: $font-color-dark;
  455. }
  456. .row {
  457. display: flex;
  458. align-items: center;
  459. position: relative;
  460. height: 80rpx;
  461. .tit {
  462. flex-shrink: 0;
  463. width: 40rpx;
  464. font-size: 30rpx;
  465. color: $font-color-dark;
  466. }
  467. .input {
  468. flex: 1;
  469. font-size: 30rpx;
  470. color: $font-color-dark;
  471. }
  472. .iconlocation {
  473. font-size: 36rpx;
  474. color: $font-color-light;
  475. }
  476. .buttom {
  477. color: $font-color;
  478. font-size: $font-base;
  479. }
  480. }
  481. }
  482. .list {
  483. padding-left: 30rpx;
  484. margin-top: 30rpx;
  485. background-color: #ffffff;
  486. .box {
  487. display: flex;
  488. align-items: center;
  489. width: 100%;
  490. height: 120rpx;
  491. border-bottom: 1px solid $border-color-light;
  492. padding-right: 25rpx;
  493. .icon {
  494. font-size: 48rpx;
  495. padding-right: 20rpx;
  496. display: flex;
  497. }
  498. .yongjing {
  499. width: 48rpx;
  500. height: 48rpx;
  501. }
  502. .iconweixin1 {
  503. color: #18bf16;
  504. }
  505. .iconzhifubao {
  506. color: #08aaec;
  507. }
  508. .title-box {
  509. flex-grow: 1;
  510. text-align: left;
  511. .title {
  512. font-size: $font-base + 2rpx;
  513. color: $font-color-base;
  514. }
  515. .node {
  516. font-size: $font-sm;
  517. color: $font-color-light;
  518. }
  519. }
  520. }
  521. }
  522. /deep/ .uni-radio-input {
  523. width: 45rpx;
  524. height: 45rpx;
  525. }
  526. .active-bg {
  527. background: linear-gradient(270deg, #6E8DF7, #08aaec);
  528. color: #FFFFFF !important;
  529. }
  530. .aaa {
  531. display: flex;
  532. width: 300rpx;
  533. height: 300rpx;
  534. background: #fff;
  535. .bbb {
  536. width: 100rpx;
  537. height: 100rpx;
  538. background: red;
  539. }
  540. }
  541. </style>