recharge.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <view class="content">
  3. <view class="row-box">
  4. <view class="money-box">
  5. <view class="money">{{ myMoney }}</view>
  6. <view class="money-text">我的糖果数量</view>
  7. </view>
  8. <!-- <view class="chong">充值记录</view> -->
  9. </view>
  10. <view class="main-box">
  11. <view class="main-top flex">
  12. <view @click="change(item)" class="main-item" v-for="(item, index) in numList" :class="{ check: money === item }" :key="index">
  13. <view class="item-top">
  14. <view class="bg"><image src="../../static/icon/candy.png" mode=""></image></view>
  15. <view class="item-name" :class="{ checks: money === item }">{{ ((item / all.rmb_price) * 1) | rule }}糖果</view>
  16. </view>
  17. <view class="item-price" :class="{ checks: money === item }">
  18. <text>{{ item }}元</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="list">
  23. <radio-group @change="tabRadio">
  24. <!-- #ifdef APP-PLUS -->
  25. <label>
  26. <view class="box">
  27. <view class="icon iconfont iconzhifubao"></view>
  28. <view class="title-box">
  29. <view class="title"><text>支付宝充值</text></view>
  30. </view>
  31. <view class="right"><radio value="ali" color="#EB001C" :checked="type == 'ali'" /></view>
  32. </view>
  33. </label>
  34. <!-- #endif -->
  35. <label>
  36. <view class="box">
  37. <view class="icon iconfont iconweixin1"></view>
  38. <view class="title-box">
  39. <view class="title"><text>微信充值</text></view>
  40. </view>
  41. <view class="right"><radio value="weixin" color=" #EB001C" :checked="type == 'weixin'" /></view>
  42. </view>
  43. </label>
  44. </radio-group>
  45. </view>
  46. <button class="add-btn up" :class="{ 'active-bg': payLoding }" @click="!payLoding ? confirm() : ''">确认充值</button>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import { wallet } from '@/api/finance.js';
  52. // #ifdef H5
  53. import { rechargeWechat } from '@/api/wallet.js';
  54. // #endif
  55. // #ifdef MP
  56. import { rechargeRoutine } from '@/api/wallet.js';
  57. // #endif
  58. // #ifdef APP-PLUS
  59. import { rechargeApp, rechargeAli } from '@/api/wallet.js';
  60. // #endif
  61. import { mapState } from 'vuex';
  62. export default {
  63. filters: {
  64. rule(i) {
  65. console.log(i);
  66. let j = Math.floor(i * 100) / 100;
  67. return j;
  68. }
  69. },
  70. data() {
  71. return {
  72. type: 'weixin',
  73. numList: ['10', '20', '50', '80', '100', '200'],
  74. money: 10, //充值金额
  75. payLoding: false, //是否加载中
  76. myMoney: 0, //我的糖果数
  77. all: '' //糖果的具体情况
  78. };
  79. },
  80. onLoad(options) {
  81. wallet({}).then(({ data }) => {
  82. const obj = this;
  83. const arr = Object.keys(data.back);
  84. arr.forEach(e => {
  85. if (e == 'LALA') {
  86. obj.myMoney = data.back[e].money.money * 1;
  87. obj.all = data.back[e];
  88. }
  89. });
  90. });
  91. },
  92. computed: {
  93. // #ifdef H5
  94. ...mapState(['weichatObj'])
  95. // #endif
  96. },
  97. methods: {
  98. // 跳转
  99. navTo(url) {
  100. uni.navigateTo({
  101. url: url
  102. });
  103. },
  104. change(item) {
  105. this.money = item;
  106. },
  107. // 切换选中对象
  108. tabRadio(e) {
  109. this.type = e.detail.value;
  110. console.log(this.type, '选择支付方式');
  111. },
  112. // 提交
  113. confirm() {
  114. let obj = this;
  115. obj.payLoding = true;
  116. console.log(this.money);
  117. // #ifdef H5
  118. rechargeWechat({ price: this.money, from: this.type, get_money_type: 'LALA' })
  119. .then(e => {
  120. let da = e.data.data;
  121. obj.weichatObj.chooseWXPay({
  122. timestamp: da.timestamp,
  123. nonceStr: da.nonceStr,
  124. package: da.package,
  125. signType: da.signType,
  126. paySign: da.paySign,
  127. success: function(res) {
  128. uni.showToast({
  129. title: '充值成功',
  130. duration: 2000,
  131. position: 'top'
  132. });
  133. }
  134. });
  135. obj.payLoding = false;
  136. })
  137. .catch(e => {
  138. obj.payLoding = false;
  139. console.log(e);
  140. });
  141. // #endif
  142. // #ifdef MP
  143. rechargeRoutine({ price: this.money, get_money_type: 'LALA' })
  144. .then(e => {
  145. let da = e.data;
  146. wx.requestPayment({
  147. timeStamp: da.timestamp,
  148. nonceStr: da.nonceStr,
  149. package: da.package,
  150. signType: da.signType,
  151. paySign: da.paySign,
  152. success: function(res) {
  153. uni.redirectTo({
  154. url: '/pages/money/paySuccess'
  155. });
  156. }
  157. });
  158. obj.payLoding = false;
  159. })
  160. .catch(e => {
  161. obj.payLoding = false;
  162. console.log(e);
  163. });
  164. // #endif
  165. // #ifdef APP-PLUS
  166. if (this.type == 'weixin') {
  167. rechargeApp({ price: this.money, get_money_type: 'LALA' })
  168. .then(e => {
  169. let da = e.data;
  170. let data = {
  171. appid: da.appid,
  172. noncestr: da.noncestr,
  173. package: da.package,
  174. partnerid: da.partnerid,
  175. prepayid: da.prepayid,
  176. timestamp: da.timestamp,
  177. sign: da.sign
  178. };
  179. uni.requestPayment({
  180. provider: 'wxpay',
  181. orderInfo: data,
  182. success(res) {
  183. console.log(res);
  184. },
  185. fail(res) {
  186. console.log('微信掉起失败');
  187. console.log(res, '失败');
  188. }
  189. });
  190. obj.payLoding = false;
  191. })
  192. .catch(e => {
  193. obj.payLoding = false;
  194. console.log(e);
  195. });
  196. } else {
  197. rechargeAli({ price: this.money, get_money_type: 'LALA' }).then(e => {
  198. console.log(e, 'url');
  199. const url = e.msg;
  200. uni.requestPayment({
  201. provider: 'alipay',
  202. orderInfo: url,
  203. success: res => {
  204. console.log(res);
  205. uni.showToast({
  206. title: '支付成功',
  207. duration: 2000
  208. });
  209. },
  210. fail: e => {
  211. console.log(e);
  212. },
  213. complete: () => {}
  214. });
  215. obj.payLoding = false;
  216. });
  217. }
  218. // #endif
  219. },
  220. //获取订单列表
  221. loadData(source) {
  222. console.log(source);
  223. //这里是将订单挂载到tab列表下
  224. let index = this.tabCurrentIndex;
  225. let navItem = this.navList[index];
  226. let state = navItem.state;
  227. if (source === 'tabChange' && navItem.loaded === true) {
  228. //tab切换只有第一次需要加载数据
  229. return;
  230. }
  231. if (navItem.loadingType === 'loading') {
  232. //防止重复加载
  233. return;
  234. }
  235. navItem.loadingType = 'loading';
  236. setTimeout(() => {
  237. let orderList = [];
  238. orderList.forEach(item => {
  239. navItem.orderList.push(item);
  240. });
  241. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  242. this.$set(navItem, 'loaded', true);
  243. //判断是否还有数据, 有改为 more, 没有改为noMore
  244. navItem.loadingType = 'more';
  245. }, 600);
  246. }
  247. }
  248. };
  249. </script>
  250. <style lang="scss">
  251. page {
  252. height: 100%;
  253. background: #ffffff;
  254. }
  255. .add-btn {
  256. &.modified {
  257. color: $base-color;
  258. }
  259. &.up {
  260. background-color: $base-color;
  261. color: #fff;
  262. }
  263. display: flex;
  264. align-items: center;
  265. justify-content: center;
  266. width: 690rpx;
  267. height: 80rpx;
  268. margin: 0 auto;
  269. margin-top: 30rpx;
  270. font-size: $font-lg;
  271. border-radius: 10rpx;
  272. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  273. }
  274. .row-box {
  275. width: 750rpx;
  276. height: 354rpx;
  277. background: linear-gradient(0deg, #2e58ff, #32c6ff);
  278. .money-box {
  279. padding-top: 80rpx;
  280. margin: 0 auto;
  281. text-align: center;
  282. position: relative;
  283. .money {
  284. font-size: 74rpx;
  285. font-family: PingFang SC;
  286. font-weight: 500;
  287. color: #ffffff;
  288. }
  289. .money-text {
  290. font-size: 30rpx;
  291. font-family: PingFang SC;
  292. font-weight: 500;
  293. color: #ffffff;
  294. }
  295. }
  296. .chong {
  297. position: absolute;
  298. top: 36rpx;
  299. right: 0;
  300. width: 128rpx;
  301. height: 45rpx;
  302. line-height: 45rpx;
  303. background: #2e58ff;
  304. border-radius: 23rpx 0px 0px 23rpx;
  305. font-size: 25rpx;
  306. font-family: PingFang SC;
  307. font-weight: 500;
  308. color: #ffffff;
  309. text-align: center;
  310. }
  311. }
  312. .main-box {
  313. margin-top: -100rpx;
  314. width: 750rpx;
  315. background: #ffffff;
  316. border-radius: 50rpx;
  317. padding-top: 46rpx;
  318. .main-top {
  319. flex-wrap: wrap;
  320. justify-content: space-around;
  321. align-items: center;
  322. .check {
  323. background: #fff6f6 !important;
  324. border: 1px solid #d7272b;
  325. }
  326. .main-item {
  327. text-align: center;
  328. margin-top: 30rpx;
  329. width: 220rpx;
  330. background: #ffffff;
  331. box-shadow: 0px 2rpx 20rpx 0px rgba(215, 39, 43, 0.12);
  332. border-radius: 20rpx;
  333. padding: 46rpx 0 52rpx;
  334. .item-top {
  335. display: flex;
  336. justify-content: center;
  337. .bg {
  338. width: 42rpx;
  339. height: 42rpx;
  340. image {
  341. width: 42rpx;
  342. height: 42rpx;
  343. }
  344. }
  345. .item-name {
  346. padding-left: 6rpx;
  347. font-size: 28rpx;
  348. font-family: PingFang SC;
  349. font-weight: bold;
  350. color: #333333;
  351. }
  352. }
  353. .checks {
  354. color: #d7272b !important;
  355. }
  356. .item-price {
  357. padding-top: 14rpx;
  358. font-size: 20rpx;
  359. font-family: PingFang SC;
  360. font-weight: bold;
  361. color: #999999;
  362. text {
  363. font-size: 28rpx;
  364. }
  365. }
  366. }
  367. }
  368. }
  369. .list {
  370. padding-left: 30rpx;
  371. margin-top: 30rpx;
  372. background-color: #ffffff;
  373. .box {
  374. display: flex;
  375. align-items: center;
  376. width: 100%;
  377. height: 120rpx;
  378. border-bottom: 1px solid $border-color-light;
  379. .icon {
  380. font-size: 48rpx;
  381. padding-right: 20rpx;
  382. }
  383. .iconweixin1 {
  384. color: #18bf16;
  385. }
  386. .iconzhifubao {
  387. color: #08aaec;
  388. }
  389. .title-box {
  390. flex-grow: 1;
  391. text-align: left;
  392. .title {
  393. font-size: $font-base + 2rpx;
  394. color: $font-color-base;
  395. }
  396. .node {
  397. font-size: $font-sm;
  398. color: $font-color-light;
  399. }
  400. }
  401. }
  402. }
  403. /deep/ .uni-radio-input {
  404. width: 45rpx;
  405. height: 45rpx;
  406. }
  407. .active-bg {
  408. background-color: $color-gray !important;
  409. }
  410. </style>