index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view>
  3. <view class="payment-top acea-row row-column row-center-wrapper">
  4. <span class="name">我的余额</span>
  5. <view class="pic">
  6. ¥<span class="pic-font">{{ user.money || 0 }}</span>
  7. </view>
  8. </view>
  9. <view class="payment">
  10. <view class="nav acea-row row-around row-middle">
  11. <view class="item">充值账户:{{ user.mobile }}</view>
  12. </view>
  13. <view class='tip picList'>
  14. <view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic == index ? 'pic-box-color-active' : ''"
  15. v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)">
  16. <view class="pic-number-pic">
  17. {{ item.name }}<span class="pic-number"></span>
  18. </view>
  19. <view class="pic-number">{{ item.upname }}</view>
  20. </view>
  21. <view class="pic-box pic-box-color acea-row row-center-wrapper" :class="activePic == picList.length ? 'pic-box-color-active' : ''"
  22. @click="picCharge(picList.length)">
  23. <input type="number" placeholder="其他" v-model="money" class="pic-box-money pic-number-pic" :class="activePic == picList.length ? 'pic-box-color-active' : ''" />
  24. </view>
  25. <view class="tips-box">
  26. <view>支付方式:<text class="iconfont icon-weixinzhifu"></text>微信付款</view>
  27. <view>用户协议:
  28. <checkbox checked="true"></checkbox>
  29. 接受<navigator hover-class="none" url="/pages/users/recharge/xieyi">《充值协议》</navigator>
  30. </view>
  31. </view>
  32. </view>
  33. <button class='btn' @click="recharge">立即充值</button>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. mapGetters
  40. } from "vuex";
  41. import {
  42. toLogin
  43. } from '@/libs/login.js';
  44. import {
  45. getUserInfo,
  46. rechargeInit,
  47. wxRecharge
  48. } from '@/api/api.js';
  49. export default {
  50. data() {
  51. return {
  52. user: {},
  53. picList: [],
  54. activePic: 0,
  55. money: '',
  56. rechar_id: '',
  57. numberPic: '',
  58. code: ''
  59. }
  60. },
  61. computed: mapGetters(['isLogin']),
  62. onLoad(options) {
  63. if (this.isLogin) {
  64. getUserInfo().then(res => {
  65. this.user = res.data;
  66. if(this.$wechat.isWeixin() && !this.user.openid){
  67. if(options.code){
  68. this.code = options.code;
  69. }else{
  70. var appID = "wxa9130b2090dfb130"; // 公众号AppID
  71. var redirect_uri = "https://www.babalipin.com/h5/pages/users/recharge/index"; // 授权接口地址
  72. var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appID + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
  73. window.location.href = url;
  74. }
  75. }
  76. });
  77. this.getRecharge();
  78. }else{
  79. toLogin();
  80. }
  81. },
  82. methods: {
  83. getRecharge: function() {
  84. rechargeInit().then(res => {
  85. this.picList = res.data;
  86. if (this.picList[0]) {
  87. this.rechar_id = this.picList[0].name;
  88. this.numberPic = this.picList[0].v;
  89. }
  90. });
  91. },
  92. //选择金额
  93. picCharge(idx, item) {
  94. this.activePic = idx;
  95. if (item === undefined) {
  96. this.rechar_id = "";
  97. this.numberPic = "";
  98. } else {
  99. this.money = "";
  100. this.rechar_id = item.name;
  101. this.numberPic = item.v;
  102. }
  103. },
  104. recharge: function() {
  105. let that = this;
  106. uni.showLoading({
  107. title: '正在支付',
  108. })
  109. let money = parseFloat(that.money);
  110. if( that.rechar_id == ''){
  111. if(Number.isNaN(money)){
  112. return that.$util.Tips({title: '充值金额必须为数字'});
  113. }
  114. if(money <= 0){
  115. return that.$util.Tips({title: '充值金额不能为0'});
  116. }
  117. }else{
  118. money = that.numberPic
  119. }
  120. wxRecharge({
  121. money: money,
  122. from: that.$wechat.isWeixin() ? 'weixin' : 'h5',
  123. code: that.code
  124. }).then(res => {
  125. if (res.data.result === undefined) return that.$util.Tips({
  126. title: '缺少支付参数'
  127. });
  128. if (res.data.type == "WECHAT_H5_PAY") {
  129. location.replace(res.data.result.mweb_url+'&redirect_url=https%3A%2F%2Fbabalipin.com%2Fh5%2Fpages%2Fmy%2Findex');
  130. } else {
  131. let response = res.data.result;
  132. if (typeof WeixinJSBridge == "undefined") {
  133. if (document.addEventListener) {
  134. document.addEventListener('WeixinJSBridgeReady', that.onBridgeReady(response), false);
  135. } else if (document.attachEvent) {
  136. document.attachEvent('WeixinJSBridgeReady', that.onBridgeReady(response));
  137. document.attachEvent('onWeixinJSBridgeReady', that.onBridgeReady(response));
  138. }
  139. } else {
  140. that.onBridgeReady(response);
  141. }
  142. }
  143. }).catch(err => {
  144. uni.hideLoading();
  145. return that.$util.Tips({
  146. title: err
  147. })
  148. });
  149. },
  150. onBridgeReady: function(response) {
  151. let that = this;
  152. WeixinJSBridge.invoke(
  153. 'getBrandWCPayRequest', {
  154. "appId": response.appId, //公众号名称,由商户传入
  155. "timeStamp": response.timeStamp, //时间戳,自1970年以来的秒数
  156. "nonceStr": response.nonceStr, //随机串
  157. "package": response.package,
  158. "signType": response.signType, //微信签名方式
  159. "paySign": response.paySign //微信签名
  160. },
  161. function(res){
  162. WeixinJSBridge.log(res.err_msg);
  163. if (res.err_msg == "get_brand_wcpay_request:cancel") {
  164. uni.hideLoading();
  165. return that.$util.Tips({
  166. title: '支付失败'
  167. }, {
  168. tab: 1,
  169. url: '/pages/my/index'
  170. });
  171. } else {
  172. uni.hideLoading();
  173. return that.$util.Tips({
  174. title: '支付成功',
  175. icon: 'success'
  176. }, {
  177. tab: 4,
  178. url: '/pages/my/index'
  179. });
  180. }
  181. }
  182. );
  183. }
  184. }
  185. }
  186. </script>
  187. <style scoped lang="scss">
  188. page {
  189. width: 100%;
  190. height: 100%;
  191. background-color: #fff;
  192. }
  193. .payment {
  194. position: relative;
  195. top: -60rpx;
  196. width: 100%;
  197. background-color: #fff;
  198. border-radius: 10rpx;
  199. padding-top: 25rpx;
  200. border-top-right-radius: 39rpx;
  201. border-top-left-radius: 39rpx;
  202. }
  203. .payment .nav {
  204. height: 75rpx;
  205. line-height: 75rpx;
  206. padding: 0 100rpx;
  207. }
  208. .payment .nav .item {
  209. font-size: 30rpx;
  210. color: #333;
  211. }
  212. .payment .nav .item.on {
  213. font-weight: bold;
  214. border-bottom: 4rpx solid #e83323;
  215. }
  216. .payment .input {
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. border-bottom: 1px dashed #dddddd;
  221. margin: 60rpx auto 0 auto;
  222. padding-bottom: 20rpx;
  223. font-size: 56rpx;
  224. color: #333333;
  225. flex-wrap: nowrap;
  226. }
  227. .payment .input text {
  228. padding-left: 106rpx;
  229. }
  230. .payment .input input {
  231. padding-right: 106rpx;
  232. width: 300rpx;
  233. height: 94rpx;
  234. text-align: center;
  235. font-size: 70rpx;
  236. }
  237. .payment .placeholder {
  238. color: #d0d0d0;
  239. height: 100%;
  240. line-height: 94rpx;
  241. }
  242. .payment .tip {
  243. font-size: 26rpx;
  244. color: #888888;
  245. padding: 0 30rpx;
  246. margin-top: 25rpx;
  247. }
  248. .payment .btn {
  249. color: #fff;
  250. background: #ff5c00;
  251. font-size: 30rpx;
  252. width: 700rpx;
  253. height: 86rpx;
  254. border-radius: 50rpx;
  255. margin: 46rpx auto 0 auto;
  256. line-height: 86rpx;
  257. }
  258. .payment-top {
  259. width: 100%;
  260. height: 350rpx;
  261. background-color: #ff5c00;
  262. .name {
  263. font-size: 26rpx;
  264. color: rgba(255, 255, 255, 0.8);
  265. margin-top: -38rpx;
  266. margin-bottom: 30rpx;
  267. }
  268. .pic {
  269. font-size: 32rpx;
  270. color: #fff;
  271. }
  272. .pic-font {
  273. font-size: 78rpx;
  274. color: #fff;
  275. }
  276. }
  277. .picList {
  278. display: flex;
  279. flex-wrap: wrap;
  280. margin: 30rpx 0;
  281. .pic-box {
  282. width: 32%;
  283. height: auto;
  284. border-radius: 20rpx;
  285. margin-top: 21rpx;
  286. padding: 20rpx 0;
  287. margin-right: 12rpx;
  288. &:nth-child(3n) {
  289. margin-right: 0;
  290. }
  291. }
  292. .pic-box-color {
  293. background-color: #f4f4f4;
  294. color: #656565;
  295. }
  296. .pic-number {
  297. font-size: 22rpx;
  298. }
  299. .pic-number-pic {
  300. font-size: 38rpx;
  301. margin-right: 10rpx;
  302. text-align: center;
  303. }
  304. .pic-box-color-active {
  305. background-color: #ff5c00 !important;
  306. color: #fff !important;
  307. }
  308. }
  309. .tips-box{
  310. margin-top: 70rpx;
  311. view{
  312. font-size: 28rpx;
  313. margin-bottom: 20rpx;
  314. display: flex;
  315. align-items: center;
  316. .iconfont{
  317. color:#09bb07;
  318. font-size: 45rpx;
  319. margin-right: 10rpx;
  320. }
  321. checkbox{
  322. border-radius: 0;
  323. }
  324. navigator{
  325. text-decoration: underline;
  326. }
  327. }
  328. }
  329. .tips-title{
  330. margin-top: 20rpx;
  331. font-size: 24rpx;
  332. color: #333;
  333. }
  334. </style>