Procházet zdrojové kódy

新增我要提现功能

wyling007 před 3 roky
rodič
revize
e67b03cf76

+ 12 - 0
src/api/modules/cashOut.ts

@@ -1,6 +1,10 @@
 import { AxiosPromise } from "axios";
 import request from "../request";
 
+export interface CashoutRes extends Common.Res {
+	data: {};
+}
+
 class CashOut {
 	/**
 	 * 查询收益列表
@@ -18,6 +22,14 @@ class CashOut {
 	extractList(): AxiosPromise<CashOutType.ExtractList> {
 		return request("/wx/extract/list");
 	}
+
+	/**微信提现 */
+	cashout(params: { amount: number }): AxiosPromise<CashoutRes> {
+		return request("wx/extract/withdraw", {
+			params,
+			method: "post",
+		});
+	}
 }
 
 export const cashOut = new CashOut();

+ 9 - 0
src/dataModel/cashOut.ts

@@ -41,4 +41,13 @@ export class CashOutModel {
 
 		return data;
 	}
+
+	/**提现 */
+	async cashout(amount: number) {
+		const { data } = await this.api.cashout({
+			amount,
+		});
+
+		return data;
+	}
 }

+ 6 - 0
src/hooks/index.ts

@@ -11,6 +11,12 @@ export const useLogin = async (query: LocationQuery) => {
 	const res = await API.login(query.code);
 	store.commit("setToken", res.data.token);
 	store.commit("setUserData", res.data.wxUserInfo);
+	//更新用户信息
+	useUpdateUserInfo();
+};
+
+/**更新用户信息 */
+export const useUpdateUserInfo = async () => {
 	//获取用户信息
 	const userDataRes = await API.userInfo();
 	store.commit("setUserData", {

+ 1 - 1
src/route/guard.ts

@@ -2,7 +2,7 @@ import { Router } from "vue-router";
 import store from "@/store";
 import dayjs from "dayjs";
 import { Toast } from "vant";
-import { useLogin } from "@/hooks";
+import { useLogin, useUpdateUserInfo } from "@/hooks";
 import { userInfo } from "@/api";
 
 const guard = (router: Router) => {

+ 9 - 0
src/views/cashOut/components/cashout.ts

@@ -0,0 +1,9 @@
+import { mountComponent, useUnmountComponent } from "@/utils/mount-component";
+import cashout from "./cashout.vue";
+
+export const showCashout = () => {
+	const { unmount } = mountComponent(cashout);
+	return {
+		unmount,
+	};
+};

+ 90 - 0
src/views/cashOut/components/cashout.vue

@@ -0,0 +1,90 @@
+<template>
+	<Overlay :show="true">
+		<div class="wrapper" @click.stop>
+			<div class="block">
+				<Form @submit="handleCashout">
+					<CellGroup inset>
+						<Field v-model="amount" label="提现金额(分)" type="number" placeholder="请输入提现金额" />
+					</CellGroup>
+					<div class="submit-box">
+						<Button :loading="loading" type="primary" hairline native-type="submit" loading-text="结算中..."> 提现 </Button>
+						<Button type="default" hairline @click="props.unmount"> 取消 </Button>
+					</div>
+				</Form>
+			</div>
+		</div>
+	</Overlay>
+</template>
+
+<script lang="ts">
+	import { Toast } from "vant";
+	import { CashOutModel } from "@/dataModel/cashOut";
+	const cashOutModel = new CashOutModel();
+	const useCashout = () => {
+		const amount = ref<number>(0);
+		const loading = ref(false);
+		const cashout = async () => {
+			loading.value = true;
+			const data = await cashOutModel.cashout(amount.value);
+			loading.value = false;
+			if (data.code === 200) {
+				Toast.success("提现成功");
+				return true;
+			} else {
+				Toast.fail(data.msg);
+				return false;
+			}
+		};
+		return {
+			amount,
+			loading,
+			cashout,
+		};
+	};
+</script>
+
+<script lang="ts" setup>
+	import { Overlay, Field, CellGroup, Form, Button } from "vant";
+	import { ref } from "vue";
+	import { useUpdateUserInfo } from "@/hooks";
+	const props = defineProps<{
+		unmount: () => void;
+	}>();
+
+	const { amount, loading, cashout } = useCashout();
+
+	const handleCashout = async () => {
+		if (await cashout()) {
+			props.unmount();
+			useUpdateUserInfo();
+		}
+	};
+</script>
+
+<style scoped lang="scss">
+	.wrapper {
+		display: flex;
+		align-items: center;
+		justify-content: center;
+		height: 100%;
+	}
+	.block {
+		width: 300px;
+		background-color: #fff;
+		padding: 20px;
+		border-radius: 10px;
+	}
+	.user-img {
+		display: flex;
+		justify-content: center;
+		align-items: center;
+		font-size: 20px;
+		margin-bottom: 10px;
+	}
+	.submit-box {
+		display: flex;
+		justify-content: space-around;
+		align-items: center;
+		margin-top: 10px;
+	}
+</style>

+ 2 - 16
src/views/cashOut/index.vue

@@ -12,7 +12,7 @@
 					>
 				</div>
 			</div>
-			<m-button @click="fn" class="continue" width="90px" height="30px" text="我要提现" />
+			<m-button @click="showCashout" class="continue" width="90px" height="30px" text="我要提现" />
 		</div>
 	</div>
 	<div class="summary content-box">
@@ -34,9 +34,6 @@
 			</tr>
 		</table>
 	</div>
-	<van-dialog v-model="show" title="我要提现" show-cancel-button>
-		<img src="https://img01.yzcdn.cn/vant/apple-3.jpg" />
-	</van-dialog>
 </template>
 
 <script lang="ts">
@@ -69,22 +66,11 @@
 
 <script lang="ts" setup>
 	import { useProfitPrice } from "@/hooks/user";
-	import { Dialog } from "vant";
+	import { showCashout } from "./components/cashout";
 	const searchValue = ref("");
 
 	const { profitPrice } = useProfitPrice();
 	const { extractList } = useExtract();
-
-	console.log(profitPrice.value);
-
-	const show = ref(false);
-	const fn = () => {
-		console.log(123);
-		Dialog({
-			title: "暂未开放",
-		});
-		show.value = true;
-	};
 </script>
 
 <style scoped lang="scss">

+ 2 - 0
src/views/myIntegral/components/settlement.ts

@@ -3,6 +3,7 @@ import Settlement from "./settlement.vue";
 import { BranchModel } from "@/dataModel/myBranchList";
 import { ref } from "vue";
 import { Toast } from "vant";
+import { useUpdateUserInfo } from "@/hooks";
 
 const branchModel = new BranchModel();
 
@@ -30,6 +31,7 @@ export const useSettlementIntegral = (props: { openid: string; settlePoints: num
 		if (data.code === 200) {
 			Toast.success("结算成功");
 			unmountComponent();
+			useUpdateUserInfo();
 		} else {
 			Toast.fail(data.msg);
 		}