recharge.vue 12 KB

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