| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <template>
- <view class="page">
- <view class="recharge">
- <view v-for="(recharge,idx) in state.configList" :key="idx"
- @click="handleRechargeClick(recharge,idx)"
- class="recharge-item" :class="idx===state.chosenIdx?'active':''">
- <view class="recharge-item_amt">{{ (recharge.rechargeAmount/100).toFixed(2) }}</view>
- <view class="recharge-item_grant" v-if="recharge.grantsAmount>0">
- <uv-icon name="gift" :color="idx===state.chosenIdx?'#C6171E':'#2b2b2b'" size="14px"></uv-icon>
- {{ (recharge.grantsAmount/100).toFixed(2) }}元
- </view>
- </view>
- </view>
- <view class="recharge-pay">
- <uv-button type="primary" iconColor="white" color="#C6171E" text="充值" @click="debounceConfirm"></uv-button>
- </view>
- </view>
- </template>
- <script setup lang="ts">
- import {reactive, ref} from "vue";
- import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
- import {debounce} from "@/utils/common";
- import {get, post,body} from "@/utils/https";
- const initState = () => ({
- configList: [],
- chosenIdx: -1,
- stationId:'000'
- })
- const state = reactive(initState())
- onLoad((options:any)=>{
- console.log(options)
- if(options.stationId){
- state.stationId = options.stationId;
- }
- })
- onShow(() => {
- loadRechargeConfig();
- })
- onHide(() => {
- Object.assign(state, initState());
- })
- const handleRechargeClick = (recharge: any, idx: number) => {
- state.chosenIdx = idx;
- }
- const loadRechargeConfig = () => {
- get(`/common/rechargeConfig`).then((res: any) => {
- state.configList = res;
- })
- }
- const debounceConfirm = debounce(() => {
- confirm();
- }, 500)
- const confirm = () => {
- if (state.chosenIdx < 0) {
- return;
- }
- uni.showLoading({
- title: "",
- });
- let recharge = state.configList[state.chosenIdx]
- get("/payment/wxPay", {rechargeConfigId:recharge.id,stationId:state.stationId}).then((res: any) => {
- // #ifdef MP-WEIXIN
- wx.requestPayment({
- timeStamp: `${res.timeStamp}`,
- nonceStr: res.nonceStr,
- package: res.packageVal,
- signType: res.signType,
- paySign: res.paySign,
- success:function (res: any) {
- console.log(res)
- uni.showToast({
- title:'充值完成',
- icon:'success'
- })
- setTimeout(()=>{
- uni.redirectTo({
- url:'/pages/user/index'
- })
- },500)
- },
- fail: function (e) {
- console.error(e)
- },
- });
- // #endif
- // #ifndef MP-WEIXIN
- uni.showToast({title: '目前仅支持微信支付'})
- // #endif
- });
- }
- </script>
- <style lang="scss" scoped>
- .page {
- min-height: 100vh;
- width: 100%;
- background-color: #fff;
- }
- .recharge {
- display: flex;
- flex-wrap: wrap;
- justify-content: end;
- align-items: start;
- align-content: center;
- &-item {
- display: flex;
- flex-direction: column;
- width: 200rpx;
- height: 100rpx;
- background-color: #eeefff;
- margin: 20rpx auto;
- padding: 10rpx;
- border-radius: 10rpx;
- &_amt {
- font-size: 20px;
- font-weight: 600;
- }
- &_grant {
- font-size: 12px;
- margin-top: 4rpx;
- display: inline-flex;
- }
- }
- }
- .active {
- border-radius: 10rpx solid $uni-color-primary;
- .recharge-item {
- &_amt {
- color: $uni-color-primary;
- }
- &_grant {
- color: $uni-color-primary;
- }
- }
- }
- .recharge-pay {
- width: calc(100vw - 40rpx);
- position: fixed;
- bottom: 10rpx;
- left: 20rpx;
- }
- </style>
|