补齐店务端改密导出员工订单
This commit is contained in:
@@ -18,12 +18,25 @@ const adminApi = axios.create({
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
const normalizeResponse = <T>(response: { data: { code?: number; message?: string; data: T } }): T => {
|
||||
interface ApiResponsePayload<T> {
|
||||
code?: number
|
||||
message?: string
|
||||
data: T
|
||||
}
|
||||
|
||||
const isApiResponsePayload = <T>(payload: ApiResponsePayload<T> | T): payload is ApiResponsePayload<T> => (
|
||||
payload !== null && payload !== undefined && typeof payload === 'object' && 'data' in payload
|
||||
)
|
||||
|
||||
const normalizeResponse = <T>(response: { config?: { responseType?: string }; data: ApiResponsePayload<T> | T }): T => {
|
||||
if (response.config?.responseType === 'blob' || response.config?.responseType === 'arraybuffer') {
|
||||
return response.data as T
|
||||
}
|
||||
const payload = response.data
|
||||
if (payload && payload.code !== undefined && payload.code !== 200) {
|
||||
if (isApiResponsePayload(payload) && payload.code !== undefined && payload.code !== 200) {
|
||||
throw new Error(payload.message || '请求失败')
|
||||
}
|
||||
return payload.data as T
|
||||
return isApiResponsePayload(payload) ? payload.data : payload
|
||||
}
|
||||
|
||||
const handleExpired = async (): Promise<void> => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
ArtistScheduleRuleSetting,
|
||||
EmployeeCreateRequest
|
||||
} from '@/types/manager'
|
||||
import type { Appointment } from '@/types/manager'
|
||||
|
||||
export interface ManagerDefaultPasswordResponse {
|
||||
password: string
|
||||
@@ -20,6 +21,9 @@ export const managerEmployeesApi = {
|
||||
detail(userId: IdType): Promise<Artist> {
|
||||
return adminApi.get(`/manager/employees/${userId}`)
|
||||
},
|
||||
orders(userId: IdType, params: { startDate: string; endDate: string }): Promise<Appointment[]> {
|
||||
return adminApi.get(`/manager/employees/${userId}/orders`, { params })
|
||||
},
|
||||
save(data: Partial<Artist>): Promise<Artist> {
|
||||
return adminApi.post('/manager/employees', data)
|
||||
},
|
||||
|
||||
@@ -16,5 +16,8 @@ export const managerShopApi = {
|
||||
},
|
||||
exportPreview(params: { type: string; startDate: string; endDate: string }): Promise<unknown> {
|
||||
return adminApi.get('/export', { params })
|
||||
},
|
||||
exportData(params: { type: string; startDate: string; endDate: string }): Promise<Blob> {
|
||||
return adminApi.get('/export', { params, responseType: 'blob' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,5 +7,8 @@ export const userApi = {
|
||||
},
|
||||
update(data: Partial<UserInfo>): Promise<boolean> {
|
||||
return api.put('/user/info', data)
|
||||
},
|
||||
updatePassword(data: { oldPassword: string; password: string }): Promise<boolean> {
|
||||
return api.put('/user/password', data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,120 @@
|
||||
<template>
|
||||
<MobileShell title="员工作品/订单">
|
||||
<EmptyState title="暂无员工作品/订单" description="当前小程序页面为返回入口,Web 端按现状保留轻量视图。" mark="单" />
|
||||
<div class="employee-orders-view">
|
||||
<section class="card form-card">
|
||||
<label class="field">
|
||||
<span class="field-label">开始日期</span>
|
||||
<DatePickerField v-model="startDate" placeholder="请选择开始日期" title="日期选择" @confirm="loadOrders" />
|
||||
</label>
|
||||
<label class="field">
|
||||
<span class="field-label">结束日期</span>
|
||||
<DatePickerField v-model="endDate" placeholder="请选择结束日期" title="日期选择" @confirm="loadOrders" />
|
||||
</label>
|
||||
</section>
|
||||
|
||||
<LoadingState v-if="loading" text="订单加载中" />
|
||||
<EmptyState v-else-if="loadError" title="订单加载失败" :description="loadError" />
|
||||
<EmptyState v-else-if="orders.length === 0" title="暂无员工作品/订单" description="当前日期范围内没有订单" mark="单" />
|
||||
<section v-else class="order-list section">
|
||||
<article v-for="order in orders" :key="String(order.orderItemId)" class="card list-card" @click="openOrder(order)">
|
||||
<div>
|
||||
<h2 class="list-card__title">{{ order.productTitle || '预约作品' }}</h2>
|
||||
<div class="list-card__subtitle">{{ order.date || shortDate(order.startTime) }} · {{ order.customerName || '到店客户' }}</div>
|
||||
<div class="list-card__meta">{{ order.artistName || '未分配' }} · {{ timeRange(order) }} · {{ order.statusText || '-' }}</div>
|
||||
</div>
|
||||
<strong class="amount">{{ orderAmount(order) }}</strong>
|
||||
</article>
|
||||
</section>
|
||||
</div>
|
||||
</MobileShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import DatePickerField from '@/components/DatePickerField.vue'
|
||||
import EmptyState from '@/components/EmptyState.vue'
|
||||
import LoadingState from '@/components/LoadingState.vue'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
import { managerEmployeesApi } from '@/api/managerEmployees'
|
||||
import { formatDate, startOfMonth } from '@/utils/date'
|
||||
import type { Appointment } from '@/types/manager'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const employeeId = String(route.params.id || '')
|
||||
const startDate = ref(formatDate(startOfMonth(new Date())))
|
||||
const endDate = ref(formatDate(new Date()))
|
||||
const orders = ref<Appointment[]>([])
|
||||
const loading = ref(false)
|
||||
const loadError = ref('')
|
||||
|
||||
const shortDate = (value: unknown): string => String(value || '').slice(0, 10) || '-'
|
||||
|
||||
const timeRange = (item: Appointment): string => {
|
||||
const start = String(item.startTime || '').slice(11, 16)
|
||||
const end = String(item.endTime || '').slice(11, 16)
|
||||
if (!start && !end) {
|
||||
return '-'
|
||||
}
|
||||
return `${start || '-'}-${end || '-'}`
|
||||
}
|
||||
|
||||
const orderAmount = (item: Appointment): string => {
|
||||
const value = item.amount ?? item.manualProductPrice
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return '¥0'
|
||||
}
|
||||
const amount = Number(value)
|
||||
return Number.isNaN(amount) ? `¥${value}` : `¥${amount.toFixed(2).replace(/\.00$/, '')}`
|
||||
}
|
||||
|
||||
const loadOrders = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
orders.value = await managerEmployeesApi.orders(employeeId, {
|
||||
startDate: startDate.value,
|
||||
endDate: endDate.value
|
||||
})
|
||||
} catch (error) {
|
||||
orders.value = []
|
||||
loadError.value = error instanceof Error ? error.message : '员工订单加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openOrder = (order: Appointment): void => {
|
||||
if (!order.orderItemId) {
|
||||
return
|
||||
}
|
||||
router.push(`/appointments/${order.orderItemId}`)
|
||||
}
|
||||
|
||||
onMounted(loadOrders)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.employee-orders-view {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.order-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.list-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.amount {
|
||||
color: #5f8f7f;
|
||||
font-size: 15px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
<div class="fixed-bottom">
|
||||
<div class="fixed-bottom__inner">
|
||||
<button class="primary-btn" type="button" @click="exportExcel">导出 Excel</button>
|
||||
<button class="primary-btn" type="button" :disabled="exporting" @click="exportExcel">{{ exporting ? '导出中...' : '导出 Excel' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -60,6 +60,7 @@ import MobileShell from '@/components/MobileShell.vue'
|
||||
import { managerCustomersApi } from '@/api/managerCustomers'
|
||||
import { managerEmployeesApi } from '@/api/managerEmployees'
|
||||
import { managerPlanningApi } from '@/api/managerPlanning'
|
||||
import { managerShopApi } from '@/api/managerShop'
|
||||
import { formatDate, startOfMonth } from '@/utils/date'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
import type { Appointment, Artist } from '@/types/manager'
|
||||
@@ -78,6 +79,7 @@ const previewColumns = ref<string[]>([])
|
||||
const previewRows = ref<PreviewRow[]>([])
|
||||
const previewLoading = ref(false)
|
||||
const previewError = ref('')
|
||||
const exporting = ref(false)
|
||||
|
||||
const shortDateTime = (value: unknown): string => {
|
||||
const text = String(value || '')
|
||||
@@ -169,8 +171,35 @@ const loadPreview = async (): Promise<void> => {
|
||||
}
|
||||
}
|
||||
|
||||
const exportExcel = (): void => {
|
||||
toast.success('导出任务已创建')
|
||||
const buildExportFileName = (): string => `${type.value}_${startDate.value}_${endDate.value}.xlsx`
|
||||
|
||||
const downloadBlob = (blob: Blob): void => {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = buildExportFileName()
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
const exportExcel = async (): Promise<void> => {
|
||||
if (exporting.value) {
|
||||
return
|
||||
}
|
||||
exporting.value = true
|
||||
try {
|
||||
const blob = await managerShopApi.exportData({
|
||||
type: type.value,
|
||||
startDate: startDate.value,
|
||||
endDate: endDate.value
|
||||
})
|
||||
downloadBlob(blob)
|
||||
toast.success('Excel 已开始下载')
|
||||
} finally {
|
||||
exporting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadPreview)
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<div class="fixed-bottom">
|
||||
<div class="fixed-bottom__inner">
|
||||
<button class="primary-btn" type="button" @click="save">保存密码</button>
|
||||
<button class="primary-btn" type="button" :disabled="saving" @click="save">{{ saving ? '保存中...' : '保存密码' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -26,18 +26,31 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive } from 'vue'
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { userApi } from '@/api/user'
|
||||
import MobileShell from '@/components/MobileShell.vue'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
import { useToastStore } from '@/stores/toast'
|
||||
|
||||
const toast = useToastStore()
|
||||
const router = useRouter()
|
||||
const session = useSessionStore()
|
||||
const saving = ref(false)
|
||||
const form = reactive({
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
const save = (): void => {
|
||||
const save = async (): Promise<void> => {
|
||||
if (saving.value) {
|
||||
return
|
||||
}
|
||||
if (!form.oldPassword) {
|
||||
toast.error('请填写原密码')
|
||||
return
|
||||
}
|
||||
if (!form.newPassword || !form.confirmPassword) {
|
||||
toast.error('请填写新密码')
|
||||
return
|
||||
@@ -46,7 +59,18 @@ const save = (): void => {
|
||||
toast.error('两次密码不一致')
|
||||
return
|
||||
}
|
||||
toast.success('已提交')
|
||||
saving.value = true
|
||||
try {
|
||||
await userApi.updatePassword({
|
||||
oldPassword: form.oldPassword,
|
||||
password: form.newPassword
|
||||
})
|
||||
toast.success('密码已修改,请重新登录')
|
||||
session.clear()
|
||||
await router.replace('/login')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user