recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <view class="content">
  3. <view class="now">
  4. <view>当前余额:</view>
  5. <view class="now-money">¥{{new_money}}</view>
  6. </view>
  7. <view class="main-jg"></view>
  8. <view class="add-wrapper">
  9. <view class="add-box">
  10. <view class="add-log">¥</view>
  11. <input type="text" v-model="money" placeholder="请输入充值金额" placeholder-class="place"
  12. @keyup="clearNoNum()" />
  13. </view>
  14. <view class="jg" style="height: 1px; background-color: #E6E6E6;"></view>
  15. <view class="add-tags">
  16. <view class="tag" v-for="(item, index) in addTags" :key="item" @click="tagClick(index)"
  17. :class="{ action: currentIndex === index && money == addTags[index] }">
  18. <text>{{ item }}</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="main-jg"></view>
  23. <!-- <view class="btn-wrapper">
  24. <view class="icon iconfont iconweixin1"><view>微信充值</view></view>
  25. <view class="btn" @click="btnClick" :class="{'actiont': isSect}"><image src="../../static/icon/btncz.png" mode="" :class="{'action':!isSect}"></image></view>
  26. </view> -->
  27. <!-- <view class="row-box">
  28. <view class="title">充值金额</view>
  29. <view class="row">
  30. <text class="tit">¥</text>
  31. <input class="input" type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="placeholder" />
  32. </view>
  33. </view> -->
  34. <view class="list">
  35. <radio-group @change="tabRadio">
  36. <label>
  37. <view class="box">
  38. <view class="icon iconfont iconzhifubao"></view>
  39. <view class="title-box">
  40. <view class="title"><text>支付宝充值</text></view>
  41. </view>
  42. <view class="right">
  43. <radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" />
  44. </view>
  45. </view>
  46. </label>
  47. <!-- <label>
  48. <view class="box">
  49. <view class="icon iconfont iconweixin1"></view>
  50. <view class="title-box">
  51. <view class="title"><text>微信充值</text></view>
  52. <view class="node"><text>真实姓名(代勇明)</text></view>
  53. </view>
  54. <view class="right"><radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" /></view>
  55. </view>
  56. </label> -->
  57. </radio-group>
  58. </view>
  59. <button class="add-btn up" :class="{ 'active-bg': payLoding }"
  60. @click="!payLoding ? confirm() : ''">立即充值</button>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. getMoneyStyle
  66. } from '@/utils/rocessor.js';
  67. // #ifdef H5
  68. import {
  69. rechargeWechat,
  70. userBalance
  71. } from '@/api/wallet.js';
  72. // #endif
  73. // #ifdef MP
  74. import {
  75. rechargeRoutine,
  76. userBalance
  77. } from '@/api/wallet.js';
  78. // #endif
  79. // #ifdef APP-PLUS
  80. import {
  81. rechargeRoutine,
  82. userBalance,
  83. rechargeAli
  84. } from '@/api/wallet.js';
  85. // #endif
  86. import {
  87. mapState
  88. } from 'vuex';
  89. import {
  90. orderData,
  91. getUserInfo
  92. } from '@/api/user.js';
  93. export default {
  94. filters: {
  95. getMoneyStyle
  96. },
  97. data() {
  98. return {
  99. type: 'alipay',
  100. money: '', //充值金额
  101. payLoding: false, //是否加载中
  102. addTags: [300, 200, 150, 100, 50,5],
  103. currentIndex: 0,
  104. addMoney: 0,
  105. isSect: false, //是否选择微信充值
  106. new_money: 0,
  107. };
  108. },
  109. onLoad(options) {
  110. this.userBalance()
  111. },
  112. computed: {
  113. // #ifdef H5
  114. ...mapState(['weichatObj'])
  115. // #endif
  116. },
  117. methods: {
  118. // 跳转
  119. navTo(url) {
  120. uni.navigateTo({
  121. url: url
  122. });
  123. },
  124. // 切换选中对象
  125. tabRadio(e) {
  126. console.log(e)
  127. this.type = e;
  128. },
  129. // 提交
  130. confirm() {
  131. if (this.money == 0) {
  132. return this.$api.msg('请输入充值金额');
  133. }
  134. let obj = this;
  135. obj.payLoding = true;
  136. // #ifdef APP-PLUS
  137. console.log(obj.money,'obj.money+++')
  138. rechargeAli({
  139. price: obj.money*1,
  140. }).then(res => {
  141. uni.requestPayment({
  142. provider: 'alipay',
  143. orderInfo: res.msg,
  144. success: res => {
  145. console.log(res);
  146. uni.showToast({
  147. title: '支付成功',
  148. duration: 2000
  149. });
  150. obj.userBalance()
  151. obj.payLoding = false;
  152. },
  153. fail: e => {
  154. console.log(e);
  155. obj.payLoding = false;
  156. },
  157. complete: () => {}
  158. });
  159. })
  160. // #endif
  161. // #ifdef H5
  162. rechargeWechat({
  163. price: obj.money,
  164. from: obj.type
  165. })
  166. .then(e => {
  167. let da = e.data.data;
  168. obj.weichatObj.chooseWXPay({
  169. timestamp: da.timestamp,
  170. nonceStr: da.nonceStr,
  171. package: da.package,
  172. signType: da.signType,
  173. paySign: da.paySign,
  174. success: function(res) {
  175. uni.showToast({
  176. title: '充值成功',
  177. duration: 2000,
  178. position: 'top'
  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({
  191. price: this.money
  192. })
  193. .then(e => {
  194. let da = e.data;
  195. wx.requestPayment({
  196. timeStamp: da.timestamp,
  197. nonceStr: da.nonceStr,
  198. package: da.package,
  199. signType: da.signType,
  200. paySign: da.paySign,
  201. success: function(res) {
  202. uni.redirectTo({
  203. url: '/pages/money/paySuccess?isshow=false'
  204. });
  205. }
  206. });
  207. obj.payLoding = false;
  208. })
  209. .catch(e => {
  210. obj.payLoding = false;
  211. console.log(e);
  212. });
  213. // #endif
  214. },
  215. //获取订单列表
  216. loadData(source) {
  217. console.log(source);
  218. //这里是将订单挂载到tab列表下
  219. let index = this.tabCurrentIndex;
  220. let navItem = this.navList[index];
  221. let state = navItem.state;
  222. if (source === 'tabChange' && navItem.loaded === true) {
  223. //tab切换只有第一次需要加载数据
  224. return;
  225. }
  226. if (navItem.loadingType === 'loading') {
  227. //防止重复加载
  228. return;
  229. }
  230. navItem.loadingType = 'loading';
  231. setTimeout(() => {
  232. let orderList = [];
  233. orderList.forEach(item => {
  234. navItem.orderList.push(item);
  235. });
  236. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  237. this.$set(navItem, 'loaded', true);
  238. //判断是否还有数据, 有改为 more, 没有改为noMore
  239. navItem.loadingType = 'more';
  240. }, 600);
  241. },
  242. tagClick(index) {
  243. this.currentIndex = index;
  244. this.money = this.addTags[index];
  245. },
  246. clearNoNum() {
  247. this.money = this.money.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
  248. switch (this.money) {
  249. case '300':
  250. this.currentIndex = 0;
  251. break;
  252. case '200':
  253. this.currentIndex = 1;
  254. break;
  255. case '150':
  256. this.currentIndex = 2;
  257. break;
  258. case '100':
  259. this.currentIndex = 3;
  260. break;
  261. case '50':
  262. this.currentIndex = 4;
  263. break;
  264. }
  265. },
  266. btnClick() {
  267. this.isSect = !this.isSect
  268. },
  269. userBalance() {
  270. getUserInfo().then(res => {
  271. this.new_money = res.data.now_money
  272. console.log(res)
  273. })
  274. }
  275. }
  276. };
  277. </script>
  278. <style lang="scss">
  279. page {
  280. height: 100%;
  281. background-color: #fff;
  282. }
  283. .add-btn {
  284. &.modified {
  285. color: $base-color;
  286. }
  287. &.up {
  288. background: linear-gradient(-90deg, #FAC545, #FFE000);
  289. color: #6B4216;
  290. }
  291. display: flex;
  292. align-items: center;
  293. justify-content: center;
  294. width: 604rpx;
  295. height: 90rpx;
  296. margin: 0 auto;
  297. margin-top: 30rpx;
  298. font-size: $font-lg;
  299. border-radius: 10rpx;
  300. }
  301. .row-box {
  302. margin-top: 30rpx;
  303. padding: 20rpx 30rpx;
  304. background: #fff;
  305. .title {
  306. font-size: $font-base + 2rpx;
  307. color: $font-color-dark;
  308. }
  309. .row {
  310. display: flex;
  311. align-items: center;
  312. position: relative;
  313. height: 80rpx;
  314. .tit {
  315. flex-shrink: 0;
  316. width: 40rpx;
  317. font-size: 30rpx;
  318. color: $font-color-dark;
  319. }
  320. .input {
  321. flex: 1;
  322. font-size: 30rpx;
  323. color: $font-color-dark;
  324. }
  325. .iconlocation {
  326. font-size: 36rpx;
  327. color: $font-color-light;
  328. }
  329. .buttom {
  330. color: $font-color;
  331. font-size: $font-base;
  332. }
  333. }
  334. }
  335. .list {
  336. padding-left: 30rpx;
  337. margin-top: 30rpx;
  338. background-color: #ffffff;
  339. .box {
  340. display: flex;
  341. align-items: center;
  342. width: 100%;
  343. height: 120rpx;
  344. border-bottom: 1px solid $border-color-light;
  345. .icon {
  346. font-size: 48rpx;
  347. padding-right: 20rpx;
  348. }
  349. .iconweixin1 {
  350. color: #18bf16;
  351. }
  352. .iconzhifubao {
  353. color: #08aaec;
  354. }
  355. .title-box {
  356. flex-grow: 1;
  357. text-align: left;
  358. .title {
  359. font-size: $font-base + 2rpx;
  360. color: $font-color-base;
  361. }
  362. .node {
  363. font-size: $font-sm;
  364. color: $font-color-light;
  365. }
  366. }
  367. }
  368. }
  369. /deep/ .uni-radio-input {
  370. width: 45rpx;
  371. height: 45rpx;
  372. }
  373. .active-bg {
  374. background-color: $color-gray !important;
  375. }
  376. .now {
  377. width: 100%;
  378. height: 86rpx;
  379. padding: 0 26rpx 0 47rpx;
  380. display: flex;
  381. justify-content: space-between;
  382. line-height: 86rpx;
  383. background-color: #fff;
  384. // margin-bottom: 21rpx;
  385. view {
  386. font-size: 28rpx;
  387. font-weight: 500;
  388. color: #333333;
  389. }
  390. .now-money {
  391. font-size: 32rpx;
  392. font-weight: bold;
  393. color: #FF4C4C;
  394. }
  395. }
  396. .add-wrapper {
  397. width: 750rpx;
  398. height: 338rpx;
  399. padding-left: 30rpx;
  400. background: #ffffff;
  401. display: flex;
  402. flex-direction: column;
  403. align-items: center;
  404. // margin-bottom: 22rpx;
  405. .add-box {
  406. width: 100%;
  407. height: 103rpx;
  408. display: flex;
  409. flex-direction: row;
  410. justify-content: space-between;
  411. padding: 0 39rpx 0 10rpx;
  412. align-items: center;
  413. .add-log {
  414. font-size: 37rpx;
  415. font-weight: bold;
  416. }
  417. input {
  418. width: 218rpx;
  419. height: 30rpx;
  420. font-size: 32rpx;
  421. font-weight: 500;
  422. color: #000;
  423. line-height: 40px;
  424. text-align: right;
  425. .place {
  426. color: #bfbfbf;
  427. }
  428. }
  429. }
  430. .jg {
  431. width: 100%;
  432. }
  433. .add-tags {
  434. height: 234rpx;
  435. padding-top: 47rpx;
  436. padding-bottom: 17rpx;
  437. display: flex;
  438. flex-direction: row;
  439. flex-wrap: wrap;
  440. // justify-content: space-between;
  441. .tag {
  442. width: 210rpx;
  443. height: 70rpx;
  444. background-color: #f0f0f0;
  445. border-radius: 4rpx;
  446. margin: 0 30rpx 30rpx 0;
  447. text-align: center;
  448. line-height: 70rpx;
  449. font-size: 22rpx;
  450. text {
  451. font-size: 32rpx;
  452. font-weight: 500;
  453. }
  454. }
  455. .action {
  456. color: #6B4216;
  457. background: linear-gradient(-90deg, #FAC545, #FFE000);
  458. }
  459. }
  460. }
  461. .btn-wrapper {
  462. padding: 49rpx 32rpx 0 40rpx;
  463. height: 183rpx;
  464. display: flex;
  465. justify-content: space-between;
  466. background-color: #fff;
  467. .iconweixin1 {
  468. color: #18bf16;
  469. font-size: 48rpx;
  470. display: flex;
  471. view {
  472. // display: inline-block;
  473. height: 48rpx;
  474. text-align: 48rpx;
  475. padding-left: 20rpx;
  476. // padding-top: 10rpx;
  477. color: #000000;
  478. font-size: 30rpx;
  479. }
  480. }
  481. .btn {
  482. width: 36rpx;
  483. height: 36rpx;
  484. border: 4rpx #333 solid;
  485. border-radius: 8rpx 8rpx;
  486. image {
  487. // display: none;
  488. width: 100%;
  489. height: 100%;
  490. }
  491. .action {
  492. display: none;
  493. }
  494. }
  495. .actiont {
  496. border: none;
  497. }
  498. }
  499. .main-jg {
  500. width: 100%;
  501. height: 21rpx;
  502. background-color: #f8f6f6;
  503. }
  504. </style>