recharge.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="content">
  3. <view class="row-box">
  4. <view class="title">充值金额</view>
  5. <view class="row">
  6. <text class="tit">¥</text>
  7. <input class="input" type="number" v-model="money" placeholder="请输入充值金额" placeholder-class="placeholder" />
  8. </view>
  9. </view>
  10. <view class="list" v-if="!weichatBsrowser">
  11. <radio-group @change="tabRadio">
  12. <!-- #ifdef APP-PLUS -->
  13. <!-- <label>
  14. <view class="box">
  15. <view class="icon iconfont iconzhifubao"></view>
  16. <view class="title-box">
  17. <view class="title"><text>支付宝充值</text></view>
  18. </view>
  19. <view class="right"><radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" /></view>
  20. </view>
  21. </label> -->
  22. <!-- #endif -->
  23. <label>
  24. <view class="box">
  25. <view class="icon iconfont iconweixin1"></view>
  26. <view class="title-box">
  27. <view class="title"><text>微信充值</text></view>
  28. </view>
  29. <view class="right"><radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" /></view>
  30. </view>
  31. </label>
  32. </radio-group>
  33. </view>
  34. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认充值</button>
  35. </view>
  36. </template>
  37. <script>
  38. import { getMoneyStyle } from '@/utils/rocessor.js';
  39. import { rechargeWechat } from '@/api/wallet.js';
  40. import { mapState } from 'vuex';
  41. export default {
  42. filters: {
  43. getMoneyStyle
  44. },
  45. data() {
  46. return {
  47. // #ifdef APP-PLUS
  48. type: 'weixinapp',
  49. // #endif
  50. // #ifdef H5
  51. type: 'weixin',
  52. // #endif
  53. money: '', //充值金额
  54. payLoding: false, //是否加载中
  55. // #ifdef H5
  56. weichatBsrowser: false,
  57. // #endif
  58. // #ifdef APP-PLUS
  59. weichatBsrowser: true
  60. // #endif
  61. };
  62. },
  63. onLoad(options) {
  64. // #ifdef H5
  65. this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
  66. // #endif
  67. },
  68. computed: {
  69. // #ifdef H5
  70. ...mapState(['weichatObj'])
  71. // #endif
  72. },
  73. methods: {
  74. // 跳转
  75. navTo(url) {
  76. uni.navigateTo({
  77. url: url
  78. });
  79. },
  80. // 切换选中对象
  81. tabRadio(e) {
  82. this.type = e;
  83. },
  84. // 提交
  85. confirm() {
  86. let obj = this;
  87. obj.payLoding = true;
  88. if(this.money<=0){
  89. uni.showToast({
  90. title: '请输入金额',
  91. duration: 2000,
  92. icon:'none'
  93. });
  94. return
  95. }
  96. rechargeWechat({ price: this.money, from: this.type })
  97. .then(e => {
  98. console.log(e);
  99. // #ifdef H5
  100. let da = e.data.data;
  101. obj.weichatObj.chooseWXPay({
  102. timestamp: da.timestamp,
  103. nonceStr: da.nonceStr,
  104. package: da.package,
  105. signType: da.signType,
  106. paySign: da.paySign,
  107. success: function(res) {
  108. uni.showToast({
  109. title: '充值成功',
  110. duration: 2000,
  111. position: 'top'
  112. });
  113. }
  114. });
  115. // #endif
  116. // #ifdef APP-PLUS
  117. uni.requestPayment({
  118. provider: 'wxpay',
  119. orderInfo: e.data.data,
  120. success: function() {
  121. uni.showToast({
  122. title: '充值成功',
  123. duration: 2000,
  124. position: 'top'
  125. });
  126. },
  127. fail(e) {
  128. console.log(e);
  129. }
  130. });
  131. // #endif
  132. obj.payLoding = false;
  133. })
  134. .catch(e => {
  135. obj.payLoding = false;
  136. console.log(e);
  137. });
  138. },
  139. //获取订单列表
  140. loadData(source) {
  141. console.log(source);
  142. //这里是将订单挂载到tab列表下
  143. let index = this.tabCurrentIndex;
  144. let navItem = this.navList[index];
  145. let state = navItem.state;
  146. if (source === 'tabChange' && navItem.loaded === true) {
  147. //tab切换只有第一次需要加载数据
  148. return;
  149. }
  150. if (navItem.loadingType === 'loading') {
  151. //防止重复加载
  152. return;
  153. }
  154. navItem.loadingType = 'loading';
  155. setTimeout(() => {
  156. let orderList = [];
  157. orderList.forEach(item => {
  158. navItem.orderList.push(item);
  159. });
  160. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  161. this.$set(navItem, 'loaded', true);
  162. //判断是否还有数据, 有改为 more, 没有改为noMore
  163. navItem.loadingType = 'more';
  164. }, 600);
  165. }
  166. }
  167. };
  168. </script>
  169. <style lang="scss">
  170. page {
  171. height: 100%;
  172. }
  173. .add-btn {
  174. &.modified {
  175. color: $base-color;
  176. }
  177. &.up {
  178. background-color: $base-color;
  179. color: #fff;
  180. }
  181. display: flex;
  182. align-items: center;
  183. justify-content: center;
  184. width: 690rpx;
  185. height: 80rpx;
  186. margin: 0 auto;
  187. margin-top: 30rpx;
  188. font-size: $font-lg;
  189. border-radius: 10rpx;
  190. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  191. }
  192. .row-box {
  193. margin-top: 30rpx;
  194. padding: 20rpx 30rpx;
  195. background: #fff;
  196. .title {
  197. font-size: $font-base + 2rpx;
  198. color: $font-color-dark;
  199. }
  200. .row {
  201. display: flex;
  202. align-items: center;
  203. position: relative;
  204. height: 80rpx;
  205. .tit {
  206. flex-shrink: 0;
  207. width: 40rpx;
  208. font-size: 30rpx;
  209. color: $font-color-dark;
  210. }
  211. .input {
  212. flex: 1;
  213. font-size: 30rpx;
  214. color: $font-color-dark;
  215. }
  216. .iconlocation {
  217. font-size: 36rpx;
  218. color: $font-color-light;
  219. }
  220. .buttom {
  221. color: $font-color;
  222. font-size: $font-base;
  223. }
  224. }
  225. }
  226. .list {
  227. padding-left: 30rpx;
  228. margin-top: 30rpx;
  229. background-color: #ffffff;
  230. .box {
  231. display: flex;
  232. align-items: center;
  233. width: 100%;
  234. height: 120rpx;
  235. border-bottom: 1px solid $border-color-light;
  236. .icon {
  237. font-size: 48rpx;
  238. padding-right: 20rpx;
  239. }
  240. .iconweixin1 {
  241. color: #18bf16;
  242. }
  243. .iconzhifubao {
  244. color: #08aaec;
  245. }
  246. .title-box {
  247. flex-grow: 1;
  248. text-align: left;
  249. .title {
  250. font-size: $font-base + 2rpx;
  251. color: $font-color-base;
  252. }
  253. .node {
  254. font-size: $font-sm;
  255. color: $font-color-light;
  256. }
  257. }
  258. }
  259. }
  260. /deep/ .uni-radio-input {
  261. width: 45rpx;
  262. height: 45rpx;
  263. }
  264. .active-bg {
  265. background-color: $color-gray !important;
  266. }
  267. </style>