index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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. // #ifndef APP-PLUS
  110. {
  111. name: '微信支付',
  112. icon: 'icon-weixinzhifu',
  113. value: 'weixin',
  114. title: '微信快捷支付',
  115. payStatus: true
  116. },
  117. // #endif
  118. // #ifdef H5 ||APP-PLUS
  119. ,
  120. {
  121. name: '支付宝支付',
  122. icon: 'icon-zhifubao',
  123. value: 'alipay',
  124. title: '支付宝支付',
  125. payStatus: true
  126. }
  127. // #endif
  128. ],
  129. pay_close: false,
  130. payType: '',
  131. totalPrice: '0',
  132. formContent: '',
  133. // #ifdef H5
  134. isWeixin: this.$wechat.isWeixin(),
  135. // #endif
  136. type: '',
  137. rechargeAttention:[],
  138. moneyMaxLeng:8
  139. };
  140. },
  141. computed: mapGetters(['isLogin']),
  142. watch:{
  143. isLogin:{
  144. handler:function(newV,oldV){
  145. if(newV){
  146. //#ifndef MP
  147. this.getOrderPayType();
  148. this.getUserInfo();
  149. this.getRecharge();
  150. //#endif
  151. }
  152. },
  153. deep:true
  154. }
  155. },
  156. onLoad(options) {
  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. return that.$util.Tips({
  332. title: '支付成功',
  333. icon: 'success'
  334. }, {
  335. tab: 5,
  336. url: '/pages/users/user_money/index'
  337. });
  338. },
  339. fail: function() {
  340. return that.$util.Tips({
  341. title: '支付失败'
  342. });
  343. },
  344. complete: function(res) {
  345. if (res.errMsg == 'requestPayment:cancel') return that.$util.Tips({
  346. title: '取消支付'
  347. });
  348. }
  349. })
  350. }).catch(err => {
  351. uni.hideLoading();
  352. return that.$util.Tips({
  353. title: err
  354. })
  355. });
  356. // #endif
  357. // #ifdef H5
  358. let that = this
  359. this.pay_close = true;
  360. this.totalPrice = this.rechar_id == 0 ? this.money : this.numberPic;
  361. if (!this.payType) {
  362. this.changePayType(type);
  363. }
  364. rechargeWechat({
  365. price: parseFloat(this.totalPrice),
  366. // from: this.payType == '' ? this.$wechat.isWeixin() ? 'weixin' :'weixinh5' : this.payType,
  367. from: this.payType,
  368. rechar_id: that.rechar_id
  369. }).then(res => {
  370. let data = res.data;
  371. if (data.type == "weixinh5") {
  372. uni.showToast({
  373. title: data.msg,
  374. success() {
  375. location.href = data.data.mweb_url;
  376. }
  377. });
  378. }else if(data.type == "alipay") {
  379. uni.hideLoading();
  380. uni.hideLoading();
  381. this.formContent = data.data;
  382. this.$nextTick(() => {
  383. document.getElementById('alipaysubmit').submit();
  384. });
  385. }else if(data.type == "weixin") {
  386. this.$wechat.pay(data.data).then(res => {
  387. this.$util.Tips({
  388. title: '支付成功',
  389. icon: 'success'
  390. }, {
  391. tab: 5,
  392. url: '/pages/users/user_money/index'
  393. });
  394. }).catch(err => {
  395. if (err.errMsg == 'chooseWXPay:cancel') {
  396. uni.showToast({
  397. title: '取消支付',
  398. icon: 'none'
  399. });
  400. }
  401. });
  402. }
  403. }).catch(err=>{
  404. uni.hideLoading();
  405. return that.$util.Tips({
  406. title: err
  407. })
  408. })
  409. // #endif
  410. },
  411. /*
  412. * 用户充值
  413. */
  414. submitSub: function(e) {
  415. let that = this
  416. let value = e.detail.value.number;
  417. // 转入余额
  418. if (that.active) {
  419. if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
  420. return that.$util.Tips({
  421. title: '请输入金额'
  422. });
  423. }
  424. uni.showModal({
  425. title: '转入余额',
  426. content: '转入余额后无法再次转出,确认是否转入余额',
  427. success(res) {
  428. if (res.confirm) {
  429. // #ifdef MP || APP-PLUS
  430. rechargeRoutine({
  431. price: parseFloat(value),
  432. type: 1
  433. })
  434. // #endif
  435. // #ifdef H5
  436. rechargeWechat({
  437. price: parseFloat(value),
  438. from: that.from,
  439. type: 1
  440. })
  441. // #endif
  442. .then(res => {
  443. // that.$set(that, 'userinfo.now_money', that.$util.$h.Add(value, that.userinfo.now_money))
  444. return that.$util.Tips({
  445. title: '转入成功',
  446. icon: 'success'
  447. }, {
  448. tab: 5,
  449. url: '/pages/users/user_money/index'
  450. });
  451. }).catch(err => {
  452. return that.$util.Tips({
  453. title: err
  454. })
  455. });
  456. } else if (res.cancel) {
  457. return that.$util.Tips({
  458. title: '已取消'
  459. });
  460. }
  461. },
  462. })
  463. } else {
  464. // #ifdef MP
  465. this.pay_close = true;
  466. // #endif
  467. // #ifndef MP
  468. this.pay_close = true;
  469. // #endif
  470. this.totalPrice = this.rechar_id == 0 ? parseFloat(this.money) : parseFloat(this.numberPic);
  471. }
  472. }
  473. }
  474. }
  475. </script>
  476. <style lang="scss">
  477. page {
  478. width: 100%;
  479. height: 100%;
  480. background-color: #fff;
  481. }
  482. .bgcolor{
  483. background-color: var(--view-theme)
  484. }
  485. .payment {
  486. position: relative;
  487. width: 100%;
  488. background-color: #fff;
  489. border-radius: 10rpx;
  490. padding-top: 25rpx;
  491. border-top-right-radius: 39rpx;
  492. border-top-left-radius: 39rpx;
  493. }
  494. .payment .nav {
  495. height: 75rpx;
  496. line-height: 75rpx;
  497. padding: 0 100rpx;
  498. }
  499. .payment .nav .item {
  500. font-size: 30rpx;
  501. color: #333;
  502. }
  503. .payment .nav .item.on {
  504. font-weight: bold;
  505. border-bottom: 4rpx solid var(--view-theme);
  506. }
  507. .payment .input {
  508. display: flex;
  509. align-items: center;
  510. justify-content: center;
  511. border-bottom: 1px dashed #dddddd;
  512. margin: 60rpx auto 0 auto;
  513. padding-bottom: 20rpx;
  514. font-size: 56rpx;
  515. color: #333333;
  516. flex-wrap: nowrap;
  517. }
  518. .payment .input text {
  519. padding-left: 106rpx;
  520. }
  521. .payment .input input {
  522. padding-right: 106rpx;
  523. width: 300rpx;
  524. height: 94rpx;
  525. text-align: center;
  526. font-size: 70rpx;
  527. }
  528. .payment .placeholder {
  529. color: #d0d0d0;
  530. height: 100%;
  531. line-height: 94rpx;
  532. }
  533. .payment .tip {
  534. font-size: 26rpx;
  535. color: #888888;
  536. padding: 0 30rpx;
  537. margin-top: 25rpx;
  538. }
  539. .payment .but {
  540. color: #fff;
  541. font-size: 30rpx;
  542. width: 700rpx;
  543. height: 86rpx;
  544. border-radius: 50rpx;
  545. margin: 46rpx auto 0 auto;
  546. line-height: 86rpx;
  547. }
  548. .payment-top {
  549. width: 100%;
  550. height: 350rpx;
  551. background-color: var(--view-theme);
  552. .name {
  553. font-size: 26rpx;
  554. color: rgba(255, 255, 255, 0.8);
  555. margin-top: -38rpx;
  556. margin-bottom: 30rpx;
  557. }
  558. .pic {
  559. font-size: 32rpx;
  560. color: #fff;
  561. }
  562. .pic-font {
  563. font-size: 78rpx;
  564. color: #fff;
  565. }
  566. }
  567. .picList {
  568. display: flex;
  569. flex-wrap: wrap;
  570. margin: 30rpx 0;
  571. .pic-box {
  572. width: 32%;
  573. height: auto;
  574. border-radius: 20rpx;
  575. margin-top: 21rpx;
  576. padding: 20rpx 0;
  577. margin-right: 12rpx;
  578. &:nth-child(3n) {
  579. margin-right: 0;
  580. }
  581. }
  582. .pic-box-color {
  583. background-color: #f4f4f4;
  584. color: #656565;
  585. }
  586. .pic-number {
  587. font-size: 22rpx;
  588. }
  589. .pic-number-pic {
  590. font-size: 38rpx;
  591. margin-right: 10rpx;
  592. text-align: center;
  593. }
  594. .pic-box-color-active {
  595. background-color: var(--view-theme) !important;
  596. color: #fff !important;
  597. }
  598. }
  599. .tips-box{
  600. .tips {
  601. font-size: 28rpx;
  602. color: #333333;
  603. font-weight: 800;
  604. margin-bottom: 14rpx;
  605. margin-top: 20rpx;
  606. }
  607. .tips-samll {
  608. font-size: 24rpx;
  609. color: #333333;
  610. margin-bottom: 14rpx;
  611. }
  612. .tip-box {
  613. margin-top: 30rpx;
  614. }
  615. }
  616. .tips-title{
  617. margin-top: 20rpx;
  618. font-size: 24rpx;
  619. color: #333;
  620. }
  621. </style>