recharge.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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="请选择充值金额" placeholder-class="placeholder" disabled />
  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.price, index, item.id)">
  16. {{ item.price }}元
  17. </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"><radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" /></view>
  40. </view>
  41. </label>
  42. </radio-group>
  43. </view>
  44. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">立即充值</button>
  45. </view>
  46. </template>
  47. <script>
  48. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  49. import { getMoneyStyle } from '@/utils/rocessor.js';
  50. // #ifdef H5
  51. import { rechargeWechat } from '@/api/wallet.js';
  52. // #endif
  53. import { rechargeRoutine } from '@/api/wallet.js';
  54. import { mapState, mapMutations } from 'vuex';
  55. import { getUserInfo } from '@/api/login.js';
  56. export default {
  57. components: {
  58. uniPopup
  59. },
  60. filters: {
  61. getMoneyStyle
  62. },
  63. data() {
  64. return {
  65. moneyList: [{ price: 300, id: 0 }, { price: 200, id: 1 }, { price: 150, id: 2 }, { price: 100, id: 3 }, { price: 50, id: 4 }],
  66. choose: -1,
  67. // #ifdef APP-PLUS
  68. type: 'weixinapp',
  69. // #endif
  70. // #ifdef H5
  71. type: 'weixin',
  72. // #endif
  73. money: '', //充值金额
  74. payLoding: false, //是否加载中
  75. // #ifdef H5
  76. weichatBsrowser: false,
  77. // #endif
  78. // #ifdef APP-PLUS
  79. weichatBsrowser: true,
  80. // #endif
  81. nowmoney: 0
  82. };
  83. },
  84. onLoad(options) {
  85. // #ifdef H5
  86. this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
  87. // #endif
  88. },
  89. computed: {
  90. // #ifdef H5
  91. ...mapState(['weichatObj']),
  92. // #endif
  93. ...mapState('user', ['userInfo'])
  94. },
  95. methods: {
  96. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  97. // 跳转
  98. navTo(url) {
  99. uni.navigateTo({
  100. url: url
  101. });
  102. },
  103. // 切换选中对象
  104. tabRadio(e) {
  105. this.type = e;
  106. },
  107. // 提交
  108. confirm() {
  109. let obj = this;
  110. obj.payLoding = true;
  111. if (this.money <= 0) {
  112. uni.showToast({
  113. title: '请输入金额',
  114. duration: 2000,
  115. icon: 'none'
  116. });
  117. return;
  118. }
  119. // #ifdef H5
  120. rechargeWechat({
  121. price: this.money,
  122. from: this.type,
  123. rechar_id: this.chooseId
  124. })
  125. .then(e => {
  126. console.log(e);
  127. // #ifdef H5
  128. let da = e.data.data;
  129. obj.weichatObj.chooseWXPay({
  130. timestamp: da.timestamp,
  131. nonceStr: da.nonceStr,
  132. package: da.package,
  133. signType: da.signType,
  134. paySign: da.paySign,
  135. success: function(res) {
  136. uni.showToast({
  137. title: '充值成功',
  138. duration: 2000,
  139. position: 'top'
  140. });
  141. getUserInfo()
  142. .then(({ data }) => {
  143. obj.setUserInfo(data);
  144. })
  145. .catch(e => {
  146. console.log(e);
  147. });
  148. }
  149. });
  150. // #endif
  151. // #ifdef APP-PLUS
  152. uni.requestPayment({
  153. provider: 'wxpay',
  154. orderInfo: e.data.data,
  155. success: function() {
  156. uni.showToast({
  157. title: '充值成功',
  158. duration: 2000,
  159. position: 'top'
  160. });
  161. getUserInfo()
  162. .then(({ data }) => {
  163. obj.setUserInfo(data);
  164. })
  165. .catch(e => {
  166. console.log(e);
  167. });
  168. },
  169. fail(e) {
  170. console.log(e);
  171. }
  172. });
  173. // #endif
  174. obj.payLoding = false;
  175. })
  176. .catch(e => {
  177. obj.payLoding = false;
  178. console.log(e);
  179. });
  180. // #endif
  181. // #ifdef MP-WEIXIN
  182. rechargeRoutine({
  183. price: this.money
  184. })
  185. .then(e => {
  186. console.log(e);
  187. let da = e.data;
  188. wx.requestPayment({
  189. timeStamp: da.timestamp,
  190. nonceStr: da.nonceStr,
  191. package: da.package,
  192. signType: da.signType,
  193. paySign: da.paySign,
  194. success: function(res) {
  195. uni.redirectTo({
  196. url: '/pages/money/paySuccess'
  197. });
  198. }
  199. });
  200. obj.payLoding = false;
  201. })
  202. .catch(e => {
  203. obj.payLoding = false;
  204. });
  205. // #endif
  206. },
  207. go() {
  208. this.$refs.popup.open();
  209. },
  210. cancel() {
  211. this.$refs.popup.close();
  212. this.card = '';
  213. this.pwd = '';
  214. },
  215. //获取订单列表
  216. loadData(source) {
  217. console.log(source);
  218. //这里是将订单挂载到tab列表下
  219. let index = this.tabCurrentIndex;
  220. let navItem = this.navList[index];
  221. let state = navItem.state;
  222. if (source === 'tabChange' && navItem.loaded === true) {
  223. //tab切换只有第一次需要加载数据
  224. return;
  225. }
  226. if (navItem.loadingType === 'loading') {
  227. //防止重复加载
  228. return;
  229. }
  230. navItem.loadingType = 'loading';
  231. setTimeout(() => {
  232. let orderList = [];
  233. orderList.forEach(item => {
  234. navItem.orderList.push(item);
  235. });
  236. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  237. this.$set(navItem, 'loaded', true);
  238. //判断是否还有数据, 有改为 more, 没有改为noMore
  239. navItem.loadingType = 'more';
  240. }, 600);
  241. },
  242. changemoney(item, index, id) {
  243. this.choose = index;
  244. this.money = item;
  245. this.chooseId = id;
  246. }
  247. }
  248. };
  249. </script>
  250. <style lang="scss">
  251. page {
  252. height: 100%;
  253. }
  254. .yue {
  255. display: flex;
  256. justify-content: space-between;
  257. padding: 30rpx 48rpx 30rpx 26rpx;
  258. background: #ffffff;
  259. .font {
  260. font-size: 28rpx;
  261. font-family: PingFang SC;
  262. font-weight: 500;
  263. color: #333333;
  264. }
  265. .money {
  266. font-size: 30rpx;
  267. font-family: PingFang SC;
  268. font-weight: bold;
  269. color: #ff6f0f;
  270. }
  271. }
  272. .add-btn {
  273. &.modified {
  274. color: $base-color;
  275. }
  276. &.up {
  277. background-color: #24a17d;
  278. color: #fff;
  279. }
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. width: 690rpx;
  284. height: 80rpx;
  285. margin: 0 auto;
  286. margin-top: 30rpx;
  287. font-size: $font-lg;
  288. border-radius: 10rpx;
  289. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  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: #24a17d !important;
  389. color: #fff;
  390. }
  391. </style>