recharge.vue 10 KB

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