recharge.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. if(res.code!=200&&res.msg){
  119. uni.$u.toast(res.msg)
  120. }
  121. this.gotoPay({orderId:res.data.orderId,openid:this.vuex_wechatOpenid,paymentMode:4});
  122. }).catch(err=>{
  123. console.log('charge',err);
  124. })
  125. },
  126. gotoPay(params){//获取支付参数
  127. console.log('gotoPay',this.params);
  128. this.$u.api.rechargePay(params).then(res=>{
  129. this.payResult = res.data.payResult;
  130. this.wxPay()
  131. }).catch(err=>{
  132. console.log('gotoPay',err);
  133. })
  134. },
  135. wxPay(){
  136. uni.requestPayment({
  137. ... this.payResult,
  138. "provider": "wxpay",
  139. success(res) {
  140. uni.reLaunch({url: '/center/rechargesuccess'})
  141. },
  142. fail(e) {
  143. console.log('充值失败',e);
  144. }
  145. })
  146. },
  147. checkboxChange(e){
  148. this.checkboxVal = e[0];
  149. }
  150. }
  151. }
  152. </script>
  153. <style>
  154. page{
  155. background-color: #F5F5F5;
  156. }
  157. </style>
  158. <style lang="scss" scoped>
  159. .balance{
  160. height: 180rpx;
  161. background: #00A447;
  162. border-radius: 8rpx;
  163. margin-bottom: 20rpx;
  164. padding: 0 30rpx;
  165. font-size: 30rpx;
  166. font-weight: 400;
  167. color: #FFFFFF;
  168. .number{
  169. font-size: 54rpx;
  170. font-weight: 600;
  171. font-family: PingFangSC-Semibold, PingFang SC;
  172. }
  173. }
  174. .num-wrap{
  175. padding: 30rpx;
  176. background-color: #fff;
  177. border-radius: 8rpx;
  178. .title{
  179. font-size: 32rpx;
  180. font-weight: 400;
  181. color: #333333;
  182. line-height: 45rpx;
  183. margin-bottom: 20rpx;
  184. }
  185. .inner{
  186. margin-bottom: 40rpx;
  187. .num-item{
  188. width: 30%;
  189. height: 88rpx;
  190. line-height: 88rpx;
  191. background-color: #F5F5F5;
  192. border: 4rpx solid #F5F5F5;
  193. text-align: center;
  194. font-size: 30rpx;
  195. font-weight: 600;
  196. color: #02AB35;
  197. margin-bottom: 20rpx;
  198. font-family: PingFangSC-Semibold, PingFang SC;
  199. &.active{
  200. border-color: #00A447;
  201. }
  202. }
  203. }
  204. .full-btn{
  205. background-color: #00A447;;
  206. }
  207. }
  208. .customize{
  209. margin-bottom: 50rpx;
  210. &.active{
  211. /deep/ .u-input{
  212. border-color: #00A447!important;
  213. }
  214. }
  215. }
  216. .rule-wrap{
  217. margin: 40rpx auto;
  218. font-size: 26rpx;
  219. line-height: 1.5;
  220. .link{
  221. white-space: nowrap;
  222. color: #00A447;
  223. }
  224. }
  225. </style>