recharge.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="content">
  3. <view class="row-box">
  4. <view class="title">充值金额</view>
  5. <view class="row">
  6. <text class="tit">¥</text>
  7. <input class="input" type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="placeholder" />
  8. </view>
  9. </view>
  10. <view class="list">
  11. <radio-group @change="tabRadio">
  12. <label>
  13. <view class="box">
  14. <view class="icon iconfont iconzhifubao"></view>
  15. <view class="title-box">
  16. <view class="title"><text>支付宝充值</text></view>
  17. </view>
  18. <view class="right"><radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" /></view>
  19. </view>
  20. </label>
  21. <label>
  22. <view class="box">
  23. <view class="icon iconfont iconweixin1"></view>
  24. <view class="title-box">
  25. <view class="title"><text>微信充值</text></view>
  26. <view class="node"><text>真实姓名(代勇明)</text></view>
  27. </view>
  28. <view class="right"><radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" /></view>
  29. </view>
  30. </label>
  31. </radio-group>
  32. </view>
  33. <button class="add-btn" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认充值</button>
  34. </view>
  35. </template>
  36. <script>
  37. import { getMoneyStyle } from '@/utils/rocessor.js';
  38. // #ifdef H5
  39. // import { rechargeWechat } from '@/api/wallet.js';
  40. // #endif
  41. // #ifdef MP
  42. import { rechargeRoutine } from '@/api/wallet.js';
  43. // #endif
  44. import { mapState } from 'vuex';
  45. export default {
  46. filters: {
  47. getMoneyStyle
  48. },
  49. data() {
  50. return {
  51. type: 'weixin',
  52. money: '', //充值金额
  53. payLoding: false //是否加载中
  54. };
  55. },
  56. onLoad(options) {},
  57. computed: {
  58. // #ifdef H5
  59. ...mapState(['weichatObj'])
  60. // #endif
  61. },
  62. methods: {
  63. // 跳转
  64. navTo(url) {
  65. uni.navigateTo({
  66. url: url
  67. });
  68. },
  69. // 切换选中对象
  70. tabRadio(e) {
  71. this.type = e;
  72. },
  73. // 提交
  74. confirm() {
  75. let obj = this;
  76. obj.payLoding = true;
  77. // #ifdef H5
  78. rechargeWechat({ price: this.money, from: this.type })
  79. .then(e => {
  80. let da = e.data.data;
  81. obj.weichatObj.chooseWXPay({
  82. timestamp: da.timestamp,
  83. nonceStr: da.nonceStr,
  84. package: da.package,
  85. signType: da.signType,
  86. paySign: da.paySign,
  87. success: function(res) {
  88. uni.showToast({
  89. title: '充值成功',
  90. duration: 2000,
  91. position: 'top'
  92. });
  93. }
  94. });
  95. obj.payLoding = false;
  96. })
  97. .catch(e => {
  98. obj.payLoding = false;
  99. console.log(e);
  100. });
  101. // #endif
  102. // #ifdef MP
  103. rechargeRoutine({ price: this.money})
  104. .then(e => {
  105. let da = e.data;
  106. wx.requestPayment({
  107. timeStamp: da.timestamp,
  108. nonceStr: da.nonceStr,
  109. package: da.package,
  110. signType: da.signType,
  111. paySign: da.paySign,
  112. success: function(res) {
  113. uni.redirectTo({
  114. url: '/pages/money/paySuccess'
  115. });
  116. },
  117. })
  118. obj.payLoding = false;
  119. })
  120. .catch(e => {
  121. obj.payLoding = false;
  122. console.log(e);
  123. });
  124. // #endif
  125. },
  126. }
  127. };
  128. </script>
  129. <style lang="scss">
  130. page {
  131. height: 100%;
  132. }
  133. .content{
  134. padding-top: 25rpx;
  135. }
  136. .add-btn {
  137. background-color: #6786FB;
  138. color: #FFFFFF;
  139. width: 70%;
  140. margin: 50rpx auto;
  141. margin-top: 80rpx;
  142. font-size: $font-lg;
  143. border-radius: 40rpx;
  144. }
  145. .row-box {
  146. padding: 20rpx 30rpx;
  147. background: #fff;
  148. .title {
  149. font-size: $font-base + 2rpx;
  150. color: $font-color-dark;
  151. }
  152. .row {
  153. display: flex;
  154. align-items: center;
  155. position: relative;
  156. height: 80rpx;
  157. .tit {
  158. flex-shrink: 0;
  159. width: 40rpx;
  160. font-size: 30rpx;
  161. color: $font-color-dark;
  162. }
  163. .input {
  164. flex: 1;
  165. font-size: 30rpx;
  166. color: $font-color-dark;
  167. }
  168. .iconlocation {
  169. font-size: 36rpx;
  170. color: $font-color-light;
  171. }
  172. .buttom {
  173. color: $font-color;
  174. font-size: $font-base;
  175. }
  176. }
  177. }
  178. .list {
  179. padding-left: 30rpx;
  180. margin-top: 30rpx;
  181. background-color: #ffffff;
  182. .box {
  183. display: flex;
  184. align-items: center;
  185. width: 100%;
  186. height: 120rpx;
  187. border-bottom: 1px solid $border-color-light;
  188. .icon {
  189. font-size: 48rpx;
  190. padding-right: 20rpx;
  191. }
  192. .iconweixin1 {
  193. color: #18bf16;
  194. }
  195. .iconzhifubao {
  196. color: #08aaec;
  197. }
  198. .title-box {
  199. flex-grow: 1;
  200. text-align: left;
  201. .title {
  202. font-size: $font-base + 2rpx;
  203. color: $font-color-base;
  204. }
  205. .node {
  206. font-size: $font-sm;
  207. color: $font-color-light;
  208. }
  209. }
  210. }
  211. }
  212. /deep/ .uni-radio-input {
  213. width: 45rpx;
  214. height: 45rpx;
  215. }
  216. .active-bg {
  217. background-color: $color-gray !important;
  218. }
  219. </style>