recharge.vue 10 KB

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