recharge.vue 8.2 KB

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