recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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. <!-- #ifndef APP-PLUS -->
  17. <label v-if="bool">
  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 }}</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. // #ifdef H5
  56. import { rechargeWechat,userBalance,extractBank} from '@/api/wallet.js';
  57. import weixinBJ from "@/utils/wxAuthorized.js";
  58. // #endif
  59. // #ifdef MP
  60. import { rechargeRoutine } from '@/api/wallet.js';
  61. // #endif
  62. import { mapState } from 'vuex';
  63. export default {
  64. filters: {
  65. getMoneyStyle
  66. },
  67. data() {
  68. return {
  69. type: 'weixin',
  70. money: '', //充值金额
  71. payLoding: false ,//是否加载中
  72. yongMoney:'',
  73. nowmoney:'',
  74. bool: true
  75. };
  76. },
  77. onShow() {
  78. this.yongMoney = ''
  79. userBalance({}).then(({ data }) => {
  80. console.log(data);
  81. this.nowmoney = data.now_money;
  82. });
  83. extractBank({}).then(({ data }) => {
  84. this.yongMoney = (data.commissionCount * 1).toFixed(2); //累积佣金
  85. console.log(data,'wwwww');
  86. this.disable= true
  87. });
  88. },
  89. onLoad(options) {
  90. this.bool = uni.getStorageSync('weichatBrowser');
  91. if(!this.bool) {
  92. // this.payType = 3
  93. this.type = 'yongjing'
  94. this.typeText = 1
  95. }
  96. },
  97. computed: {
  98. // #ifdef H5
  99. ...mapState(['weichatObj'])
  100. // #endif
  101. },
  102. methods: {
  103. // 跳转
  104. navTo(url) {
  105. uni.navigateTo({
  106. url: url
  107. });
  108. },
  109. // 切换选中对象
  110. tabRadio(e) {
  111. console.log(e);
  112. if (e.detail.value == 'weixin') {
  113. this.typeText = 0;
  114. }
  115. if (e.detail.value == 'yongjing') {
  116. this.typeText = 1;
  117. }
  118. // if (e.detail.value == 'ali') {
  119. // this.typeText = 2;
  120. // }
  121. // #ifdef APP-PLUS
  122. this.type = e.target.value
  123. // #endif
  124. // #ifndef APP-PLUS
  125. this.type = e;
  126. // #endif
  127. console.log(this.typeText);
  128. },
  129. // 提交
  130. // confirm() {
  131. // let obj = this;
  132. // obj.payLoding = true;
  133. // // #ifdef H5
  134. // rechargeWechat({ price: this.money, from: this.type })
  135. // .then(e => {
  136. // let da = e.data.data;
  137. // obj.weichatObj.chooseWXPay({
  138. // timestamp: da.timestamp,
  139. // nonceStr: da.nonceStr,
  140. // package: da.package,
  141. // signType: da.signType,
  142. // paySign: da.paySign,
  143. // success: function(res) {
  144. // uni.showToast({
  145. // title: '充值成功',
  146. // duration: 2000,
  147. // position: 'top'
  148. // });
  149. // }
  150. // });
  151. // obj.payLoding = false;
  152. // })
  153. // .catch(e => {
  154. // obj.payLoding = false;
  155. // console.log(e);
  156. // });
  157. // // #endif
  158. // // #ifdef MP
  159. // rechargeRoutine({ price: this.money})
  160. // .then(e => {
  161. // let da = e.data;
  162. // wx.requestPayment({
  163. // timeStamp: da.timestamp,
  164. // nonceStr: da.nonceStr,
  165. // package: da.package,
  166. // signType: da.signType,
  167. // paySign: da.paySign,
  168. // success: function(res) {
  169. // uni.redirectTo({
  170. // url: '/pages/money/paySuccess'
  171. // });
  172. // },
  173. // })
  174. // obj.payLoding = false;
  175. // })
  176. // .catch(e => {
  177. // obj.payLoding = false;
  178. // console.log(e);
  179. // });
  180. // // #endif
  181. // },
  182. confirm() {
  183. console.log('开始充值');
  184. let obj = this;
  185. if(obj.payLoding) {
  186. return;
  187. }
  188. if (obj.money == '') {
  189. obj.$api.msg('请输入充值金额');
  190. obj.payLoding = false;
  191. return;
  192. }
  193. if (obj.type == 'yongjin' && obj.money > parseInt(obj.yongMoney)) {
  194. obj.$api.msg('佣金不足');
  195. obj.payLoding = false;
  196. return;
  197. }
  198. obj.payLoding = true
  199. // #ifdef APP-PLUS
  200. const pushDate = { price: this.money, from:this.typeText==2?'ali':'yongjing', type: this.typeText }
  201. console.log(pushDate);
  202. rechargeWechat(pushDate)
  203. .then(e => {
  204. console.log(e,'返回数据');
  205. let da = e.data;
  206. obj.money = '';
  207. obj.yongMoney = ''
  208. console.log(obj.type,'ali');
  209. if (obj.type == 'ali') {
  210. const url = e.data.data;
  211. console.log(url,'url');
  212. uni.requestPayment({
  213. provider: 'alipay',
  214. orderInfo: url,
  215. success: res => {
  216. console.log(res);
  217. uni.showToast({
  218. title: '充值成功',
  219. duration: 2000,
  220. });
  221. },
  222. fail: e => {
  223. console.log(e);
  224. },
  225. complete: () => {}
  226. });
  227. obj.payLoding = false;
  228. }
  229. if (obj.type == 'yongjing') {
  230. // uni.navigateTo({
  231. // url: '/pages/money/rechargeSuccess'
  232. // });
  233. obj.payLoding = false;
  234. uni.showToast({
  235. title: '充值成功',
  236. duration: 2000,
  237. });
  238. extractBank({}).then(({ data }) => {
  239. obj.yongMoney = (data.commissionCount * 1).toFixed(2); //累积佣金
  240. console.log(data,'wwwww');
  241. obj.disable= true
  242. });
  243. console.log(e, '佣金');
  244. }
  245. })
  246. .catch(e => {
  247. obj.money = '';
  248. obj.payLoding = false;
  249. console.log(e);
  250. });
  251. // #endif
  252. // #ifdef H5
  253. // rechargeWechat({ price: this.money, from: this.type })
  254. const pushDate = { price: this.money, from: 'weixin', type: this.typeText };
  255. rechargeWechat(pushDate)
  256. .then(e => {
  257. console.log(e);
  258. if (obj.type == 'weixin') {
  259. let da = e.data.data;
  260. weixinBJ.weixinObj.chooseWXPay({
  261. timestamp: da.timestamp,
  262. nonceStr: da.nonceStr,
  263. package: da.package,
  264. signType: da.signType,
  265. paySign: da.paySign,
  266. success: function(res) {
  267. uni.showToast({
  268. title: '充值成功',
  269. duration: 2000,
  270. position: 'top'
  271. });
  272. }
  273. });
  274. obj.payLoding = false;
  275. }
  276. if (obj.type == 'yongjing') {
  277. obj.yongMoney = ''
  278. uni.navigateTo({
  279. url: '/pages/money/rechargeSuccess'
  280. });
  281. obj.payLoding = false;
  282. console.log(e, '佣金');
  283. }
  284. })
  285. .catch(e => {
  286. obj.payLoding = false;
  287. console.log(e);
  288. });
  289. // #endif
  290. // #ifdef MP
  291. rechargeRoutine({ price: this.money })
  292. .then(e => {
  293. let da = e.data;
  294. wx.requestPayment({
  295. timeStamp: da.timestamp,
  296. nonceStr: da.nonceStr,
  297. package: da.package,
  298. signType: da.signType,
  299. paySign: da.paySign,
  300. success: function(res) {
  301. obj.yongMoney = ''
  302. uni.redirectTo({
  303. url: '/pages/money/paySuccess'
  304. });
  305. }
  306. });
  307. obj.payLoding = false;
  308. })
  309. .catch(e => {
  310. obj.payLoding = false;
  311. console.log(e);
  312. });
  313. // #endif
  314. },
  315. //获取订单列表
  316. loadData(source) {
  317. console.log(source);
  318. //这里是将订单挂载到tab列表下
  319. let index = this.tabCurrentIndex;
  320. let navItem = this.navList[index];
  321. let state = navItem.state;
  322. if (source === 'tabChange' && navItem.loaded === true) {
  323. //tab切换只有第一次需要加载数据
  324. return;
  325. }
  326. if (navItem.loadingType === 'loading') {
  327. //防止重复加载
  328. return;
  329. }
  330. navItem.loadingType = 'loading';
  331. setTimeout(() => {
  332. let orderList = [];
  333. orderList.forEach(item => {
  334. navItem.orderList.push(item);
  335. });
  336. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  337. this.$set(navItem, 'loaded', true);
  338. //判断是否还有数据, 有改为 more, 没有改为noMore
  339. navItem.loadingType = 'more';
  340. }, 600);
  341. }
  342. }
  343. };
  344. </script>
  345. <style lang="scss">
  346. page {
  347. height: 100%;
  348. }
  349. .yue {
  350. display: flex;
  351. justify-content: space-between;
  352. padding: 30rpx 48rpx 30rpx 26rpx;
  353. background: #ffffff;
  354. .font {
  355. font-size: 28rpx;
  356. font-family: PingFang SC;
  357. font-weight: 500;
  358. color: #333333;
  359. }
  360. .money {
  361. font-size: 30rpx;
  362. font-family: PingFang SC;
  363. font-weight: bold;
  364. color: #ef041f;
  365. }
  366. }
  367. .add-btn {
  368. &.modified {
  369. color: $base-color;
  370. }
  371. &.up {
  372. background-color: $base-color;
  373. color: #fff;
  374. }
  375. display: flex;
  376. align-items: center;
  377. justify-content: center;
  378. width: 690rpx;
  379. height: 80rpx;
  380. margin: 0 auto;
  381. margin-top: 30rpx;
  382. font-size: $font-lg;
  383. border-radius: 10rpx;
  384. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  385. }
  386. .row-box {
  387. margin-top: 30rpx;
  388. padding: 20rpx 30rpx;
  389. background: #fff;
  390. .title {
  391. font-size: $font-base + 2rpx;
  392. color: $font-color-dark;
  393. }
  394. .row {
  395. display: flex;
  396. align-items: center;
  397. position: relative;
  398. height: 80rpx;
  399. .tit {
  400. flex-shrink: 0;
  401. width: 40rpx;
  402. font-size: 30rpx;
  403. color: $font-color-dark;
  404. }
  405. .input {
  406. flex: 1;
  407. font-size: 30rpx;
  408. color: $font-color-dark;
  409. }
  410. .iconlocation {
  411. font-size: 36rpx;
  412. color: $font-color-light;
  413. }
  414. .buttom {
  415. color: $font-color;
  416. font-size: $font-base;
  417. }
  418. }
  419. }
  420. .list {
  421. padding-left: 30rpx;
  422. margin-top: 30rpx;
  423. background-color: #ffffff;
  424. .box {
  425. display: flex;
  426. align-items: center;
  427. width: 100%;
  428. height: 120rpx;
  429. border-bottom: 1px solid $border-color-light;
  430. .icon {
  431. font-size: 48rpx;
  432. padding-right: 20rpx;
  433. }
  434. .yongjing {
  435. width: 48rpx;
  436. height: 48rpx;
  437. }
  438. .iconweixin1 {
  439. color: #18bf16;
  440. }
  441. .iconzhifubao {
  442. color: #08aaec;
  443. }
  444. .title-box {
  445. flex-grow: 1;
  446. text-align: left;
  447. .title {
  448. font-size: $font-base + 2rpx;
  449. color: $font-color-base;
  450. }
  451. .node {
  452. font-size: $font-sm;
  453. color: $font-color-light;
  454. }
  455. }
  456. }
  457. }
  458. /deep/ .uni-radio-input {
  459. width: 45rpx;
  460. height: 45rpx;
  461. }
  462. .active-bg {
  463. background-color: $color-gray !important;
  464. }
  465. </style>