recharge.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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" v-if="!weichatBsrowser">
  19. <radio-group @change="tabRadio">
  20. <!-- #ifdef APP-PLUS -->
  21. <!-- <label>
  22. <view class="box">
  23. <view class="icon iconfont iconzhifubao"></view>
  24. <view class="title-box">
  25. <view class="title"><text>支付宝充值</text></view>
  26. </view>
  27. <view class="right"><radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" /></view>
  28. </view>
  29. </label> -->
  30. <!-- #endif -->
  31. <label>
  32. <view class="box">
  33. <view class="icon iconfont iconweixin1"></view>
  34. <view class="title-box">
  35. <view class="title"><text>微信充值</text></view>
  36. </view>
  37. <view class="right"><radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" /></view>
  38. </view>
  39. </label>
  40. </radio-group>
  41. </view>
  42. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">立即充值</button>
  43. <button class="card" @click="go()">充值卡兑换</button>
  44. <uni-popup ref="popup" type="center">
  45. <view class="popup-box">
  46. <view class="img">
  47. <view class="img-font">兑换充值卡</view>
  48. <view class="img-bg"><image src="../../static/img/img009.png" mode=""></image></view>
  49. </view>
  50. <view class="mian">
  51. <view class="main-item">
  52. <view class="font">卡号</view>
  53. <input type="text" v-model="card" class="input" placeholder="请输入卡号" placeholder-class="input-font"/>
  54. </view>
  55. <view class="main-item" style="margin-top: 40rpx;">
  56. <view class="font">密码</view>
  57. <input type="password" v-model="pwd" placeholder="请输入密码" class="input" placeholder-class="input-font"/>
  58. </view>
  59. <view class="comfirm-box">
  60. <view class="cancel" @click="cancel">取消</view>
  61. <view class="comfirm" @click="comfirm()">确认兑换</view>
  62. </view>
  63. </view>
  64. </view>
  65. </uni-popup>
  66. </view>
  67. </template>
  68. <script>
  69. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  70. import { verification } from '@/api/merchant.js';
  71. import { getMoneyStyle } from '@/utils/rocessor.js';
  72. import { rechargeWechat } from '@/api/wallet.js';
  73. import { mapState, mapMutations} from 'vuex';
  74. import { getUserInfo } from '@/api/login.js';
  75. export default {
  76. components: {
  77. uniPopup
  78. },
  79. filters: {
  80. getMoneyStyle
  81. },
  82. data() {
  83. return {
  84. moneyList: [300, 200, 150, 100, 50],
  85. choose: -1,
  86. // #ifdef APP-PLUS
  87. type: 'weixinapp',
  88. // #endif
  89. // #ifdef H5
  90. type: 'weixin',
  91. // #endif
  92. money: '', //充值金额
  93. payLoding: false, //是否加载中
  94. // #ifdef H5
  95. weichatBsrowser: false,
  96. // #endif
  97. // #ifdef APP-PLUS
  98. weichatBsrowser: true,
  99. // #endif
  100. nowmoney:0,
  101. card:'',
  102. pwd:''
  103. };
  104. },
  105. onLoad(options) {
  106. // #ifdef H5
  107. this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
  108. // #endif
  109. },
  110. computed: {
  111. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  112. // #ifdef H5
  113. ...mapState(['weichatObj'])
  114. // #endif
  115. },
  116. methods: {
  117. // 跳转
  118. navTo(url) {
  119. uni.navigateTo({
  120. url: url
  121. });
  122. },
  123. // 切换选中对象
  124. tabRadio(e) {
  125. this.type = e;
  126. },
  127. // 提交
  128. confirm() {
  129. let obj = this;
  130. obj.payLoding = true;
  131. if(this.money<=0){
  132. uni.showToast({
  133. title: '请输入金额',
  134. duration: 2000,
  135. icon:'none'
  136. });
  137. return
  138. }
  139. rechargeWechat({ price: this.money, from: this.type })
  140. .then(e => {
  141. console.log(e);
  142. // #ifdef H5
  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. });
  156. }
  157. });
  158. // #endif
  159. // #ifdef APP-PLUS
  160. uni.requestPayment({
  161. provider: 'wxpay',
  162. orderInfo: e.data.data,
  163. success: function() {
  164. uni.showToast({
  165. title: '充值成功',
  166. duration: 2000,
  167. position: 'top'
  168. });
  169. },
  170. fail(e) {
  171. console.log(e);
  172. }
  173. });
  174. // #endif
  175. obj.payLoding = false;
  176. })
  177. .catch(e => {
  178. obj.payLoding = false;
  179. console.log(e);
  180. });
  181. },
  182. go(){
  183. this.$refs.popup.open()
  184. },
  185. cancel() {
  186. this.$refs.popup.close();
  187. this.card = '';
  188. this.pwd = '';
  189. },
  190. comfirm() {
  191. let obj = this
  192. verification({
  193. card_number:this.card,
  194. card_password:this.pwd,
  195. is_confirm: 1,
  196. type: 1,
  197. }).then(e =>{
  198. console.log(e)
  199. this.card = '';
  200. this.pwd = '';
  201. getUserInfo()
  202. .then(({ data }) => {
  203. obj.setUserInfo(data);
  204. })
  205. .catch(e => {
  206. console.log(e);
  207. });
  208. }).catch(e =>{
  209. console.log(e)
  210. })
  211. this.$refs.popup.close();
  212. },
  213. //获取订单列表
  214. loadData(source) {
  215. console.log(source);
  216. //这里是将订单挂载到tab列表下
  217. let index = this.tabCurrentIndex;
  218. let navItem = this.navList[index];
  219. let state = navItem.state;
  220. if (source === 'tabChange' && navItem.loaded === true) {
  221. //tab切换只有第一次需要加载数据
  222. return;
  223. }
  224. if (navItem.loadingType === 'loading') {
  225. //防止重复加载
  226. return;
  227. }
  228. navItem.loadingType = 'loading';
  229. setTimeout(() => {
  230. let orderList = [];
  231. orderList.forEach(item => {
  232. navItem.orderList.push(item);
  233. });
  234. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  235. this.$set(navItem, 'loaded', true);
  236. //判断是否还有数据, 有改为 more, 没有改为noMore
  237. navItem.loadingType = 'more';
  238. }, 600);
  239. },
  240. changemoney(item, index) {
  241. this.choose = index;
  242. this.money = item;
  243. }
  244. }
  245. };
  246. </script>
  247. <style lang="scss">
  248. page {
  249. height: 100%;
  250. }
  251. .yue {
  252. display: flex;
  253. justify-content: space-between;
  254. padding: 30rpx 48rpx 30rpx 26rpx;
  255. background: #ffffff;
  256. .font {
  257. font-size: 28rpx;
  258. font-family: PingFang SC;
  259. font-weight: 500;
  260. color: #333333;
  261. }
  262. .money {
  263. font-size: 30rpx;
  264. font-family: PingFang SC;
  265. font-weight: bold;
  266. color: #ff6f0f;
  267. }
  268. }
  269. .add-btn {
  270. &.modified {
  271. color: $base-color;
  272. }
  273. &.up {
  274. background-color: $base-color;
  275. color: #fff;
  276. }
  277. display: flex;
  278. align-items: center;
  279. justify-content: center;
  280. width: 690rpx;
  281. height: 80rpx;
  282. margin: 0 auto;
  283. margin-top: 30rpx;
  284. font-size: $font-lg;
  285. border-radius: 10rpx;
  286. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  287. }
  288. .card {
  289. background: #ffffff;
  290. border: 1px solid $base-color;
  291. color: $base-color;
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. width: 690rpx;
  296. height: 80rpx;
  297. margin: 30rpx auto 0;
  298. font-size: $font-lg;
  299. border-radius: 10rpx;
  300. }
  301. .row-box {
  302. margin-top: 30rpx;
  303. padding: 20rpx 0rpx 20rpx 30rpx;
  304. background: #fff;
  305. .title {
  306. font-size: $font-base + 2rpx;
  307. color: $font-color-dark;
  308. }
  309. .row {
  310. display: flex;
  311. align-items: center;
  312. position: relative;
  313. height: 80rpx;
  314. .tit {
  315. flex-shrink: 0;
  316. width: 40rpx;
  317. font-size: 30rpx;
  318. color: $font-color-dark;
  319. }
  320. .input {
  321. flex: 1;
  322. font-size: 30rpx;
  323. color: $font-color-dark;
  324. }
  325. .iconlocation {
  326. font-size: 36rpx;
  327. color: $font-color-light;
  328. }
  329. .buttom {
  330. color: $font-color;
  331. font-size: $font-base;
  332. }
  333. }
  334. .xian {
  335. width: 700rpx;
  336. height: 1rpx;
  337. background: #e6e6e6;
  338. margin-bottom: 16rpx;
  339. }
  340. .moneyBtn-box {
  341. display: flex;
  342. justify-content: flex-start;
  343. flex-wrap: wrap;
  344. .moneyBtn {
  345. margin-right: 30rpx;
  346. width: 210rpx;
  347. height: 70rpx;
  348. background: #f0f0f0;
  349. border-radius: 4px;
  350. margin-top: 30rpx;
  351. text-align: center;
  352. line-height: 70rpx;
  353. }
  354. }
  355. }
  356. .list {
  357. padding-left: 30rpx;
  358. margin-top: 30rpx;
  359. background-color: #ffffff;
  360. .box {
  361. display: flex;
  362. align-items: center;
  363. width: 100%;
  364. height: 120rpx;
  365. border-bottom: 1px solid $border-color-light;
  366. .icon {
  367. font-size: 48rpx;
  368. padding-right: 20rpx;
  369. }
  370. .iconweixin1 {
  371. color: #18bf16;
  372. }
  373. .iconzhifubao {
  374. color: #08aaec;
  375. }
  376. .title-box {
  377. flex-grow: 1;
  378. text-align: left;
  379. .title {
  380. font-size: $font-base + 2rpx;
  381. color: $font-color-base;
  382. }
  383. .node {
  384. font-size: $font-sm;
  385. color: $font-color-light;
  386. }
  387. }
  388. }
  389. }
  390. /deep/ .uni-radio-input {
  391. width: 45rpx;
  392. height: 45rpx;
  393. }
  394. .active-bg {
  395. background-color: $color-gray !important;
  396. }
  397. .current {
  398. background: $base-color !important;
  399. color: #fff;
  400. }
  401. .popup-box {
  402. width: 650rpx;
  403. padding-bottom: 30rpx;
  404. background-color: #ffffff;
  405. border-radius: 20rpx;
  406. position: relative;
  407. .img {
  408. position: relative;
  409. top: -56rpx;
  410. left: 0;
  411. width: 650rpx;
  412. height: 132rpx;
  413. z-index: 100;
  414. text-align: center;
  415. line-height: 132rpx;
  416. .img-bg {
  417. position: absolute;
  418. left: 50%;
  419. top: 0;
  420. margin-left: -250rpx;
  421. border-radius: 20rpx 20rpx 0 0;
  422. width: 500rpx;
  423. height: 132rpx;
  424. image {
  425. width: 100%;
  426. height: 100%;
  427. }
  428. }
  429. .img-font {
  430. line-height: 120rpx;
  431. position: relative;
  432. z-index: 10;
  433. text-align: center;
  434. font-size: 32rpx;
  435. font-weight: bold;
  436. color: #54300f;
  437. }
  438. }
  439. .mian {
  440. margin-top: -10rpx;
  441. display: flex;
  442. flex-direction: column;
  443. align-items: center;
  444. // padding: 32rpx 32rpx;
  445. background-color: #ffffff;
  446. border-radius: 0 0 20rpx 20rpx;
  447. text-align: center;
  448. padding: 20rpx;
  449. width: 100%;
  450. .main-item {
  451. display: flex;
  452. width: 580rpx;
  453. align-items: center;
  454. padding: 20rpx 40rpx;
  455. border-radius: 10rpx;
  456. background: #f5f2e5;
  457. height: 100rpx;
  458. .font{
  459. color: #623324;
  460. font-size: 30rpx;
  461. }
  462. .input {
  463. margin-left: 20rpx;
  464. text-align: left;
  465. color: #cdc0b3;
  466. font-size: 28rpx;
  467. }
  468. .input-font {
  469. color: #cdc0b3;
  470. font-size: 28rpx;
  471. }
  472. }
  473. .comfirm-box {
  474. margin-top: 80rpx;
  475. display: flex;
  476. // margin-bottom: 32rpx;
  477. // justify-content: space-around;
  478. .cancel {
  479. display: flex;
  480. align-items: center;
  481. justify-content: center;
  482. width: 260rpx;
  483. height: 100rpx;
  484. border: 1px solid #dcc786;
  485. border-radius: 10px;
  486. font-size: 32rpx;
  487. color: #605128;
  488. }
  489. .comfirm {
  490. margin-left: 60rpx;
  491. display: flex;
  492. align-items: center;
  493. justify-content: center;
  494. width: 260rpx;
  495. height: 100rpx;
  496. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  497. border-radius: 10px;
  498. font-size: 32rpx;
  499. color: #605128;
  500. }
  501. }
  502. }
  503. }
  504. </style>