recharge.vue 6.9 KB

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