recharge.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="container">
  3. <view class="box">充值金额</view>
  4. <view class="list dffs">
  5. <view class="button_money" @click="selItem(item, index)" v-for="(item, index) in rspData" :key="index" :class="[item.id == money ? 'sel' : '', 'li']">
  6. <view style="color: #0bb291;">{{ item.money }}元</view>
  7. <view style="font-size: 26rpx;font-weight: normal;color: #0bb291;">{{ item.bean }}学豆</view>
  8. </view>
  9. <!-- <input v-if="active == 5" type="number" placeholder-style="font-size:32rpx" v-model="money" placeholder="请输入自定义金额" /> -->
  10. </view>
  11. <view class="cen">
  12. <view class="cen-title textgrey">支付方式</view>
  13. <!-- //开启的支付方式 1:微信+支付宝 2:支付宝 3:微信 -->
  14. <view class="pay-item bb dffs">
  15. <image class="left-icon" src="/static/img/pro/paywx.png"></image>
  16. <text class="pay-til">微信</text>
  17. <image class="right-icon" src="/static/img/pro/paysel.png"></image>
  18. </view>
  19. </view>
  20. <navigator url="/pages/user/funManage/list?type=3" class="mt30 fontmid prosecond">充值记录></navigator>
  21. <u-button color="#00952E" shape="circle" class="custom-style" @click="submitClickEvent">立即支付</u-button>
  22. </view>
  23. </template>
  24. <script>
  25. import payPassWord from '@/components/pay-password-keyboard/pay-password-keyboard.vue';
  26. export default {
  27. components: {
  28. payPassWord
  29. },
  30. data() {
  31. return {
  32. cv_bean:0, //比例
  33. active: 0,
  34. total: '',
  35. payType: 2,
  36. money: '',
  37. rspData: [],
  38. // rspData: ['50', '100', '200', '500', '1000', '自定义'],
  39. customStyle: {
  40. background: '#00952E',
  41. width: '690rpx',
  42. marginTop: '40rpx'
  43. }
  44. };
  45. },
  46. onLoad(opt) {
  47. this.getBean();
  48. // this.money=this.rspData[0];
  49. // this.loadData();
  50. },
  51. methods: {
  52. // 选中
  53. selItem(item, index) {
  54. // if (index != 5) {
  55. // this.active = index;
  56. this.money = item.id;
  57. // } else {
  58. // this.active = 5;
  59. // this.money = '';
  60. // }
  61. },
  62. //组合充值金额
  63. moneyArray() {
  64. var cv_bean = this.cv_bean;
  65. var new_array = [];
  66. var array = ['50', '100', '200', '500', '1000', '自定义'];
  67. array.forEach(function(v,k)
  68. {
  69. let item = {};
  70. if(v != '自定义')
  71. {
  72. item.money = v + '元';
  73. item.s_bean = (parseInt(v) * parseInt(cv_bean)) + '学豆';
  74. }else{
  75. item.money = v;
  76. item.s_bean = '';
  77. }
  78. new_array.push(item);
  79. })
  80. this.rspData = new_array;
  81. // console.log('新: ',new_array);
  82. },
  83. //获取学豆比例配置
  84. getBean(){
  85. this.$api
  86. .request(`index/getRecharge`)
  87. .then(res => {
  88. if (res.code == 200) {
  89. // let cv_bean = res.data.cv_bean || 0;
  90. // this.cv_bean = cv_bean;
  91. // this.moneyArray();
  92. this.rspData=res.data;
  93. this.money = res.data[0].id;
  94. }
  95. });
  96. },
  97. submitClickEvent() {
  98. if (!this.money) {
  99. this.$api.toast('请输入或选择充值金额!');
  100. return;
  101. }
  102. this.$api
  103. .request(`payment/beanPay`, {
  104. id: this.money
  105. })
  106. .then(res => {
  107. if (res.code && res.code != 200) {
  108. // this.$refs.confirmBtn.stop();
  109. this.$api.toast(res.msg || '获取支付信息失败');
  110. return;
  111. }
  112. console.log(res);
  113. console.log(res, this.payType);
  114. const orderInfo = res;
  115. const { timeStamp, nonceStr, paySign } = orderInfo;
  116. const payParams = {
  117. provider: 'wxpay',
  118. orderInfo: res,
  119. timeStamp,
  120. nonceStr,
  121. package: orderInfo.package,
  122. signType: 'MD5',
  123. paySign,
  124. success: e => {
  125. this.$api.toast('支付成功');
  126. },
  127. fail: err => {
  128. if (err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') > 1 || err.errMsg.indexOf('-2') > -1) {
  129. this.$api.toast('取消支付');
  130. } else {
  131. this.$api.toast('支付遇到错误,请稍候重试');
  132. console.log(err);
  133. }
  134. console.log(err);
  135. }
  136. };
  137. uni.requestPayment(payParams);
  138. });
  139. },
  140. // async loadData() {
  141. // this.$api.request(`recharge/getConfig`).then(res => {
  142. // if (res.code == '200') {
  143. // let data = res.data;
  144. // this.money = data[0];
  145. // this.rspData = data;
  146. // } else {
  147. // this.$api.toast(res.msg);
  148. // this.rspData = false;
  149. // }
  150. // });
  151. // }
  152. }
  153. };
  154. </script>
  155. <style lang="scss">
  156. page {
  157. background-color: #f5f5f5;
  158. }
  159. </style>
  160. <style lang="scss" scoped>
  161. .container {
  162. padding: 45rpx 30rpx;
  163. background-color: #fff;
  164. .button_money{
  165. display: flex;
  166. flex-direction:column;
  167. align-items: center;
  168. justify-content: center;
  169. }
  170. .box {
  171. font-size: 36rpx;
  172. font-family: PingFangSC-Semibold, PingFang SC;
  173. font-weight: 600;
  174. }
  175. .custom-style {
  176. background: #ed742e;
  177. width: 690rpx;
  178. margintop: 600rpx;
  179. color: #fff;
  180. margin-top: 40rpx;
  181. }
  182. .list {
  183. padding: 40rpx 0rpx 120rpx;
  184. flex-wrap: wrap;
  185. &:nth-of-type(3) {
  186. margin-right: 0;
  187. }
  188. .li {
  189. width: 218rpx;
  190. height: 110rpx;
  191. // line-height: 110rpx;
  192. background: #ffffff;
  193. // text-align: center;
  194. border-radius: 9rpx;
  195. color: #0bb291;
  196. font-size: 38rpx;
  197. font-family: PingFang SC;
  198. font-weight: bold;
  199. margin-right: 18rpx;
  200. margin-bottom: 22rpx;
  201. border: 1px solid #0bb291;
  202. &:nth-of-type(3n) {
  203. margin-right: 0;
  204. }
  205. }
  206. .sel {
  207. background: rgba(11, 178, 145, 0.1);
  208. border: 1px solid #0bb291;
  209. }
  210. input {
  211. margin-top: 42rpx;
  212. width: 690rpx;
  213. height: 86rpx;
  214. line-height: 86rpx;
  215. padding: 0 30rpx;
  216. border: 1px solid #dfdfdf;
  217. }
  218. }
  219. .cen {
  220. margin-bottom: 40rpx;
  221. .pay-item {
  222. background: #ffffff;
  223. width: 100%;
  224. margin-top: 20rpx;
  225. padding: 30rpx 0;
  226. .left-icon {
  227. width: 68rpx;
  228. height: 68rpx;
  229. }
  230. .pay-til {
  231. font-size: 32rpx;
  232. color: #333333;
  233. margin-left: 18rpx;
  234. flex: 1;
  235. }
  236. .right-icon {
  237. width: 36rpx;
  238. height: 36rpx;
  239. }
  240. }
  241. }
  242. .tips {
  243. width: 100%;
  244. padding: 26rpx 30rpx;
  245. text-align: left;
  246. }
  247. }
  248. </style>