recharge.vue 7.2 KB

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