recharge.vue 9.3 KB

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