recharge.vue 7.3 KB

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