Commit 9345359e authored by wykolor's avatar wykolor

feat: 对接提现部分接口

parent bfbe5096
......@@ -11,6 +11,7 @@
"amfe-flexible": "^2.2.1",
"axios": "^0.21.1",
"core-js": "^3.6.5",
"js-cookie": "^2.2.1",
"vant": "^3.0.9",
"vconsole": "^3.4.0",
"vue": "^3.0.0",
......
/*
* @Author: wykolor
* @Date: 2021-03-23 11:44:35
* @Last Modified by: wykolor
* @Last Modified time: 2021-03-26 15:38:13
* @Last Modified by: mikey.zhaopeng
* @Last Modified time: 2021-04-06 19:01:39
*/
export interface PageParams {
......@@ -69,14 +69,20 @@ export interface WithdrawListResponse {
}
export interface CheckCaptchaParams {
userId: string;
ticket: string;
randStr: string;
}
export interface WithdrawParams {
withdrawAmount: number;
userId: number;
studentId: number;
smsVerifyCode: string;
}
export interface WithdrawResponse {
serialNo: string;
withdrawAccount: string;
amount: number;
withdrawApplyTime: string;
expectedPayTime: string;
}
......@@ -6,34 +6,40 @@ import {
Paging,
WithdrawListParams,
WithdrawListResponse,
WithdrawParams
WithdrawParams,
WithdrawResponse
} from "@/model/bonus";
import { get, post } from "../../request";
// 奖励金收支列表
export const getBonusList = (params: BonusListParams) => {
return post<Paging<BonusListResponse>>(
`/mock/api-jksxb-app/v1/marketingAccount/bonus/flow/list`,
return get<Paging<BonusListResponse>>(
`/api-jksxb-app/v1/marketingAccount/bonus/flow/list`,
params
);
};
// 奖励金账户信息
export const getBonusAccount = (studentId: string) => {
return get<BonusAccountResponse>(`/mock/api-jksxb-app/v1/marketingAccount/bonus/count`, { studentId });
return get<BonusAccountResponse>(`/api-jksxb-app/v1/marketingAccount/bonus/count`, { studentId });
};
// 提现记录列表
export const getWithdrawList = (params: WithdrawListParams) => {
return post<Paging<WithdrawListResponse>>(`/mock/api-jksxb-app/v1/withdraw/query`, params);
return get<Paging<WithdrawListResponse>>(`/api-jksxb-app/v1/withdraw/query`, params);
};
// 检验图形验证码
export const checkCaptcha = (params: CheckCaptchaParams) => {
return get<string>(`/v1/withdraw/checkCaptcha`, params);
return post<string>(`/api-jksxb-app/v1/withdraw/checkCaptcha`, params);
};
// 提现
export const withdraw = (params: WithdrawParams) => {
return post<string>("/v1/withdraw", params);
return post<WithdrawResponse>("/api-jksxb-app/v1/withdraw", params);
};
// 绑定微信
export const bindWeiChat = (params: { code: string}) => {
return post("/api-jksxb-app/v1/withdraw/bind/wx/parent", params)
}
let baseURL = "";
if (process.env.NODE_ENV === "development") {
baseURL = "/api";
} else {
// baseURL = "";
}
export default baseURL;
import axios, { AxiosRequestConfig } from "axios";
import Cookies from 'js-cookie';
import { Toast } from "vant";
const instance = axios.create({
// headers: {
// 'content-type': 'application/json;charset=UTF-8',
// 'token': 'one'
// },
headers: {
'content-type': 'application/json;charset=UTF-8',
'Authorization': `Bearer ${Cookies.get('token')}`
},
baseURL: "",
timeout: 10000,
withCredentials: true
......@@ -53,7 +55,10 @@ instance.interceptors.request.use(
// 响应拦截器
instance.interceptors.response.use(
response => {
// 隐藏加载样式
const { code, msg } = response.data;
if (code !== 0) {
return Promise.reject(msg);
}
return response.data;
},
error => {
......
import axios from "./http";
import { BaseResponse } from "../model/bonus/index";
/**
* 封装的get请求
* @param {*} url 请求路径
......@@ -7,7 +6,7 @@ import { BaseResponse } from "../model/bonus/index";
* @returns
*/
export function get<T>(url: string, params?: object) {
return axios.get<T>(url, params);
return axios.get<T>(url, { params });
}
/**
......@@ -16,6 +15,6 @@ export function get<T>(url: string, params?: object) {
* @param {*} params 请求参数
* @returns
*/
export function post<T>(url: string, params?: object) {
return axios.post<T>(url, params);
export function post<T>(url: string, data?: object) {
return axios.post<T>(url, data);
}
import Cookies from 'js-cookie'
const bonus = {
namespaced: true,
state: () => ({
......@@ -11,6 +12,7 @@ const bonus = {
state.studentId = payload;
},
saveToken(state, payload) {
Cookies.set('token', payload)
state.token = payload;
},
saveUserId(state, payload) {
......
......@@ -24,6 +24,7 @@ window.$geek_excuteJS = function (args) {
const params = JSON.parse(args);
eventBus.emit<NativeInvokeFuncParams>(GEEK_NATIVE_NAME, params);
} catch (error) {
eventBus.emit<NativeInvokeFuncParams>(GEEK_NATIVE_NAME, args);
}
};
......
......@@ -14,11 +14,11 @@
v-model:loading="loading"
v-model:error="error"
:finished="finished"
finished-text="~我是有底线的~"
finished-text="~暂无更多数据~"
@load="onLoad"
>
<van-tab name="REDUCE" title="支出" class="bonus-detail-pay-list">
<template v-if="reduceList.length">
<template>
<div v-for="item in reduceList" :key="item.id" class="bonus-detail-pay-item">
<ul>
<li style="color: #000">{{ item.bizTypeName }}</li>
......@@ -52,10 +52,10 @@
</ul>
</div>
</template>
<van-empty description="暂无数据~" v-else />
<!-- <van-empty description="暂无数据~" v-else /> -->
</van-tab>
<van-tab name="ADD" title="收入" class="bonus-detail-income-list">
<template v-if="addList.length">
<template>
<div class="bonus-detail-income-item" v-for="item in addList" :key="item.id">
<ul>
<li class="flex ">
......@@ -71,7 +71,7 @@
</ul>
</div>
</template>
<van-empty description="暂无数据~" v-else />
<!-- <van-empty description="暂无数据~" v-else /> -->
</van-tab>
</van-list>
</van-pull-refresh>
......@@ -140,6 +140,10 @@ const BonusDetail = defineComponent({
};
bonusModel.getBonusList(params).then(res => {
const { list, total } = res.data;
if (total === 0) {
state.finished = true;
return;
}
state.loading = false;
if (state.active === FlowType.REDUCE) {
bonusList.reduceList = bonusList.reduceList.concat(list);
......
......@@ -12,7 +12,7 @@
<van-row class="bonus-account-money" align="center">
<van-col span="12" class="money-desc">
<span style="position: relative"
>¥{{ bonusAccount?.balanceTotal }}
>¥{{ bonusAccount?.balanceTotal || 0 }}
<label
class="frozen"
v-if="bonusAccount?.status && bonusAccount?.status === BonusAccountStatus.FREEZE"
......@@ -35,21 +35,38 @@
<van-row class="bonus-account-status">
<van-col span="8">
<label>累计收入</label>
<span>¥{{ bonusAccount?.addTotal }}</span>
<span>¥{{ bonusAccount?.addTotal || 0 }}</span>
</van-col>
<van-col span="8">
<label>累计提现</label>
<span>¥{{ bonusAccount?.withdrawedTotal }}</span>
<span>¥{{ bonusAccount?.withdrawedTotal || 0 }}</span>
</van-col>
<van-col span="8">
<label>提现中</label>
<span>¥{{ bonusAccount?.withdrawing }}</span>
<span>¥{{ bonusAccount?.withdrawing || 0 }}</span>
</van-col>
</van-row>
</div>
<van-cell
center
:title="`可提现金额:¥${bonusAccount?.withdrawableTotal}`"
:title="`微信(${bonusAccount?.withdrawAccount || '未绑定'})`"
size="large"
style="border-radius: 0.3rem; margin-bottom: 0.3rem"
:border="false"
>
<van-button
color="#39BF17"
:plain="bonusAccount?.withdrawAccount ? true : false"
round
size="small"
@click="bindWeiChatOrUnbind"
style="width: 70%"
>{{ bonusAccount?.withdrawAccount ? "换绑微信" : "绑定微信" }}</van-button
>
</van-cell>
<van-cell
center
:title="`可提现金额:¥${bonusAccount?.withdrawableTotal || 0}`"
size="large"
style="border-radius: 0.3rem;"
:border="false"
......@@ -62,14 +79,14 @@
<van-row>
<van-col span="12" class="tip">&emsp;奖励金提现金额</van-col>
<van-col span="12" class="tip-money" style="text-align: right; font-weight: 550"
>总计:{{ bonusAccount?.withdrawedTotal }}元&nbsp;</van-col
>总计:{{ bonusAccount?.withdrawedTotal || 0 }}元&nbsp;</van-col
>
</van-row>
<van-list
v-model:loading="loading"
:finished="finished"
finished-text="~我是有底线的~"
finished-text="~暂无更多数据~"
@load="onLoad"
:immediate-check="false"
>
......@@ -135,11 +152,15 @@
v-model:show="showBindWx"
:show-cancel-button="false"
:show-confirm-button="false"
title="绑定微信后,才可进行提现!"
:title="
bonusAccount?.withdrawAccount
? '换绑后,将提现到新绑定的微信零钱中!'
: '绑定微信后,才可进行提现!'
"
>
<div class="dialog-handle-btns">
<van-button type="default" round @click="showBindWx = false">取消</van-button
><van-button type="primary" round @click="bindWeiChat" :disabled="binding"
><van-button type="primary" round @click="bindWeiChatModal" :disabled="binding"
><van-loading v-if="binding" size="20px" color="#ccc">绑定中...</van-loading
><span v-else>绑定微信</span></van-button
>
......@@ -167,13 +188,14 @@ import { computed, defineComponent, onMounted, reactive, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useStore } from "vuex";
import { Dialog, Button, Col, Row, Cell, List, Loading } from "vant";
import { Dialog, Button, Col, Row, Cell, List, Loading, Toast } from "vant";
import { BonusAccountResponse, WithdrawListParams, WithdrawListResponse } from "@/model/bonus";
import { bonusModel } from "@/server/api";
import { BonusAccountStatus, ErrCode } from "@/model/bonus/constant";
import { bindWeChat, useNativeBridge, makeCall } from "@/util/use-native-bridge";
import { formatBonusTipTxt } from "@/util/formatBonusTipTxt";
import { bindWeiChat } from "@/server/api/bonus";
interface BonusState {
withdrawList: WithdrawListResponse[];
......@@ -223,7 +245,11 @@ const Bonus = defineComponent({
const onLoad = () => {
state.loading = true;
bonusModel.getWithdrawList(withdrawListParams).then(res => {
const { hasNextPage, list } = res.data;
const { hasNextPage, list, total } = res.data;
if (!list || total === 0) {
state.finished = true;
return;
}
state.loading = false;
state.finished = !hasNextPage;
state.withdrawList = state.withdrawList.concat(list);
......@@ -239,32 +265,57 @@ const Bonus = defineComponent({
onLoad();
});
const withdraw = () => {
if (!state.bonusAccount?.errCode) {
// 都正常的状态
router.push({
name: "withdraw",
params: {
withdrawableTotal: state.bonusAccount?.withdrawableTotal || 0,
withdrawAccount: state.bonusAccount?.withdrawAccount || ""
}
});
} else if (state.bonusAccount?.errCode === ErrCode.NOT_BIND) {
state.showBindWx = true;
// if (!state.bonusAccount?.errCode) {
// // 都正常的状态
// router.push("withdraw");
// } else if (state.bonusAccount?.errCode === ErrCode.NOT_BIND) {
// state.showBindWx = true;
// } else {
// state.showDangerous = true;
// }
} else {
state.showDangerous = true;
}
};
const withdrawRule = () => {
state.showWithdrawRules = true;
};
const phoneCall = () => {
makeCall("400—8777389")
// sendNativeMessage({
// type: "phoneCall",
// data: "400—8777389"
// });
makeCall("400—8777389");
};
const bindWeiChat = () => {
const bindWeiChatModal = async () => {
state.binding = true;
bindWeChat().then(() => {
const params = await bindWeChat();
bindWeiChat(params)
.then(() => {
Toast("绑定成功");
state.showBindWx = false;
state.binding = false;
getBonusAccount();
})
.catch(() => {
Toast("绑定失败");
});
};
// 绑定或者换邦
const bindWeiChatOrUnbind = async () => {
// 已经绑定微信
if (state.bonusAccount?.withdrawAccount) {
state.showBindWx = true;
return false;
}
const params = await bindWeChat();
bindWeiChat(params)
.then(() => {
getBonusAccount();
Toast("绑定成功");
})
.catch(() => {
Toast("绑定失败");
});
};
return {
......@@ -273,7 +324,8 @@ const Bonus = defineComponent({
withdraw,
withdrawRule,
phoneCall,
bindWeiChat,
bindWeiChatModal,
bindWeiChatOrUnbind,
bonusStoreState,
formatBonusTipTxt
};
......
......@@ -21,12 +21,12 @@
type="primary"
round
color="#F1551E"
@click="withdrawAmount = maxMoney"
@click="withdrawAmount = withdrawableTotal"
>全部</van-button
>
</template>
</van-field>
<p class="bonus-withdraw-input-valid">今日可提现金额¥{{ maxMoney }}元</p>
<p class="bonus-withdraw-input-valid">今日可提现金额¥{{ withdrawableTotal }}元</p>
<p class="bonus-withdraw-input-tip">
<i class="iconfont icon-wenhao"></i>
<span>单日累计提现不超过500元!</span>
......@@ -35,7 +35,7 @@
<van-cell class="van-cell-tip" title="提现至" size="large" :border="false">
<div class="slot-value">
<img class="wechat" src="../../../assets/images/bonus/wechat.png" alt="微信图片" />
<span class="van-ellipsis">微信名字k~k~kolor</span>
<span class="van-ellipsis">微信名字:{{ withdrawAccount }}</span>
</div>
</van-cell>
<div class="handle-btn">
......@@ -52,7 +52,7 @@
class="withdraw-dialog"
>
<ul class="withdraw-dialog-header">
<li>提现至微信账户:k~k~kolor</li>
<li>提现至微信账户:{{ withdrawAccount }}</li>
<li class="withdraw-dialog-header-money">¥{{ withdrawAmount }}</li>
</ul>
<ul class="withdraw-dialog-field">
......@@ -74,7 +74,9 @@
</template>
</van-field>
</li>
<li class="withdraw-dialog-field-tip">今日可提现已将验证码发送至{{ mobileTip }}</li>
<li class="withdraw-dialog-field-tip" v-if="mobileTip">
今日可提现已将验证码发送至{{ mobileTip }}
</li>
</ul>
<div class="handle-btns">
<van-button round type="primary" size="large" block color="#027AFF;" @click="withdrawReal"
......@@ -104,11 +106,11 @@
<ul class="withdraw-success-dialog-text">
<li>提现申请成功!</li>
<li>提现金额:</li>
<li>¥1345.00</li>
<li>¥{{ withdrawResponse?.amount }}</li>
<li>提现至微信</li>
<li>k~k~kololr</li>
<li>{{ withdrawResponse?.withdrawAccount }}</li>
<li>预计到账时间</li>
<li>2021/3/7 12:12:12</li>
<li>{{ withdrawResponse?.expectedPayTime }}</li>
</ul>
<div class="withdraw-success-dialog-btns">
<van-button
......@@ -129,10 +131,14 @@
<script lang="ts">
// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const TencentCaptcha: any;
import { defineComponent, onMounted, reactive, toRefs } from "vue";
import { computed, defineComponent, onMounted, reactive, ref, toRefs } from "vue";
import { Button, Cell, Dialog, Field, Toast } from "vant";
import { useRoute } from "vue-router";
import { useStore } from "vuex";
import { useNativeBridge } from "@/util/use-native-bridge";
import { countDown } from "../../../util/timer";
import { checkCaptcha, withdraw } from "@/server/api/bonus";
import { WithdrawResponse } from "@/model/bonus";
interface TencentCaptchaResponse {
ret: number;
ticket: string;
......@@ -140,6 +146,11 @@ interface TencentCaptchaResponse {
bizState: unknown;
randstr: string;
}
interface State {
WithdrawResponse: WithdrawResponse | object;
[key: string]: unknown;
}
const Withdraw = defineComponent({
components: {
[Button.name]: Button,
......@@ -148,21 +159,29 @@ const Withdraw = defineComponent({
[Dialog.Component.name]: Dialog.Component
},
setup() {
const [sendNativeMessage, eventBus] = useNativeBridge("title", function(arg) {
const [sendNativeMessage] = useNativeBridge("title", function(arg) {
console.log(this, arg);
});
const route = useRoute();
const store = useStore();
const bonusStoreState = computed(() => store.state.bonus);
const state = reactive({
withdrawAmount: "",
withdrawAmount: 0,
smsVerifyCode: "",
maxMoney: 500.32,
withdrawableTotal: 500.32,
showTime: "获取验证码",
showWithdraw: false,
showWithdrawSuccess: false,
mobileTip: "191****1273"
mobileTip: "",
withdrawAccount: "",
withdrawResponse: {}
});
const { withdrawableTotal, withdrawAccount } = route.params;
state.withdrawableTotal = Number(withdrawableTotal);
state.withdrawAccount = withdrawAccount as string;
const formatter = value => {
if (value > state.maxMoney) {
return state.maxMoney;
if (value > state.withdrawAccount) {
return state.withdrawAccount;
}
return value && Number(value).toFixed(2);
......@@ -183,8 +202,10 @@ const Withdraw = defineComponent({
const getSmsVerifyCode = () => {
const captcha1 = new TencentCaptcha(
"2087826974",
(res: TencentCaptchaResponse) => {
const { ret } = res;
async (res: TencentCaptchaResponse) => {
const { ret, randstr, ticket } = res;
const { data } = await checkCaptcha({ randStr: randstr, ticket });
state.mobileTip = data;
if (ret === 0) {
countDown(60, 1000, (time: number) => {
time === 0 ? (state.showTime = `获取验证码`) : (state.showTime = `${time} 后再获取`);
......@@ -198,12 +219,25 @@ const Withdraw = defineComponent({
captcha1.show();
};
const withdrawReal = () => {
const withdrawReal = async () => {
if (!state.smsVerifyCode) {
Toast("请输入验证码");
return;
}
try {
const params = {
studentId: bonusStoreState.value.studentId,
smsVerifyCode: state.smsVerifyCode,
withdrawAmount: state.withdrawAmount
};
const { data } = await withdraw(params);
state.withdrawResponse = data;
state.showWithdrawSuccess = true;
} catch (err) {
Toast(err);
}
// state.showWithdrawSuccess = true;
};
onMounted(() => {
const message = {
......@@ -211,7 +245,7 @@ const Withdraw = defineComponent({
data: "提现"
};
sendNativeMessage(message);
})
});
return {
...toRefs(state),
formatter,
......
......@@ -12,13 +12,13 @@ module.exports = {
ws: true,
changOrigin: true //允许跨域
},
"/api": {
target: "http://192.168.44.114:4100",
"/service": {
target: "http://172.10.62.92",
ws: true,
changOrigin: true //允许跨域
},
"/service": {
target: "http://192.168.44.114:4100",
"/api": {
target: "http://172.10.62.92",
ws: true,
changOrigin: true //允许跨域
}
......
......@@ -5328,6 +5328,11 @@ js-base64@^2.1.9:
resolved "https://registry.npm.taobao.org/js-base64/download/js-base64-2.6.4.tgz?cache=0&sync_timestamp=1604450326544&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjs-base64%2Fdownload%2Fjs-base64-2.6.4.tgz#f4e686c5de1ea1f867dbcad3d46d969428df98c4"
integrity sha1-9OaGxd4eofhn28rT1G2WlCjfmMQ=
js-cookie@^2.2.1:
version "2.2.1"
resolved "https://registry.npm.taobao.org/js-cookie/download/js-cookie-2.2.1.tgz#69e106dc5d5806894562902aa5baec3744e9b2b8"
integrity sha1-aeEG3F1YBolFYpAqpbrsN0Tpsrg=
js-message@1.0.7:
version "1.0.7"
resolved "https://registry.npm.taobao.org/js-message/download/js-message-1.0.7.tgz#fbddd053c7a47021871bb8b2c95397cc17c20e47"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment