recharge.vue 5.4 KB

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