recharge.vue 11 KB

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