recharge.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <view class="content">
  3. <view class="yue">
  4. <view class="font">当前余额</view>
  5. <view class="money">{{ nowmoney | getMoneyStyle }}</view>
  6. </view>
  7. <view class="row-box">
  8. <view class="title">充值金额</view>
  9. <view class="row">
  10. <text class="tit">¥</text>
  11. <input class="input" type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="placeholder" />
  12. </view>
  13. </view>
  14. <view class="list">
  15. <radio-group @change="tabRadio">
  16. <!-- #ifdef APP-PLUS -->
  17. <label>
  18. <view class="box">
  19. <view class="icon iconfont iconweixin1"></view>
  20. <view class="title-box">
  21. <view class="title"><text>微信充值</text></view>
  22. </view>
  23. <view class="right"><radio value="weixin" color=" #456ffb" :checked="type == 'weixin'" /></view>
  24. </view>
  25. </label>
  26. <!-- #endif -->
  27. <!-- #ifdef APP-PLUS -->
  28. <!-- <label>
  29. <view class="box">
  30. <view class="icon iconfont iconzhifubao"></view>
  31. <view class="title-box">
  32. <view class="title"><text>支付宝支付</text></view>
  33. </view>
  34. <view class="right"><radio value="ali" color=" #456ffb" :checked="type == 'ali'" /></view>
  35. </view>
  36. </label> -->
  37. <!-- #endif -->
  38. <label>
  39. <view class="box">
  40. <view class="icon iconfont"><image class="yongjing" src="http://xmpt.liuniu946.com/img/yongjing.png"></image></view>
  41. <view class="title-box">
  42. <view class="title"><text>佣金充值</text></view>
  43. <view class="node">可用佣金¥{{ yongMoney ? yongMoney : 0 }}</view>
  44. </view>
  45. <view class="right"><radio value="yongjing" color=" #456ffb" :checked="type == 'yongjing'" /></view>
  46. </view>
  47. </label>
  48. </radio-group>
  49. </view>
  50. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认充值</button>
  51. </view>
  52. </template>
  53. <script>
  54. import { getMoneyStyle } from '@/utils/rocessor.js';
  55. import { userBalance, extractBank, rechargeWechat } from '@/api/wallet.js';
  56. // #ifdef H5
  57. import weixinObj from '@/plugin/jweixin-module/index.js';
  58. // #endif
  59. // #ifdef MP
  60. import { rechargeRoutine } from '@/api/wallet.js';
  61. // #endif
  62. // #ifdef APP-PLUS
  63. import { rechargeApp, rechargeAli, moneyChong } from '@/api/wallet.js';
  64. // #endif
  65. import { mapState } from 'vuex';
  66. export default {
  67. filters: {
  68. getMoneyStyle
  69. },
  70. data() {
  71. return {
  72. // #ifdef H5
  73. type: 'yongjing',
  74. // #endif
  75. // #ifndef H5
  76. type: 'yongjing',
  77. // #endif
  78. money: '', //充值金额
  79. payLoding: false, //是否加载中
  80. yongMoney: '',
  81. nowmoney: '',
  82. typeText: 1 //默认支付方式
  83. };
  84. },
  85. watch: {
  86. type(newValue, oldValue) {
  87. console.log(newValue);
  88. console.log(oldValue);
  89. }
  90. },
  91. onShow() {
  92. this.yongMoney = '';
  93. userBalance({}).then(({ data }) => {
  94. console.log(data);
  95. this.nowmoney = data.now_money;
  96. });
  97. extractBank({}).then(({ data }) => {
  98. this.yongMoney = (data.commissionCount * 1).toFixed(2); //累积佣金
  99. console.log(data, 'wwwww');
  100. this.disable = true;
  101. });
  102. },
  103. onLoad(options) {},
  104. computed: {
  105. // #ifdef H5
  106. ...mapState(['weichatObj'])
  107. // #endif
  108. },
  109. methods: {
  110. // 跳转
  111. navTo(url) {
  112. uni.navigateTo({
  113. url: url
  114. });
  115. },
  116. // 切换选中对象
  117. tabRadio(e) {
  118. if (e.detail.value == 'weixin') {
  119. this.typeText = 0;
  120. }
  121. if (e.detail.value == 'yongjing') {
  122. this.typeText = 1;
  123. }
  124. // if (e.detail.value == 'ali') {
  125. // this.typeText = 2;
  126. // }
  127. // #ifdef APP-PLUS
  128. this.type = e.target.value;
  129. // #endif
  130. // #ifndef APP-PLUS
  131. this.type = e.detail.value;
  132. // #endif
  133. console.log(this.typeText);
  134. },
  135. // 提交
  136. // confirm() {
  137. // let obj = this;
  138. // obj.payLoding = true;
  139. // // #ifdef H5
  140. // rechargeWechat({ price: this.money, from: this.type })
  141. // .then(e => {
  142. // let da = e.data.data;
  143. // obj.weichatObj.chooseWXPay({
  144. // timestamp: da.timestamp,
  145. // nonceStr: da.nonceStr,
  146. // package: da.package,
  147. // signType: da.signType,
  148. // paySign: da.paySign,
  149. // success: function(res) {
  150. // uni.showToast({
  151. // title: '充值成功',
  152. // duration: 2000,
  153. // position: 'top'
  154. // });
  155. // }
  156. // });
  157. // obj.payLoding = false;
  158. // })
  159. // .catch(e => {
  160. // obj.payLoding = false;
  161. // console.log(e);
  162. // });
  163. // // #endif
  164. // // #ifdef MP
  165. // rechargeRoutine({ price: this.money})
  166. // .then(e => {
  167. // let da = e.data;
  168. // wx.requestPayment({
  169. // timeStamp: da.timestamp,
  170. // nonceStr: da.nonceStr,
  171. // package: da.package,
  172. // signType: da.signType,
  173. // paySign: da.paySign,
  174. // success: function(res) {
  175. // uni.redirectTo({
  176. // url: '/pages/money/paySuccess'
  177. // });
  178. // },
  179. // })
  180. // obj.payLoding = false;
  181. // })
  182. // .catch(e => {
  183. // obj.payLoding = false;
  184. // console.log(e);
  185. // });
  186. // // #endif
  187. // },
  188. confirm() {
  189. console.log('开始充值');
  190. let obj = this;
  191. if (obj.payLoding) {
  192. return;
  193. }
  194. if (obj.money == '') {
  195. obj.$api.msg('请输入充值金额');
  196. obj.payLoding = false;
  197. return;
  198. }
  199. if (obj.typeText == null) {
  200. obj.$api.msg('请选择充值方式');
  201. obj.payLoding = false;
  202. return;
  203. }
  204. if (obj.type == 'yongjing' && obj.money > parseInt(obj.yongMoney)) {
  205. obj.$api.msg('佣金不足');
  206. obj.payLoding = false;
  207. return;
  208. }
  209. obj.payLoding = true;
  210. // // #ifdef H5
  211. // rechargeWechat({ price: this.money, from: this.type })
  212. // .then(e => {
  213. // let da = e.data.data;
  214. // obj.weichatObj.chooseWXPay({
  215. // timestamp: da.timestamp,
  216. // nonceStr: da.nonceStr,
  217. // package: da.package,
  218. // signType: da.signType,
  219. // paySign: da.paySign,
  220. // success: function(res) {
  221. // uni.showToast({
  222. // title: '充值成功',
  223. // duration: 2000,
  224. // position: 'top'
  225. // });
  226. // }
  227. // });
  228. // obj.payLoding = false;
  229. // })
  230. // .catch(e => {
  231. // obj.payLoding = false;
  232. // console.log(e);
  233. // });
  234. // // #endif
  235. // // #ifdef MP
  236. // rechargeRoutine({ price: this.money})
  237. // .then(e => {
  238. // let da = e.data;
  239. // wx.requestPayment({
  240. // timeStamp: da.timestamp,
  241. // nonceStr: da.nonceStr,
  242. // package: da.package,
  243. // signType: da.signType,
  244. // paySign: da.paySign,
  245. // success: function(res) {
  246. // uni.redirectTo({
  247. // url: '/pages/money/paySuccess'
  248. // });
  249. // },
  250. // })
  251. // obj.payLoding = false;
  252. // })
  253. // .catch(e => {
  254. // obj.payLoding = false;
  255. // console.log(e);
  256. // });
  257. // // #endif
  258. // #ifdef APP-PLUS
  259. if(obj.typeText == 0){
  260. console.log(obj.money,obj.typeText,'0weixin');
  261. rechargeApp({ price: obj.money })
  262. .then(e => {
  263. console.log(e,"123456");
  264. let da = e.data;
  265. let data = {
  266. appid: da.appid,
  267. noncestr: da.noncestr,
  268. package: da.package,
  269. partnerid: da.partnerid,
  270. prepayid: da.prepayid,
  271. timestamp: da.timestamp,
  272. sign: da.sign
  273. };
  274. uni.requestPayment({
  275. provider: 'wxpay',
  276. orderInfo: data,
  277. success(res) {
  278. console.log(res);
  279. },
  280. fail(res) {
  281. console.log('微信掉起失败');
  282. console.log(res, '失败');
  283. }
  284. });
  285. obj.payLoding = false;
  286. })
  287. .catch(e => {
  288. obj.payLoding = false;
  289. console.log(e,"123456789");
  290. });
  291. }else {
  292. console.log(this.typeText,'other');
  293. const pushDate = {
  294. price: this.money,
  295. from: this.typeText == 1 ? 'yongjing' : 'ali',
  296. type: this.typeText
  297. };
  298. console.log(pushDate, '徐浩岚', rechargeWechat);
  299. console.log(obj.type, 'type');
  300. rechargeWechat(pushDate)
  301. .then(e => {
  302. console.log(e, '返回数据');
  303. // let da = e.data;
  304. // obj.money = '';
  305. // obj.yongMoney = ''
  306. console.log(obj.type, 'ali');
  307. if (obj.type == 'yongjing') {
  308. // const url = e.data.data;
  309. // console.log(url,'url');
  310. uni.showToast({
  311. title: '充值成功',
  312. duration: 2000
  313. });
  314. obj.yongMoney = '';
  315. userBalance({}).then(({ data }) => {
  316. console.log(data);
  317. obj.nowmoney = data.now_money;
  318. });
  319. extractBank({}).then(({ data }) => {
  320. obj.yongMoney = (data.commissionCount * 1).toFixed(2); //累积佣金
  321. console.log(data, 'wwwww');
  322. obj.disable = true;
  323. obj.payLoding = false;
  324. });
  325. }
  326. })
  327. .catch(e => {
  328. obj.money = '';
  329. obj.payLoding = false;
  330. console.log(e);
  331. });
  332. }
  333. // #endif
  334. // #ifdef H5
  335. // rechargeWechat({ price: this.money, from: this.type })
  336. const pushDate = {
  337. price: this.money,
  338. from: 'weixin',
  339. type: this.typeText
  340. };
  341. rechargeWechat(pushDate)
  342. .then(e => {
  343. console.log(e);
  344. if (obj.type == 'weixin') {
  345. let da = e.data.data;
  346. console.log(weixinObj, 'weixin');
  347. weixinObj.chooseWXPay({
  348. timestamp: da.timestamp,
  349. nonceStr: da.nonceStr,
  350. package: da.package,
  351. signType: da.signType,
  352. paySign: da.paySign,
  353. success: function(res) {
  354. uni.showToast({
  355. title: '充值成功',
  356. duration: 2000,
  357. position: 'top'
  358. });
  359. }
  360. });
  361. obj.payLoding = false;
  362. }
  363. console.log(obj.type, '当前', obj.type == 'yongjing');
  364. if (obj.type == 'yongjing') {
  365. obj.yongMoney = '';
  366. uni.navigateTo({
  367. url: './paySuccess',
  368. fail(e) {
  369. console.log(e, '错误');
  370. }
  371. });
  372. obj.payLoding = false;
  373. console.log(e, '佣金');
  374. }
  375. })
  376. .catch(e => {
  377. obj.payLoding = false;
  378. console.log(e);
  379. });
  380. // #endif
  381. // #ifdef MP
  382. rechargeRoutine({
  383. price: this.money
  384. })
  385. .then(e => {
  386. let da = e.data;
  387. wx.requestPayment({
  388. timeStamp: da.timestamp,
  389. nonceStr: da.nonceStr,
  390. package: da.package,
  391. signType: da.signType,
  392. paySign: da.paySign,
  393. success: function(res) {
  394. obj.yongMoney = '';
  395. uni.redirectTo({
  396. url: '/pages/money/paySuccess'
  397. });
  398. }
  399. });
  400. obj.payLoding = false;
  401. })
  402. .catch(e => {
  403. obj.payLoding = false;
  404. console.log(e);
  405. });
  406. // #endif
  407. },
  408. //获取订单列表
  409. loadData(source) {
  410. console.log(source);
  411. //这里是将订单挂载到tab列表下
  412. let index = this.tabCurrentIndex;
  413. let navItem = this.navList[index];
  414. let state = navItem.state;
  415. if (source === 'tabChange' && navItem.loaded === true) {
  416. //tab切换只有第一次需要加载数据
  417. return;
  418. }
  419. if (navItem.loadingType === 'loading') {
  420. //防止重复加载
  421. return;
  422. }
  423. navItem.loadingType = 'loading';
  424. setTimeout(() => {
  425. let orderList = [];
  426. orderList.forEach(item => {
  427. navItem.orderList.push(item);
  428. });
  429. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  430. this.$set(navItem, 'loaded', true);
  431. //判断是否还有数据, 有改为 more, 没有改为noMore
  432. navItem.loadingType = 'more';
  433. }, 600);
  434. }
  435. }
  436. };
  437. </script>
  438. <style lang="scss">
  439. page {
  440. height: 100%;
  441. }
  442. .yue {
  443. display: flex;
  444. justify-content: space-between;
  445. padding: 30rpx 48rpx 30rpx 26rpx;
  446. background: #ffffff;
  447. .font {
  448. font-size: 28rpx;
  449. font-family: PingFang SC;
  450. font-weight: 500;
  451. color: #333333;
  452. }
  453. .money {
  454. font-size: 30rpx;
  455. font-family: PingFang SC;
  456. font-weight: bold;
  457. color: #ef041f;
  458. }
  459. }
  460. .add-btn {
  461. &.modified {
  462. color: $base-color;
  463. }
  464. &.up {
  465. background-color: $base-color;
  466. color: #fff;
  467. }
  468. display: flex;
  469. align-items: center;
  470. justify-content: center;
  471. width: 690rpx;
  472. height: 80rpx;
  473. margin: 0 auto;
  474. margin-top: 30rpx;
  475. font-size: $font-lg;
  476. border-radius: 10rpx;
  477. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  478. }
  479. .row-box {
  480. margin-top: 30rpx;
  481. padding: 20rpx 30rpx;
  482. background: #fff;
  483. .title {
  484. font-size: $font-base + 2rpx;
  485. color: $font-color-dark;
  486. }
  487. .row {
  488. display: flex;
  489. align-items: center;
  490. position: relative;
  491. height: 80rpx;
  492. .tit {
  493. flex-shrink: 0;
  494. width: 40rpx;
  495. font-size: 30rpx;
  496. color: $font-color-dark;
  497. }
  498. .input {
  499. flex: 1;
  500. font-size: 30rpx;
  501. color: $font-color-dark;
  502. }
  503. .iconlocation {
  504. font-size: 36rpx;
  505. color: $font-color-light;
  506. }
  507. .buttom {
  508. color: $font-color;
  509. font-size: $font-base;
  510. }
  511. }
  512. }
  513. .list {
  514. padding-left: 30rpx;
  515. margin-top: 30rpx;
  516. background-color: #ffffff;
  517. .box {
  518. display: flex;
  519. align-items: center;
  520. width: 100%;
  521. height: 120rpx;
  522. border-bottom: 1px solid $border-color-light;
  523. .icon {
  524. font-size: 48rpx;
  525. padding-right: 20rpx;
  526. }
  527. .yongjing {
  528. width: 48rpx;
  529. height: 48rpx;
  530. }
  531. .iconweixin1 {
  532. color: #18bf16;
  533. }
  534. .iconzhifubao {
  535. color: #08aaec;
  536. }
  537. .title-box {
  538. flex-grow: 1;
  539. text-align: left;
  540. .title {
  541. font-size: $font-base + 2rpx;
  542. color: $font-color-base;
  543. }
  544. .node {
  545. font-size: $font-sm;
  546. color: $font-color-light;
  547. }
  548. }
  549. }
  550. }
  551. /deep/ .uni-radio-input {
  552. width: 45rpx;
  553. height: 45rpx;
  554. }
  555. .active-bg {
  556. background-color: $color-gray !important;
  557. }
  558. </style>