index.vue 17 KB

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