You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

676 lines
16 KiB

3 months ago
  1. <template>
  2. <view :data-theme="theme" class="user_payment">
  3. <form @submit="submitSub" report-submit='true'>
  4. <view class="payment-top acea-row row-column row-center-wrapper">
  5. <span class="name1">我的余额</span>
  6. <view class="pic">
  7. <span class="pic-font">{{ userInfo.nowMoney || 0 }}</span>
  8. </view>
  9. </view>
  10. <view class="payment">
  11. <view class="nav acea-row row-around row-middle">
  12. <view class="item" :class="active==index?'on':''" v-for="(item,index) in navRecharge" :key="index" @click="navRecharges(index)">{{item}}</view>
  13. </view>
  14. <view class='tip picList' v-if='!active'>
  15. <view class="pic-box pic-box-color acea-row row-center-wrapper row-column" :class="activePic === index ? 'pic-box-color-active' : ''"
  16. v-for="(item, index) in picList" :key="index" @click="picCharge(index, item)">
  17. <view class="pic-number-pic">
  18. {{ item.price }}<span class="pic-number"> </span>
  19. </view>
  20. <view class="pic-number">赠送{{ item.giveMoney }} </view>
  21. </view>
  22. <view class="pic-box pic-box-color acea-row row-center-wrapper" :class="parseFloat(activePic)===parseFloat(picList.length)?'pic-box-color-active':''" @click="picCharge(picList.length)">
  23. <input type="number" placeholder="其他" v-model="money" maxlength="5" class="pic-box-money pic-number-pic uni-input" :class="parseFloat(activePic) === parseFloat(picList.length) ? 'pic-box-color-active' : ''" @blur="addMoney()" />
  24. </view>
  25. <view class="tips-box">
  26. <view class="tips mt-30">注意事项</view>
  27. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  28. {{ item }}
  29. </view>
  30. </view>
  31. </view>
  32. <view class="tip" v-else>
  33. <view class='input'><text></text>
  34. <input placeholder="0.00" type='number' placeholder-class='placeholder' :value="number"
  35. name="number"></input></view>
  36. <view class="tips-title">
  37. <view style="font-weight: bold; font-size: 26rpx;">提示</view>
  38. <view style="margin-top: 10rpx;">当前佣金为 <text class='font-color'>{{userInfo.brokeragePrice || 0}}</text></view>
  39. </view>
  40. <view class="tips-box">
  41. <view class="tips mt-30">注意事项</view>
  42. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  43. {{ item }}
  44. </view>
  45. </view>
  46. </view>
  47. <!-- #ifndef MP-->
  48. <view class='wrapper borRadius14 px-30' v-if='!active'>
  49. <view class='item'>
  50. <view>支付方式</view>
  51. <view class='list'>
  52. <view class='payItem acea-row row-middle' :class='curActive==index ?"on":""'
  53. @tap='payItem(index)' v-for="(item,index) in cartArr" :key='index'
  54. v-if="item.payStatus===1">
  55. <view class='name acea-row row-center-wrapper'>
  56. <view class='iconfont animated'
  57. :class='(item.icon) + " " + (animated==true&&active==index ?"bounceIn":"")'>
  58. </view>
  59. {{item.name}}
  60. </view>
  61. <view class='tip'>{{item.title}}</view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. <!-- #endif -->
  67. <button class='but' formType="submit"> {{active ? '立即转入': '立即充值' }}</button>
  68. <view class="alipaysubmit" v-html="formContent"></view>
  69. </view>
  70. </form>
  71. </view>
  72. </template>
  73. <script>
  74. import {
  75. rechargeRoutine,
  76. rechargeWechat,
  77. getRechargeApi,
  78. transferIn,
  79. appWechat,
  80. } from '@/api/user.js';
  81. import { wechatQueryPayResult,getOrderPayConfig} from '@/api/order.js';
  82. import {
  83. toLogin
  84. } from '@/libs/login.js';
  85. import {
  86. mapGetters
  87. } from "vuex";
  88. import {Debounce} from '@/utils/validate.js'
  89. let app = getApp();
  90. export default {
  91. data() {
  92. let that = this;
  93. return {
  94. now_money: 0,
  95. navRecharge: ['账户充值', '佣金转入'],
  96. active: 0,
  97. number: '',
  98. placeholder: "0.00",
  99. from: '',
  100. picList: [],
  101. activePic: 0,
  102. money: "",
  103. numberPic: '',
  104. rechar_id: 0,
  105. rechargeAttention: [],
  106. theme:app.globalData.theme,
  107. //支付方式
  108. cartArr: [{
  109. "name": "微信支付",
  110. "icon": "icon-weixin2",
  111. value: 'weixin',
  112. title: '微信快捷支付',
  113. // #ifdef APP
  114. payStatus: 0,
  115. // #endif
  116. // #ifndef APP
  117. payStatus: 1,
  118. // #endif
  119. },
  120. ],
  121. payType: 'weixin', //支付方式
  122. openType: 1, //优惠券打开方式 1=使用
  123. curActive: 0, //支付方式切换
  124. animated: false,
  125. formContent:''
  126. };
  127. },
  128. computed: mapGetters(['isLogin', 'systemPlatform','userInfo']),
  129. watch:{
  130. isLogin:{
  131. handler:function(newV,oldV){
  132. if(newV){
  133. this.getRecharge();
  134. }
  135. },
  136. deep:true
  137. }
  138. },
  139. onLoad(options) {
  140. // #ifdef H5
  141. this.from = this.$wechat.isWeixin() ? "public" : "weixinh5";
  142. // #endif
  143. // #ifdef APP-PLUS
  144. this.from = this.systemPlatform === 'ios' ? 'weixinAppIos' : 'weixinAppAndroid';
  145. // #endif
  146. if (this.isLogin) {
  147. this.getRecharge();
  148. this.payConfig();
  149. } else {
  150. toLogin();
  151. }
  152. },
  153. methods: {
  154. /**
  155. * 选择金额
  156. */
  157. picCharge(idx, item) {
  158. this.activePic = idx;
  159. if (item === undefined) {
  160. this.rechar_id = 0;
  161. this.numberPic = "";
  162. } else {
  163. this.money = "";
  164. this.rechar_id = item.id;
  165. this.numberPic = item.price;
  166. }
  167. },
  168. /**
  169. * 充值额度选择
  170. */
  171. getRecharge() {
  172. getRechargeApi()
  173. .then(res => {
  174. this.picList = res.data.rechargeQuota;
  175. if (this.picList[0]) {
  176. this.rechar_id = this.picList[0].id;
  177. this.numberPic = this.picList[0].price;
  178. }
  179. this.rechargeAttention = res.data.rechargeAttention || [];
  180. })
  181. .catch(res => {
  182. this.$dialog.toast({
  183. mes: res
  184. });
  185. });
  186. },
  187. // 支付配置
  188. payConfig(){
  189. getOrderPayConfig().then(res=>{
  190. this.cartArr[0].payStatus = res.data.payWechatOpen ? 1 : 0;
  191. // #ifndef MP
  192. // this.cartArr[1].payStatus = res.data.aliPayStatus ? 1 : 0;
  193. // #endif
  194. if(this.$wechat.isWeixin()) this.cartArr.pop();
  195. })
  196. },
  197. navRecharges: function(index) {
  198. this.active = index;
  199. },
  200. payItem: function(e) {
  201. let that = this;
  202. let active = e;
  203. that.curActive = active;
  204. that.animated = true;
  205. that.payType = that.cartArr[active].value;
  206. },
  207. /*
  208. * 用户充值
  209. */
  210. submitSub: Debounce(function(e) {
  211. let that = this
  212. let value = e.detail.value.number ? e.detail.value.number :that.numberPic;
  213. // 转入余额
  214. if (that.active) {
  215. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  216. return that.$util.Tips({
  217. title: '请输入金额'
  218. });
  219. }
  220. uni.showModal({
  221. title: '转入余额',
  222. content: '转入余额后无法再次转出,确认是否转入余额',
  223. success(res) {
  224. if (res.confirm) {
  225. transferIn({
  226. price: parseFloat(value)
  227. }).then(res => {
  228. that.$store.commit("changInfo", {
  229. amount1: 'brokeragePrice',
  230. amount2: that.$util.$h.Sub(that.userInfo.brokeragePrice, parseFloat(value))
  231. });
  232. return that.$util.Tips({
  233. title: '转入成功',
  234. icon: 'success'
  235. }, {
  236. tab: 5,
  237. url: '/pages/users/user_money/index'
  238. });
  239. }).catch(err=>{
  240. return that.$util.Tips({
  241. title: err
  242. });
  243. })
  244. } else if (res.cancel) {
  245. return that.$util.Tips({
  246. title: '已取消'
  247. });
  248. }
  249. },
  250. })
  251. } else {
  252. uni.showLoading({
  253. title: '正在支付',
  254. })
  255. let money = parseFloat(this.money);
  256. if (this.rechar_id == 0) {
  257. if (Number.isNaN(money)) {
  258. return that.$util.Tips({
  259. title: '充值金额必须为数字'
  260. });
  261. }
  262. if (money <= 0) {
  263. return that.$util.Tips({
  264. title: '充值金额不能为0'
  265. });
  266. }
  267. if (money > 50000) {
  268. return that.$util.Tips({
  269. title: '充值金额最大值为50000'
  270. });
  271. }
  272. } else {
  273. money = this.numberPic
  274. }
  275. switch (that.payType){
  276. case 'weixin':
  277. // #ifdef APP-PLUS
  278. appWechat({
  279. from: that.from,
  280. price: money,
  281. type: 0,
  282. rechar_id: this.rechar_id
  283. }).then(res => {
  284. uni.hideLoading();
  285. let jsConfig = res.data.jsConfig;
  286. uni.requestPayment({
  287. provider: 'wxpay',
  288. orderInfo: {
  289. "appid": jsConfig.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  290. "noncestr": jsConfig.nonceStr, // 随机字符串
  291. "package": "Sign=WXPay", // 固定值
  292. "partnerid": jsConfig.partnerid, // 微信支付商户号
  293. "prepayid": jsConfig.packages, // 统一下单订单号
  294. "timestamp": Number(jsConfig.timeStamp), // 时间戳(单位:秒)
  295. "sign": this.systemPlatform === 'ios' ? 'MD5' : jsConfig.paySign // 签名,这里用的 MD5 签名
  296. }, //订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  297. success: function(res) {
  298. that.$store.commit("changInfo", {
  299. amount1: 'nowMoney',
  300. amount2: that.$util.$h.Add(value, that.userInfo.nowMoney)
  301. });
  302. return that.$util.Tips({
  303. title: '支付成功',
  304. icon: 'success'
  305. }, {
  306. tab: 5,
  307. url: '/pages/users/user_money/index'
  308. });
  309. },
  310. fail: function(err) {
  311. return that.$util.Tips({
  312. title: '支付失败'
  313. });
  314. },
  315. complete: function(res) {
  316. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  317. title: '取消支付'
  318. });
  319. }
  320. })
  321. }).catch(err => {
  322. uni.hideLoading();
  323. return that.$util.Tips({
  324. title: err
  325. })
  326. });
  327. // #endif
  328. // #ifdef MP
  329. rechargeRoutine({
  330. price: money,
  331. type: 0,
  332. rechar_id: this.rechar_id
  333. }).then(res => {
  334. uni.hideLoading();
  335. let jsConfig = res.data.data.jsConfig;
  336. uni.requestPayment({
  337. timeStamp: jsConfig.timeStamp,
  338. nonceStr: jsConfig.nonceStr,
  339. package: jsConfig.packages,
  340. signType: jsConfig.signType,
  341. paySign: jsConfig.paySign,
  342. success: function(res) {
  343. that.$store.commit("changInfo", {
  344. amount1: 'nowMoney',
  345. amount2: that.$util.$h.Add(value, that.userInfo.nowMoney)
  346. });
  347. return that.$util.Tips({
  348. title: '支付成功',
  349. icon: 'success'
  350. }, {
  351. tab: 5,
  352. url: '/pages/users/user_money/index'
  353. });
  354. },
  355. fail: function(err) {
  356. return that.$util.Tips({
  357. title: '支付失败'
  358. });
  359. },
  360. complete: function(res) {
  361. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  362. title: '取消支付'
  363. });
  364. }
  365. })
  366. }).catch(err => {
  367. uni.hideLoading();
  368. return that.$util.Tips({
  369. title: err
  370. })
  371. });
  372. // #endif
  373. // #ifdef H5
  374. rechargeWechat({
  375. price: money,
  376. from: that.from,
  377. rechar_id: that.rechar_id,
  378. payType: 0
  379. }).then(res => {
  380. let jsConfig = res.data.jsConfig;
  381. let orderNo = res.data.orderNo;
  382. let data = {
  383. timestamp:jsConfig.timeStamp,
  384. nonceStr:jsConfig.nonceStr,
  385. package:jsConfig.packages,
  386. signType:jsConfig.signType,
  387. paySign:jsConfig.paySign
  388. };
  389. if (that.from == "weixinh5") {
  390. uni.hideLoading();
  391. that.$util.Tips({
  392. title: '支付成功'
  393. }, {
  394. tab: 5,
  395. url:'/pages/users/user_money/index'
  396. });
  397. setTimeout(() => {
  398. location.href = jsConfig.mwebUrl;
  399. }, 100)
  400. } else {
  401. that.$wechat.pay(data)
  402. .finally(() => {
  403. that.$store.commit("changInfo", {
  404. amount1: 'nowMoney',
  405. amount2: that.$util.$h.Add(value, that.userInfo.nowMoney)
  406. });
  407. return that.$util.Tips({
  408. title: '支付成功',
  409. icon: 'success'
  410. }, {
  411. tab: 5,
  412. url: '/pages/users/user_money/index'
  413. });
  414. })
  415. .catch(function(err) {
  416. return that.$util.Tips({
  417. title: '支付失败'
  418. });
  419. });
  420. }
  421. }).catch(res=>{
  422. uni.hideLoading();
  423. return that.$util.Tips({
  424. title: res
  425. });
  426. })
  427. // #endif
  428. break;
  429. }
  430. }
  431. }),
  432. addMoney(){
  433. this.money = this.money.replace(/[^\d]/g,'').replace(/^0{1,}/g,'');
  434. }
  435. }
  436. }
  437. </script>
  438. <style lang="scss">
  439. .user_payment{
  440. height: 100vh;
  441. background-color: #fff;
  442. }
  443. .payment {
  444. position: relative;
  445. top: -60rpx;
  446. width: 100%;
  447. background-color: #fff;
  448. border-radius: 10rpx;
  449. padding-top: 25rpx;
  450. border-top-right-radius: 14rpx;
  451. border-top-left-radius: 14rpx;
  452. }
  453. .payment .nav {
  454. height: 75rpx;
  455. line-height: 75rpx;
  456. padding: 0 100rpx;
  457. }
  458. .payment .nav .item {
  459. font-size: 30rpx;
  460. color: #333;
  461. }
  462. .payment .nav .item.on {
  463. font-weight: bold;
  464. @include tab_border_bottom(theme);
  465. }
  466. .payment .input {
  467. display: flex;
  468. align-items: center;
  469. justify-content: center;
  470. border-bottom: 1px dashed #dddddd;
  471. margin: 60rpx auto 0 auto;
  472. padding-bottom: 20rpx;
  473. font-size: 56rpx;
  474. color: #333333;
  475. flex-wrap: nowrap;
  476. }
  477. .payment .input text {
  478. padding-left: 106rpx;
  479. }
  480. .payment .input input {
  481. padding-right: 106rpx;
  482. width: 300rpx;
  483. height: 94rpx;
  484. text-align: center;
  485. font-size: 70rpx;
  486. }
  487. .payment .placeholder {
  488. color: #d0d0d0;
  489. height: 100%;
  490. line-height: 94rpx;
  491. }
  492. .payment .tip {
  493. font-size: 26rpx;
  494. color: #888888;
  495. padding: 0 30rpx;
  496. // margin-top: 25rpx;
  497. }
  498. .payment .but {
  499. color: #fff;
  500. font-size: 30rpx;
  501. width: 700rpx;
  502. height: 86rpx;
  503. border-radius: 43rpx;
  504. margin: 50rpx auto 0 auto;
  505. @include linear-gradient(theme);
  506. line-height: 86rpx;
  507. }
  508. .payment-top {
  509. width: 100%;
  510. height: 350rpx;
  511. @include main_bg_color(theme);
  512. .name1 {
  513. font-size: 26rpx;
  514. color: rgba(255, 255, 255, 0.8);
  515. margin-top: -38rpx;
  516. margin-bottom: 30rpx;
  517. }
  518. .pic {
  519. font-size: 32rpx;
  520. color: #fff;
  521. }
  522. .pic-font {
  523. font-size: 78rpx;
  524. color: #fff;
  525. }
  526. }
  527. .picList {
  528. display: flex;
  529. flex-wrap: wrap;
  530. margin: 30rpx 0;
  531. .pic-box {
  532. width: 32%;
  533. height: auto;
  534. border-radius: 20rpx;
  535. margin-top: 21rpx;
  536. padding: 20rpx 0;
  537. margin-right: 12rpx;
  538. &:nth-child(3n) {
  539. margin-right: 0;
  540. }
  541. }
  542. .pic-box-color {
  543. background-color: #f4f4f4;
  544. color: #656565;
  545. }
  546. .pic-number {
  547. font-size: 22rpx;
  548. }
  549. .pic-number-pic {
  550. font-size: 38rpx;
  551. margin-right: 10rpx;
  552. text-align: center;
  553. }
  554. }
  555. .pic-box-color-active {
  556. @include linear-gradient(theme);
  557. color: #fff !important;
  558. }
  559. .tips-box {
  560. .tips {
  561. font-size: 28rpx;
  562. color: #333333;
  563. font-weight: 800;
  564. margin-bottom: 14rpx;
  565. margin-top: 20rpx;
  566. }
  567. .tips-samll {
  568. font-size: 24rpx;
  569. color: #333333;
  570. margin-bottom: 14rpx;
  571. }
  572. .tip-box {
  573. margin-top: 30rpx;
  574. }
  575. }
  576. .tips-title {
  577. margin-top: 20rpx;
  578. font-size: 24rpx;
  579. color: #333;
  580. }
  581. .wrapper .item textarea {
  582. background-color: #f9f9f9;
  583. width: auto !important;
  584. height: 140rpx;
  585. border-radius: 14rpx;
  586. margin-top: 30rpx;
  587. padding: 15rpx;
  588. box-sizing: border-box;
  589. font-weight: 400;
  590. }
  591. .px-30{
  592. padding-left: 30rpx;
  593. padding-rigt: 30rpx;
  594. }
  595. .wrapper .item .placeholder {
  596. color: #ccc;
  597. }
  598. .wrapper .item .list {
  599. margin-top: 35rpx;
  600. }
  601. .wrapper .item .list .payItem {
  602. border: 1px solid #eee;
  603. border-radius: 14rpx;
  604. height: 86rpx;
  605. width: 95%;
  606. box-sizing: border-box;
  607. margin-top: 20rpx;
  608. font-size: 28rpx;
  609. color: #282828;
  610. }
  611. .wrapper .item .list .payItem.on {
  612. // border-color: #fc5445;
  613. @include coupons_border_color(theme);
  614. color: $theme-color;
  615. }
  616. .name {
  617. width: 50%;
  618. text-align: center;
  619. border-right: 1px solid #eee;
  620. }
  621. .name .iconfont {
  622. width: 44rpx;
  623. height: 44rpx;
  624. border-radius: 50%;
  625. text-align: center;
  626. line-height: 44rpx;
  627. background-color: #fe960f;
  628. color: #fff;
  629. font-size: 30rpx;
  630. margin-right: 15rpx;
  631. }
  632. .name .iconfont.icon-weixin2 {
  633. background-color: #41b035;
  634. }
  635. .name .iconfont.icon-zhifubao {
  636. background-color: #00AAEA;
  637. }
  638. .payItem .tip {
  639. width: 49%;
  640. text-align: center;
  641. font-size: 26rpx;
  642. color: #aaa;
  643. }
  644. </style>