recharge.vue 11 KB

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