功能:落地待优化建议与VIP资产联动
This commit is contained in:
@@ -146,10 +146,10 @@ export interface Tag {
|
||||
|
||||
export const adminTagApi = {
|
||||
listAllTags: () => {
|
||||
return adminApi.get<Tag[]>('/tag/list/all')
|
||||
return adminApi.get<Tag[]>('/tag/list/all') as unknown as Promise<Tag[]>
|
||||
},
|
||||
listTagsByShopId: (shopId: number) => {
|
||||
return adminApi.get<Tag[]>(`/tag/list/by-shop/${shopId}`)
|
||||
return adminApi.get<Tag[]>(`/tag/list/by-shop/${shopId}`) as unknown as Promise<Tag[]>
|
||||
},
|
||||
createTag: (data: { tagName: string; textColor?: string; bgColor?: string; borderColor?: string; shopId?: number }) => {
|
||||
return adminApi.post<number>('/tag/create', data)
|
||||
@@ -185,15 +185,27 @@ export const adminArtistApi = {
|
||||
|
||||
export interface Coupon {
|
||||
id: number
|
||||
couponCode?: string
|
||||
couponName: string
|
||||
couponType: number
|
||||
couponTypeName?: string
|
||||
discountValue?: string
|
||||
minAmount?: number
|
||||
reduceAmount?: string
|
||||
totalCount?: number
|
||||
usedCount?: number
|
||||
remainingCount?: number
|
||||
startTime: string
|
||||
endTime: string
|
||||
status?: number
|
||||
statusName?: string
|
||||
shopId?: number
|
||||
shopName?: string
|
||||
couponScene?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatch?: number
|
||||
availableTags?: Tag[]
|
||||
unavailableTags?: Tag[]
|
||||
createTime: string
|
||||
updateTime: string
|
||||
}
|
||||
@@ -201,7 +213,7 @@ export interface Coupon {
|
||||
export const adminCouponApi = {
|
||||
listAllCoupons: (shopId?: number) => {
|
||||
const params = shopId ? { shopId } : {}
|
||||
return adminApi.get<Coupon[]>('/coupon/list/all', { params })
|
||||
return adminApi.get<Coupon[]>('/coupon/list/all', { params }) as unknown as Promise<Coupon[]>
|
||||
},
|
||||
createCoupon: (data: any) => {
|
||||
return adminApi.post<number>('/coupon/create', data)
|
||||
@@ -213,7 +225,7 @@ export const adminCouponApi = {
|
||||
return adminApi.delete<boolean>(`/coupon/delete/${id}`)
|
||||
},
|
||||
distributeCoupon: (data: any) => {
|
||||
return adminApi.post<boolean>('/coupon/distribute', data)
|
||||
return adminApi.post<boolean>('/coupon/distribute', null, { params: data })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,10 +300,10 @@ export interface CreateShopRequest {
|
||||
|
||||
export const adminShopApi = {
|
||||
listShops: (params: { page: number; size: number; keyword?: string; shopId?: number }) => {
|
||||
return adminApi.get<ShopListResponse>('/shops/list', { params })
|
||||
return adminApi.get<ShopListResponse>('/shops/list', { params }) as unknown as Promise<ShopListResponse>
|
||||
},
|
||||
listAllShops: () => {
|
||||
return adminApi.get<Shop[]>('/shops/list/all')
|
||||
return adminApi.get<Shop[]>('/shops/list/all') as unknown as Promise<Shop[]>
|
||||
},
|
||||
createShop: (data: CreateShopRequest) => {
|
||||
return adminApi.post<number>('/shops/create', data)
|
||||
@@ -311,12 +323,14 @@ export interface UserVO {
|
||||
nickname: string
|
||||
account: string
|
||||
avatar: string
|
||||
phone?: string
|
||||
signature?: string
|
||||
level?: string
|
||||
type: number
|
||||
vipId?: number
|
||||
createTime: string
|
||||
updateTime: string
|
||||
status?: number
|
||||
}
|
||||
|
||||
export interface PageResult<T> {
|
||||
@@ -328,10 +342,10 @@ export interface PageResult<T> {
|
||||
|
||||
export const adminUserApi = {
|
||||
listUsers: (params: { page: number; size: number; keyword?: string; type?: number; shopId?: number; status?: number }) => {
|
||||
return adminApi.get<PageResult<UserVO>>('/user/list', { params })
|
||||
return adminApi.get<PageResult<UserVO>>('/user/list', { params }) as unknown as Promise<PageResult<UserVO>>
|
||||
},
|
||||
listAllUsers: () => {
|
||||
return adminApi.get<UserVO[]>('/user/list/all')
|
||||
return adminApi.get<UserVO[]>('/user/list/all') as unknown as Promise<UserVO[]>
|
||||
},
|
||||
createUser: (data: any) => {
|
||||
return adminApi.post<number>('/user/create', data)
|
||||
@@ -349,10 +363,71 @@ export const adminUserApi = {
|
||||
return adminApi.post<string>(`/user/reset-password/${id}`)
|
||||
},
|
||||
getUserInfo: () => {
|
||||
return adminApi.get<UserVO>('/user/info')
|
||||
return adminApi.get<UserVO>('/user/info') as unknown as Promise<UserVO>
|
||||
},
|
||||
getUserAsset: (id: number) => {
|
||||
return adminApi.get<UserAssetVO>(`/user/${id}/asset`) as unknown as Promise<UserAssetVO>
|
||||
},
|
||||
getUserBalanceHistory: (id: number) => {
|
||||
return adminApi.get<UserBalanceHistoryItem[]>(`/user/${id}/balance/history`) as unknown as Promise<UserBalanceHistoryItem[]>
|
||||
},
|
||||
changeUserBalance: (id: number, data: AdminUserBalanceChangeRequest) => {
|
||||
return adminApi.post<UserAssetVO>(`/user/${id}/balance/change`, data) as unknown as Promise<UserAssetVO>
|
||||
},
|
||||
overrideUserVip: (id: number, data: AdminUserVipOverrideRequest) => {
|
||||
return adminApi.post<UserAssetVO>(`/user/${id}/vip/override`, data) as unknown as Promise<UserAssetVO>
|
||||
},
|
||||
recalculateUserVip: (id: number) => {
|
||||
return adminApi.post<UserAssetVO>(`/user/${id}/vip/recalculate`) as unknown as Promise<UserAssetVO>
|
||||
}
|
||||
}
|
||||
|
||||
export interface UserAssetVO {
|
||||
userId: number
|
||||
nickname: string
|
||||
balance: number
|
||||
totalRechargeAmount: number
|
||||
lastRechargeTime?: string
|
||||
vipInfoId?: number
|
||||
vipLevel: string
|
||||
benefitId?: number
|
||||
benefitInfo?: string
|
||||
manualOverride: boolean
|
||||
vipStartTime?: string
|
||||
vipExpireTime?: string
|
||||
}
|
||||
|
||||
export interface UserBalanceHistoryItem {
|
||||
id: number
|
||||
userId: number
|
||||
userNickname?: string
|
||||
amount: number
|
||||
type?: string
|
||||
currentBalance?: number
|
||||
beforeBalance?: number
|
||||
afterBalance?: number
|
||||
changeScene?: string
|
||||
relatedOrderId?: number
|
||||
relatedOrderNo?: string
|
||||
externalOrderNo?: string
|
||||
operatorId?: number
|
||||
remark?: string
|
||||
changeTime: string
|
||||
}
|
||||
|
||||
export interface AdminUserBalanceChangeRequest {
|
||||
amount: number
|
||||
changeScene: string
|
||||
relatedOrderId?: number
|
||||
externalOrderNo?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface AdminUserVipOverrideRequest {
|
||||
vipLevel: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
// 别名导出,兼容旧代码
|
||||
export const userApi = adminUserApi
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ export interface Coupon {
|
||||
status: number
|
||||
statusName: string
|
||||
shopId?: number
|
||||
couponScene?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatch?: number
|
||||
availableTags: Tag[]
|
||||
unavailableTags: Tag[]
|
||||
}
|
||||
@@ -41,6 +44,9 @@ export interface UserCoupon {
|
||||
statusName: string
|
||||
obtainTime: string
|
||||
useTime: string
|
||||
sourceType?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatched?: boolean
|
||||
}
|
||||
|
||||
export interface CreateCouponRequest {
|
||||
@@ -53,6 +59,9 @@ export interface CreateCouponRequest {
|
||||
totalCount: number
|
||||
startTime: string
|
||||
endTime: string
|
||||
couponScene?: string
|
||||
requiredVipLevel?: string
|
||||
autoMatch?: number
|
||||
availableTagIds: number[]
|
||||
unavailableTagIds: number[]
|
||||
}
|
||||
@@ -136,11 +145,11 @@ export const couponApi = {
|
||||
},
|
||||
|
||||
// 获取作品可用的优惠券
|
||||
getAvailableCoupons: (productTags: string, productPrice: number) => {
|
||||
getAvailableCoupons: (productTags: string, productPrice: number, shopId?: number) => {
|
||||
return request({
|
||||
url: '/coupon/available',
|
||||
method: 'get',
|
||||
params: { productTags, productPrice }
|
||||
params: { productTags, productPrice, shopId }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,7 @@ api.interceptors.response.use(
|
||||
const isWhitelistedPath = (url: string) => {
|
||||
return url?.includes('/user/login') ||
|
||||
url?.includes('/user/register') ||
|
||||
url?.includes('/user/check/') ||
|
||||
url?.includes('/user/refresh-token') ||
|
||||
url?.includes('/user/send-verification-code') ||
|
||||
url?.includes('/user/phone-login') ||
|
||||
|
||||
@@ -9,6 +9,7 @@ interface OrderItem {
|
||||
|
||||
interface CreateOrderRequest {
|
||||
couponId?: number
|
||||
couponSourceType?: string
|
||||
items: OrderItem[]
|
||||
}
|
||||
|
||||
|
||||
@@ -64,6 +64,12 @@ export interface AvailabilityCheckResponse {
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface LoginAccountCheckResponse {
|
||||
exists: boolean
|
||||
nickname?: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface UpdatePhoneRequest {
|
||||
oldPhone: string
|
||||
newPhone: string
|
||||
@@ -92,6 +98,9 @@ export const userApi = {
|
||||
checkAccountAvailability: (account: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/account/${encodeURIComponent(account)}`)
|
||||
},
|
||||
checkLoginAccountAvailability: (account: string) => {
|
||||
return api.get<LoginAccountCheckResponse>(`/user/check/login-account/${encodeURIComponent(account)}`)
|
||||
},
|
||||
checkPhoneAvailability: (phone: string) => {
|
||||
return api.get<AvailabilityCheckResponse>(`/user/check/phone/${encodeURIComponent(phone)}`)
|
||||
},
|
||||
|
||||
+248
-126
@@ -7,15 +7,15 @@
|
||||
</div>
|
||||
|
||||
<div class="tab-container">
|
||||
<div
|
||||
class="tab-item"
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'login' }"
|
||||
@click="activeTab = 'login'"
|
||||
>
|
||||
登录
|
||||
</div>
|
||||
<div
|
||||
class="tab-item"
|
||||
<div
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'register' }"
|
||||
@click="activeTab = 'register'"
|
||||
>
|
||||
@@ -26,13 +26,13 @@
|
||||
<div v-if="activeTab === 'login'" class="login-type-toggle">
|
||||
<a-radio-group v-model:value="loginType" button-style="solid">
|
||||
<a-radio-button value="password">账号密码登录</a-radio-button>
|
||||
<a-radio-button value="phone">手机验证码登录</a-radio-button>
|
||||
<a-radio-button value="phone">手机号验证码登录</a-radio-button>
|
||||
</a-radio-group>
|
||||
</div>
|
||||
|
||||
<a-form
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:rules="currentRules"
|
||||
@finish="handleSubmit"
|
||||
layout="vertical"
|
||||
class="auth-form"
|
||||
@@ -99,8 +99,8 @@
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !formData.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
@@ -110,7 +110,11 @@
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="account" label="账号" v-if="activeTab === 'login' && loginType === 'password'">
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'password'"
|
||||
name="account"
|
||||
label="账号"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="formData.account"
|
||||
placeholder="请输入账号"
|
||||
@@ -120,9 +124,20 @@
|
||||
<UserOutlined style="color: #999" />
|
||||
</template>
|
||||
</a-input>
|
||||
<div
|
||||
v-if="loginAccountStatus"
|
||||
class="field-status"
|
||||
:class="loginAccountStatus.exists ? 'success' : 'error'"
|
||||
>
|
||||
{{ loginAccountStatus.message }}
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="phone" label="手机号" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'phone'"
|
||||
name="phone"
|
||||
label="手机号"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="formData.phone"
|
||||
placeholder="请输入手机号"
|
||||
@@ -138,7 +153,11 @@
|
||||
</div>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="verificationCode" label="验证码" v-if="activeTab === 'login' && loginType === 'phone'">
|
||||
<a-form-item
|
||||
v-if="activeTab === 'login' && loginType === 'phone'"
|
||||
name="verificationCode"
|
||||
label="验证码"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="formData.verificationCode"
|
||||
placeholder="请输入验证码"
|
||||
@@ -148,8 +167,8 @@
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="countdown > 0 || !formData.phone"
|
||||
@click="handleSendVerificationCode"
|
||||
>
|
||||
@@ -187,7 +206,11 @@
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item name="password" label="密码" v-if="activeTab === 'login' && loginType === 'password' || activeTab === 'register'">
|
||||
<a-form-item
|
||||
v-if="(activeTab === 'login' && loginType === 'password') || activeTab === 'register'"
|
||||
name="password"
|
||||
label="密码"
|
||||
>
|
||||
<a-input-password
|
||||
v-model:value="formData.password"
|
||||
placeholder="请输入密码"
|
||||
@@ -218,16 +241,16 @@
|
||||
size="large"
|
||||
:loading="loadingShops"
|
||||
>
|
||||
<a-select-option
|
||||
<a-select-option
|
||||
v-if="shops.length === 0"
|
||||
disabled
|
||||
value=""
|
||||
>
|
||||
暂无店铺数据
|
||||
</a-select-option>
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
<a-select-option
|
||||
v-for="shop in shops"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
@@ -243,10 +266,10 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="loading"
|
||||
>
|
||||
@@ -274,9 +297,8 @@
|
||||
</a-form>
|
||||
</div>
|
||||
|
||||
<!-- 忘记密码弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="forgotPasswordVisible"
|
||||
v-model:open="forgotPasswordVisible"
|
||||
title="忘记密码"
|
||||
:footer="null"
|
||||
width="90%"
|
||||
@@ -310,8 +332,8 @@
|
||||
<LockOutlined style="color: #999" />
|
||||
</template>
|
||||
<template #suffix>
|
||||
<a-button
|
||||
type="link"
|
||||
<a-button
|
||||
type="link"
|
||||
:disabled="forgotCountdown > 0 || !forgotPasswordForm.phone"
|
||||
@click="handleSendForgotCode"
|
||||
>
|
||||
@@ -334,10 +356,10 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item>
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
<a-button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
size="large"
|
||||
block
|
||||
:loading="resettingPassword"
|
||||
>
|
||||
@@ -356,14 +378,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { UserOutlined, LockOutlined, WechatOutlined, QqOutlined, InfoCircleOutlined } from '@ant-design/icons-vue'
|
||||
import { InfoCircleOutlined, LockOutlined, QqOutlined, UserOutlined, WechatOutlined } from '@ant-design/icons-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { Rule } from 'ant-design-vue/es/form'
|
||||
import { authApi } from '@/api/auth'
|
||||
import { shopApi } from '@/api/shop'
|
||||
import { userApi, type AvailabilityCheckResponse } from '@/api/user'
|
||||
import { userApi, type AvailabilityCheckResponse, type LoginAccountCheckResponse } from '@/api/user'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
@@ -373,6 +395,7 @@ const loading = ref(false)
|
||||
const loadingShops = ref(false)
|
||||
const shops = ref<any[]>([])
|
||||
const countdown = ref(0)
|
||||
const loginAccountStatus = ref<LoginAccountCheckResponse | null>(null)
|
||||
const registerAccountStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||
const registerPhoneStatus = ref<AvailabilityCheckResponse | null>(null)
|
||||
|
||||
@@ -397,22 +420,30 @@ const formData = reactive({
|
||||
rememberMe: false
|
||||
})
|
||||
|
||||
const validatePassword = async (_rule: any, value: string) => {
|
||||
if (value.length < 6) {
|
||||
return Promise.reject('密码长度不能少于6位')
|
||||
let loginAccountCheckTimer: number | undefined
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
const verificationCodeRegex = /^\d{6}$/
|
||||
|
||||
const validatePassword = async (_rule: Rule, value: string) => {
|
||||
if (!value || value.length < 6) {
|
||||
return Promise.reject('密码长度不能少于 6 位')
|
||||
}
|
||||
|
||||
let count = 0
|
||||
if (/\d/.test(value)) count++
|
||||
if (/[a-z]/.test(value)) count++
|
||||
if (/[A-Z]/.test(value)) count++
|
||||
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(value)) count++
|
||||
if (/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>/?]/.test(value)) count++
|
||||
|
||||
if (count < 3) {
|
||||
return Promise.reject('密码必须包含数字、小写字母、大写字母和符号中的至少3种')
|
||||
return Promise.reject('密码需至少包含数字、小写字母、大写字母、符号中的 3 种')
|
||||
}
|
||||
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
const validateConfirmPassword = async (_rule: Rule, value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject('请确认密码')
|
||||
}
|
||||
@@ -422,17 +453,17 @@ const validateConfirmPassword = async (_rule: any, value: string) => {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
const rules: Record<string, Rule[]> = {
|
||||
const registerRules: Record<string, Rule[]> = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
|
||||
{ pattern: phoneRegex, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
{ pattern: verificationCodeRegex, message: '验证码必须为 6 位数字', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
@@ -444,7 +475,7 @@ const rules: Record<string, Rule[]> = {
|
||||
],
|
||||
nickname: [
|
||||
{ required: true, message: '请输入昵称', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '昵称长度在2到20个字符', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '昵称长度需为 2 到 20 个字符', trigger: 'blur' },
|
||||
{ pattern: /^[\u4e00-\u9fa5a-zA-Z0-9_]+$/, message: '昵称不能包含特殊符号', trigger: 'blur' }
|
||||
],
|
||||
shopId: [
|
||||
@@ -452,20 +483,47 @@ const rules: Record<string, Rule[]> = {
|
||||
]
|
||||
}
|
||||
|
||||
const forgotPasswordRules: Record<string, Rule[]> = {
|
||||
const loginPasswordRules: Record<string, Rule[]> = {
|
||||
account: [
|
||||
{ required: true, message: '请输入账号', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const loginPhoneRules: Record<string, Rule[]> = {
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
|
||||
{ pattern: phoneRegex, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码必须是6位数字', trigger: 'blur' }
|
||||
{ pattern: verificationCodeRegex, message: '验证码必须为 6 位数字', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const forgotPasswordRules: Record<string, Rule[]> = {
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: phoneRegex, message: '手机号格式不正确', trigger: 'blur' }
|
||||
],
|
||||
verificationCode: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: verificationCodeRegex, message: '验证码必须为 6 位数字', trigger: 'blur' }
|
||||
],
|
||||
newPassword: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const currentRules = computed<Record<string, Rule[]>>(() => {
|
||||
if (activeTab.value === 'register') {
|
||||
return registerRules
|
||||
}
|
||||
return loginType.value === 'phone' ? loginPhoneRules : loginPasswordRules
|
||||
})
|
||||
|
||||
const fetchShops = async () => {
|
||||
loadingShops.value = true
|
||||
try {
|
||||
@@ -479,12 +537,76 @@ const fetchShops = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const resetLoginAccountStatus = () => {
|
||||
if (loginAccountCheckTimer !== undefined) {
|
||||
window.clearTimeout(loginAccountCheckTimer)
|
||||
loginAccountCheckTimer = undefined
|
||||
}
|
||||
loginAccountStatus.value = null
|
||||
}
|
||||
|
||||
const checkLoginAccountAvailability = async (account = formData.account) => {
|
||||
const trimmedAccount = account.trim()
|
||||
if (activeTab.value !== 'login' || loginType.value !== 'password' || !trimmedAccount) {
|
||||
loginAccountStatus.value = null
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await userApi.checkLoginAccountAvailability(trimmedAccount) as unknown as LoginAccountCheckResponse
|
||||
if (
|
||||
activeTab.value === 'login'
|
||||
&& loginType.value === 'password'
|
||||
&& formData.account.trim() === trimmedAccount
|
||||
) {
|
||||
loginAccountStatus.value = response
|
||||
}
|
||||
return response
|
||||
} catch (error) {
|
||||
if (formData.account.trim() === trimmedAccount) {
|
||||
loginAccountStatus.value = null
|
||||
}
|
||||
console.error('登录账号检测失败:', error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const checkRegisterAccountAvailability = async (showWarning = true) => {
|
||||
const trimmedAccount = formData.account.trim()
|
||||
if (activeTab.value !== 'register' || !trimmedAccount) {
|
||||
registerAccountStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkAccountAvailability(trimmedAccount) as unknown as AvailabilityCheckResponse
|
||||
registerAccountStatus.value = response
|
||||
if (showWarning && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
}
|
||||
|
||||
const checkRegisterPhoneAvailability = async (showWarning = true) => {
|
||||
const trimmedPhone = formData.phone.trim()
|
||||
if (activeTab.value !== 'register' || !trimmedPhone) {
|
||||
registerPhoneStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkPhoneAvailability(trimmedPhone) as unknown as AvailabilityCheckResponse
|
||||
registerPhoneStatus.value = response
|
||||
if (showWarning && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
if (activeTab.value === 'login') {
|
||||
let response
|
||||
|
||||
|
||||
if (loginType.value === 'phone') {
|
||||
response = await authApi.phoneLogin({
|
||||
phone: formData.phone,
|
||||
@@ -499,51 +621,58 @@ const handleSubmit = async () => {
|
||||
shopId: formData.shopId
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const loginData = response as any
|
||||
|
||||
if (loginData.accessToken && loginData.refreshToken) {
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
if (loginData.needSetPassword) {
|
||||
localStorage.setItem('needSetPassword', 'true')
|
||||
} else {
|
||||
localStorage.removeItem('needSetPassword')
|
||||
}
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/home').catch(err => {
|
||||
console.error('跳转到首页失败:', err)
|
||||
window.location.href = '/home'
|
||||
})
|
||||
} else {
|
||||
console.error('登录响应缺少token:', loginData)
|
||||
if (!loginData.accessToken || !loginData.refreshToken) {
|
||||
console.error('登录响应缺少 token:', loginData)
|
||||
message.error('登录失败:响应数据异常')
|
||||
}
|
||||
} else {
|
||||
const accountAvailable = await checkRegisterAccountAvailability(false)
|
||||
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||
if (!accountAvailable || !phoneAvailable) {
|
||||
message.error('请先处理注册信息中的占用问题')
|
||||
return
|
||||
}
|
||||
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
nickname: formData.nickname,
|
||||
phone: formData.phone,
|
||||
verificationCode: formData.verificationCode,
|
||||
shopId: formData.shopId!
|
||||
localStorage.setItem('accessToken', loginData.accessToken)
|
||||
localStorage.setItem('refreshToken', loginData.refreshToken)
|
||||
localStorage.setItem('userInfo', JSON.stringify(loginData.userInfo))
|
||||
sessionStorage.setItem('accessToken', loginData.accessToken)
|
||||
|
||||
if (loginData.needSetPassword) {
|
||||
localStorage.setItem('needSetPassword', 'true')
|
||||
} else {
|
||||
localStorage.removeItem('needSetPassword')
|
||||
}
|
||||
|
||||
message.success('登录成功')
|
||||
router.push('/home').catch(err => {
|
||||
console.error('跳转首页失败:', err)
|
||||
window.location.href = '/home'
|
||||
})
|
||||
|
||||
message.success('注册成功,请登录')
|
||||
activeTab.value = 'login'
|
||||
return
|
||||
}
|
||||
|
||||
const accountAvailable = await checkRegisterAccountAvailability(false)
|
||||
const phoneAvailable = await checkRegisterPhoneAvailability(false)
|
||||
if (!accountAvailable || !phoneAvailable) {
|
||||
message.error('请先处理注册信息中的占用问题')
|
||||
return
|
||||
}
|
||||
|
||||
await authApi.register({
|
||||
account: formData.account,
|
||||
password: formData.password,
|
||||
nickname: formData.nickname,
|
||||
phone: formData.phone,
|
||||
verificationCode: formData.verificationCode,
|
||||
shopId: formData.shopId!
|
||||
})
|
||||
|
||||
message.success('注册成功,请登录')
|
||||
activeTab.value = 'login'
|
||||
loginType.value = 'password'
|
||||
formData.password = ''
|
||||
formData.confirmPassword = ''
|
||||
formData.verificationCode = ''
|
||||
resetLoginAccountStatus()
|
||||
} catch (error: any) {
|
||||
console.error('登录失败:', error)
|
||||
console.error(activeTab.value === 'login' ? '登录失败:' : '注册失败:', error)
|
||||
message.error(error.message || (activeTab.value === 'login' ? '登录失败' : '注册失败'))
|
||||
} finally {
|
||||
loading.value = false
|
||||
@@ -559,8 +688,6 @@ const handleSendForgotCode = async () => {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(forgotPasswordForm.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
@@ -570,10 +697,10 @@ const handleSendForgotCode = async () => {
|
||||
await authApi.sendVerificationCode({ phone: forgotPasswordForm.phone })
|
||||
message.success('验证码已发送')
|
||||
forgotCountdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
const timer = window.setInterval(() => {
|
||||
forgotCountdown.value--
|
||||
if (forgotCountdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error: any) {
|
||||
@@ -591,7 +718,6 @@ const handleResetPassword = async () => {
|
||||
})
|
||||
message.success('密码重置成功,请使用新密码登录')
|
||||
forgotPasswordVisible.value = false
|
||||
|
||||
forgotPasswordForm.phone = ''
|
||||
forgotPasswordForm.verificationCode = ''
|
||||
forgotPasswordForm.newPassword = ''
|
||||
@@ -607,35 +733,7 @@ const handleWeChatLogin = () => {
|
||||
}
|
||||
|
||||
const handleQQLogin = () => {
|
||||
message.info('QQ登录功能开发中')
|
||||
}
|
||||
|
||||
const checkRegisterAccountAvailability = async (showSuccessMessage = true) => {
|
||||
if (activeTab.value !== 'register' || !formData.account.trim()) {
|
||||
registerAccountStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkAccountAvailability(formData.account.trim()) as unknown as AvailabilityCheckResponse
|
||||
registerAccountStatus.value = response
|
||||
if (showSuccessMessage && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
}
|
||||
|
||||
const checkRegisterPhoneAvailability = async (showSuccessMessage = true) => {
|
||||
if (activeTab.value !== 'register' || !formData.phone.trim()) {
|
||||
registerPhoneStatus.value = null
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await userApi.checkPhoneAvailability(formData.phone.trim()) as unknown as AvailabilityCheckResponse
|
||||
registerPhoneStatus.value = response
|
||||
if (showSuccessMessage && !response.available) {
|
||||
message.warning(response.message)
|
||||
}
|
||||
return response.available
|
||||
message.info('QQ 登录功能开发中')
|
||||
}
|
||||
|
||||
const handleRegisterAccountBlur = async () => {
|
||||
@@ -657,8 +755,6 @@ const handleRegisterPhoneBlur = async () => {
|
||||
registerPhoneStatus.value = null
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(formData.phone)) {
|
||||
registerPhoneStatus.value = null
|
||||
return
|
||||
@@ -677,8 +773,6 @@ const handleSendVerificationCode = async () => {
|
||||
message.error('请输入手机号')
|
||||
return
|
||||
}
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
if (!phoneRegex.test(formData.phone)) {
|
||||
message.error('手机号格式不正确')
|
||||
return
|
||||
@@ -696,10 +790,10 @@ const handleSendVerificationCode = async () => {
|
||||
await userApi.sendVerificationCode({ phone: formData.phone })
|
||||
message.success('验证码已发送')
|
||||
countdown.value = 60
|
||||
const timer = setInterval(() => {
|
||||
const timer = window.setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value <= 0) {
|
||||
clearInterval(timer)
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} catch (error: any) {
|
||||
@@ -716,15 +810,43 @@ const handleAdminLogin = () => {
|
||||
localStorage.removeItem('adminUserInfo')
|
||||
sessionStorage.removeItem('accessToken')
|
||||
sessionStorage.removeItem('adminAccessToken')
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
window.setTimeout(() => {
|
||||
window.location.href = '/admin/login'
|
||||
}, 100)
|
||||
}
|
||||
|
||||
watch([activeTab, loginType], () => {
|
||||
resetLoginAccountStatus()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => formData.account,
|
||||
value => {
|
||||
if (activeTab.value !== 'login' || loginType.value !== 'password') {
|
||||
return
|
||||
}
|
||||
|
||||
resetLoginAccountStatus()
|
||||
const trimmedAccount = value.trim()
|
||||
if (!trimmedAccount) {
|
||||
return
|
||||
}
|
||||
|
||||
loginAccountCheckTimer = window.setTimeout(() => {
|
||||
loginAccountCheckTimer = undefined
|
||||
void checkLoginAccountAvailability(trimmedAccount)
|
||||
}, 400)
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
fetchShops()
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
resetLoginAccountStatus()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
+129
-32
@@ -56,10 +56,10 @@
|
||||
</div>
|
||||
</a-card>
|
||||
|
||||
<a-card v-if="selectedCount" class="coupon-card" @click="showCouponModal = true">
|
||||
<a-card v-if="selectedCount" class="coupon-card" @click="openCouponModal">
|
||||
<div class="coupon-row">
|
||||
<span>优惠券</span>
|
||||
<span>{{ selectedCoupon?.couponName || '使用优惠券' }}</span>
|
||||
<span>{{ selectedCoupon ? formatCouponDisplay(selectedCoupon) : '使用优惠券' }}</span>
|
||||
</div>
|
||||
<div v-if="selectedCoupon" class="coupon-discount">优惠金额 -¥{{ discountAmount.toFixed(2) }}</div>
|
||||
</a-card>
|
||||
@@ -79,12 +79,15 @@
|
||||
</footer>
|
||||
|
||||
<a-modal v-model:open="showCouponModal" title="使用优惠券" @ok="applyCouponSelection" @cancel="showCouponModal = false">
|
||||
<a-radio-group v-model:value="couponSelectionId" class="coupon-options">
|
||||
<a-radio :value="0">不使用优惠券</a-radio>
|
||||
<a-radio v-for="coupon in availableCoupons" :key="coupon.id" :value="coupon.id">
|
||||
{{ coupon.couponName }}
|
||||
<a-radio-group v-model:value="couponSelectionKey" class="coupon-options">
|
||||
<a-radio :value="NO_COUPON_KEY">不使用优惠券</a-radio>
|
||||
<a-radio v-for="coupon in availableCoupons" :key="getCouponKey(coupon)" :value="getCouponKey(coupon)">
|
||||
{{ formatCouponDisplay(coupon) }}
|
||||
</a-radio>
|
||||
</a-radio-group>
|
||||
<div class="coupon-tip">
|
||||
系统只会默认预选 VIP 自动券,普通用户券需要你手动选择后才会在下单时使用。
|
||||
</div>
|
||||
</a-modal>
|
||||
|
||||
<a-modal v-model:open="showBookingModal" :title="bookingTitle" @ok="confirmBooking" @cancel="closeBookingModal">
|
||||
@@ -131,6 +134,8 @@ import { userApi } from '../api/user'
|
||||
const router = useRouter()
|
||||
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
|
||||
|
||||
const NO_COUPON_KEY = 'NONE'
|
||||
|
||||
interface ArtistOption {
|
||||
id: number
|
||||
name: string
|
||||
@@ -161,7 +166,8 @@ const cartItems = ref<CartItem[]>([])
|
||||
const imageIdCache = ref<Record<string, string>>({})
|
||||
const availableCoupons = ref<UserCoupon[]>([])
|
||||
const selectedCoupon = ref<UserCoupon | null>(null)
|
||||
const couponSelectionId = ref(0)
|
||||
const couponSelectionKey = ref(NO_COUPON_KEY)
|
||||
const couponSelectionTouched = ref(false)
|
||||
const showCouponModal = ref(false)
|
||||
const showBookingModal = ref(false)
|
||||
const currentItem = ref<CartItem | null>(null)
|
||||
@@ -170,15 +176,11 @@ const draftArtistId = ref<number>()
|
||||
const draftAppointmentTime = ref('')
|
||||
const currentShopHours = ref('')
|
||||
|
||||
const selectedCount = computed(() => cartItems.value.filter(item => item.selected).length)
|
||||
const totalQuantity = computed(() => cartItems.value.filter(item => item.selected).reduce((sum, item) => sum + item.quantity, 0))
|
||||
const subtotal = computed(() => cartItems.value.filter(item => item.selected).reduce((sum, item) => sum + item.price * item.quantity, 0))
|
||||
const discountAmount = computed(() => {
|
||||
if (!selectedCoupon.value) return 0
|
||||
if (selectedCoupon.value.couponType === 1) return subtotal.value - subtotal.value * parseFloat(selectedCoupon.value.discountValue) / 10
|
||||
if (selectedCoupon.value.couponType === 2) return parseFloat(selectedCoupon.value.reduceAmount)
|
||||
return 0
|
||||
})
|
||||
const selectedItems = computed(() => cartItems.value.filter(item => item.selected))
|
||||
const selectedCount = computed(() => selectedItems.value.length)
|
||||
const totalQuantity = computed(() => selectedItems.value.reduce((sum, item) => sum + item.quantity, 0))
|
||||
const subtotal = computed(() => selectedItems.value.reduce((sum, item) => sum + item.price * item.quantity, 0))
|
||||
const discountAmount = computed(() => calculateCouponDiscount(selectedCoupon.value, subtotal.value))
|
||||
const totalAmount = computed(() => Math.max(0, subtotal.value - discountAmount.value))
|
||||
const bookingTitle = computed(() => currentItem.value ? '为 ' + currentItem.value.productTitle + ' 选择预约信息' : '选择预约信息')
|
||||
const bookingHelperText = computed(() => {
|
||||
@@ -204,6 +206,39 @@ const minAppointmentTime = computed(() => {
|
||||
].join('')
|
||||
})
|
||||
|
||||
const getCouponKey = (coupon: UserCoupon) => `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
|
||||
|
||||
const calculateCouponDiscount = (coupon: UserCoupon | null, amount: number) => {
|
||||
if (!coupon || amount <= 0) {
|
||||
return 0
|
||||
}
|
||||
if (coupon.couponType === 1) {
|
||||
const discountValue = Number(coupon.discountValue || 0)
|
||||
if (!discountValue) {
|
||||
return 0
|
||||
}
|
||||
return amount - amount * discountValue / 10
|
||||
}
|
||||
if (coupon.couponType === 2) {
|
||||
return Number(coupon.reduceAmount || 0)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
const formatCouponDisplay = (coupon: UserCoupon) => {
|
||||
const badge = coupon.sourceType === 'SYSTEM_VIP' ? '[VIP 自动券]' : '[用户券]'
|
||||
const benefit = coupon.couponType === 1
|
||||
? `${coupon.discountValue}折`
|
||||
: `满${coupon.minAmount}减${coupon.reduceAmount}`
|
||||
return `${badge} ${coupon.couponName} ${benefit}`
|
||||
}
|
||||
|
||||
const findBestSystemVipCoupon = (coupons: UserCoupon[]) => {
|
||||
return coupons
|
||||
.filter(coupon => coupon.sourceType === 'SYSTEM_VIP')
|
||||
.sort((left, right) => calculateCouponDiscount(right, subtotal.value) - calculateCouponDiscount(left, subtotal.value))[0] || null
|
||||
}
|
||||
|
||||
const openProduct = (item: CartItem) => {
|
||||
router.push('/product/' + item.productId)
|
||||
}
|
||||
@@ -217,6 +252,9 @@ const loadCartItems = async () => {
|
||||
productImage: '',
|
||||
appointmentTime: item.appointmentTime
|
||||
}))
|
||||
couponSelectionTouched.value = false
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
selectedCoupon.value = null
|
||||
await Promise.all([loadProductImages(), loadAvailableCoupons()])
|
||||
}
|
||||
|
||||
@@ -227,7 +265,9 @@ const loadProductImages = async () => {
|
||||
if (!match?.[1]) continue
|
||||
const imageId = match[1]
|
||||
try {
|
||||
if (!imageIdCache.value[imageId]) imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
imageIdCache.value[imageId] = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
}
|
||||
item.productImage = imageIdCache.value[imageId] || ''
|
||||
} catch {
|
||||
item.productImage = ''
|
||||
@@ -236,17 +276,56 @@ const loadProductImages = async () => {
|
||||
}
|
||||
|
||||
const loadAvailableCoupons = async () => {
|
||||
try {
|
||||
const tags = new Set<string>()
|
||||
cartItems.value.filter(item => item.selected).forEach(item => item.tagNames?.split(',').map(tag => tag.trim()).forEach(tag => tag && tags.add(tag)))
|
||||
const data = subtotal.value > 0 ? await couponApi.getAvailableCoupons(Array.from(tags).join(','), subtotal.value) as unknown as any[] : []
|
||||
availableCoupons.value = data || []
|
||||
if (selectedCoupon.value && !availableCoupons.value.some(coupon => coupon.id === selectedCoupon.value?.id)) selectedCoupon.value = null
|
||||
couponSelectionId.value = selectedCoupon.value?.id || 0
|
||||
} catch {
|
||||
const currentSelectedKey = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : couponSelectionKey.value
|
||||
const selectedShopId = selectedItems.value[0]?.shopId
|
||||
|
||||
if (!selectedItems.value.length || subtotal.value <= 0) {
|
||||
availableCoupons.value = []
|
||||
selectedCoupon.value = null
|
||||
couponSelectionId.value = 0
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const tags = new Set<string>()
|
||||
selectedItems.value.forEach(item => {
|
||||
item.tagNames?.split(',').map(tag => tag.trim()).forEach(tag => {
|
||||
if (tag) {
|
||||
tags.add(tag)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
const data = await couponApi.getAvailableCoupons(Array.from(tags).join(','), subtotal.value, selectedShopId) as unknown as UserCoupon[]
|
||||
availableCoupons.value = Array.isArray(data) ? data : []
|
||||
|
||||
const matchedCoupon = availableCoupons.value.find(coupon => getCouponKey(coupon) === currentSelectedKey) || null
|
||||
if (matchedCoupon) {
|
||||
selectedCoupon.value = matchedCoupon
|
||||
couponSelectionKey.value = getCouponKey(matchedCoupon)
|
||||
return
|
||||
}
|
||||
|
||||
if (couponSelectionTouched.value && currentSelectedKey === NO_COUPON_KEY) {
|
||||
selectedCoupon.value = null
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
return
|
||||
}
|
||||
|
||||
couponSelectionTouched.value = false
|
||||
const defaultVipCoupon = findBestSystemVipCoupon(availableCoupons.value)
|
||||
if (defaultVipCoupon) {
|
||||
selectedCoupon.value = defaultVipCoupon
|
||||
couponSelectionKey.value = getCouponKey(defaultVipCoupon)
|
||||
} else {
|
||||
selectedCoupon.value = null
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取可用优惠券失败:', error)
|
||||
availableCoupons.value = []
|
||||
selectedCoupon.value = null
|
||||
couponSelectionKey.value = NO_COUPON_KEY
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,13 +413,23 @@ const confirmBooking = () => {
|
||||
closeBookingModal()
|
||||
}
|
||||
|
||||
const openCouponModal = () => {
|
||||
couponSelectionKey.value = selectedCoupon.value ? getCouponKey(selectedCoupon.value) : NO_COUPON_KEY
|
||||
showCouponModal.value = true
|
||||
}
|
||||
|
||||
const applyCouponSelection = () => {
|
||||
selectedCoupon.value = availableCoupons.value.find(coupon => coupon.id === couponSelectionId.value) || null
|
||||
couponSelectionTouched.value = true
|
||||
if (couponSelectionKey.value === NO_COUPON_KEY) {
|
||||
selectedCoupon.value = null
|
||||
} else {
|
||||
selectedCoupon.value = availableCoupons.value.find(coupon => getCouponKey(coupon) === couponSelectionKey.value) || null
|
||||
}
|
||||
showCouponModal.value = false
|
||||
}
|
||||
|
||||
const checkout = async () => {
|
||||
const items = cartItems.value.filter(item => item.selected)
|
||||
const items = selectedItems.value
|
||||
if (!items.length) return message.warning('请先选择要结算的作品')
|
||||
if (items.some(item => !item.artistId)) return message.warning('请先为所有项目选择美甲师')
|
||||
if (items.some(item => !item.appointmentTime)) return message.warning('请先为所有项目选择预约时间')
|
||||
@@ -351,6 +440,7 @@ const checkout = async () => {
|
||||
try {
|
||||
await orderApi.createOrder({
|
||||
couponId: selectedCoupon.value?.id,
|
||||
couponSourceType: selectedCoupon.value?.sourceType || (couponSelectionTouched.value && !selectedCoupon.value ? NO_COUPON_KEY : undefined),
|
||||
items: items.map(item => ({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
@@ -361,12 +451,18 @@ const checkout = async () => {
|
||||
await Promise.all([loadCartItems(), updateCartCount()])
|
||||
message.success('订单创建成功')
|
||||
router.push('/orders')
|
||||
} catch {
|
||||
message.error('创建订单失败')
|
||||
} catch (error: any) {
|
||||
console.error('创建订单失败:', error)
|
||||
message.error(error?.message || '创建订单失败')
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => cartItems.value.map(item => String(item.id) + '-' + item.selected + '-' + item.quantity), loadAvailableCoupons)
|
||||
watch(
|
||||
() => cartItems.value.map(item => `${item.id}-${item.selected}-${item.quantity}`).join('|'),
|
||||
() => {
|
||||
void loadAvailableCoupons()
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
@@ -395,7 +491,8 @@ onMounted(async () => {
|
||||
.selector .value { flex: 1; color: #1890ff; font-size: 13px; }
|
||||
.actions, .qty, .coupon-row, .summary-row { display: flex; align-items: center; justify-content: space-between; }
|
||||
.qty { gap: 8px; }
|
||||
.duration, .coupon-discount, .helper { color: #666; font-size: 12px; }
|
||||
.duration, .coupon-discount, .helper, .coupon-tip { color: #666; font-size: 12px; }
|
||||
.coupon-tip { margin-top: 12px; line-height: 1.6; }
|
||||
.summary-row.total { font-weight: 700; }
|
||||
.footer { bottom: 60px; padding: 15px; border-top: 1px solid #f0f0f0; box-shadow: 0 -2px 8px rgba(0,0,0,.06); }
|
||||
.coupon-options { display: flex; flex-direction: column; gap: 8px; }
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -541,7 +541,7 @@ const fetchCoupons = async () => {
|
||||
try {
|
||||
const response = await adminCouponApi.listAllCoupons()
|
||||
const res = typeof response === 'object' && 'data' in response ? response.data : response
|
||||
coupons.value = res || []
|
||||
coupons.value = (res as any[]) || []
|
||||
} catch (error) {
|
||||
console.error('获取优惠券列表失败', error)
|
||||
message.error('获取优惠券列表失败')
|
||||
@@ -945,4 +945,4 @@ watch(() => formState.shopId, (newShopId) => {
|
||||
.product-images :deep(.ant-image) {
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user