recharge.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <view class="content">
  3. <view class="yue">
  4. <view class="font">当前余额</view>
  5. <view class="money">¥{{ userInfo.now_money | 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="请选择充值金额"
  12. placeholder-class="placeholder" />
  13. </view>
  14. <view class="xian"></view>
  15. <view class="moneyBtn-box">
  16. <view class="moneyBtn" v-for="(item, index) in moneyList" :class="{ current: choose == index }"
  17. :key="index" @click="changemoney(item, index,item.id)">{{ item*1 }}元</view>
  18. </view>
  19. </view>
  20. <view class="list" v-if="!weichatBsrowser">
  21. <radio-group @change="tabRadio">
  22. <!-- #ifdef APP-PLUS -->
  23. <!-- <label>
  24. <view class="box">
  25. <view class="icon iconfont iconzhifubao"></view>
  26. <view class="title-box">
  27. <view class="title"><text>支付宝充值</text></view>
  28. </view>
  29. <view class="right"><radio value="alipay" color="#5dbc7c" :checked="type == 'alipay'" /></view>
  30. </view>
  31. </label> -->
  32. <!-- #endif -->
  33. <label>
  34. <view class="box">
  35. <view class="icon iconfont iconweixin1"></view>
  36. <view class="title-box">
  37. <view class="title"><text>微信充值</text></view>
  38. </view>
  39. <view class="right">
  40. <radio value="weixin" color=" #5dbc7c" :checked="type == 'weixin'" />
  41. </view>
  42. </view>
  43. </label>
  44. </radio-group>
  45. </view>
  46. <button class="add-btn up" :class="{ 'active-bg': payLoding }"
  47. @click="!payLoding ? confirm() : ''">立即充值</button>
  48. </view>
  49. </template>
  50. <script>
  51. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  52. import {
  53. getMoneyStyle
  54. } from '@/utils/rocessor.js';
  55. // #ifdef H5
  56. import weichatObj from '@/plugin/jweixin-module/index.js';
  57. import {
  58. rechargeWechat
  59. } from '@/api/wallet.js';
  60. // #endif
  61. // #ifdef MP
  62. import {
  63. rechargeRoutine
  64. } from '@/api/wallet.js';
  65. // #endif
  66. import {
  67. getRechargePrice
  68. } from '@/api/wallet.js';
  69. import {
  70. mapState,
  71. mapMutations
  72. } from 'vuex';
  73. import {
  74. getUserInfo
  75. } from '@/api/login.js';
  76. export default {
  77. components: {
  78. uniPopup
  79. },
  80. filters: {
  81. getMoneyStyle
  82. },
  83. data() {
  84. return {
  85. moneyList: [],
  86. choose: -1,
  87. // #ifdef APP-PLUS
  88. type: 'weixinapp',
  89. // #endif
  90. // #ifdef H5
  91. type: 'weixin',
  92. // #endif
  93. money: '', //充值金额
  94. payLoding: false, //是否加载中
  95. // #ifdef H5
  96. weichatBsrowser: false,
  97. // #endif
  98. // #ifdef APP-PLUS
  99. weichatBsrowser: true,
  100. // #endif
  101. nowmoney: 0,
  102. card: '',
  103. pwd: '',
  104. chooseId: '',
  105. };
  106. },
  107. onLoad(options) {
  108. // #ifdef H5
  109. this.weichatBsrowser = uni.getStorageSync('weichatBrowser');
  110. // #endif
  111. this.loadData()
  112. },
  113. computed: {
  114. ...mapState('user', ['userInfo'])
  115. },
  116. methods: {
  117. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  118. // 跳转
  119. navTo(url) {
  120. uni.navigateTo({
  121. url: url
  122. });
  123. },
  124. // 切换选中对象
  125. tabRadio(e) {
  126. this.type = e;
  127. },
  128. loadData() {
  129. getRechargePrice().then(({
  130. data
  131. }) => {
  132. console.log(data);
  133. this.moneyList = data
  134. })
  135. },
  136. // 提交
  137. confirm() {
  138. let obj = this;
  139. obj.payLoding = true;
  140. // #ifdef H5
  141. rechargeWechat({
  142. price: this.money,
  143. from: this.type
  144. })
  145. .then(e => {
  146. let da = e.data.data;
  147. obj.weichatObj.chooseWXPay({
  148. timestamp: da.timestamp,
  149. nonceStr: da.nonceStr,
  150. package: da.package,
  151. signType: da.signType,
  152. paySign: da.paySign,
  153. success: function(res) {
  154. uni.showToast({
  155. title: '充值成功',
  156. duration: 2000,
  157. position: 'top'
  158. });
  159. }
  160. });
  161. obj.payLoding = false;
  162. })
  163. .catch(e => {
  164. obj.payLoding = false;
  165. console.log(e);
  166. });
  167. // #endif
  168. // #ifdef MP
  169. rechargeRoutine({
  170. price: this.money
  171. })
  172. .then(e => {
  173. let da = e.data;
  174. wx.requestPayment({
  175. timeStamp: da.timestamp,
  176. nonceStr: da.nonceStr,
  177. package: da.package,
  178. signType: da.signType,
  179. paySign: da.paySign,
  180. success: function(res) {
  181. uni.redirectTo({
  182. url: '/pages/money/paySuccess'
  183. });
  184. },
  185. })
  186. obj.payLoding = false;
  187. })
  188. .catch(e => {
  189. obj.payLoding = false;
  190. console.log(e);
  191. });
  192. // #endif
  193. },
  194. comfirm() {
  195. let obj = this
  196. verification({
  197. card_number: this.card,
  198. card_password: this.pwd,
  199. is_confirm: 1,
  200. type: 1,
  201. }).then(e => {
  202. console.log(e)
  203. this.card = '';
  204. this.pwd = '';
  205. getUserInfo()
  206. .then(({
  207. data
  208. }) => {
  209. obj.setUserInfo(data);
  210. })
  211. .catch(e => {
  212. console.log(e);
  213. });
  214. }).catch(e => {
  215. console.log(e)
  216. })
  217. this.$refs.popup.close();
  218. },
  219. changemoney(item, index, id) {
  220. this.choose = index;
  221. this.money = item * 1;
  222. this.chooseId = id
  223. }
  224. }
  225. };
  226. </script>
  227. <style lang="scss">
  228. page {
  229. height: 100%;
  230. }
  231. .yue {
  232. display: flex;
  233. justify-content: space-between;
  234. padding: 30rpx 48rpx 30rpx 26rpx;
  235. background: #ffffff;
  236. .font {
  237. font-size: 28rpx;
  238. font-family: PingFang SC;
  239. font-weight: 500;
  240. color: #333333;
  241. }
  242. .money {
  243. font-size: 30rpx;
  244. font-family: PingFang SC;
  245. font-weight: bold;
  246. color: #ff6f0f;
  247. }
  248. }
  249. .add-btn {
  250. &.modified {
  251. color: $base-color;
  252. }
  253. &.up {
  254. background: linear-gradient(0deg, #C39258, #ECC89E);
  255. color: #fff;
  256. }
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. width: 690rpx;
  261. height: 80rpx;
  262. margin: 0 auto;
  263. margin-top: 30rpx;
  264. font-size: $font-lg;
  265. border-radius: 10rpx;
  266. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  267. }
  268. .card {
  269. background: #ffffff;
  270. border: 1px solid $base-color;
  271. color: $base-color;
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. width: 690rpx;
  276. height: 80rpx;
  277. margin: 30rpx auto 0;
  278. font-size: $font-lg;
  279. border-radius: 10rpx;
  280. }
  281. .row-box {
  282. margin-top: 30rpx;
  283. padding: 20rpx 0rpx 20rpx 30rpx;
  284. background: #fff;
  285. .title {
  286. font-size: $font-base + 2rpx;
  287. color: $font-color-dark;
  288. }
  289. .row {
  290. display: flex;
  291. align-items: center;
  292. position: relative;
  293. height: 80rpx;
  294. .tit {
  295. flex-shrink: 0;
  296. width: 40rpx;
  297. font-size: 30rpx;
  298. color: $font-color-dark;
  299. }
  300. .input {
  301. flex: 1;
  302. font-size: 30rpx;
  303. color: $font-color-dark;
  304. }
  305. .iconlocation {
  306. font-size: 36rpx;
  307. color: $font-color-light;
  308. }
  309. .buttom {
  310. color: $font-color;
  311. font-size: $font-base;
  312. }
  313. }
  314. .xian {
  315. width: 700rpx;
  316. height: 1rpx;
  317. background: #e6e6e6;
  318. margin-bottom: 16rpx;
  319. }
  320. .moneyBtn-box {
  321. display: flex;
  322. justify-content: flex-start;
  323. flex-wrap: wrap;
  324. .moneyBtn {
  325. margin-right: 30rpx;
  326. width: 210rpx;
  327. height: 70rpx;
  328. background: #f0f0f0;
  329. border-radius: 4px;
  330. margin-top: 30rpx;
  331. text-align: center;
  332. line-height: 70rpx;
  333. }
  334. }
  335. }
  336. .list {
  337. padding-left: 30rpx;
  338. margin-top: 30rpx;
  339. background-color: #ffffff;
  340. .box {
  341. display: flex;
  342. align-items: center;
  343. width: 100%;
  344. height: 120rpx;
  345. border-bottom: 1px solid $border-color-light;
  346. .icon {
  347. font-size: 48rpx;
  348. padding-right: 20rpx;
  349. }
  350. .iconweixin1 {
  351. color: #18bf16;
  352. }
  353. .iconzhifubao {
  354. color: #08aaec;
  355. }
  356. .title-box {
  357. flex-grow: 1;
  358. text-align: left;
  359. .title {
  360. font-size: $font-base + 2rpx;
  361. color: $font-color-base;
  362. }
  363. .node {
  364. font-size: $font-sm;
  365. color: $font-color-light;
  366. }
  367. }
  368. }
  369. }
  370. /deep/ .uni-radio-input {
  371. width: 45rpx;
  372. height: 45rpx;
  373. }
  374. .active-bg {
  375. background-color: $color-gray !important;
  376. }
  377. .current {
  378. background: $base-color !important;
  379. color: #fff;
  380. }
  381. </style>