recharge.vue 5.6 KB

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