recharge.vue 4.7 KB

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