recharge.vue 7.6 KB

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