recharge.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <view class="content">
  3. <view class="top_box">
  4. <text class="yue-tit">当前余额:</text>
  5. <text class="yue-num">¥{{ now_money | parseFloatNum }}</text>
  6. </view>
  7. <view class="line_box"></view>
  8. <view class="cz_box">
  9. <view class="cz_wrap">
  10. <text class="cz_tit">¥</text>
  11. <input class="cz_input" type="number" v-model="money" @focus="changeNum()" placeholder="请输入充值金额" placeholder-class="placeholder" />
  12. </view>
  13. <view class="zc_list_box">
  14. <view class="zc_list_price" :class="{ seletPrice: seletNum == item.price }" @click="seletChange(item, index)" v-for="(item, index) in list" :key="index">
  15. {{ item.price | parseFloatNum }}元
  16. </view>
  17. </view>
  18. </view>
  19. <!-- <view class="line_box"></view> -->
  20. <!-- <view class="row-box">
  21. <view class="title">充值金额</view>
  22. <view class="row">
  23. <text class="tit">¥</text>
  24. <input class="input" type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="placeholder" />
  25. </view>
  26. </view> -->
  27. <!-- <view class="rechar-box">
  28. <view class="rechar-title">注意事项</view>
  29. <view class="rechar-text" v-for="(item, index) in zhuyi" :key="index">
  30. <text>{{ index + 1 }}.{{item}}</text>
  31. </view>
  32. </view> -->
  33. <view class="line_box"></view>
  34. <!-- <view class="cz-type" @click.stop="changePayType('weixin')">
  35. <view class="type-left">
  36. <view class="icon iconfont iconweixin"></view>
  37. <view class="tit">微信充值</view>
  38. </view>
  39. <view class="right" v-show="loaded"><radio value="weixin" color="#EB001C" :checked="type == 'weixin'" /></view>
  40. </view> -->
  41. <view class="cz-type" @click.stop="changePayType('alipay')">
  42. <view class="type-left">
  43. <view class="icon iconfont iconzhifubao"></view>
  44. <view class="tit">支付宝充值</view>
  45. </view>
  46. <view class="right" v-show="loaded"><radio value="weixin" color="#EB001C" :checked="type == 'alipay'" /></view>
  47. </view>
  48. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">立即充值</button>
  49. </view>
  50. </template>
  51. <script>
  52. import { getMoneyStyle } from '@/utils/rocessor.js';
  53. // #ifdef H5
  54. import { rechargeWechat, rechargeIndex } from '@/api/wallet.js';
  55. // #endif
  56. // #ifdef MP
  57. import { rechargeWechat, rechargeRoutine, rechargeIndex } from '@/api/wallet.js';
  58. // #endif
  59. import { mapState } from 'vuex';
  60. import { spreadCommission, userBalance,moneyChong } from '@/api/wallet.js';
  61. export default {
  62. filters: {
  63. getMoneyStyle,
  64. // 去处小数点后的0
  65. parseFloatNum(clock) {
  66. return parseFloat(clock);
  67. }
  68. },
  69. data() {
  70. return {
  71. loaded:true,
  72. type: 'alipay',
  73. money: '', //充值金额
  74. payLoding: false ,//是否加载中
  75. list: [
  76. '300',
  77. '200',
  78. '150',
  79. '100',
  80. '50'
  81. ],
  82. now_money:'',
  83. seletNum: '300', // 选中
  84. zhuyi: [],
  85. quota: '', // 送的钱
  86. typeText: 0, // 0-微信 1-佣金
  87. };
  88. },
  89. onLoad(options) {
  90. this.loadData();
  91. },
  92. computed: {
  93. // #ifdef H5
  94. ...mapState(['weichatObj', 'userInfo'])
  95. // #endif
  96. // #ifdef MP
  97. ...mapState(['userInfo'])
  98. // #endif
  99. },
  100. methods: {
  101. //选择支付方式
  102. changePayType(type) {
  103. this.loaded = false
  104. this.type = type
  105. this.loaded = true
  106. },
  107. // 跳转
  108. navTo(url) {
  109. uni.navigateTo({
  110. url: url
  111. });
  112. },
  113. changeNum() {
  114. this.seletNum = this.money = '';
  115. console.log(this.seletNum, this.money);
  116. },
  117. seletChange(item, index) {
  118. this.seletNum = item.price;
  119. this.seletMoney = item.price;
  120. this.money = item.price
  121. },
  122. // 切换选中对象
  123. tabRadio(e) {
  124. this.type = e.detail.value;
  125. if ( e.detail.value == 'weixin' ) {
  126. this.typeText = 0
  127. } else {
  128. this.typeText = 1
  129. }
  130. },
  131. // 充值金额
  132. rechargeXuan(item) {
  133. this.money = item.price;
  134. this.quota = item.quota;
  135. },
  136. loadData() {
  137. moneyChong({}).then(({data}) =>{
  138. console.log(data,"123456789");
  139. this.list = data.recharge_quota;
  140. });
  141. userBalance({}).then(({ data }) => {
  142. this.now_money = data.now_money;
  143. });
  144. },
  145. // 提交
  146. confirm() {
  147. let obj = this;
  148. obj.payLoding = true;
  149. if( !obj.money ) {
  150. obj.$api.msg('请输入金额');
  151. obj.payLoding = false;
  152. return;
  153. }
  154. // #ifdef H5
  155. rechargeWechat({
  156. price: this.money,
  157. type: '2' ,
  158. }).then(e => {
  159. // let da = e.data.data;
  160. window.location.href=e.data.result.jsConfig.expend.pay_info
  161. // obj.weichatObj.chooseWXPay({
  162. // timestamp: da.timestamp,
  163. // nonceStr: da.nonceStr,
  164. // package: da.package,
  165. // signType: da.signType,
  166. // paySign: da.paySign,
  167. // success: function(res) {
  168. // uni.showToast({
  169. // title: '充值成功',
  170. // duration: 2000,
  171. // position: 'top',
  172. // success: function(res) {
  173. // uni.navigateBack()
  174. // }
  175. // });
  176. // }
  177. // });
  178. obj.payLoding = false;
  179. })
  180. .catch(e => {
  181. obj.payLoding = false;
  182. console.log(e);
  183. });
  184. // #endif
  185. // #ifdef MP
  186. rechargeRoutine({ price: this.money})
  187. .then(e => {
  188. let da = e.data;
  189. wx.requestPayment({
  190. timeStamp: da.timestamp,
  191. nonceStr: da.nonceStr,
  192. package: da.package,
  193. signType: da.signType,
  194. paySign: da.paySign,
  195. success: function(res) {
  196. uni.showToast({
  197. title: '充值成功',
  198. duration: 2000,
  199. position: 'top',
  200. success: function(res) {
  201. uni.navigateBack()
  202. }
  203. });
  204. },
  205. })
  206. obj.payLoding = false;
  207. })
  208. .catch(e => {
  209. obj.payLoding = false;
  210. console.log(e);
  211. });
  212. // #endif
  213. },
  214. }
  215. };
  216. </script>
  217. <style lang="scss">
  218. page {
  219. height: 100%;
  220. background: #ffffff;
  221. }
  222. .top_box {
  223. padding: 20rpx 26rpx 20rpx 47rpx;
  224. display: flex;
  225. align-items: center;
  226. justify-content: space-between;
  227. .yue-tit {
  228. font-size: 28rpx;
  229. font-family: PingFang SC;
  230. font-weight: 500;
  231. color: #333333;
  232. }
  233. .yue-num {
  234. font-size: 30rpx;
  235. font-family: PingFang SC;
  236. font-weight: bold;
  237. color: #ff6f0f;
  238. }
  239. }
  240. .line_box {
  241. width: 100%;
  242. height: 20rpx;
  243. background: #f8f8f8;
  244. }
  245. .cz_box {
  246. padding: 40rpx 20rpx 20rpx;
  247. .cz_wrap {
  248. display: flex;
  249. align-items: center;
  250. justify-content: space-between;
  251. padding-bottom: 20rpx;
  252. border-bottom: 1px solid #e6e6e6;
  253. .cz_tit {
  254. font-size: 32rpx;
  255. font-family: PingFang SC;
  256. font-weight: 500;
  257. }
  258. .cz_input {
  259. text-align: right;
  260. font-size: 32rpx;
  261. font-family: PingFang SC;
  262. font-weight: 500;
  263. // color: #BFBFBF;
  264. }
  265. }
  266. .zc_list_box {
  267. display: flex;
  268. flex-wrap: wrap;
  269. .zc_list_price {
  270. width: 202rpx;
  271. height: 60rpx;
  272. background: #f0f0f0;
  273. border-radius: 8rpx;
  274. margin-top: 36rpx;
  275. margin-right: 50rpx;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. &:nth-child(3n) {
  280. margin-right: 0;
  281. }
  282. }
  283. .seletPrice {
  284. background: linear-gradient(143.2747deg, #ff6a00, #ee0979);
  285. color: #ffffff;
  286. }
  287. }
  288. }
  289. .recha-box {
  290. padding: 50rpx 30rpx 0;
  291. display: flex;
  292. flex-wrap: wrap;
  293. .recha-frame {
  294. width: 210rpx;
  295. height: 181rpx;
  296. border: 1px solid #dbdede;
  297. border-radius: 20rpx;
  298. display: flex;
  299. align-items: center;
  300. flex-direction: column;
  301. justify-content: center;
  302. margin-right: 30rpx;
  303. margin-bottom: 30rpx;
  304. &:nth-child(3n) {
  305. margin-right: 0;
  306. }
  307. .recha-top {
  308. display: flex;
  309. align-items: center;
  310. .recha-img {
  311. width: 64rpx;
  312. height: 62rpx;
  313. }
  314. .recha-tit {
  315. margin-left: 10rpx;
  316. font-size: 36rpx;
  317. font-family: PingFang SC;
  318. font-weight: bold;
  319. color: #333333;
  320. }
  321. }
  322. .recha-song {
  323. margin-top: 20rpx;
  324. font-size: $font-base;
  325. font-family: PingFang SC;
  326. font-weight: bold;
  327. color: #ff9900;
  328. }
  329. }
  330. .select-frame {
  331. border: 1px solid #ef041f;
  332. }
  333. }
  334. .rechar-box {
  335. padding: 30rpx 20rpx 0;
  336. .rechar-title {
  337. font-size: 32rpx;
  338. font-family: PingFang SC;
  339. font-weight: bold;
  340. color: #333333;
  341. margin-bottom: 10rpx;
  342. }
  343. .rechar-text {
  344. font-size: 28rpx;
  345. font-family: PingFang SC;
  346. font-weight: bold;
  347. color: #333333;
  348. }
  349. }
  350. .cz-type {
  351. margin-top: 22rpx;
  352. display: flex;
  353. justify-content: space-between;
  354. padding: 32rpx;
  355. align-items: center;
  356. .type-left {
  357. display: flex;
  358. align-items: center;
  359. .icon {
  360. height: 38rpx;
  361. image {
  362. width: 48rpx;
  363. height: 38rpx;
  364. }
  365. }
  366. .iconweixin {
  367. color: #36cb59;
  368. }
  369. .tit {
  370. margin-left: 12rpx;
  371. font-size: 30rpx;
  372. color: #333333;
  373. }
  374. }
  375. .type-right {
  376. image {
  377. width: 36rpx;
  378. height: 36rpx;
  379. }
  380. }
  381. }
  382. .add-btn {
  383. &.modified {
  384. }
  385. &.up {
  386. color: #fff;
  387. }
  388. margin-top: 100rpx;
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. width: 604rpx;
  393. height: 90rpx;
  394. // border: 2rpx solid #F21F5D;
  395. border-radius: 10rpx;
  396. font-size: 36rpx;
  397. font-family: PingFang SC;
  398. font-weight: 500;
  399. color: #fff;
  400. line-height: 90rpx;
  401. text-align: center;
  402. background-color: #ff4c4c;
  403. }
  404. .row-box {
  405. margin-top: 30rpx;
  406. padding: 20rpx 30rpx;
  407. background: #fff;
  408. .title {
  409. font-size: $font-base + 2rpx;
  410. color: $font-color-dark;
  411. }
  412. .row {
  413. display: flex;
  414. align-items: center;
  415. position: relative;
  416. height: 80rpx;
  417. .tit {
  418. flex-shrink: 0;
  419. width: 40rpx;
  420. font-size: 30rpx;
  421. color: $font-color-dark;
  422. }
  423. .input {
  424. flex: 1;
  425. font-size: 30rpx;
  426. color: $font-color-dark;
  427. }
  428. .iconlocation {
  429. font-size: 36rpx;
  430. color: $font-color-light;
  431. }
  432. .buttom {
  433. color: $font-color;
  434. font-size: $font-base;
  435. }
  436. }
  437. }
  438. .list {
  439. padding-left: 30rpx;
  440. margin-top: 30rpx;
  441. background-color: #ffffff;
  442. .box {
  443. display: flex;
  444. align-items: center;
  445. width: 100%;
  446. height: 120rpx;
  447. border-bottom: 1px solid $border-color-light;
  448. padding-right: 25rpx;
  449. .icon {
  450. font-size: 48rpx;
  451. padding-right: 20rpx;
  452. display: flex;
  453. }
  454. .yongjing {
  455. width: 48rpx;
  456. height: 48rpx;
  457. }
  458. .iconweixin1 {
  459. color: #18bf16;
  460. }
  461. .iconzhifubao {
  462. color: #08aaec;
  463. }
  464. .title-box {
  465. flex-grow: 1;
  466. text-align: left;
  467. .title {
  468. font-size: $font-base + 2rpx;
  469. color: $font-color-base;
  470. }
  471. .node {
  472. font-size: $font-sm;
  473. color: $font-color-light;
  474. }
  475. }
  476. }
  477. }
  478. /deep/ .uni-radio-input {
  479. width: 45rpx;
  480. height: 45rpx;
  481. }
  482. .active-bg {
  483. background: #999 !important;
  484. color: #FFFFFF !important;
  485. }
  486. .iconzhifubao {
  487. color: #08aaec;
  488. }
  489. </style>