recharge.vue 4.5 KB

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