index.vue 16 KB

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