recharge.vue 10 KB

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