recharge.vue 11 KB

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