index.vue 16 KB

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