pay.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="content">
  3. <view class="banner flex">
  4. <view class="moneyBox">
  5. <view class="money">{{ userInfo.now_money }}</view>
  6. <view class="moneyText">我的剩余金币</view>
  7. </view>
  8. </view>
  9. <view class="recharge">
  10. <view class="itemBox flex">
  11. <view class="item" :class="{ action: ls.num == money }" @click="money = ls.num" v-for="ls in moneyList">{{ ls.num }}元</view>
  12. </view>
  13. <u-form ref="uForm" label-width="180">
  14. <u-form-item label="金额"><u-input type="number" placeholder="请输入充值金额" v-model="money" /></u-form-item>
  15. <u-form-item left-icon='weixin-fill' :left-icon-style='{color:"#5dbc7c"}' label="微信支付">
  16. <view class="checkedBox flex"><image class="checked" src="../../static/img/checkedIcon.png" mode="scaleToFill"></image></view>
  17. </u-form-item>
  18. </u-form>
  19. </view>
  20. <view class="buttom" @click="confirm">
  21. 充值
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import { rechargeWechat } from '@/api/tp.js';
  27. import { getUserInfo } from '@/api/login.js';
  28. import { mapState, mapMutations } from 'vuex';
  29. export default {
  30. data() {
  31. return {
  32. type: 'weixin',
  33. money: '', //充值金额
  34. payLoding: false, //是否加载中
  35. moneyList: [
  36. {
  37. num: 10
  38. },
  39. {
  40. num: 20
  41. },
  42. {
  43. num: 30
  44. },
  45. {
  46. num: 50
  47. },
  48. {
  49. num: 100
  50. },
  51. {
  52. num: 200
  53. },
  54. {
  55. num: 500
  56. },
  57. {
  58. num: 1000
  59. }
  60. ]
  61. };
  62. },
  63. onLoad(options) {
  64. console.log(this.userInfo);
  65. },
  66. computed: {
  67. ...mapState(['weichatObj']),
  68. ...mapState('user', ['userInfo'])
  69. },
  70. methods: {
  71. ...mapMutations('user',['setUserInfo']),
  72. getUserInfo(){
  73. getUserInfo().then((e) => {
  74. this.setUserInfo(e.data)
  75. }).catch((e) => {
  76. console.log(e);
  77. })
  78. },
  79. // 跳转
  80. navTo(url) {
  81. uni.navigateTo({
  82. url: url
  83. });
  84. },
  85. // 切换选中对象
  86. tabRadio(e) {
  87. this.type = e;
  88. },
  89. // 提交
  90. confirm() {
  91. if(!this.money){
  92. uni.showToast({
  93. title: '请填写金额!'
  94. });
  95. return
  96. }
  97. let obj = this;
  98. if(obj.payLoding ){
  99. return
  100. };
  101. obj.payLoding = true;
  102. rechargeWechat({ price: this.money, from: this.type })
  103. .then(e => {
  104. let da = e.data.data;
  105. obj.weichatObj.chooseWXPay({
  106. timestamp: da.timestamp,
  107. nonceStr: da.nonceStr,
  108. package: da.package,
  109. signType: da.signType,
  110. paySign: da.paySign,
  111. success: function(res) {
  112. uni.showToast({
  113. title: '充值成功',
  114. duration: 2000,
  115. position: 'top'
  116. });
  117. obj.getUserInfo()
  118. uni.showModal({
  119. title: '充值成功',
  120. content: '是否返回活动',
  121. success: res => {
  122. if(res.confirm){
  123. uni.navigateTo({
  124. url:'/pages/index'
  125. })
  126. }
  127. },
  128. });
  129. }
  130. });
  131. obj.payLoding = false;
  132. })
  133. .catch(e => {
  134. obj.payLoding = false;
  135. console.log(e);
  136. });
  137. }
  138. }
  139. };
  140. </script>
  141. <style lang="scss">
  142. page,
  143. .content {
  144. height: 100%;
  145. background-color: #ffffff;
  146. }
  147. .buttom{
  148. position:fixed;
  149. left: 0;
  150. bottom: 30rpx;
  151. right: 0;
  152. margin: 0 30rpx;
  153. padding: 15rpx;
  154. background-color: #D7272B;
  155. color: #FFFFFF;
  156. text-align: center;
  157. font-size: 36rpx;
  158. font-weight:bold;
  159. border-radius: 10rpx ;
  160. }
  161. .banner {
  162. background-color: #ff9ba7;
  163. justify-content: center;
  164. padding: 50rpx;
  165. padding-bottom: 150rpx;
  166. .moneyBox {
  167. color: #ffffff;
  168. text-align: center;
  169. .money {
  170. font-size: 74rpx;
  171. font-weight: bold;
  172. color: #ffffff;
  173. }
  174. }
  175. }
  176. .recharge {
  177. border-top-right-radius: 50rpx;
  178. border-top-left-radius: 50rpx;
  179. margin-top: -100rpx;
  180. background-color: #ffffff;
  181. padding: 0 30rpx;
  182. .checkedBox {
  183. justify-content: flex-end;
  184. width: 100%;
  185. .checked {
  186. width: 36rpx;
  187. height: 36rpx;
  188. }
  189. }
  190. .itemBox {
  191. padding-top: 50rpx;
  192. flex-wrap: wrap;
  193. color: #ffffff;
  194. font-weight: bold;
  195. .item {
  196. border-radius: 10rpx;
  197. width: 20%;
  198. margin: 10rpx;
  199. color: #ff9ba7;
  200. background-color: #ffffff;
  201. border: 1px solid #ff9ba7;
  202. padding: 10rpx;
  203. text-align: center;
  204. &.action {
  205. color: #ffffff;
  206. background-color: #ff9ba7;
  207. }
  208. }
  209. }
  210. }
  211. </style>