recharge.vue 9.3 KB

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