index.vue 15 KB

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