recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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. dataUp() {
  134. let obj = this;
  135. getUserInfo({})
  136. .then(e => {
  137. obj.login();
  138. // 保存返回用户数据
  139. obj.setUserInfo(e.data);
  140. })
  141. .catch(e => {
  142. console.log(e);
  143. });
  144. },
  145. // 切换选中对象
  146. tabRadio(e) {
  147. this.type = e;
  148. },
  149. // 提交
  150. confirm() {
  151. let obj = this;
  152. if (obj.money == 0) {
  153. return obj.$api.msg('请输入充值金额');
  154. }
  155. if (!obj.isSect) {
  156. return obj.$api.msg('请选择支付方式');
  157. }
  158. obj.payLoding = true;
  159. // #ifdef H5
  160. let datao = {}
  161. if (obj.status == 0) {
  162. datao = {
  163. price: obj.money,
  164. from: obj.type,
  165. }
  166. }
  167. if (obj.status == 2) {
  168. datao = {
  169. price: obj.money,
  170. from: obj.type,
  171. type: 2
  172. }
  173. }
  174. rechargeWechat(datao)
  175. .then(e => {
  176. let da = e.data.data;
  177. obj.weichatObj.chooseWXPay({
  178. timestamp: da.timestamp,
  179. nonceStr: da.nonceStr,
  180. package: da.package,
  181. signType: da.signType,
  182. paySign: da.paySign,
  183. success: function(res) {
  184. uni.showToast({
  185. title: '充值成功',
  186. duration: 2000,
  187. position: 'top'
  188. });
  189. }
  190. });
  191. obj.payLoding = false;
  192. })
  193. .catch(e => {
  194. obj.payLoding = false;
  195. console.log(e);
  196. });
  197. // #endif
  198. // #ifdef MP
  199. rechargeRoutine({
  200. price: this.money
  201. })
  202. .then(e => {
  203. let da = e.data;
  204. wx.requestPayment({
  205. timeStamp: da.timestamp,
  206. nonceStr: da.nonceStr,
  207. package: da.package,
  208. signType: da.signType,
  209. paySign: da.paySign,
  210. success: function(res) {
  211. uni.redirectTo({
  212. url: '/pages/money/paySuccess?isshow=false'
  213. });
  214. }
  215. });
  216. obj.payLoding = false;
  217. })
  218. .catch(e => {
  219. obj.payLoding = false;
  220. console.log(e);
  221. });
  222. // #endif
  223. },
  224. //获取订单列表
  225. loadData(source) {
  226. console.log(source);
  227. //这里是将订单挂载到tab列表下
  228. let index = this.tabCurrentIndex;
  229. let navItem = this.navList[index];
  230. let state = navItem.state;
  231. if (source === 'tabChange' && navItem.loaded === true) {
  232. //tab切换只有第一次需要加载数据
  233. return;
  234. }
  235. if (navItem.loadingType === 'loading') {
  236. //防止重复加载
  237. return;
  238. }
  239. navItem.loadingType = 'loading';
  240. setTimeout(() => {
  241. let orderList = [];
  242. orderList.forEach(item => {
  243. navItem.orderList.push(item);
  244. });
  245. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  246. this.$set(navItem, 'loaded', true);
  247. //判断是否还有数据, 有改为 more, 没有改为noMore
  248. navItem.loadingType = 'more';
  249. }, 600);
  250. },
  251. tagClick(index) {
  252. this.currentIndex = index;
  253. this.money = this.addTags[index];
  254. },
  255. clearNoNum() {
  256. this.money = this.money.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
  257. switch (this.money) {
  258. case '300':
  259. this.currentIndex = 0;
  260. break;
  261. case '200':
  262. this.currentIndex = 1;
  263. break;
  264. case '150':
  265. this.currentIndex = 2;
  266. break;
  267. case '100':
  268. this.currentIndex = 3;
  269. break;
  270. case '50':
  271. this.currentIndex = 4;
  272. break;
  273. }
  274. },
  275. btnClick() {
  276. this.isSect = !this.isSect
  277. },
  278. userBalance() {
  279. userBalance().then(res => {
  280. this.new_money = res.data.now_money
  281. console.log(res)
  282. })
  283. }
  284. }
  285. };
  286. </script>
  287. <style lang="scss">
  288. page {
  289. height: 100%;
  290. background-color: #fff;
  291. }
  292. .add-btn {
  293. &.modified {
  294. color: $base-color;
  295. }
  296. &.up {
  297. background-color: $base-color;
  298. color: #fff;
  299. }
  300. display: flex;
  301. align-items: center;
  302. justify-content: center;
  303. width: 604rpx;
  304. height: 90rpx;
  305. margin: 0 auto;
  306. margin-top: 30rpx;
  307. font-size: $font-lg;
  308. border-radius: 10rpx;
  309. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  310. }
  311. .row-box {
  312. margin-top: 30rpx;
  313. padding: 20rpx 30rpx;
  314. background: #fff;
  315. .title {
  316. font-size: $font-base + 2rpx;
  317. color: $font-color-dark;
  318. }
  319. .row {
  320. display: flex;
  321. align-items: center;
  322. position: relative;
  323. height: 80rpx;
  324. .tit {
  325. flex-shrink: 0;
  326. width: 40rpx;
  327. font-size: 30rpx;
  328. color: $font-color-dark;
  329. }
  330. .input {
  331. flex: 1;
  332. font-size: 30rpx;
  333. color: $font-color-dark;
  334. }
  335. .iconlocation {
  336. font-size: 36rpx;
  337. color: $font-color-light;
  338. }
  339. .buttom {
  340. color: $font-color;
  341. font-size: $font-base;
  342. }
  343. }
  344. }
  345. .list {
  346. padding-left: 30rpx;
  347. margin-top: 30rpx;
  348. background-color: #ffffff;
  349. .box {
  350. display: flex;
  351. align-items: center;
  352. width: 100%;
  353. height: 120rpx;
  354. border-bottom: 1px solid $border-color-light;
  355. .icon {
  356. font-size: 48rpx;
  357. padding-right: 20rpx;
  358. }
  359. .iconweixin1 {
  360. color: #18bf16;
  361. }
  362. .iconzhifubao {
  363. color: #08aaec;
  364. }
  365. .title-box {
  366. flex-grow: 1;
  367. text-align: left;
  368. .title {
  369. font-size: $font-base + 2rpx;
  370. color: $font-color-base;
  371. }
  372. .node {
  373. font-size: $font-sm;
  374. color: $font-color-light;
  375. }
  376. }
  377. }
  378. }
  379. /deep/ .uni-radio-input {
  380. width: 45rpx;
  381. height: 45rpx;
  382. }
  383. .active-bg {
  384. background-color: $color-gray !important;
  385. }
  386. .now {
  387. width: 100%;
  388. height: 86rpx;
  389. padding: 0 26rpx 0 47rpx;
  390. display: flex;
  391. justify-content: space-between;
  392. line-height: 86rpx;
  393. background-color: #fff;
  394. // margin-bottom: 21rpx;
  395. view {
  396. font-size: 28rpx;
  397. font-weight: 500;
  398. color: #333333;
  399. }
  400. .now-money {
  401. font-size: 32rpx;
  402. font-weight: bold;
  403. color: #e1262b;
  404. }
  405. }
  406. .add-wrapper {
  407. width: 750rpx;
  408. height: 338rpx;
  409. padding-left: 30rpx;
  410. background: #ffffff;
  411. display: flex;
  412. flex-direction: column;
  413. align-items: center;
  414. // margin-bottom: 22rpx;
  415. .add-box {
  416. width: 100%;
  417. height: 103rpx;
  418. display: flex;
  419. flex-direction: row;
  420. justify-content: space-between;
  421. padding: 0 39rpx 0 10rpx;
  422. align-items: center;
  423. .add-log {
  424. font-size: 37rpx;
  425. font-weight: bold;
  426. }
  427. input {
  428. width: 218rpx;
  429. height: 30rpx;
  430. font-size: 32rpx;
  431. font-weight: 500;
  432. color: #000;
  433. line-height: 40px;
  434. text-align: right;
  435. .place {
  436. color: #bfbfbf;
  437. }
  438. }
  439. }
  440. .jg {
  441. width: 100%;
  442. }
  443. .add-tags {
  444. height: 234rpx;
  445. padding-top: 47rpx;
  446. padding-bottom: 17rpx;
  447. display: flex;
  448. flex-direction: row;
  449. flex-wrap: wrap;
  450. // justify-content: space-between;
  451. .tag {
  452. width: 210rpx;
  453. height: 70rpx;
  454. background-color: #f0f0f0;
  455. border-radius: 4rpx;
  456. margin: 0 30rpx 30rpx 0;
  457. text-align: center;
  458. line-height: 70rpx;
  459. font-size: 22rpx;
  460. text {
  461. font-size: 32rpx;
  462. font-weight: 500;
  463. }
  464. }
  465. .action {
  466. color: #fff;
  467. background-color: #e1262b;
  468. }
  469. }
  470. }
  471. .btn-wrapper {
  472. padding: 49rpx 32rpx 0 40rpx;
  473. height: 183rpx;
  474. display: flex;
  475. justify-content: space-between;
  476. background-color: #fff;
  477. .iconweixin1 {
  478. color: #18bf16;
  479. font-size: 48rpx;
  480. display: flex;
  481. view {
  482. // display: inline-block;
  483. height: 48rpx;
  484. text-align: 48rpx;
  485. padding-left: 20rpx;
  486. // padding-top: 10rpx;
  487. color: #000000;
  488. font-size: 30rpx;
  489. }
  490. }
  491. .btn {
  492. width: 36rpx;
  493. height: 36rpx;
  494. border: 4rpx #e1262b solid;
  495. border-radius: 8rpx 8rpx;
  496. image {
  497. // display: none;
  498. width: 100%;
  499. height: 100%;
  500. }
  501. .action {
  502. display: none;
  503. }
  504. }
  505. .actiont {
  506. border: none;
  507. }
  508. }
  509. .main-jg {
  510. width: 100%;
  511. height: 21rpx;
  512. background-color: #f8f6f6;
  513. }
  514. </style>