index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <template>
  2. <view>
  3. <form @submit="submitSub" :style="colorStyle">
  4. <view class="payment-top acea-row row-column row-center-wrapper">
  5. <span class="name">我的余额</span>
  6. <view class="pic">
  7. ¥<span class="pic-font">{{ userinfo.now_money || 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"
  13. @click="navRecharges(index)">{{item}}</view>
  14. </view>
  15. <view class='tip picList' v-if='!active'>
  16. <view class="pic-box pic-box-color acea-row row-center-wrapper row-column"
  17. :class="activePic == index ? 'pic-box-color-active' : ''" v-for="(item, index) in picList"
  18. :key="index" @click="picCharge(index, item)" v-if="item.price">
  19. <view class="pic-number-pic">
  20. {{ item.price }}<span class="pic-number"> 元</span>
  21. </view>
  22. <view class="pic-number">赠送:{{ item.give_money }} 元</view>
  23. </view>
  24. <view class="pic-box pic-box-color acea-row row-center-wrapper"
  25. :class="activePic == picList.length ? 'pic-box-color-active' : ''"
  26. @click="picCharge(picList.length)">
  27. <input type="digit" placeholder="其他" v-model="money" class="pic-box-money pic-number-pic"
  28. :class="activePic == picList.length ? 'pic-box-color-active' : ''" />
  29. </view>
  30. <view class="tips-box">
  31. <view class="tips mt-30">注意事项:</view>
  32. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  33. {{ item }}
  34. </view>
  35. </view>
  36. </view>
  37. <view class="tip" v-else>
  38. <view class='input'><text>¥</text><input @input='inputNum' :maxlength="moneyMaxLeng"
  39. placeholder="0.00" type='digit' placeholder-class='placeholder' :value="number"
  40. name="number"></input></view>
  41. <view class="tips-title">
  42. <view style="font-weight: bold; font-size: 26rpx;">提示:</view>
  43. <view style="margin-top: 10rpx;">当前可转入佣金为 <text
  44. class='font-color'>¥{{userinfo.commissionCount || 0}}</text>,冻结佣金为<text
  45. class='font-color'>¥{{userinfo.broken_commission}}</text></view>
  46. </view>
  47. <view class="tips-box">
  48. <view class="tips mt-30">注意事项:</view>
  49. <view class="tips-samll" v-for="item in rechargeAttention" :key="item">
  50. {{ item }}
  51. </view>
  52. </view>
  53. </view>
  54. <button class='but bg-color' formType="submit"> {{active ? '立即转入': '立即充值' }}</button>
  55. </view>
  56. </form>
  57. <payment :payMode="payMode" :pay_close="pay_close" :is-call="true" @changePayType="changePayType"
  58. @onChangeFun="onChangeFun" :order_id="pay_order_id" :totalPrice="totalPrice"></payment>
  59. <home v-if="navigation"></home>
  60. <view v-show="false" v-html="formContent"></view>
  61. <!-- #ifdef MP -->
  62. <!-- <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize> -->
  63. <!-- #endif -->
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. getUserInfo,
  69. rechargeRoutine,
  70. rechargeRecharge,
  71. rechargeWechat,
  72. getRechargeApi,
  73. memberCardCreate
  74. } from '@/api/user.js';
  75. import payment from '@/components/payment';
  76. import {
  77. toLogin
  78. } from '@/libs/login.js';
  79. import {
  80. orderOfflinePayType
  81. } from '@/api/order.js';
  82. import {
  83. mapGetters
  84. } from "vuex";
  85. import home from '@/components/home';
  86. import colors from "@/mixins/color";
  87. import {
  88. openPaySubscribe
  89. } from '@/utils/SubscribeMessage.js';
  90. export default {
  91. components: {
  92. home,
  93. payment
  94. },
  95. mixins: [colors],
  96. data() {
  97. let that = this;
  98. return {
  99. now_money: 0,
  100. navRecharge: ['账户充值', '佣金转入'],
  101. active: 0,
  102. number: '',
  103. userinfo: {},
  104. placeholder: "0.00",
  105. from: '',
  106. isAuto: false, //没有授权的不会自动授权
  107. isShowAuth: false, //是否隐藏授权
  108. picList: [],
  109. activePic: 0,
  110. money: "",
  111. numberPic: '',
  112. rechar_id: 0,
  113. password: '',
  114. goodsList: [],
  115. pay_order_id: '',
  116. payMode: [{
  117. name: '微信支付',
  118. icon: 'icon-weixinzhifu',
  119. value: 'weixin',
  120. title: '微信快捷支付',
  121. payStatus: true
  122. }
  123. // #ifdef H5 ||APP-PLUS
  124. ,
  125. {
  126. name: '支付宝支付',
  127. icon: 'icon-zhifubao',
  128. value: 'alipay',
  129. title: '支付宝支付',
  130. payStatus: true
  131. }
  132. // #endif
  133. ,
  134. {
  135. "name": "慧付",
  136. "icon": "icon-yuezhifu1",
  137. value: 'huifu',
  138. title: '选择慧付支付',
  139. payStatus: true,
  140. }
  141. ],
  142. pay_close: false,
  143. payType: '',
  144. totalPrice: '0',
  145. formContent: '',
  146. // #ifdef H5
  147. isWeixin: this.$wechat.isWeixin(),
  148. // #endif
  149. type: '',
  150. rechargeAttention: [],
  151. moneyMaxLeng: 8
  152. };
  153. },
  154. computed: mapGetters(['isLogin']),
  155. watch: {
  156. isLogin: {
  157. handler: function(newV, oldV) {
  158. if (newV) {
  159. this.getOrderPayType();
  160. this.getUserInfo();
  161. this.getRecharge();
  162. }
  163. },
  164. deep: true
  165. }
  166. },
  167. onLoad(options) {
  168. // #ifdef H5
  169. this.from = this.$wechat.isWeixin() ? "weixinh5" : "alipay"
  170. // #endif
  171. if (this.isLogin) {
  172. this.getOrderPayType();
  173. this.getUserInfo();
  174. this.getRecharge();
  175. } else {
  176. toLogin();
  177. }
  178. },
  179. onShow() {
  180. uni.removeStorageSync('form_type_cart');
  181. },
  182. methods: {
  183. onLunch() {
  184. this.getOrderPayType();
  185. this.getUserInfo();
  186. this.getRecharge();
  187. },
  188. inputNum: function(e) {
  189. let val = e.detail.value;
  190. let dot = val.indexOf('.');
  191. if (dot > -1) {
  192. this.moneyMaxLeng = dot + 3;
  193. } else {
  194. this.moneyMaxLeng = 8
  195. }
  196. },
  197. /**
  198. * 选择金额
  199. */
  200. picCharge(idx, item) {
  201. this.activePic = idx;
  202. if (item === undefined) {
  203. this.rechar_id = 0;
  204. this.numberPic = "";
  205. } else {
  206. this.money = "";
  207. this.rechar_id = item.id;
  208. this.numberPic = item.price;
  209. }
  210. },
  211. /**
  212. * 充值额度选择
  213. */
  214. getRecharge() {
  215. getRechargeApi()
  216. .then(res => {
  217. this.picList = res.data.recharge_quota;
  218. if (this.picList[0]) {
  219. this.rechar_id = this.picList[0].id;
  220. this.numberPic = this.picList[0].price;
  221. }
  222. this.rechargeAttention = res.data.recharge_attention || [];
  223. })
  224. .catch(res => {
  225. this.$util.Tips({
  226. title: res
  227. })
  228. });
  229. },
  230. getOrderPayType() {
  231. orderOfflinePayType().then(res => {
  232. const {
  233. ali_pay_status,
  234. pay_weixin_open
  235. } = res.data;
  236. this.payMode[0].payStatus = !!pay_weixin_open;
  237. // #ifdef APP-PLUS || H5
  238. this.payMode[1].payStatus = !!ali_pay_status;
  239. // #endif
  240. }).catch(err => {
  241. uni.showToast({
  242. title: err,
  243. icon: 'none'
  244. });
  245. });
  246. },
  247. onLoadFun: function() {
  248. this.getOrderPayType();
  249. this.getUserInfo();
  250. this.getRecharge();
  251. this.isShowAuth = false;
  252. },
  253. // 授权关闭
  254. authColse: function(e) {
  255. this.isShowAuth = e
  256. },
  257. navRecharges: function(index) {
  258. this.active = index;
  259. },
  260. /**
  261. * 获取用户信息
  262. */
  263. getUserInfo: function() {
  264. let that = this;
  265. getUserInfo().then(res => {
  266. that.$set(that, 'userinfo', res.data);
  267. })
  268. },
  269. changePayType: function(e) {
  270. console.log(e, '267');
  271. this.payType = e;
  272. // #ifdef H5
  273. if (!this.$wechat.isWeixin() && this.payType == 'weixin') {
  274. this.payType = 'weixinh5';
  275. }
  276. // #endif
  277. // #ifdef MP
  278. if (this.payType == 'weixin') {
  279. this.payType = 'routine'
  280. }
  281. // #endif
  282. console.log('双方各大华股份不报错', this.payType);
  283. },
  284. onChangeFun: function(e) {
  285. let opt = e;
  286. let action = opt.action || null;
  287. let value = opt.value != undefined ? opt.value : null;
  288. action && this[action] && this[action](value);
  289. },
  290. payClose: function() {
  291. this.pay_close = false;
  292. },
  293. payCheck: function(type) {
  294. this.createMemberCard(type);
  295. },
  296. createMemberCard(type) {
  297. if (!this.payType) {
  298. this.payType = type;
  299. // #ifdef H5
  300. if (!this.$wechat.isWeixin() && this.payType == 'weixin') {
  301. this.payType = 'weixinh5';
  302. }
  303. // #endif
  304. // #ifdef MP
  305. if (this.payType == 'weixin') {
  306. this.payType = 'routine'
  307. }
  308. // #endif
  309. }
  310. uni.showLoading({
  311. title: '正在加载…'
  312. });
  313. // #ifdef MP || APP-PLUS
  314. uni.showLoading({
  315. title: '正在支付',
  316. })
  317. let that = this
  318. let money = parseFloat(this.money);
  319. if (this.rechar_id == 0) {
  320. if (Number.isNaN(money)) {
  321. return that.$util.Tips({
  322. title: '充值金额必须为数字'
  323. });
  324. }
  325. if (money <= 0) {
  326. return that.$util.Tips({
  327. title: '充值金额不能为0'
  328. });
  329. }
  330. } else {
  331. // money = this.numberPic
  332. }
  333. if (this.payType != 'huifu') {
  334. rechargeRecharge({
  335. price: parseFloat(this.totalPrice),
  336. type: 0,
  337. rechar_id: this.rechar_id,
  338. from: this.payType
  339. }).then(res => {
  340. uni.hideLoading();
  341. let data = res.data.data;
  342. let mp_pay_name = ''
  343. if (uni.requestOrderPayment) {
  344. mp_pay_name = 'requestOrderPayment'
  345. } else {
  346. mp_pay_name = 'requestPayment'
  347. }
  348. uni[mp_pay_name]({
  349. // #ifdef MP
  350. timeStamp: data.timestamp,
  351. nonceStr: data.nonceStr,
  352. package: data.package,
  353. signType: data.signType,
  354. paySign: data.paySign,
  355. // #endif
  356. // #ifdef APP-PLUS
  357. provider: this.payType === 'alipay' ? 'alipay' : 'wxpay',
  358. orderInfo: data,
  359. // #endif
  360. success: function(res) {
  361. return that.$util.Tips({
  362. title: '支付成功',
  363. icon: 'success'
  364. }, {
  365. tab: 5,
  366. url: '/pages/users/user_money/index'
  367. });
  368. },
  369. fail: function() {
  370. return that.$util.Tips({
  371. title: '支付失败'
  372. });
  373. },
  374. complete: function(res) {
  375. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  376. title: '取消支付'
  377. });
  378. }
  379. })
  380. }).catch(err => {
  381. uni.hideLoading();
  382. return that.$util.Tips({
  383. title: err
  384. })
  385. });
  386. } else {
  387. rechargeRecharge({
  388. price: parseFloat(this.totalPrice),
  389. type: 0,
  390. rechar_id: this.rechar_id,
  391. from: this.payType
  392. }).then(res => {
  393. uni.hideLoading();
  394. // #ifdef MP
  395. let data = JSON.parse(res.data.data.data.pay_info);
  396. console.log(data,"data")
  397. uni.requestPayment({
  398. timeStamp: data.timeStamp,
  399. nonceStr: data.nonceStr,
  400. package: data.package,
  401. signType: data.signType,
  402. paySign: data.paySign,
  403. success: function(res) {
  404. return that.$util.Tips({
  405. title: '支付成功',
  406. icon: 'success'
  407. }, {
  408. tab: 5,
  409. url: '/pages/users/user_money/index'
  410. });
  411. },
  412. fail: function() {
  413. return that.$util.Tips({
  414. title: '支付失败'
  415. });
  416. },
  417. complete: function(res) {
  418. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  419. title: '取消支付'
  420. });
  421. }
  422. })
  423. // #endif
  424. }).catch(err => {
  425. uni.hideLoading();
  426. return that.$util.Tips({
  427. title: err
  428. })
  429. });
  430. }
  431. // #endif
  432. // #ifdef H5
  433. let that = this
  434. this.pay_close = true;
  435. this.totalPrice = this.rechar_id == 0 ? this.money : this.numberPic;
  436. if (!this.payType) {
  437. this.changePayType(type);
  438. }
  439. rechargeWechat({
  440. price: parseFloat(this.totalPrice),
  441. // from: this.payType == '' ? this.$wechat.isWeixin() ? 'weixin' :'weixinh5' : this.payType,
  442. from: this.payType,
  443. rechar_id: that.rechar_id
  444. }).then(res => {
  445. let data = res.data;
  446. if (data.type == "weixinh5") {
  447. uni.showToast({
  448. title: data.msg,
  449. success() {
  450. location.href = data.data.mweb_url;
  451. }
  452. });
  453. } else if (data.type == "alipay") {
  454. uni.hideLoading();
  455. uni.hideLoading();
  456. this.formContent = data.data;
  457. this.$nextTick(() => {
  458. document.getElementById('alipaysubmit').submit();
  459. });
  460. } else if (data.type == "weixin") {
  461. this.$wechat.pay(data.data).then(res => {
  462. this.$util.Tips({
  463. title: '支付成功',
  464. icon: 'success'
  465. }, {
  466. tab: 5,
  467. url: '/pages/users/user_money/index'
  468. });
  469. }).catch(err => {
  470. if (err.errMsg == 'chooseWXPay:cancel') {
  471. uni.showToast({
  472. title: '取消支付',
  473. icon: 'none'
  474. });
  475. }
  476. });
  477. } else if (data.type == "huifu") {
  478. this.$wechat.pay(data.data).then(res => {
  479. this.$util.Tips({
  480. title: '支付成功',
  481. icon: 'success'
  482. }, {
  483. tab: 5,
  484. url: '/pages/users/user_money/index'
  485. });
  486. }).catch(err => {
  487. if (err.errMsg == 'chooseWXPay:cancel') {
  488. uni.showToast({
  489. title: '取消支付',
  490. icon: 'none'
  491. });
  492. }
  493. });
  494. }
  495. }).catch(err => {
  496. uni.hideLoading();
  497. return that.$util.Tips({
  498. title: err
  499. })
  500. })
  501. // #endif
  502. },
  503. /*
  504. * 用户充值
  505. */
  506. submitSub: function(e) {
  507. let that = this
  508. let value = e.detail.value.number;
  509. // 转入余额
  510. if (that.active) {
  511. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  512. return that.$util.Tips({
  513. title: '请输入金额'
  514. });
  515. }
  516. uni.showModal({
  517. title: '转入余额',
  518. content: '转入余额后无法再次转出,确认是否转入余额',
  519. success(res) {
  520. if (res.confirm) {
  521. // #ifdef MP || APP-PLUS
  522. rechargeRoutine({
  523. price: parseFloat(value),
  524. type: 1
  525. })
  526. // #endif
  527. // #ifdef H5
  528. rechargeWechat({
  529. price: parseFloat(value),
  530. from: that.from,
  531. type: 1
  532. })
  533. // #endif
  534. .then(res => {
  535. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
  536. return that.$util.Tips({
  537. title: '转入成功',
  538. icon: 'success'
  539. }, {
  540. tab: 5,
  541. url: '/pages/users/user_money/index'
  542. });
  543. }).catch(err => {
  544. return that.$util.Tips({
  545. title: err
  546. })
  547. });
  548. } else if (res.cancel) {
  549. return that.$util.Tips({
  550. title: '已取消'
  551. });
  552. }
  553. },
  554. })
  555. } else {
  556. // #ifdef MP
  557. this.pay_close = true;
  558. // #endif
  559. // #ifndef MP
  560. this.pay_close = true;
  561. // #endif
  562. this.totalPrice = this.rechar_id == 0 ? parseFloat(this.money) : parseFloat(this.numberPic);
  563. }
  564. }
  565. }
  566. }
  567. </script>
  568. <style lang="scss">
  569. page {
  570. width: 100%;
  571. height: 100%;
  572. background-color: #fff;
  573. }
  574. .bgcolor {
  575. background-color: var(--view-theme)
  576. }
  577. .payment {
  578. position: relative;
  579. width: 100%;
  580. background-color: #fff;
  581. border-radius: 10rpx;
  582. padding-top: 25rpx;
  583. border-top-right-radius: 39rpx;
  584. border-top-left-radius: 39rpx;
  585. }
  586. .payment .nav {
  587. height: 75rpx;
  588. line-height: 75rpx;
  589. padding: 0 100rpx;
  590. }
  591. .payment .nav .item {
  592. font-size: 30rpx;
  593. color: #333;
  594. }
  595. .payment .nav .item.on {
  596. font-weight: bold;
  597. border-bottom: 4rpx solid var(--view-theme);
  598. }
  599. .payment .input {
  600. display: flex;
  601. align-items: center;
  602. justify-content: center;
  603. border-bottom: 1px dashed #dddddd;
  604. margin: 60rpx auto 0 auto;
  605. padding-bottom: 20rpx;
  606. font-size: 56rpx;
  607. color: #333333;
  608. flex-wrap: nowrap;
  609. }
  610. .payment .input text {
  611. padding-left: 106rpx;
  612. }
  613. .payment .input input {
  614. padding-right: 106rpx;
  615. width: 300rpx;
  616. height: 94rpx;
  617. text-align: center;
  618. font-size: 70rpx;
  619. }
  620. .payment .placeholder {
  621. color: #d0d0d0;
  622. height: 100%;
  623. line-height: 94rpx;
  624. }
  625. .payment .tip {
  626. font-size: 26rpx;
  627. color: #888888;
  628. padding: 0 30rpx;
  629. margin-top: 25rpx;
  630. }
  631. .payment .but {
  632. color: #fff;
  633. font-size: 30rpx;
  634. width: 700rpx;
  635. height: 86rpx;
  636. border-radius: 50rpx;
  637. margin: 46rpx auto 0 auto;
  638. line-height: 86rpx;
  639. }
  640. .payment-top {
  641. width: 100%;
  642. height: 350rpx;
  643. background-color: var(--view-theme);
  644. .name {
  645. font-size: 26rpx;
  646. color: rgba(255, 255, 255, 0.8);
  647. margin-top: -38rpx;
  648. margin-bottom: 30rpx;
  649. }
  650. .pic {
  651. font-size: 32rpx;
  652. color: #fff;
  653. }
  654. .pic-font {
  655. font-size: 78rpx;
  656. color: #fff;
  657. }
  658. }
  659. .picList {
  660. display: flex;
  661. flex-wrap: wrap;
  662. margin: 30rpx 0;
  663. .pic-box {
  664. width: 32%;
  665. height: auto;
  666. border-radius: 20rpx;
  667. margin-top: 21rpx;
  668. padding: 20rpx 0;
  669. margin-right: 12rpx;
  670. &:nth-child(3n) {
  671. margin-right: 0;
  672. }
  673. }
  674. .pic-box-color {
  675. background-color: #f4f4f4;
  676. color: #656565;
  677. }
  678. .pic-number {
  679. font-size: 22rpx;
  680. }
  681. .pic-number-pic {
  682. font-size: 38rpx;
  683. margin-right: 10rpx;
  684. text-align: center;
  685. }
  686. .pic-box-color-active {
  687. background-color: var(--view-theme) !important;
  688. color: #fff !important;
  689. }
  690. }
  691. .tips-box {
  692. .tips {
  693. font-size: 28rpx;
  694. color: #333333;
  695. font-weight: 800;
  696. margin-bottom: 14rpx;
  697. margin-top: 20rpx;
  698. }
  699. .tips-samll {
  700. font-size: 24rpx;
  701. color: #333333;
  702. margin-bottom: 14rpx;
  703. }
  704. .tip-box {
  705. margin-top: 30rpx;
  706. }
  707. }
  708. .tips-title {
  709. margin-top: 20rpx;
  710. font-size: 24rpx;
  711. color: #333;
  712. }
  713. </style>