recharge.vue 4.3 KB

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