recharge.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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="自定义金额(不能低于100元和高于10000元)"
  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:[3000,5000,10000],
  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. const env = uni.getAccountInfoSync().miniProgram.envVersion;
  88. if((!num||num<100||num>10000)&&env!='develop'){
  89. this.customizeVal = null;
  90. uni.showToast({
  91. title:'请正确输入金额',
  92. icon:'error'
  93. })
  94. return
  95. }
  96. let payParams={
  97. orderPrice:num,
  98. isCreditDesc:this.checkboxVal?1:0,
  99. };
  100. this.$u.api.addRechargeOrder(payParams).then(res=>{//提交充值订单
  101. console.log('res',res.data);
  102. this.gotoPay({orderId:res.data.orderId,openid:this.vuex_wechatOpenid,paymentMode:4});
  103. }).catch(err=>{
  104. console.log('charge',err);
  105. })
  106. },
  107. gotoPay(params){//获取支付参数
  108. console.log('gotoPay',this.params);
  109. this.$u.api.rechargePay(params).then(res=>{
  110. this.payResult = res.data.payResult;
  111. this.wxPay()
  112. }).catch(err=>{
  113. console.log('gotoPay',err);
  114. })
  115. },
  116. wxPay(){
  117. uni.requestPayment({
  118. ... this.payResult,
  119. "provider": "wxpay",
  120. success(res) {
  121. uni.reLaunch({url: '/center/rechargesuccess'})
  122. },
  123. fail(e) {
  124. console.log('充值失败',e);
  125. }
  126. })
  127. },
  128. checkboxChange(e){
  129. this.checkboxVal = e[0];
  130. }
  131. }
  132. }
  133. </script>
  134. <style>
  135. page{
  136. background-color: #F5F5F5;
  137. }
  138. </style>
  139. <style lang="scss" scoped>
  140. .top-bg{
  141. width: 100%;
  142. height: 450rpx;
  143. background-color: #00A447;
  144. border-radius: 0 0 20% 20%;
  145. position: absolute;
  146. top: 0;
  147. left: 0;
  148. z-index:-1;
  149. }
  150. .num-wrap{
  151. padding: 20rpx;
  152. background-color: #fff;
  153. border-radius: 8rpx;
  154. .title{
  155. font-size: 32rpx;
  156. font-weight: 600;
  157. margin-bottom: 20rpx;
  158. }
  159. .inner{
  160. margin-bottom: 40rpx;
  161. .num-item{
  162. width: 30%;
  163. height: 260rpx;
  164. line-height: 260rpx;
  165. background-color: #EBF8F1;
  166. border: 4rpx solid #EBF8F1;
  167. text-align: center;
  168. font-size: 36rpx;
  169. font-weight: 600;
  170. color: #333333;
  171. &.active{
  172. border-color: #00A447;
  173. }
  174. }
  175. }
  176. .full-btn{
  177. background-color: #FFB600;;
  178. }
  179. }
  180. .customize{
  181. &.active{
  182. /deep/ .u-input{
  183. border-color: #00A447!important;
  184. }
  185. }
  186. // /deep/ .u-input{
  187. // background-color: #bababa;
  188. // border-color: #bababa;
  189. // input{
  190. // color: #fff!important;
  191. // height: 70rpx;
  192. // font-size: 50rpx!important;
  193. // text-align: center!important;
  194. // &::-webkit-input-placeholder{
  195. // color: red!important;
  196. // }
  197. // }
  198. // }
  199. }
  200. .rule-wrap{
  201. margin: 40rpx auto;
  202. .link{
  203. color: #00A447;
  204. }
  205. }
  206. </style>