recharge.vue 9.2 KB

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