diff --git a/src/common/apis/ab98/index.ts b/src/common/apis/ab98/index.ts index ecfbb60..e7a91d6 100644 --- a/src/common/apis/ab98/index.ts +++ b/src/common/apis/ab98/index.ts @@ -1,5 +1,6 @@ import { request } from '@/http/axios' import { + BindQyUserCommand, GetTokenParams, LoginData, LogoutResponse, @@ -8,6 +9,7 @@ import { VerifySmsParams, WechatQrCodeParams } from './type' +import { ab98UserDTO } from '../shop/type' /** 获取临时令牌 */ export function getTokenApi(appName: string) { @@ -61,4 +63,12 @@ export function tokenLogin(token: string, userid: string, openid: string) { method: 'get', params: { token, userid, openid } }) +} + +export function bindQyUserApi(data: BindQyUserCommand) { + return request>({ + url: '/wx/login/bindQyUser', + method: 'post', + data + }) } \ No newline at end of file diff --git a/src/common/apis/ab98/type.ts b/src/common/apis/ab98/type.ts index 2f1e78a..c27e65b 100644 --- a/src/common/apis/ab98/type.ts +++ b/src/common/apis/ab98/type.ts @@ -58,4 +58,10 @@ export type VerifySmsParams = { vcode: string userid: string openid: string +} + +export interface BindQyUserCommand { + qyUserId: number; + name: string; + idNum: string; } \ No newline at end of file diff --git a/src/common/apis/shop/type.ts b/src/common/apis/shop/type.ts index c0cd808..4343aac 100644 --- a/src/common/apis/shop/type.ts +++ b/src/common/apis/shop/type.ts @@ -110,10 +110,39 @@ export interface GetBalanceResponse { } export interface QyLoginDTO { - userid: string - openid: string - isCabinetAdmin: number - name: string + userid: string; + openid: string; + isCabinetAdmin: number; + qyUserId: number; + name: string; + ab98User: ab98UserDTO; +} + +export interface ab98UserDTO { + /** 主键ID */ + ab98UserId?: number; + /** openid */ + openid?: string; + /** 汇邦云用户唯一ID */ + userid?: string; + /** 真实姓名 */ + name?: string; + /** 手机号码 */ + tel?: string; + /** 身份证号码 */ + idnum?: string; + /** 性别(男 女) */ + sex?: string; + /** 人脸照片地址 */ + faceImg?: string; + /** 身份证正面地址 */ + idcardFront?: string; + /** 身份证背面地址 */ + idcardBack?: string; + /** 身份证登记地址 */ + address?: string; + /** 是否已注册(0未注册 1已注册) */ + registered?: boolean; } export interface OpenCabinetApiData { diff --git a/src/pages/product/ProductList.vue b/src/pages/product/ProductList.vue index fd45cb5..76255ab 100644 --- a/src/pages/product/ProductList.vue +++ b/src/pages/product/ProductList.vue @@ -9,15 +9,19 @@ import { computed, onBeforeUnmount, onMounted, ref } from "vue" import Cart from "./components/cart.vue" import Detail from "./components/detail.vue" import { useRoute } from 'vue-router' +import { useWxStore } from "@/pinia/stores/wx" +import { bindQyUserApi } from "@/common/apis/ab98" const router = useRouter() const route = useRoute() // 状态管理 -const productStore = useProductStore() -const cartStore = useCartStore() -const { cartItems, totalPrice, totalQuantity } = storeToRefs(cartStore) // 新增购物车状态 +const productStore = useProductStore(); +const cartStore = useCartStore(); +const wxStore = useWxStore(); +const { cartItems, totalPrice, totalQuantity } = storeToRefs(cartStore); // 新增购物车状态 // 从 store 解构分类标签和商品数据 -const { labels, categories } = storeToRefs(productStore) +const { labels, categories } = storeToRefs(productStore); +const { openid, corpidLogin, ab98User, qyUserId } = storeToRefs(wxStore); // 当前选中的分类索引 const activeCategory = ref(0) @@ -40,7 +44,11 @@ const currentProduct = computed(() => // 购物车弹窗控制 const showCartPopup = ref(false) -const searchQuery = ref('') +const searchQuery = ref(''); + +const name = ref(''); +const idNum = ref(''); +const showAb98BindPopup = ref(false); // 点击分类导航 function handleCategoryClick(index: number) { @@ -131,7 +139,38 @@ watch(() => route.path, (newPath) => { if (newPath === '/') { productStore.getGoods() } -}) +}); + +let showAb98BindPopupOnce = false; +watch(openid, async () => { + if (openid.value && corpidLogin.value && !ab98User.value + && !showAb98BindPopup.value && !showAb98BindPopupOnce) { + // 显示绑定弹窗 + showAb98BindPopup.value = true; + showAb98BindPopupOnce = true; + } +}, { immediate: true }); + +async function handleAb98Bind() { + try { + const ab98UserData = await bindQyUserApi({ + qyUserId: qyUserId.value, + name: name.value, + idNum: idNum.value + }); + + if (ab98UserData?.code === 0) { + wxStore.setAb98User(ab98UserData.data); + showAb98BindPopup.value = false; + name.value = ''; + idNum.value = ''; + } else { + console.error('绑定失败:', ab98UserData?.msg); + } + } catch (error) { + console.error('绑定失败:', error); + } +}