recharge.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="">
  3. <u-navbar
  4. title="充值中心"
  5. :placeholder="true"
  6. :autoBack="true"
  7. :safeAreaInsetTop="true"
  8. >
  9. </u-navbar>
  10. <view class="balance u-flex u-row-between">
  11. <view class="left">个人余额</view>
  12. <view class="right number">¥ {{memberInfo.balance}}</view>
  13. </view>
  14. <view class="">
  15. <view class="num-wrap">
  16. <view class="title">充值金额</view>
  17. <view class="customize" :class="{active:usecustomize}" >
  18. <u--input
  19. prefixIcon="rmb"
  20. type="number"
  21. placeholder="请输入"
  22. border="bottom"
  23. v-model="customizeVal"
  24. clearable
  25. fontSize="36rpx"
  26. :customStyle="{height:'50rpx'}"
  27. ></u--input>
  28. </view>
  29. <view class="title">其他充值金额</view>
  30. <view class="inner u-flex u-row-around u-flex-wrap">
  31. <view class="num-item"
  32. :class="{active:activeIndex == index&&!usecustomize}"
  33. @click="numClick(index)"
  34. v-for="(item,index) in numItem" :key="item">
  35. {{item}} 元
  36. </view>
  37. </view>
  38. <view class="rule-wrap u-flex u-flex-wrap">
  39. <u-checkbox-group v-model="checked" @change="checkboxChange" placement="row">
  40. <u-checkbox activeColor="#00A447" name="同意" labelSize="26rpx" label="点击确认充值,即表示您已经同意"></u-checkbox>
  41. </u-checkbox-group>
  42. <text class="link" @click="$u.route('/credits/regulation',{regulationName:'充值协议'})">《充值协议》</text>
  43. </view>
  44. <view class="full-btn" @click="submit">立即充值</view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. checked:false,
  54. checkboxVal:null,
  55. customizeVal:null,
  56. activeIndex:0,
  57. numItem:[10,30,50,100,200,300],
  58. payResult:{},
  59. memberInfo:{},
  60. }
  61. },
  62. onShow() {
  63. this.getMemberInfo();
  64. },
  65. onLoad() {
  66. },
  67. computed:{
  68. usecustomize:function(){
  69. if(this.customizeVal){
  70. return true
  71. }else{
  72. return false
  73. }
  74. }
  75. },
  76. methods: {
  77. getMemberInfo(){
  78. this.$u.api.memberInfo({id:this.vuex_member_info.id}).then(res=>{
  79. this.memberInfo = res.data;
  80. this.avatar = res.data.avatar;
  81. this.$u.vuex('vuex_member_info', res.data);
  82. // console.log('memberInfo',this.memberInfo);
  83. }).catch(err=>{
  84. console.log('memberInfo',err.data);
  85. })
  86. },
  87. numClick(index){
  88. this.customizeVal = '';
  89. this.activeIndex = index
  90. },
  91. submit(){
  92. // uni.reLaunch({url: '/center/rechargesuccess'})
  93. // console.log('usecustomize',this.usecustomize);
  94. if(!this.checkboxVal){
  95. uni.showToast({
  96. title:'请先同意充值协议',
  97. icon:'none'
  98. })
  99. return
  100. }
  101. let num = Number(this.usecustomize?this.customizeVal:this.numItem[this.activeIndex]);
  102. console.log('num',num);
  103. // const env = uni.getAccountInfoSync().miniProgram.envVersion;
  104. // if((!num||num<100||num>10000)&&env!='develop'){
  105. // this.customizeVal = null;
  106. // uni.showToast({
  107. // title:'请正确输入金额',
  108. // icon:'error'
  109. // })
  110. // return
  111. // }
  112. let payParams={
  113. orderPrice:num,
  114. isCreditDesc:this.checkboxVal?1:0,
  115. };
  116. this.$u.api.addRechargeOrder(payParams).then(res=>{//提交充值订单
  117. console.log('res',res.data);
  118. this.gotoPay({orderId:res.data.orderId,openid:this.vuex_wechatOpenid,paymentMode:4});
  119. }).catch(err=>{
  120. console.log('charge',err);
  121. })
  122. },
  123. gotoPay(params){//获取支付参数
  124. console.log('gotoPay',this.params);
  125. this.$u.api.rechargePay(params).then(res=>{
  126. this.payResult = res.data.payResult;
  127. this.wxPay()
  128. }).catch(err=>{
  129. console.log('gotoPay',err);
  130. })
  131. },
  132. wxPay(){
  133. uni.requestPayment({
  134. ... this.payResult,
  135. "provider": "wxpay",
  136. success(res) {
  137. uni.reLaunch({url: '/center/rechargesuccess'})
  138. },
  139. fail(e) {
  140. console.log('充值失败',e);
  141. }
  142. })
  143. },
  144. checkboxChange(e){
  145. this.checkboxVal = e[0];
  146. }
  147. }
  148. }
  149. </script>
  150. <style>
  151. page{
  152. background-color: #F5F5F5;
  153. }
  154. </style>
  155. <style lang="scss" scoped>
  156. .balance{
  157. height: 180rpx;
  158. background: #00A447;
  159. border-radius: 8rpx;
  160. margin-bottom: 20rpx;
  161. padding: 0 30rpx;
  162. font-size: 30rpx;
  163. font-weight: 400;
  164. color: #FFFFFF;
  165. .number{
  166. font-size: 54rpx;
  167. font-weight: 600;
  168. font-family: PingFangSC-Semibold, PingFang SC;
  169. }
  170. }
  171. .num-wrap{
  172. padding: 30rpx;
  173. background-color: #fff;
  174. border-radius: 8rpx;
  175. .title{
  176. font-size: 32rpx;
  177. font-weight: 400;
  178. color: #333333;
  179. line-height: 45rpx;
  180. margin-bottom: 20rpx;
  181. }
  182. .inner{
  183. margin-bottom: 40rpx;
  184. .num-item{
  185. width: 30%;
  186. height: 88rpx;
  187. line-height: 88rpx;
  188. background-color: #F5F5F5;
  189. border: 4rpx solid #F5F5F5;
  190. text-align: center;
  191. font-size: 30rpx;
  192. font-weight: 600;
  193. color: #02AB35;
  194. margin-bottom: 20rpx;
  195. font-family: PingFangSC-Semibold, PingFang SC;
  196. &.active{
  197. border-color: #00A447;
  198. }
  199. }
  200. }
  201. .full-btn{
  202. background-color: #00A447;;
  203. }
  204. }
  205. .customize{
  206. margin-bottom: 50rpx;
  207. &.active{
  208. /deep/ .u-input{
  209. border-color: #00A447!important;
  210. }
  211. }
  212. }
  213. .rule-wrap{
  214. margin: 40rpx auto;
  215. font-size: 26rpx;
  216. line-height: 1.5;
  217. .link{
  218. white-space: nowrap;
  219. color: #00A447;
  220. }
  221. }
  222. </style>