recharge.vue 11 KB

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