recharge.vue 7.2 KB

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