recharge.vue 8.5 KB

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