recharge.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <view class="content" :class="['qn-page-' + theme]">
  3. <view class="now">
  4. <view>当前余额:</view>
  5. <view class="now-money">¥{{Number(userInfo.memberBalance) || 0 }}</view>
  6. </view>
  7. <view class="main-jg"></view>
  8. <view class="add-wrapper">
  9. <view class="add-box">
  10. <view class="add-log">¥</view>
  11. <input type="text" v-model="money" placeholder="请输入充值金额" placeholder-class="place"
  12. @keyup="clearNoNum()" />
  13. </view>
  14. <view class="jg" style="height: 1px; background-color: #E6E6E6;"></view>
  15. <view class="add-tags">
  16. <view class="tag" v-for="(item, index) in addTags" :key="item" @click="tagClick(index)"
  17. :class="{ 'primary-lg': currentIndex === index && money == addTags[index].money }">
  18. <view class="">
  19. <text>{{ item.money }}</text>
  20. </view>
  21. <view class="give">
  22. 赠送:<text>{{ item.give }}</text>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="main-jg"></view>
  28. <button class="add-btn up primary-lg" :class="{ 'active-bg': payLoding }"
  29. @click="!payLoding ? confirm() : ''">立即充值</button>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. mapState
  35. } from 'vuex';
  36. export default {
  37. data() {
  38. return {
  39. userInfo: {},
  40. type: 'weixin',
  41. money: '', //充值金额
  42. payLoding: false, //是否加载中
  43. addTags: [],
  44. currentIndex: 0,
  45. addMoney: 0,
  46. isSect: false, //是否选择微信充值
  47. new_money: 0,
  48. };
  49. },
  50. onLoad(options) {
  51. this.getCustomerInfo()
  52. this.getRechargeList()
  53. },
  54. computed: {},
  55. methods: {
  56. getCustomerInfo() {
  57. this.$u.api.getCustomerInfo().then(({
  58. data
  59. }) => {
  60. console.log(data);
  61. this.userInfo = data;
  62. });
  63. },
  64. getRechargeList() {
  65. this.$u.api.getRechargeList({
  66. page: 1,
  67. pageSize: 100
  68. }).then(res => {
  69. console.log(res);
  70. this.addTags = res.data
  71. })
  72. },
  73. // 跳转
  74. navTo(url) {
  75. uni.navigateTo({
  76. url: url
  77. });
  78. },
  79. // 切换选中对象
  80. tabRadio(e) {
  81. this.type = e;
  82. },
  83. // 提交
  84. confirm() {
  85. let obj = this;
  86. if (this.money == 0) {
  87. return this.$api.msg('请输入充值金额');
  88. }
  89. obj.payLoding = true;
  90. obj.$u.api.recharge({
  91. // price: this.money
  92. request_id: obj.userInfo.id,
  93. pay_type: 1,
  94. money: obj.money,
  95. source: obj.$common.source()
  96. })
  97. .then(e => {
  98. let da = e.data.data;
  99. console.log(da,'da');
  100. try{
  101. wx.requestPayment({
  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.redirectTo({
  109. // url: '/pages/money/paySuccess?isshow=false'
  110. // });
  111. uni.showToast({
  112. title: '充值成功'
  113. });
  114. setTimeout(()=> {
  115. uni.navigateBack()
  116. })
  117. },fail(e) {
  118. console.log(e);
  119. }
  120. });
  121. }catch(e){
  122. console.log(e,'e');
  123. //TODO handle the exception
  124. }
  125. obj.payLoding = false;
  126. })
  127. .catch(e => {
  128. obj.payLoding = false;
  129. console.log(e);
  130. });
  131. },
  132. //获取订单列表
  133. loadData(source) {
  134. console.log(source);
  135. //这里是将订单挂载到tab列表下
  136. let index = this.tabCurrentIndex;
  137. let navItem = this.navList[index];
  138. let state = navItem.state;
  139. if (source === 'tabChange' && navItem.loaded === true) {
  140. //tab切换只有第一次需要加载数据
  141. return;
  142. }
  143. if (navItem.loadingType === 'loading') {
  144. //防止重复加载
  145. return;
  146. }
  147. navItem.loadingType = 'loading';
  148. setTimeout(() => {
  149. let orderList = [];
  150. orderList.forEach(item => {
  151. navItem.orderList.push(item);
  152. });
  153. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  154. this.$set(navItem, 'loaded', true);
  155. //判断是否还有数据, 有改为 more, 没有改为noMore
  156. navItem.loadingType = 'more';
  157. }, 600);
  158. },
  159. tagClick(index) {
  160. this.currentIndex = index;
  161. this.money = this.addTags[index].money;
  162. },
  163. clearNoNum() {
  164. this.money = this.money.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
  165. // switch (this.money) {
  166. // case '300':
  167. // this.currentIndex = 0;
  168. // break;
  169. // case '200':
  170. // this.currentIndex = 1;
  171. // break;
  172. // case '150':
  173. // this.currentIndex = 2;
  174. // break;
  175. // case '100':
  176. // this.currentIndex = 3;
  177. // break;
  178. // case '50':
  179. // this.currentIndex = 4;
  180. // break;
  181. // }
  182. // let item = this.addTags.find(item=> {
  183. // return item.money == this.money
  184. // })
  185. this.addTags.forEach((item, index) => {
  186. if (item.money * 1 == this.money * 1) {
  187. this.currentIndex = index
  188. console.log(this.currentIndex);
  189. }
  190. })
  191. },
  192. btnClick() {
  193. this.isSect = !this.isSect
  194. },
  195. userBalance() {
  196. userBalance().then(res => {
  197. this.new_money = res.data.now_money
  198. console.log(res)
  199. })
  200. }
  201. }
  202. };
  203. </script>
  204. <style lang="scss">
  205. page {
  206. height: 100%;
  207. background-color: #fff;
  208. }
  209. .add-btn {
  210. &.modified {
  211. color: $base-color;
  212. }
  213. &.up {
  214. background-color: $base-color;
  215. color: #fff;
  216. }
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. width: 604rpx;
  221. height: 90rpx;
  222. margin: 0 auto;
  223. margin-top: 30rpx;
  224. font-size: $font-lg;
  225. border-radius: 10rpx;
  226. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  227. }
  228. .row-box {
  229. margin-top: 30rpx;
  230. padding: 20rpx 30rpx;
  231. background: #fff;
  232. .title {
  233. font-size: 28rpx;
  234. color: $font-color-dark;
  235. }
  236. .row {
  237. display: flex;
  238. align-items: center;
  239. position: relative;
  240. height: 80rpx;
  241. .tit {
  242. flex-shrink: 0;
  243. width: 40rpx;
  244. font-size: 30rpx;
  245. color: $font-color-dark;
  246. }
  247. .input {
  248. flex: 1;
  249. font-size: 30rpx;
  250. color: $font-color-dark;
  251. }
  252. .iconlocation {
  253. font-size: 36rpx;
  254. color: $font-color-light;
  255. }
  256. .buttom {
  257. color: $font-color;
  258. font-size: $font-base;
  259. }
  260. }
  261. }
  262. .list {
  263. padding-left: 30rpx;
  264. margin-top: 30rpx;
  265. background-color: #ffffff;
  266. .box {
  267. display: flex;
  268. align-items: center;
  269. width: 100%;
  270. height: 120rpx;
  271. border-bottom: 1px solid $border-color-light;
  272. .icon {
  273. font-size: 48rpx;
  274. padding-right: 20rpx;
  275. }
  276. .iconweixin1 {
  277. color: #18bf16;
  278. }
  279. .iconzhifubao {
  280. color: #08aaec;
  281. }
  282. .title-box {
  283. flex-grow: 1;
  284. text-align: left;
  285. .title {
  286. font-size: $font-base + 2upx;
  287. color: $font-color-base;
  288. }
  289. .node {
  290. font-size: $font-sm;
  291. color: $font-color-light;
  292. }
  293. }
  294. }
  295. }
  296. /deep/ .uni-radio-input {
  297. width: 45rpx;
  298. height: 45rpx;
  299. }
  300. .active-bg {
  301. background-color: red !important;
  302. }
  303. .now {
  304. width: 100%;
  305. height: 86rpx;
  306. padding: 0 26rpx 0 47rpx;
  307. display: flex;
  308. justify-content: space-between;
  309. line-height: 86rpx;
  310. background-color: #fff;
  311. // margin-bottom: 21rpx;
  312. view {
  313. font-size: 28rpx;
  314. font-weight: 500;
  315. color: #333333;
  316. }
  317. .now-money {
  318. font-size: 32rpx;
  319. font-weight: bold;
  320. }
  321. }
  322. .add-wrapper {
  323. width: 750rpx;
  324. height: 338rpx;
  325. padding-left: 30rpx;
  326. background: #ffffff;
  327. display: flex;
  328. flex-direction: column;
  329. align-items: center;
  330. // margin-bottom: 22rpx;
  331. .add-box {
  332. width: 100%;
  333. height: 103rpx;
  334. display: flex;
  335. flex-direction: row;
  336. justify-content: space-between;
  337. padding: 0 39rpx 0 10rpx;
  338. align-items: center;
  339. .add-log {
  340. font-size: 37rpx;
  341. font-weight: bold;
  342. }
  343. input {
  344. width: 218rpx;
  345. height: 30rpx;
  346. font-size: 32rpx;
  347. font-weight: 500;
  348. color: #000;
  349. line-height: 40px;
  350. text-align: right;
  351. .place {
  352. color: #bfbfbf;
  353. }
  354. }
  355. }
  356. .jg {
  357. width: 100%;
  358. }
  359. .add-tags {
  360. // height: 234rpx;
  361. padding-top: 47rpx;
  362. padding-bottom: 17rpx;
  363. display: flex;
  364. flex-direction: row;
  365. flex-wrap: wrap;
  366. // justify-content: space-between;
  367. .tag {
  368. width: 210rpx;
  369. // height: 140rpx;
  370. padding-top: 10rpx;
  371. padding-bottom: 10rpx;
  372. background-color: #f0f0f0;
  373. border-radius: 4rpx;
  374. margin: 0 30rpx 30rpx 0;
  375. text-align: center;
  376. // line-height: 70rpx;
  377. font-size: 22rpx;
  378. text {
  379. font-size: 32rpx;
  380. font-weight: 500;
  381. }
  382. .give {
  383. font-size: 24rpx;
  384. text {
  385. font-size: 24rpx;
  386. }
  387. }
  388. }
  389. .action {
  390. color: #fff;
  391. background-color: #901b21;
  392. }
  393. }
  394. }
  395. .btn-wrapper {
  396. padding: 49rpx 32rpx 0 40rpx;
  397. height: 183rpx;
  398. display: flex;
  399. justify-content: space-between;
  400. background-color: #fff;
  401. .iconweixin1 {
  402. color: #18bf16;
  403. font-size: 48rpx;
  404. display: flex;
  405. view {
  406. // display: inline-block;
  407. height: 48rpx;
  408. text-align: 48rpx;
  409. padding-left: 20rpx;
  410. // padding-top: 10rpx;
  411. color: #000000;
  412. font-size: 30rpx;
  413. }
  414. }
  415. .btn {
  416. width: 36rpx;
  417. height: 36rpx;
  418. border: 4rpx #901b21 solid;
  419. border-radius: 8rpx 8rpx;
  420. image {
  421. // display: none;
  422. width: 100%;
  423. height: 100%;
  424. }
  425. .action {
  426. display: none;
  427. }
  428. }
  429. .actiont {
  430. border: none;
  431. }
  432. }
  433. .main-jg {
  434. width: 100%;
  435. height: 21rpx;
  436. background-color: #f8f6f6;
  437. }
  438. </style>