Commit 29080f33 authored by wykolor's avatar wykolor

feat: bind weixin1

parent b9f7427a
...@@ -118,8 +118,8 @@ function invokeNativeMethod<T = any, P = any>(arg: { type: string; data?: P }): ...@@ -118,8 +118,8 @@ function invokeNativeMethod<T = any, P = any>(arg: { type: string; data?: P }):
/** /**
* 微信登录 * 微信登录
*/ */
export function bindWechat() { export function bindWeChat() {
return invokeNativeMethod<{ code: string }>({ type: "bindWechat" }); return invokeNativeMethod<{ code: string }>({ type: "bindWeChat" });
} }
/** /**
......
...@@ -139,7 +139,10 @@ ...@@ -139,7 +139,10 @@
> >
<div class="dialog-handle-btns"> <div class="dialog-handle-btns">
<van-button type="default" round @click="showBindWx = false">取消</van-button <van-button type="default" round @click="showBindWx = false">取消</van-button
><van-button type="primary" round @click="bindWeChat">绑定微信</van-button> ><van-button type="primary" round @click="bindWeiChat" :disabled="binding"
><van-loading v-if="binding" size="20px" color="#ccc">绑定中...</van-loading
><span v-else>绑定微信</span></van-button
>
</div> </div>
</van-dialog> </van-dialog>
<van-dialog <van-dialog
...@@ -164,12 +167,12 @@ import { computed, defineComponent, onMounted, reactive, toRefs } from "vue"; ...@@ -164,12 +167,12 @@ import { computed, defineComponent, onMounted, reactive, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { useStore } from "vuex"; import { useStore } from "vuex";
import { Dialog, Button, Col, Row, Cell, List, Toast } from "vant"; import { Dialog, Button, Col, Row, Cell, List, Loading } from "vant";
import { BonusAccountResponse, WithdrawListParams, WithdrawListResponse } from "@/model/bonus"; import { BonusAccountResponse, WithdrawListParams, WithdrawListResponse } from "@/model/bonus";
import { bonusModel } from "@/server/api"; import { bonusModel } from "@/server/api";
import { BonusAccountStatus, ErrCode } from "@/model/bonus/constant"; import { BonusAccountStatus, ErrCode } from "@/model/bonus/constant";
import { useNativeBridge } from "@/util/use-native-bridge"; import { bindWeChat, useNativeBridge } from "@/util/use-native-bridge";
import { formatBonusTipTxt } from "@/util/formatBonusTipTxt"; import { formatBonusTipTxt } from "@/util/formatBonusTipTxt";
interface BonusState { interface BonusState {
...@@ -195,17 +198,23 @@ const Bonus = defineComponent({ ...@@ -195,17 +198,23 @@ const Bonus = defineComponent({
showBindWx: false, showBindWx: false,
showDangerous: false, showDangerous: false,
bonusAccount: null, bonusAccount: null,
binding: false,
BonusAccountStatus, BonusAccountStatus,
withdrawList: [] withdrawList: []
}); });
const [sendNativeMessage] = useNativeBridge("bindWeChatChange", function() { const [sendNativeMessage] = useNativeBridge("test", function() {
state.showBindWx = false; // state.showBindWx = false;
}); });
// 获取奖励金信息 // 获取奖励金信息
const getBonusAccount = () => {
bonusModel.getBonusAccount(bonusStoreState.value.studentId).then(res => { bonusModel.getBonusAccount(bonusStoreState.value.studentId).then(res => {
const { data } = res; const { data } = res;
state.bonusAccount = data; state.bonusAccount = data;
}); });
};
getBonusAccount();
const withdrawListParams = reactive<WithdrawListParams>({ const withdrawListParams = reactive<WithdrawListParams>({
pageSize: 10, pageSize: 10,
pageNum: 1, pageNum: 1,
...@@ -230,14 +239,15 @@ const Bonus = defineComponent({ ...@@ -230,14 +239,15 @@ const Bonus = defineComponent({
onLoad(); onLoad();
}); });
const withdraw = () => { const withdraw = () => {
if (!state.bonusAccount?.errCode) {
// 都正常的状态
router.push("withdraw");
} else if (state.bonusAccount?.errCode === ErrCode.NOT_BIND) {
state.showBindWx = true; state.showBindWx = true;
} else { // if (!state.bonusAccount?.errCode) {
state.showDangerous = true; // // 都正常的状态
} // router.push("withdraw");
// } else if (state.bonusAccount?.errCode === ErrCode.NOT_BIND) {
// state.showBindWx = true;
// } else {
// state.showDangerous = true;
// }
}; };
const withdrawRule = () => { const withdrawRule = () => {
state.showWithdrawRules = true; state.showWithdrawRules = true;
...@@ -248,10 +258,12 @@ const Bonus = defineComponent({ ...@@ -248,10 +258,12 @@ const Bonus = defineComponent({
data: "400—8777389" data: "400—8777389"
}); });
}; };
const bindWeChat = () => { const bindWeiChat = () => {
sendNativeMessage({ state.binding = true;
type: "bindWeChat", bindWeChat().then(() => {
data: "bindWeChat" state.showBindWx = false;
state.binding = false;
getBonusAccount();
}); });
}; };
return { return {
...@@ -260,7 +272,7 @@ const Bonus = defineComponent({ ...@@ -260,7 +272,7 @@ const Bonus = defineComponent({
withdraw, withdraw,
withdrawRule, withdrawRule,
phoneCall, phoneCall,
bindWeChat, bindWeiChat,
bonusStoreState, bonusStoreState,
formatBonusTipTxt formatBonusTipTxt
}; };
...@@ -271,7 +283,8 @@ const Bonus = defineComponent({ ...@@ -271,7 +283,8 @@ const Bonus = defineComponent({
[Row.name]: Row, [Row.name]: Row,
[Cell.name]: Cell, [Cell.name]: Cell,
[List.name]: List, [List.name]: List,
[Dialog.Component.name]: Dialog.Component [Dialog.Component.name]: Dialog.Component,
[Loading.name]: Loading
} }
}); });
export default Bonus; export default Bonus;
......
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