recharge.vue 10 KB

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