recharge.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. </view>
  44. </template>
  45. <script>
  46. import { getMoneyStyle } from '@/utils/rocessor.js';
  47. import { rechargeWechat } from '@/api/wallet.js';
  48. import { mapState } from 'vuex';
  49. export default {
  50. filters: {
  51. getMoneyStyle
  52. },
  53. data() {
  54. return {
  55. moneyList: [300, 200, 150, 100, 50],
  56. choose: -1,
  57. // #ifdef APP-PLUS
  58. type: 'weixinapp',
  59. // #endif
  60. // #ifdef H5
  61. type: 'weixin',
  62. // #endif
  63. money: '', //充值金额
  64. payLoding: false, //是否加载中
  65. // #ifdef H5
  66. weichatBsrowser: false,
  67. // #endif
  68. // #ifdef APP-PLUS
  69. weichatBsrowser: true
  70. // #endif
  71. };
  72. },
  73. onLoad(options) {
  74. // #ifdef H5
  75. this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
  76. // #endif
  77. },
  78. computed: {
  79. // #ifdef H5
  80. ...mapState(['weichatObj'])
  81. // #endif
  82. },
  83. methods: {
  84. // 跳转
  85. navTo(url) {
  86. uni.navigateTo({
  87. url: url
  88. });
  89. },
  90. // 切换选中对象
  91. tabRadio(e) {
  92. this.type = e;
  93. },
  94. // 提交
  95. confirm() {
  96. let obj = this;
  97. obj.payLoding = true;
  98. if(this.money<=0){
  99. uni.showToast({
  100. title: '请输入金额',
  101. duration: 2000,
  102. icon:'none'
  103. });
  104. return
  105. }
  106. rechargeWechat({ price: this.money, from: this.type })
  107. .then(e => {
  108. console.log(e);
  109. // #ifdef H5
  110. let da = e.data.data;
  111. obj.weichatObj.chooseWXPay({
  112. timestamp: da.timestamp,
  113. nonceStr: da.nonceStr,
  114. package: da.package,
  115. signType: da.signType,
  116. paySign: da.paySign,
  117. success: function(res) {
  118. uni.showToast({
  119. title: '充值成功',
  120. duration: 2000,
  121. position: 'top'
  122. });
  123. }
  124. });
  125. // #endif
  126. // #ifdef APP-PLUS
  127. uni.requestPayment({
  128. provider: 'wxpay',
  129. orderInfo: e.data.data,
  130. success: function() {
  131. uni.showToast({
  132. title: '充值成功',
  133. duration: 2000,
  134. position: 'top'
  135. });
  136. },
  137. fail(e) {
  138. console.log(e);
  139. }
  140. });
  141. // #endif
  142. obj.payLoding = false;
  143. })
  144. .catch(e => {
  145. obj.payLoding = false;
  146. console.log(e);
  147. });
  148. },
  149. //获取订单列表
  150. loadData(source) {
  151. console.log(source);
  152. //这里是将订单挂载到tab列表下
  153. let index = this.tabCurrentIndex;
  154. let navItem = this.navList[index];
  155. let state = navItem.state;
  156. if (source === 'tabChange' && navItem.loaded === true) {
  157. //tab切换只有第一次需要加载数据
  158. return;
  159. }
  160. if (navItem.loadingType === 'loading') {
  161. //防止重复加载
  162. return;
  163. }
  164. navItem.loadingType = 'loading';
  165. setTimeout(() => {
  166. let orderList = [];
  167. orderList.forEach(item => {
  168. navItem.orderList.push(item);
  169. });
  170. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  171. this.$set(navItem, 'loaded', true);
  172. //判断是否还有数据, 有改为 more, 没有改为noMore
  173. navItem.loadingType = 'more';
  174. }, 600);
  175. },
  176. changemoney(item, index) {
  177. this.choose = index;
  178. this.money = item;
  179. }
  180. }
  181. };
  182. </script>
  183. <style lang="scss">
  184. page {
  185. height: 100%;
  186. }
  187. .yue {
  188. display: flex;
  189. justify-content: space-between;
  190. padding: 30rpx 48rpx 30rpx 26rpx;
  191. background: #ffffff;
  192. .font {
  193. font-size: 28rpx;
  194. font-family: PingFang SC;
  195. font-weight: 500;
  196. color: #333333;
  197. }
  198. .money {
  199. font-size: 30rpx;
  200. font-family: PingFang SC;
  201. font-weight: bold;
  202. color: #FF6F0F;
  203. }
  204. }
  205. .add-btn {
  206. &.modified {
  207. color: $base-color;
  208. }
  209. &.up {
  210. background-color: $base-color;
  211. color: #fff;
  212. }
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. width: 690rpx;
  217. height: 80rpx;
  218. margin: 0 auto;
  219. margin-top: 30rpx;
  220. font-size: $font-lg;
  221. border-radius: 10rpx;
  222. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  223. }
  224. .row-box {
  225. margin-top: 30rpx;
  226. padding: 20rpx 0rpx 20rpx 30rpx;
  227. background: #fff;
  228. .title {
  229. font-size: $font-base + 2rpx;
  230. color: $font-color-dark;
  231. }
  232. .row {
  233. display: flex;
  234. align-items: center;
  235. position: relative;
  236. height: 80rpx;
  237. .tit {
  238. flex-shrink: 0;
  239. width: 40rpx;
  240. font-size: 30rpx;
  241. color: $font-color-dark;
  242. }
  243. .input {
  244. flex: 1;
  245. font-size: 30rpx;
  246. color: $font-color-dark;
  247. }
  248. .iconlocation {
  249. font-size: 36rpx;
  250. color: $font-color-light;
  251. }
  252. .buttom {
  253. color: $font-color;
  254. font-size: $font-base;
  255. }
  256. }
  257. .xian {
  258. width: 700rpx;
  259. height: 1rpx;
  260. background: #e6e6e6;
  261. margin-bottom: 16rpx;
  262. }
  263. .moneyBtn-box {
  264. display: flex;
  265. justify-content: flex-start;
  266. flex-wrap: wrap;
  267. .moneyBtn {
  268. margin-right: 30rpx;
  269. width: 210rpx;
  270. height: 70rpx;
  271. background: #f0f0f0;
  272. border-radius: 4px;
  273. margin-top: 30rpx;
  274. text-align: center;
  275. line-height: 70rpx;
  276. }
  277. }
  278. }
  279. .list {
  280. padding-left: 30rpx;
  281. margin-top: 30rpx;
  282. background-color: #ffffff;
  283. .box {
  284. display: flex;
  285. align-items: center;
  286. width: 100%;
  287. height: 120rpx;
  288. border-bottom: 1px solid $border-color-light;
  289. .icon {
  290. font-size: 48rpx;
  291. padding-right: 20rpx;
  292. }
  293. .iconweixin1 {
  294. color: #18bf16;
  295. }
  296. .iconzhifubao {
  297. color: #08aaec;
  298. }
  299. .title-box {
  300. flex-grow: 1;
  301. text-align: left;
  302. .title {
  303. font-size: $font-base + 2rpx;
  304. color: $font-color-base;
  305. }
  306. .node {
  307. font-size: $font-sm;
  308. color: $font-color-light;
  309. }
  310. }
  311. }
  312. }
  313. /deep/ .uni-radio-input {
  314. width: 45rpx;
  315. height: 45rpx;
  316. }
  317. .active-bg {
  318. background-color: $color-gray !important;
  319. }
  320. .current {
  321. background: $base-color!important;
  322. color: #fff;
  323. }
  324. </style>