index.vue 15 KB

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