recharge.vue 9.8 KB

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