recharge.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="content">
  3. <view class="yue">
  4. <view class="font">当前余额</view>
  5. <view class="money">¥{{ userInfo.now_money | 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="请选择充值金额"
  12. placeholder-class="placeholder" />
  13. </view>
  14. <view class="xian"></view>
  15. <view class="moneyBtn-box">
  16. <view class="moneyBtn" v-for="(item, index) in moneyList" :class="{ current: choose == index }"
  17. :key="index" @click="changemoney(item, index,item.id)">{{ item*1 }}元</view>
  18. </view>
  19. </view>
  20. <view class="list" v-if="!weichatBsrowser">
  21. <radio-group @change="tabRadio">
  22. <!-- #ifdef APP-PLUS -->
  23. <!-- <label>
  24. <view class="box">
  25. <view class="icon iconfont iconzhifubao"></view>
  26. <view class="title-box">
  27. <view class="title"><text>支付宝充值</text></view>
  28. </view>
  29. <view class="right"><radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" /></view>
  30. </view>
  31. </label> -->
  32. <!-- #endif -->
  33. <label>
  34. <view class="box">
  35. <view class="icon iconfont iconweixin1"></view>
  36. <view class="title-box">
  37. <view class="title"><text>微信充值</text></view>
  38. </view>
  39. <view class="right">
  40. <radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" />
  41. </view>
  42. </view>
  43. </label>
  44. </radio-group>
  45. </view>
  46. <button class="add-btn up" :class="{ 'active-bg': payLoding }"
  47. @click="!payLoding ? confirm() : ''">立即充值</button>
  48. </view>
  49. </template>
  50. <script>
  51. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  52. import {
  53. getMoneyStyle
  54. } from '@/utils/rocessor.js';
  55. import {
  56. rechargeWechat,
  57. getRechargePrice
  58. } from '@/api/wallet.js';
  59. import {
  60. mapState,
  61. mapMutations
  62. } from 'vuex';
  63. import {
  64. getUserInfo
  65. } from '@/api/login.js';
  66. export default {
  67. components: {
  68. uniPopup
  69. },
  70. filters: {
  71. getMoneyStyle
  72. },
  73. data() {
  74. return {
  75. moneyList: [],
  76. choose: -1,
  77. // #ifdef APP-PLUS
  78. type: 'weixinapp',
  79. // #endif
  80. // #ifdef H5
  81. type: 'weixin',
  82. // #endif
  83. money: '', //充值金额
  84. payLoding: false, //是否加载中
  85. // #ifdef H5
  86. weichatBsrowser: false,
  87. // #endif
  88. // #ifdef APP-PLUS
  89. weichatBsrowser: true,
  90. // #endif
  91. nowmoney: 0,
  92. card: '',
  93. pwd: '',
  94. chooseId: '',
  95. };
  96. },
  97. onLoad(options) {
  98. // #ifdef H5
  99. this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
  100. // #endif
  101. this.loadData()
  102. },
  103. computed: {
  104. // #ifdef H5
  105. ...mapState(['weichatObj']),
  106. // #endif
  107. ...mapState('user', ['userInfo'])
  108. },
  109. methods: {
  110. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  111. // 跳转
  112. navTo(url) {
  113. uni.navigateTo({
  114. url: url
  115. });
  116. },
  117. // 切换选中对象
  118. tabRadio(e) {
  119. this.type = e;
  120. },
  121. loadData() {
  122. getRechargePrice().then(({
  123. data
  124. }) => {
  125. console.log(data);
  126. this.moneyList = data
  127. })
  128. },
  129. // 提交
  130. confirm() {
  131. let obj = this;
  132. obj.payLoding = true;
  133. if (this.money <= 0) {
  134. uni.showToast({
  135. title: '请输入金额',
  136. duration: 2000,
  137. icon: 'none'
  138. });
  139. return
  140. }
  141. rechargeWechat({
  142. price: this.money,
  143. from: this.type,
  144. rechar_id: this.chooseId
  145. })
  146. .then(e => {
  147. console.log(e);
  148. // #ifdef H5
  149. let da = e.data.data;
  150. obj.weichatObj.chooseWXPay({
  151. timestamp: da.timestamp,
  152. nonceStr: da.nonceStr,
  153. package: da.package,
  154. signType: da.signType,
  155. paySign: da.paySign,
  156. success: function(res) {
  157. uni.showToast({
  158. title: '充值成功',
  159. duration: 2000,
  160. position: 'top'
  161. });
  162. getUserInfo()
  163. .then(({
  164. data
  165. }) => {
  166. obj.setUserInfo(data);
  167. })
  168. .catch(e => {
  169. console.log(e);
  170. });
  171. }
  172. });
  173. // #endif
  174. // #ifdef APP-PLUS
  175. uni.requestPayment({
  176. provider: 'wxpay',
  177. orderInfo: e.data.data,
  178. success: function() {
  179. uni.showToast({
  180. title: '充值成功',
  181. duration: 2000,
  182. position: 'top'
  183. });
  184. getUserInfo()
  185. .then(({
  186. data
  187. }) => {
  188. obj.setUserInfo(data);
  189. })
  190. .catch(e => {
  191. console.log(e);
  192. });
  193. },
  194. fail(e) {
  195. console.log(e);
  196. }
  197. });
  198. // #endif
  199. obj.payLoding = false;
  200. })
  201. .catch(e => {
  202. obj.payLoding = false;
  203. console.log(e);
  204. });
  205. },
  206. comfirm() {
  207. let obj = this
  208. verification({
  209. card_number: this.card,
  210. card_password: this.pwd,
  211. is_confirm: 1,
  212. type: 1,
  213. }).then(e => {
  214. console.log(e)
  215. this.card = '';
  216. this.pwd = '';
  217. getUserInfo()
  218. .then(({
  219. data
  220. }) => {
  221. obj.setUserInfo(data);
  222. })
  223. .catch(e => {
  224. console.log(e);
  225. });
  226. }).catch(e => {
  227. console.log(e)
  228. })
  229. this.$refs.popup.close();
  230. },
  231. changemoney(item, index, id) {
  232. this.choose = index;
  233. this.money = item * 1;
  234. this.chooseId = id
  235. }
  236. }
  237. };
  238. </script>
  239. <style lang="scss">
  240. page {
  241. height: 100%;
  242. }
  243. .yue {
  244. display: flex;
  245. justify-content: space-between;
  246. padding: 30rpx 48rpx 30rpx 26rpx;
  247. background: #ffffff;
  248. .font {
  249. font-size: 28rpx;
  250. font-family: PingFang SC;
  251. font-weight: 500;
  252. color: #333333;
  253. }
  254. .money {
  255. font-size: 30rpx;
  256. font-family: PingFang SC;
  257. font-weight: bold;
  258. color: #ff6f0f;
  259. }
  260. }
  261. .add-btn {
  262. &.modified {
  263. color: $base-color;
  264. }
  265. &.up {
  266. background-color: $base-color;
  267. color: #fff;
  268. }
  269. display: flex;
  270. align-items: center;
  271. justify-content: center;
  272. width: 690rpx;
  273. height: 80rpx;
  274. margin: 0 auto;
  275. margin-top: 30rpx;
  276. font-size: $font-lg;
  277. border-radius: 10rpx;
  278. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  279. }
  280. .card {
  281. background: #ffffff;
  282. border: 1px solid $base-color;
  283. color: $base-color;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. width: 690rpx;
  288. height: 80rpx;
  289. margin: 30rpx auto 0;
  290. font-size: $font-lg;
  291. border-radius: 10rpx;
  292. }
  293. .row-box {
  294. margin-top: 30rpx;
  295. padding: 20rpx 0rpx 20rpx 30rpx;
  296. background: #fff;
  297. .title {
  298. font-size: $font-base + 2rpx;
  299. color: $font-color-dark;
  300. }
  301. .row {
  302. display: flex;
  303. align-items: center;
  304. position: relative;
  305. height: 80rpx;
  306. .tit {
  307. flex-shrink: 0;
  308. width: 40rpx;
  309. font-size: 30rpx;
  310. color: $font-color-dark;
  311. }
  312. .input {
  313. flex: 1;
  314. font-size: 30rpx;
  315. color: $font-color-dark;
  316. }
  317. .iconlocation {
  318. font-size: 36rpx;
  319. color: $font-color-light;
  320. }
  321. .buttom {
  322. color: $font-color;
  323. font-size: $font-base;
  324. }
  325. }
  326. .xian {
  327. width: 700rpx;
  328. height: 1rpx;
  329. background: #e6e6e6;
  330. margin-bottom: 16rpx;
  331. }
  332. .moneyBtn-box {
  333. display: flex;
  334. justify-content: flex-start;
  335. flex-wrap: wrap;
  336. .moneyBtn {
  337. margin-right: 30rpx;
  338. width: 210rpx;
  339. height: 70rpx;
  340. background: #f0f0f0;
  341. border-radius: 4px;
  342. margin-top: 30rpx;
  343. text-align: center;
  344. line-height: 70rpx;
  345. }
  346. }
  347. }
  348. .list {
  349. padding-left: 30rpx;
  350. margin-top: 30rpx;
  351. background-color: #ffffff;
  352. .box {
  353. display: flex;
  354. align-items: center;
  355. width: 100%;
  356. height: 120rpx;
  357. border-bottom: 1px solid $border-color-light;
  358. .icon {
  359. font-size: 48rpx;
  360. padding-right: 20rpx;
  361. }
  362. .iconweixin1 {
  363. color: #18bf16;
  364. }
  365. .iconzhifubao {
  366. color: #08aaec;
  367. }
  368. .title-box {
  369. flex-grow: 1;
  370. text-align: left;
  371. .title {
  372. font-size: $font-base + 2rpx;
  373. color: $font-color-base;
  374. }
  375. .node {
  376. font-size: $font-sm;
  377. color: $font-color-light;
  378. }
  379. }
  380. }
  381. }
  382. /deep/ .uni-radio-input {
  383. width: 45rpx;
  384. height: 45rpx;
  385. }
  386. .active-bg {
  387. background-color: $color-gray !important;
  388. }
  389. .current {
  390. background: $base-color !important;
  391. color: #fff;
  392. }
  393. </style>