recharge.vue 11 KB

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