recharge.vue 8.9 KB

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