recharge.vue 11 KB

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