| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- <template>
- <view>
- <view class="content">
- <view class="withdraw y-c">
- <view class="title">提现金额</view>
- <view class="amount">
- <text class="unit">¥</text>
- <input class="amount-input" v-model="amount" type="digit" @input="handleAmountInput" />
- <image class="clear" v-if="showClearIcon" @click="clearIcon"
- src="@/static/image/healthRecords/input_close_icon.png" mode="aspectFill"></image>
- </view>
- <view class="tips">当前可以提现金额{{availableAmount}}元,<view class="all" @click="withdrawAll">全部提现</view>
- </view>
- </view>
-
- <view class="info-item">
- <view class="label">提现至</view>
- <view class="right" @click="selectAccount" v-if="payType==0">
- <view class="text">请选择提现账户</view>
- <image src="@/static/image/hall/my_right_arrow_right_icon.png"></image>
- </view>
- <view class="right y-bc" @click="selectAccount" v-if="payType==1">
- <view class="weixin x-c">
- <image src="@/static/images/wallet/order_wechat.png" mode=""></image>
- <view class="way">微信</view>
- <image src="@/static/image/hall/my_right_arrow_right_icon.png"></image>
- </view>
- <view class="text">立即到账</view>
- </view>
- </view>
- <u-popup :show="show" mode="bottom" @close="close" :round="16">
- <view class="pay-list">
- <view class="title x-bc">
- <view style="width: 48rpx;"></view>
- 请选择提现账户
- <image class="close" @click="close" src="@/static/image/hall/close_icon.png"></image>
- </view>
- <view class="pay-box">
- <radio-group @change="payTypeChange">
- <view class="item-box x-bc">
- <image src="@/static/images/wallet/order_wechat.png" mode=""></image>
- <view class="right x-bc">
- <text class="text">微信支付</text>
- <label>
- <radio :value="1" :checked="payType==1" activeBackgroundColor="#FF5C03" />
- </label>
- </view>
- </view>
- </radio-group>
- </view>
- </view>
- </u-popup>
- </view>
- <view class="btn-box">
- <view class="sub-btn" :class="{ disabled: !canSubmit }" @click="submit()">立即提现</view>
- </view>
- </view>
- </template>
- <script>
- import {
- setPwd,
- setHeadImg,
- setUserInfo,
- getUserInfo,
- withDrawal,
- getWallet
- } from '@/api/user.js';
- import {
- getRedPacketLogByCode
- } from '@/api/integral.js'
- import {
- premissionCheck
- } from "@/js_sdk/wa-permission/permission.js"
-
- export default {
- data() {
- return {
- payType: 1,
- show: false,
- showClearIcon: false,
- amount: null,
- availableAmount: '0.00', // 可提现金额
- nickName: "",
- deptName: "",
- postNames: "",
- phonenumber: "",
- email: "",
- sexPicker: ['男', '女', '未知'],
- sex: 0, // 性别
- headImg: '/static/images/detault_head.jpg', // 头像,
- headImgUrl: '',
- wxMerchantTransfer:null,
- }
- },
- computed: {
- // 是否可以提交提现
- canSubmit() {
- const amount = parseFloat(this.amount) || 0;
- const available = parseFloat(this.availableAmount) || 0;
- const minAmount = 0.1; // 最低提现金额
- return amount >= minAmount && amount <= available && this.payType > 0;
- }
- },
- onLoad() {
- this.getUserInfo();
- // 在调用插件之前添加
- console.log('当前运行基座类型:', plus.runtime.isCustomKernel ? '自定义基座' : '标准基座');
- // 获取插件
- this.wxMerchantTransfer = uni.requireNativePlugin('wxMerchantTransfer');
- console.log('插件对象:', this.wxMerchantTransfer);
- if (!this.wxMerchantTransfer) {
- console.error('插件加载失败!请确认是否正在运行自定义基座,且插件已正确打包。');
- }
- },
- onShow() {
- // 返回时清空提现金额
- this.amount = null;
- this.showClearIcon = false;
- this.getWalletInfo();
- },
- methods: {
- selectAccount() {
- this.show = true
- },
- close() {
- this.show = false
- },
- payTypeChange(e) {
- this.payType = e.detail.value
- },
- // 金额输入处理
- handleAmountInput(e) {
- const value = e.detail.value;
- this.amount = value;
- this.showClearIcon = value && value.length > 0;
- // 验证输入金额
- const inputAmount = parseFloat(value) || 0;
- const maxAmount = parseFloat(this.availableAmount) || 0;
- const minAmount = 0.1; // 最低提现金额
- // 如果输入了有效数字且小于最低金额,给出提示
- if (value && !isNaN(inputAmount) && inputAmount > 0 && inputAmount < minAmount) {
- uni.showToast({
- title: `最低提现金额为${minAmount}元`,
- icon: 'none',
- duration: 2000
- });
- }
- // 限制输入金额不超过可提现金额
- if (inputAmount > maxAmount) {
- this.amount = maxAmount;
- uni.showToast({
- title: `最多可提现${maxAmount}元`,
- icon: 'none'
- });
- }
- },
- // 全部提现
- withdrawAll() {
- const availableAmount = parseFloat(this.availableAmount) || 0;
- const minAmount = 0.1; // 最低提现金额
- if (availableAmount < minAmount) {
- uni.showToast({
- title: `可提现金额不足${minAmount}元,无法提现`,
- icon: 'none',
- duration: 2000
- });
- return;
- }
- this.amount = this.availableAmount;
- this.showClearIcon = true;
- },
- bindUser(data) {
- var that = this;
- that.nickName = data.user.nickName;
- that.posts = data.post;
- that.phonenumber = data.user.phone;
- that.email = data.user.email;
- if (data.user.sex != undefined) {
- that.sex = data.user.sex;
- }
- if (data.post != null && data.post.length > 0) {
- var postNameStr = "";
- data.post.forEach((v, i) => {
- postNameStr += v + ",";
- }, this);
- that.postNames = postNameStr.substr(0, postNameStr.length - 1);
- }
- if (!that.$isEmpty(data.user.avatar)) {
- //this.headImg=uni.getStorageSync('requestPath')+data.user.avatar;
- this.headImg = data.user.avatar;
- this.headImgUrl = data.user.avatar;
- }
- },
- getUserInfo() {
- var data = {};
- var that = this;
- getUserInfo(data).then(
- res => {
- that.bindUser(res);
- },
- rej => {}
- );
- },
- // 获取钱包信息,获取可提现金额
- getWalletInfo() {
- const user = this.$getUserInfo();
- if (!user || !user.userId) {
- return;
- }
- getWallet({
- userId: user.userId
- }).then(
- res => {
- if (res.code == 200 && res.data) {
- // 使用 mayWithdraw 作为可提现金额
- this.availableAmount = (res.data.mayWithdraw || 0);
- }
- },
- err => {
- console.error('获取钱包信息失败', err);
- }
- );
- },
- clearIcon() {
- this.amount = null;
- this.showClearIcon = false;
- },
- submit() {
- // 验证金额
- const amount = parseFloat(this.amount) || 0;
- const maxAmount = parseFloat(this.availableAmount) || 0;
- const minAmount = 0.1; // 最低提现金额
- if (amount < minAmount) {
- uni.showToast({
- title: `最低提现金额为${minAmount}元`,
- icon: 'none'
- });
- return;
- }
- if (amount > maxAmount) {
- uni.showToast({
- title: `提现金额不能超过${maxAmount}元`,
- icon: 'none'
- });
- return;
- }
- // 验证提现账户
- if (this.payType === 0) {
- uni.showToast({
- title: "请选择提现账户",
- icon: 'none'
- });
- return;
- }
- var data = {
- applicationAmount: amount,
- appId: 'wx703c4bd07bbd1695',
- source: 3,
- };
- uni.showLoading({
- title: '处理中...'
- });
- withDrawal(data).then(
- res => {
- uni.hideLoading();
- console.log('提现API返回:', res);
- if (res.code == 200) {
- const orderCode = res.orderCode
- const params = {
- appId: res.appId, // 您的微信 AppID
- mchId: res.mchId, // 您的商户号
- package: res.package // 服务端返回的 package 字符串
- };
- this.wxMerchantTransfer.open(params, (res) => {
- console.log('回调结果:', res);
- if (res.code === 0) {
- // 跳转到成功页面,传递orderCode用于查询订单状态
- setTimeout(() => {
- uni.navigateTo({
- url: '/pages/user/wallet/success?orderCode=' +
- orderCode
- });
- }, 1500);
- } else if (res.code === -3) {
- // 微信版本过低,插件已弹出 Toast 提示,此处可记录日志
- console.warn('用户微信版本过低');
- } else {
- console.log('回调结果:', res);
- uni.showModal({
- title: '错误',
- content: res.message,
- showCancel: false
- });
- }
- });
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg || '提现失败',
- });
- }
- },
- err => {
- uni.hideLoading();
- console.error('提现API错误:', err);
- uni.showToast({
- icon: 'none',
- title: err.msg || '网络错误,请稍后重试',
- });
- }
- );
- }
- }
- }
- </script>
- <style scoped lang="scss">
- page {
- background: #F5F7FA;
- }
- .content {
- padding: 24rpx;
- //border-top: 1px solid #F5F6FA;
- }
- .withdraw {
- background: #FFFFFF;
- padding: 32rpx;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- margin-bottom: 20rpx;
- .title {
- font-family: PingFang SC, PingFang SC;
- font-weight: 500;
- font-size: 32rpx;
- color: #222222;
- line-height: 56rpx;
- }
- .amount {
- margin-top: 48rpx;
- margin-bottom: 48rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .unit {
- font-family: PingFang SC, PingFang SC;
- font-weight: 600;
- font-size: 60rpx;
- color: #222222;
- }
- .amount-input {
- height: 88rpx;
- font-family: DIN, DIN;
- font-weight: 500;
- font-size: 72rpx;
- color: #222222;
- line-height: 88rpx;
- }
- .clear {
- width: 48rpx;
- height: 32rpx;
- }
- }
- .tips {
- display: flex;
- align-items: center;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 24rpx;
- color: #999999;
- .all {
- color: #E69A22;
- }
- }
- }
- .info-item {
- height: 120rpx;
- background: #FFFFFF;
- padding: 0 32rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- .label {
- font-family: PingFang SC, PingFang SC;
- font-weight: 500;
- font-size: 32rpx;
- color: #222222;
- line-height: 56rpx;
- }
- .right {
- display: flex;
- align-items: center;
- justify-content: center;
- .text {
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #999999;
- }
- .way {
- margin-left: 16rpx;
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #222222;
- }
- image {
- margin-left: 10rpx;
- width: 48rpx;
- height: 48rpx;
- }
- }
- .head {
- border-radius: 50%;
- width: 80rpx;
- height: 80rpx;
- }
- .arrow {
- width: 30rpx;
- height: 30rpx;
- }
- .text {
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- .input {
- text-align: right;
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- }
- &.password {
- margin-top: 20rpx;
- .right {
- display: flex;
- align-items: center;
- .text {
- font-size: 30rpx;
- font-family: PingFang SC;
- font-weight: 400;
- color: #0F1826;
- margin-right: 15rpx;
- }
- }
- }
- }
- .pay-list {
- background-color: #F5F7FA;
- padding: 24rpx;
- min-height: 400rpx;
- .title {
- height: 96rpx;
- line-height: 96rpx;
- padding-bottom: 24rpx;
- font-family: PingFang SC, PingFang SC;
- font-weight: 500;
- font-size: 36rpx;
- color: #222222;
- .close {
- width: 48rpx;
- height: 48rpx;
- }
- }
- .pay-box {
- padding: 0 32rpx;
- background: #FFFFFF;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- .item-box {
- image {
- margin-right: 24rpx;
- width: 48rpx;
- height: 48rpx;
- }
- .right {
- flex: 1;
- padding: 36rpx 0;
- border-bottom: 1px solid #ECECEC;
- .text {
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #222222;
- }
- }
- &:last-child {
- .right {
- border-bottom: none;
- }
- }
- }
- }
- }
- .btn-box {
- margin-top: 15rpx;
- height: 120rpx;
- padding: 0 30rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- .sub-btn {
- width: 100%;
- height: 98rpx;
- line-height: 98rpx;
- text-align: center;
- font-size: 32rpx;
- font-family: PingFang SC;
- font-weight: bold;
- color: #FFFFFF;
- background: #FF5C03;
- border-radius: 16rpx;
- &.disabled {
- background: #FDAB8D;
- pointer-events: none;
- }
- }
- }
- </style>
|