recharge.vue 10 KB

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