recharge.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. <!-- #ifndef MP -->
  11. <view class="list">
  12. <radio-group @change="tabRadio">
  13. <label>
  14. <view class="box">
  15. <view class="icon iconfont iconzhifubao"></view>
  16. <view class="title-box">
  17. <view class="title"><text>支付宝充值</text></view>
  18. </view>
  19. <view class="right"><radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" /></view>
  20. </view>
  21. </label>
  22. <label>
  23. <view class="box1">
  24. <view class="icon iconfont iconweixin1"></view>
  25. <view class="title-box">
  26. <view class="title"><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. <!-- #endif -->
  34. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认</button>
  35. </view>
  36. </template>
  37. <script>
  38. import { getMoneyStyle } from '@/utils/rocessor.js';
  39. // #ifdef H5
  40. import { rechargeWechat } from '@/api/wallet.js';
  41. // #endif
  42. // #ifdef MP
  43. import { rechargeRoutine } from '@/api/wallet.js';
  44. // #endif
  45. import { mapState } from 'vuex';
  46. export default {
  47. filters: {
  48. getMoneyStyle
  49. },
  50. data() {
  51. return {
  52. type: 'weixin',
  53. money: '', //充值金额
  54. payLoding: false //是否加载中
  55. };
  56. },
  57. onLoad(options) {},
  58. computed: {
  59. // #ifdef H5
  60. ...mapState(['weichatObj'])
  61. // #endif
  62. },
  63. methods: {
  64. // 跳转
  65. navTo(url) {
  66. uni.navigateTo({
  67. url: url
  68. });
  69. },
  70. // 切换选中对象
  71. tabRadio(e) {
  72. this.type = e;
  73. console.log(this.type,'this.type')
  74. },
  75. // 提交
  76. confirm() {
  77. let obj = this;
  78. obj.payLoding = true;
  79. console.log(obj.money);
  80. if ( obj.money == '') {
  81. this.$api.msg('金额不能为空');
  82. obj.payLoding = false;
  83. return
  84. }
  85. // #ifdef APP-PLUS
  86. if(obj.type == 'alipay')
  87. {
  88. uni.requestPayment({
  89. provider: 'alipay',
  90. orderInfo: 'orderInfo', //微信、支付宝订单数据
  91. success: function (res) {
  92. console.log('success:' + JSON.stringify(res));
  93. },
  94. fail: function (err) {
  95. console.log('fail:' + JSON.stringify(err));
  96. }
  97. });
  98. }else{
  99. uni.requestPayment({
  100. provider: 'weixin',
  101. orderInfo: 'orderInfo', //微信、支付宝订单数据
  102. success: function (res) {
  103. console.log('success:' + JSON.stringify(res));
  104. },
  105. fail: function (err) {
  106. console.log('fail:' + JSON.stringify(err));
  107. }
  108. });
  109. }
  110. // #endif
  111. // #ifdef H5
  112. rechargeWechat({ price: this.money, from: this.type })
  113. .then(e => {
  114. let da = e.data.data;
  115. obj.weichatObj.chooseWXPay({
  116. timestamp: da.timestamp,
  117. nonceStr: da.nonceStr,
  118. package: da.package,
  119. signType: da.signType,
  120. paySign: da.paySign,
  121. success: function(res) {
  122. uni.navigateTo({
  123. url: '/pages/money/rechargeSuccess'
  124. });
  125. /* uni.showToast({
  126. title: '充值成功',
  127. duration: 2000,
  128. position: 'top'
  129. }); */
  130. }
  131. });
  132. obj.payLoding = false;
  133. })
  134. .catch(e => {
  135. obj.payLoding = false;
  136. console.log(e);
  137. });
  138. // #endif
  139. // #ifdef MP
  140. rechargeRoutine({ price: this.money})
  141. .then(e => {
  142. let da = e.data;
  143. wx.requestPayment({
  144. timeStamp: da.timestamp,
  145. nonceStr: da.nonceStr,
  146. package: da.package,
  147. signType: da.signType,
  148. paySign: da.paySign,
  149. success: function(res) {
  150. uni.redirectTo({
  151. url: '/pages/money/paySuccess'
  152. });
  153. },
  154. fail:function(res){
  155. uni.showToast({
  156. title: '支付失败',
  157. duration: 3000
  158. });
  159. },
  160. complete:function(){}
  161. })
  162. obj.payLoding = false;
  163. })
  164. .catch(e => {
  165. obj.payLoding = false;
  166. console.log(e);
  167. });
  168. // #endif
  169. }
  170. }
  171. };
  172. </script>
  173. <style lang="scss">
  174. page {
  175. height: 100%;
  176. }
  177. .add-btn {
  178. &.modified {
  179. color: $base-color;
  180. }
  181. &.up {
  182. background:$base-color;
  183. color: #fff;
  184. }
  185. display: flex;
  186. align-items: center;
  187. justify-content: center;
  188. width: 560rpx;
  189. height: 80rpx;
  190. margin: 0 auto;
  191. margin-top: 60rpx;
  192. font-size: $font-lg;
  193. border-radius: 40rpx;
  194. }
  195. .row-box {
  196. border-top: 1px solid #EEEEEE;
  197. padding: 20rpx 30rpx;
  198. background: #fff;
  199. .title {
  200. font-size: $font-base + 2rpx;
  201. color: $font-color-dark;
  202. }
  203. .row {
  204. display: flex;
  205. align-items: center;
  206. position: relative;
  207. height: 80rpx;
  208. .tit {
  209. flex-shrink: 0;
  210. width: 40rpx;
  211. font-size: 30rpx;
  212. color: $font-color-dark;
  213. }
  214. .input {
  215. flex: 1;
  216. font-size: 30rpx;
  217. color: $font-color-dark;
  218. }
  219. .iconlocation {
  220. font-size: 36rpx;
  221. color: $font-color-light;
  222. }
  223. .buttom {
  224. color: $font-color;
  225. font-size: $font-base;
  226. }
  227. }
  228. }
  229. .list {
  230. padding:0 30rpx;
  231. margin-top: 20rpx;
  232. background-color: #ffffff;
  233. .box {
  234. display: flex;
  235. align-items: center;
  236. width: 100%;
  237. height: 100rpx;
  238. border-bottom: 1px solid $border-color-light;
  239. }
  240. .box1{
  241. display: flex;
  242. align-items: center;
  243. width: 100%;
  244. height: 100rpx;
  245. }
  246. .icon {
  247. font-size: 48rpx;
  248. padding-right: 20rpx;
  249. }
  250. .iconweixin1 {
  251. color: #18bf16;
  252. }
  253. .iconzhifubao {
  254. color: #08aaec;
  255. }
  256. .title-box {
  257. flex-grow: 1;
  258. text-align: left;
  259. .title {
  260. font-size: $font-base + 2rpx;
  261. color: #333333;
  262. }
  263. /* .node {
  264. font-size: $font-base;
  265. color: #333333;
  266. } */
  267. }
  268. image {
  269. width: 25rpx;
  270. height: 25rpx;
  271. }
  272. }
  273. /deep/ .uni-radio-input {
  274. width: 45rpx;
  275. height: 45rpx;
  276. }
  277. .active-bg {
  278. background-color: $color-gray !important;
  279. }
  280. </style>