recharge.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <view class="content">
  3. <view class="yue">
  4. <view class="font">当前余额</view>
  5. <view class="money">¥{{ userInfo.now_money | getMoneyStyle }}</view>
  6. </view>
  7. <view class="row-box">
  8. <view class="title">充值金额</view>
  9. <view class="row">
  10. <text class="tit">¥</text>
  11. <input class="input" type="number" v-model="money" placeholder="请输入充值金额"
  12. placeholder-class="placeholder" />
  13. </view>
  14. <view class="xian"></view>
  15. <view class="moneyBtn-box">
  16. <view class="moneyBtn" v-for="(item, index) in moneyList" :class="{ current: choose == index }"
  17. :key="index" @click="changemoney(item, index)">{{ item }}元</view>
  18. </view>
  19. </view>
  20. <view class="list" v-if="!weichatBsrowser">
  21. <radio-group @change="tabRadio">
  22. <!-- #ifdef APP-PLUS -->
  23. <!-- <label>
  24. <view class="box">
  25. <view class="icon iconfont iconzhifubao"></view>
  26. <view class="title-box">
  27. <view class="title"><text>支付宝充值</text></view>
  28. </view>
  29. <view class="right"><radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" /></view>
  30. </view>
  31. </label> -->
  32. <!-- #endif -->
  33. <label>
  34. <view class="box">
  35. <view class="icon iconfont iconweixin1"></view>
  36. <view class="title-box">
  37. <view class="title"><text>微信充值</text></view>
  38. </view>
  39. <view class="right">
  40. <radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" />
  41. </view>
  42. </view>
  43. </label>
  44. </radio-group>
  45. </view>
  46. <button class="add-btn up" :class="{ 'active-bg': payLoding }"
  47. @click="!payLoding ? confirm() : ''">立即充值</button>
  48. <button class="card" @click="go()">充值卡兑换</button>
  49. <uni-popup ref="popup" type="center">
  50. <view class="popup-box">
  51. <view class="img">
  52. <view class="img-font">兑换充值卡</view>
  53. <view class="img-bg">
  54. <image src="../../static/img/img009.png" mode=""></image>
  55. </view>
  56. </view>
  57. <view class="mian">
  58. <view class="main-item">
  59. <view class="font">卡号</view>
  60. <input type="text" v-model="card" class="input" placeholder="请输入卡号"
  61. placeholder-class="input-font" />
  62. </view>
  63. <view class="main-item" style="margin-top: 40rpx;">
  64. <view class="font">密码</view>
  65. <input type="password" v-model="pwd" placeholder="请输入密码" class="input"
  66. placeholder-class="input-font" />
  67. </view>
  68. <view class="comfirm-box">
  69. <view class="cancel" @click="cancel">取消</view>
  70. <view class="comfirm" @click="comfirm()">确认兑换</view>
  71. </view>
  72. </view>
  73. </view>
  74. </uni-popup>
  75. </view>
  76. </template>
  77. <script>
  78. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  79. import {
  80. verification
  81. } from '@/api/merchant.js';
  82. import {
  83. getMoneyStyle
  84. } from '@/utils/rocessor.js';
  85. import {
  86. rechargeWechat,
  87. getRechargeList
  88. } from '@/api/wallet.js';
  89. import {
  90. mapState,
  91. mapMutations
  92. } from 'vuex';
  93. import {
  94. getUserInfo
  95. } from '@/api/login.js';
  96. export default {
  97. components: {
  98. uniPopup
  99. },
  100. filters: {
  101. getMoneyStyle
  102. },
  103. data() {
  104. return {
  105. moneyList: [],
  106. choose: -1,
  107. // #ifdef APP-PLUS
  108. type: 'weixinapp',
  109. // #endif
  110. // #ifdef H5
  111. type: 'weixin',
  112. // #endif
  113. money: '', //充值金额
  114. payLoding: false, //是否加载中
  115. // #ifdef H5
  116. weichatBsrowser: false,
  117. // #endif
  118. // #ifdef APP-PLUS
  119. weichatBsrowser: true,
  120. // #endif
  121. nowmoney: 0,
  122. card: '',
  123. pwd: ''
  124. };
  125. },
  126. onLoad(options) {
  127. // #ifdef H5
  128. this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
  129. // #endif
  130. this.getRechargeList()
  131. },
  132. computed: {
  133. // #ifdef H5
  134. ...mapState(['weichatObj']),
  135. // #endif
  136. ...mapState('user', ['userInfo'])
  137. },
  138. methods: {
  139. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  140. getRechargeList() {
  141. getRechargeList().then(({
  142. data
  143. }) => {
  144. console.log(data, 'getRechargeList')
  145. data.recharge_quota.forEach(item => {
  146. this.moneyList.push(item.price * 1)
  147. })
  148. })
  149. },
  150. // 跳转
  151. navTo(url) {
  152. uni.navigateTo({
  153. url: url
  154. });
  155. },
  156. // 切换选中对象
  157. tabRadio(e) {
  158. this.type = e;
  159. },
  160. // 提交
  161. confirm() {
  162. let obj = this;
  163. obj.payLoding = true;
  164. if (this.money <= 0) {
  165. uni.showToast({
  166. title: '请输入金额',
  167. duration: 2000,
  168. icon: 'none'
  169. });
  170. return
  171. }
  172. rechargeWechat({
  173. price: this.money,
  174. from: this.type
  175. })
  176. .then(e => {
  177. console.log(e);
  178. // #ifdef H5
  179. let da = e.data.data;
  180. obj.weichatObj.chooseWXPay({
  181. timestamp: da.timestamp,
  182. nonceStr: da.nonceStr,
  183. package: da.package,
  184. signType: da.signType,
  185. paySign: da.paySign,
  186. success: function(res) {
  187. uni.showToast({
  188. title: '充值成功',
  189. duration: 2000,
  190. position: 'top'
  191. });
  192. getUserInfo()
  193. .then(({
  194. data
  195. }) => {
  196. obj.setUserInfo(data);
  197. })
  198. .catch(e => {
  199. console.log(e);
  200. });
  201. }
  202. });
  203. // #endif
  204. // #ifdef APP-PLUS
  205. uni.requestPayment({
  206. provider: 'wxpay',
  207. orderInfo: e.data.data,
  208. success: function() {
  209. uni.showToast({
  210. title: '充值成功',
  211. duration: 2000,
  212. position: 'top'
  213. });
  214. getUserInfo()
  215. .then(({
  216. data
  217. }) => {
  218. obj.setUserInfo(data);
  219. })
  220. .catch(e => {
  221. console.log(e);
  222. });
  223. },
  224. fail(e) {
  225. console.log(e);
  226. }
  227. });
  228. // #endif
  229. obj.payLoding = false;
  230. })
  231. .catch(e => {
  232. obj.payLoding = false;
  233. console.log(e);
  234. });
  235. },
  236. go() {
  237. this.$refs.popup.open()
  238. },
  239. cancel() {
  240. this.$refs.popup.close();
  241. this.card = '';
  242. this.pwd = '';
  243. },
  244. comfirm() {
  245. let obj = this
  246. verification({
  247. card_number: this.card,
  248. card_password: this.pwd,
  249. is_confirm: 1,
  250. type: 1,
  251. }).then(e => {
  252. console.log(e)
  253. this.card = '';
  254. this.pwd = '';
  255. getUserInfo()
  256. .then(({
  257. data
  258. }) => {
  259. obj.setUserInfo(data);
  260. })
  261. .catch(e => {
  262. console.log(e);
  263. });
  264. }).catch(e => {
  265. console.log(e)
  266. })
  267. this.$refs.popup.close();
  268. },
  269. //获取订单列表
  270. loadData(source) {
  271. console.log(source);
  272. //这里是将订单挂载到tab列表下
  273. let index = this.tabCurrentIndex;
  274. let navItem = this.navList[index];
  275. let state = navItem.state;
  276. if (source === 'tabChange' && navItem.loaded === true) {
  277. //tab切换只有第一次需要加载数据
  278. return;
  279. }
  280. if (navItem.loadingType === 'loading') {
  281. //防止重复加载
  282. return;
  283. }
  284. navItem.loadingType = 'loading';
  285. setTimeout(() => {
  286. let orderList = [];
  287. orderList.forEach(item => {
  288. navItem.orderList.push(item);
  289. });
  290. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  291. this.$set(navItem, 'loaded', true);
  292. //判断是否还有数据, 有改为 more, 没有改为noMore
  293. navItem.loadingType = 'more';
  294. }, 600);
  295. },
  296. changemoney(item, index) {
  297. this.choose = index;
  298. this.money = item;
  299. }
  300. }
  301. };
  302. </script>
  303. <style lang="scss">
  304. page {
  305. height: 100%;
  306. }
  307. .yue {
  308. display: flex;
  309. justify-content: space-between;
  310. padding: 30rpx 48rpx 30rpx 26rpx;
  311. background: #ffffff;
  312. .font {
  313. font-size: 28rpx;
  314. font-family: PingFang SC;
  315. font-weight: 500;
  316. color: #333333;
  317. }
  318. .money {
  319. font-size: 30rpx;
  320. font-family: PingFang SC;
  321. font-weight: bold;
  322. color: #ff6f0f;
  323. }
  324. }
  325. .add-btn {
  326. &.modified {
  327. color: $base-color;
  328. }
  329. &.up {
  330. background-color: $base-color;
  331. color: #fff;
  332. }
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. width: 690rpx;
  337. height: 80rpx;
  338. margin: 0 auto;
  339. margin-top: 30rpx;
  340. font-size: $font-lg;
  341. border-radius: 10rpx;
  342. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  343. }
  344. .card {
  345. background: #ffffff;
  346. border: 1px solid $base-color;
  347. color: $base-color;
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. width: 690rpx;
  352. height: 80rpx;
  353. margin: 30rpx auto 0;
  354. font-size: $font-lg;
  355. border-radius: 10rpx;
  356. }
  357. .row-box {
  358. margin-top: 30rpx;
  359. padding: 20rpx 0rpx 20rpx 30rpx;
  360. background: #fff;
  361. .title {
  362. font-size: $font-base + 2rpx;
  363. color: $font-color-dark;
  364. }
  365. .row {
  366. display: flex;
  367. align-items: center;
  368. position: relative;
  369. height: 80rpx;
  370. .tit {
  371. flex-shrink: 0;
  372. width: 40rpx;
  373. font-size: 30rpx;
  374. color: $font-color-dark;
  375. }
  376. .input {
  377. flex: 1;
  378. font-size: 30rpx;
  379. color: $font-color-dark;
  380. }
  381. .iconlocation {
  382. font-size: 36rpx;
  383. color: $font-color-light;
  384. }
  385. .buttom {
  386. color: $font-color;
  387. font-size: $font-base;
  388. }
  389. }
  390. .xian {
  391. width: 700rpx;
  392. height: 1rpx;
  393. background: #e6e6e6;
  394. margin-bottom: 16rpx;
  395. }
  396. .moneyBtn-box {
  397. display: flex;
  398. justify-content: flex-start;
  399. flex-wrap: wrap;
  400. .moneyBtn {
  401. margin-right: 30rpx;
  402. width: 210rpx;
  403. height: 70rpx;
  404. background: #f0f0f0;
  405. border-radius: 4px;
  406. margin-top: 30rpx;
  407. text-align: center;
  408. line-height: 70rpx;
  409. }
  410. }
  411. }
  412. .list {
  413. padding-left: 30rpx;
  414. margin-top: 30rpx;
  415. background-color: #ffffff;
  416. .box {
  417. display: flex;
  418. align-items: center;
  419. width: 100%;
  420. height: 120rpx;
  421. border-bottom: 1px solid $border-color-light;
  422. .icon {
  423. font-size: 48rpx;
  424. padding-right: 20rpx;
  425. }
  426. .iconweixin1 {
  427. color: #18bf16;
  428. }
  429. .iconzhifubao {
  430. color: #08aaec;
  431. }
  432. .title-box {
  433. flex-grow: 1;
  434. text-align: left;
  435. .title {
  436. font-size: $font-base + 2rpx;
  437. color: $font-color-base;
  438. }
  439. .node {
  440. font-size: $font-sm;
  441. color: $font-color-light;
  442. }
  443. }
  444. }
  445. }
  446. /deep/ .uni-radio-input {
  447. width: 45rpx;
  448. height: 45rpx;
  449. }
  450. .active-bg {
  451. background-color: $color-gray !important;
  452. }
  453. .current {
  454. background: $base-color !important;
  455. color: #fff;
  456. }
  457. .popup-box {
  458. width: 650rpx;
  459. padding-bottom: 30rpx;
  460. background-color: #ffffff;
  461. border-radius: 20rpx;
  462. position: relative;
  463. .img {
  464. position: relative;
  465. top: -56rpx;
  466. left: 0;
  467. width: 650rpx;
  468. height: 132rpx;
  469. z-index: 100;
  470. text-align: center;
  471. line-height: 132rpx;
  472. .img-bg {
  473. position: absolute;
  474. left: 50%;
  475. top: 0;
  476. margin-left: -250rpx;
  477. border-radius: 20rpx 20rpx 0 0;
  478. width: 500rpx;
  479. height: 132rpx;
  480. image {
  481. width: 100%;
  482. height: 100%;
  483. }
  484. }
  485. .img-font {
  486. line-height: 120rpx;
  487. position: relative;
  488. z-index: 10;
  489. text-align: center;
  490. font-size: 32rpx;
  491. font-weight: bold;
  492. color: #54300f;
  493. }
  494. }
  495. .mian {
  496. margin-top: -10rpx;
  497. display: flex;
  498. flex-direction: column;
  499. align-items: center;
  500. // padding: 32rpx 32rpx;
  501. background-color: #ffffff;
  502. border-radius: 0 0 20rpx 20rpx;
  503. text-align: center;
  504. padding: 20rpx;
  505. width: 100%;
  506. .main-item {
  507. display: flex;
  508. width: 580rpx;
  509. align-items: center;
  510. padding: 20rpx 40rpx;
  511. border-radius: 10rpx;
  512. background: #f5f2e5;
  513. height: 100rpx;
  514. .font {
  515. color: #623324;
  516. font-size: 30rpx;
  517. }
  518. .input {
  519. margin-left: 20rpx;
  520. text-align: left;
  521. color: #cdc0b3;
  522. font-size: 28rpx;
  523. }
  524. .input-font {
  525. color: #cdc0b3;
  526. font-size: 28rpx;
  527. }
  528. }
  529. .comfirm-box {
  530. margin-top: 80rpx;
  531. display: flex;
  532. // margin-bottom: 32rpx;
  533. // justify-content: space-around;
  534. .cancel {
  535. display: flex;
  536. align-items: center;
  537. justify-content: center;
  538. width: 260rpx;
  539. height: 100rpx;
  540. border: 1px solid #dcc786;
  541. border-radius: 10px;
  542. font-size: 32rpx;
  543. color: #605128;
  544. }
  545. .comfirm {
  546. margin-left: 60rpx;
  547. display: flex;
  548. align-items: center;
  549. justify-content: center;
  550. width: 260rpx;
  551. height: 100rpx;
  552. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  553. border-radius: 10px;
  554. font-size: 32rpx;
  555. color: #605128;
  556. }
  557. }
  558. }
  559. }
  560. </style>