Files
JayuCloud/JC-Salon-Frontend/src/views/admin/OrdersView.vue
T

1075 lines
42 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="orders">
<a-page-header v-if="!isMobile" title="订单管理" sub-title="管理系统订单" />
<section v-else class="admin-page-intro">
<span class="admin-page-intro__eyebrow">订单</span>
<h1 class="admin-page-intro__title">订单工作台</h1>
<p class="admin-page-intro__subtitle">
手机端不再默认展示横向大表格,而是把筛选、状态和处理按钮压到单列卡片里。
</p>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">订单 {{ filteredOrders.length }}</span>
<span class="admin-page-chip">{{ canProcessOrders ? '可处理订单' : '查看模式' }}</span>
</div>
</section>
<a-card :bordered="false">
<template #title v-if="isMobile">
订单列表
</template>
<template #extra>
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
<a-input-search
v-model:value="keyword"
class="admin-toolbar__grow"
placeholder="搜索订单号、用户 ID 或优惠券"
@search="loadOrders"
/>
</div>
</template>
<AdminFilterPanel :active-count="activeFilterCount">
<a-select
v-model:value="statusFilter"
:options="statusOptions"
style="width: 160px"
@change="loadOrders"
/>
<a-select
v-model:value="shopFilter"
:allow-clear="currentUserType === 4"
placeholder="所属店铺"
style="width: 180px"
:loading="shopLoading"
:disabled="currentUserType !== 4 && !!currentUserInfo?.shopId"
@change="loadOrders"
>
<a-select-option
v-for="shop in shopList"
:key="shop.id"
:value="getShopOptionValue(shop)"
>
{{ shop.shopName }}
</a-select-option>
</a-select>
<a-input v-model:value="artistKeyword" allow-clear placeholder="美甲师" style="width: 160px" @pressEnter="noop" />
<a-input v-model:value="userKeyword" allow-clear placeholder="用户ID/客户" style="width: 160px" @pressEnter="noop" />
<a-range-picker v-model:value="createRange" value-format="YYYY-MM-DD HH:mm:ss" show-time />
<a-range-picker v-model:value="appointmentRange" value-format="YYYY-MM-DD HH:mm:ss" show-time />
<a-input-number v-model:value="minAmount" :min="0" placeholder="最低金额" style="width: 120px" />
<a-input-number v-model:value="maxAmount" :min="0" placeholder="最高金额" style="width: 120px" />
<a-button @click="resetFilters">重置筛选</a-button>
</AdminFilterPanel>
<a-table v-if="!isMobile" :columns="columns" :data-source="filteredOrders" :loading="loading" row-key="id" :scroll="{ x: 'max-content' }">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
<a-tag :color="statusColor(record.status)">{{ orderStatusText(record) }}</a-tag>
</template>
<template v-else-if="column.key === 'totalAmount'">
{{ formatMoney(record.totalAmount) }}
</template>
<template v-else-if="column.key === 'actualAmount'">
{{ formatMoney(record.actualAmount) }}
</template>
<template v-else-if="column.key === 'actions'">
<a-space>
<a-button type="link" size="small" @click="openDetail(record)">查看</a-button>
<a-button
v-if="canManualConfirmPayment(record)"
type="link"
size="small"
@click="openManualPay(record)"
>
手动确认支付
</a-button>
<a-button
v-if="canOpenAfterSales(record)"
type="link"
size="small"
@click="openAfterSales(record)"
>
售后
</a-button>
<a-button
v-if="record.status === 1 && canProcessOrders"
type="primary"
size="small"
@click="process(record.id, 2)"
>
确认完成
</a-button>
<a-button
v-if="record.status === 1 && canProcessOrders && !isArtist"
danger
size="small"
@click="process(record.id, 3)"
>
取消订单
</a-button>
<a-button
v-if="record.status === 4 && canProcessOrders"
type="primary"
size="small"
@click="process(record.id, 2)"
>
完成补单
</a-button>
<a-button
v-if="record.status === 4 && canProcessOrders && !isArtist"
danger
size="small"
@click="process(record.id, 3)"
>
取消补单
</a-button>
</a-space>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="filteredOrders" empty-description="暂无订单数据">
<template #item="{ item }">
<article class="admin-mobile-card">
<div class="admin-mobile-card__head">
<div class="admin-mobile-card__body">
<div class="admin-mobile-card__title">{{ item.orderNo }}</div>
<div class="admin-mobile-card__subtitle">
用户 {{ item.userId }} · {{ item.createTime }}
</div>
</div>
<a-tag :color="statusColor(item.status)">{{ orderStatusText(item) }}</a-tag>
</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>总金额</span>
<strong>{{ formatMoney(item.totalAmount) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>实付金额</span>
<strong>{{ formatMoney(item.actualAmount) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>优惠券</span>
<strong>{{ item.couponName || '无' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>预约项目</span>
<strong>{{ item.items?.length || 0 }} 个</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button size="small" @click="openDetail(item)">查看详情</a-button>
<a-button
v-if="canManualConfirmPayment(item)"
size="small"
@click="openManualPay(item)"
>
确认支付
</a-button>
<a-button
v-if="canOpenAfterSales(item)"
size="small"
@click="openAfterSales(item)"
>
售后
</a-button>
<a-button
v-if="item.status === 1 && canProcessOrders"
size="small"
type="primary"
@click="process(item.id, 2)"
>
完成
</a-button>
<a-button
v-if="item.status === 1 && canProcessOrders && !isArtist"
size="small"
danger
@click="process(item.id, 3)"
>
取消
</a-button>
<a-button v-if="item.status === 4 && canProcessOrders" size="small" type="primary" @click="process(item.id, 2)">完成补单</a-button>
<a-button v-if="item.status === 4 && canProcessOrders && !isArtist" size="small" danger @click="process(item.id, 3)">取消补单</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
</a-card>
<AdminResponsiveModal
v-model:open="detailVisible"
title="订单详情"
:desktop-width="860"
@cancel="currentOrder = null"
>
<template v-if="currentOrder">
<a-descriptions :column="isMobile ? 1 : 2" bordered size="small">
<a-descriptions-item label="订单编号">{{ currentOrder.orderNo }}</a-descriptions-item>
<a-descriptions-item label="用户ID">{{ currentOrder.userId }}</a-descriptions-item>
<a-descriptions-item label="订单总额">{{ formatMoney(currentOrder.totalAmount) }}</a-descriptions-item>
<a-descriptions-item label="实付金额">{{ formatMoney(currentOrder.actualAmount) }}</a-descriptions-item>
<a-descriptions-item label="优惠券">{{ currentOrder.couponName || '无' }}</a-descriptions-item>
<a-descriptions-item label="订单状态">{{ orderStatusText(currentOrder) }}</a-descriptions-item>
<a-descriptions-item label="订单来源">{{ currentOrder.orderSource === 'HISTORICAL_BACKFILL' ? '历史补单' : '正常订单' }}</a-descriptions-item>
<a-descriptions-item label="创建时间" :span="isMobile ? 1 : 2">{{ currentOrder.createTime }}</a-descriptions-item>
</a-descriptions>
<template v-if="hasQuoteInfo(currentOrder)">
<a-divider>询价信息</a-divider>
<a-descriptions :column="isMobile ? 1 : 2" bordered size="small">
<a-descriptions-item label="客户备注" :span="isMobile ? 1 : 2">
{{ currentOrder.customerRemark || '无' }}
</a-descriptions-item>
<a-descriptions-item label="报价状态">
<a-tag :color="quoteStatusColor(currentOrder.quoteStatus)">{{ quoteStatusText(currentOrder) }}</a-tag>
</a-descriptions-item>
<a-descriptions-item label="客户确认">
<a-tag :color="confirmationColor(currentOrder.quoteUserConfirmed)">{{ confirmationText(currentOrder.quoteUserConfirmed) }}</a-tag>
</a-descriptions-item>
<a-descriptions-item label="门店确认">
<a-tag :color="confirmationColor(currentOrder.quoteShopConfirmed)">{{ confirmationText(currentOrder.quoteShopConfirmed) }}</a-tag>
</a-descriptions-item>
<a-descriptions-item label="过期时间">
{{ currentOrder.quoteExpireTime || '--' }}
</a-descriptions-item>
</a-descriptions>
</template>
<a-divider>订单项目</a-divider>
<a-table
v-if="!isMobile"
:columns="itemColumns"
:data-source="currentOrder.items"
row-key="id"
:pagination="false"
:scroll="{ x: 'max-content' }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'price'">{{ formatMoney(record.price) }}</template>
<template v-else-if="column.key === 'referencePrice'">{{ formatMoney(record.referencePrice) }}</template>
<template v-else-if="column.key === 'quotedPrice'">{{ formatMoney(record.quotedPrice) }}</template>
<template v-else-if="column.key === 'confirmedPrice'">{{ formatMoney(record.confirmedPrice) }}</template>
<template v-else-if="column.key === 'totalPrice'">{{ formatMoney(Number(record.price || 0) * Number(record.quantity || 0)) }}</template>
</template>
</a-table>
<div v-else class="detail-items">
<article v-for="item in currentOrder.items" :key="item.id" class="admin-mobile-card">
<div class="admin-mobile-card__title">{{ item.productTitle }}</div>
<div class="admin-mobile-card__subtitle">{{ item.artistName || '未指定美甲师' }}</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>预约时间</span>
<strong>{{ item.appointmentTime || '--' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>单价</span>
<strong>{{ formatMoney(item.price) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>参考价</span>
<strong>{{ formatMoney(item.referencePrice) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>报价</span>
<strong>{{ formatMoney(item.quotedPrice) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>最终价</span>
<strong>{{ formatMoney(item.confirmedPrice) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>数量</span>
<strong>{{ item.quantity }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>小计</span>
<strong>{{ formatMoney(Number(item.price || 0) * Number(item.quantity || 0)) }}</strong>
</div>
</div>
</article>
</div>
<template v-if="hasQuoteInfo(currentOrder)">
<a-divider>报价历史</a-divider>
<div v-if="quoteHistory(currentOrder).length" class="quote-history">
<article
v-for="(history, index) in quoteHistory(currentOrder)"
:key="quoteHistoryKey(history, index)"
class="quote-history__item"
>
<div class="quote-history__head">
<strong>{{ history.actionText || history.action || history.actorTypeText || '报价记录' }}</strong>
<span>{{ history.createTime || '--' }}</span>
</div>
<p v-if="history.remark" class="quote-history__remark">{{ history.remark }}</p>
<div v-if="quoteHistoryItems(history).length" class="quote-history__prices">
<span
v-for="(line, lineIndex) in quoteHistoryItems(history)"
:key="`${quoteHistoryKey(history, index)}-${lineIndex}`"
>
{{ line }}
</span>
</div>
</article>
</div>
<a-empty v-else description="暂无报价历史" />
</template>
<template v-if="isQuoteOrder(currentOrder) && canQuoteCurrentOrder">
<a-divider>门店报价</a-divider>
<a-form layout="vertical" class="quote-form">
<div class="quote-form__items">
<div v-for="item in currentOrder.items || []" :key="item.id" class="quote-form__item">
<div class="quote-form__meta">
<strong>{{ item.productTitle || `订单项 ${item.id}` }}</strong>
<span>参考价 {{ formatMoney(item.referencePrice ?? item.price) }}</span>
</div>
<a-input-number
:value="quoteInputValue(item)"
:min="0"
:precision="2"
placeholder="报价"
style="width: 180px"
@change="value => setQuoteInputValue(item, value)"
/>
</div>
</div>
<a-form-item label="报价备注">
<a-textarea v-model:value="quoteForm.remark" :rows="3" :maxlength="300" placeholder="填写给客户的报价说明" />
</a-form-item>
<div class="quote-form__actions">
<a-button type="primary" :loading="quoteSubmitting" @click="submitQuote">提交报价</a-button>
<a-button :loading="quoteConfirming" @click="confirmQuote">确认当前价格</a-button>
</div>
</a-form>
</template>
</template>
</AdminResponsiveModal>
<AdminResponsiveModal
v-model:open="manualPayOpen"
title="手动确认支付"
:desktop-width="560"
:confirm-loading="manualPayLoading"
@ok="submitManualPay"
@cancel="closeManualPay"
>
<a-form layout="vertical">
<a-alert
v-if="manualPayOrder"
class="order-action-alert"
type="warning"
show-icon
:message="manualPayOrder.orderNo"
:description="`将把订单标记为已支付,实付金额 ¥${moneyText(manualPayOrder.actualAmount || manualPayOrder.totalAmount)}`"
/>
<a-form-item label="确认备注">
<a-textarea v-model:value="manualPayRemark" :rows="3" :maxlength="200" placeholder="例如:线下现金已核验" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
</div>
</template>
<script setup lang="ts">
/**
* OrdersView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { useRoute, useRouter } from 'vue-router'
/**
* Purpose: Shop supports OrdersView.vue by holding or executing the shop page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminOrderApi, adminShopApi, type Shop } from '@/api/admin'
import { usePermission } from '@/utils/permission'
import type { IdType } from '@/utils/id'
import { sameId } from '@/utils/id'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { isMobile } = useAdminViewport()
const router = useRouter()
const route = useRoute()
/**
* Purpose: orders supports OrdersView.vue by holding or executing the orders page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const orders = ref<any[]>([])
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/**
* Purpose: shopLoading supports OrdersView.vue by holding or executing the shop loading page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopLoading = ref(false)
/**
* Purpose: currentOrder supports OrdersView.vue by holding or executing the current order page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentOrder = ref<any | null>(null)
const manualPayOpen = ref(false)
const manualPayLoading = ref(false)
const manualPayOrder = ref<any | null>(null)
const manualPayRemark = ref('')
const quoteSubmitting = ref(false)
const quoteConfirming = ref(false)
const quoteForm = reactive({
remark: '',
items: {} as Record<string, number | undefined>
})
/**
* Purpose: currentUserType supports OrdersView.vue by holding or executing the current user type page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentUserType = ref<number | null>(null)
/**
* Purpose: currentUserInfo supports OrdersView.vue by holding or executing the current user info page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentUserInfo = (() => {
try {
const cached = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
return cached ? JSON.parse(cached) : null
} catch (error) {
console.error('获取当前用户信息失败', error)
return null
}
})()
/** keyword is a reactive state variable used by the template and event handlers. */
const keyword = ref('')
/**
* Purpose: statusFilter supports OrdersView.vue by holding or executing the status filter page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const statusFilter = ref<'all' | string>('all')
/**
* Purpose: shopList supports OrdersView.vue by holding or executing the shop list page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopList = ref<Shop[]>([])
/**
* Purpose: shopFilter supports OrdersView.vue by holding or executing the shop filter page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopFilter = ref<string | undefined>()
/**
* Purpose: artistKeyword supports OrdersView.vue by holding or executing the artist keyword page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const artistKeyword = ref('')
/**
* Purpose: userKeyword supports OrdersView.vue by holding or executing the user keyword page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userKeyword = ref('')
/**
* Purpose: createRange supports OrdersView.vue by holding or executing the create range page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const createRange = ref<[string, string] | undefined>()
/**
* Purpose: appointmentRange supports OrdersView.vue by holding or executing the appointment range page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const appointmentRange = ref<[string, string] | undefined>()
/**
* Purpose: minAmount supports OrdersView.vue by holding or executing the min amount page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const minAmount = ref<number | undefined>()
/**
* Purpose: maxAmount supports OrdersView.vue by holding or executing the max amount page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const maxAmount = ref<number | undefined>()
const { hasPermission, loadUserPermissions } = usePermission()
/** detailVisible is a reactive state variable used by the template and event handlers. */
const detailVisible = computed({
get: () => !!currentOrder.value,
set: value => { if (!value) currentOrder.value = null }
})
/** canProcessOrders is a reactive state variable used by the template and event handlers. */
const canProcessOrders = computed(() => hasPermission('order:process'))
const canManagePayments = computed(() => hasPermission('payment:manage'))
const canViewAfterSales = computed(() => hasPermission('after_sale:view'))
/** isArtist is a reactive state variable used by the template and event handlers. */
const isArtist = computed(() => currentUserType.value === 3)
/**
* Purpose: statusOptions supports OrdersView.vue by holding or executing the status options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const statusOptions = [
{ label: '全部状态', value: 'all' },
{ label: '待报价', value: '0' },
{ label: '待完成', value: '1' },
{ label: '已完成', value: '2' },
{ label: '已取消', value: '3' },
{ label: '服务中', value: '4' }
]
const activeFilterCount = computed(() => [
keyword.value,
statusFilter.value === 'all' ? undefined : statusFilter.value,
currentUserType.value === 4 ? shopFilter.value : undefined,
artistKeyword.value,
userKeyword.value,
createRange.value?.length ? 'createDate' : '',
appointmentRange.value?.length ? 'appointmentDate' : '',
minAmount.value,
maxAmount.value
].filter(value => value !== undefined && value !== null && value !== '').length)
/** filteredOrders is a reactive state variable used by the template and event handlers. */
const filteredOrders = computed(() => {
const keywordValue = keyword.value.trim().toLowerCase()
return orders.value.filter(order => {
const matchStatus = statusFilter.value === 'all' || String(order.status) === String(statusFilter.value)
if (!matchStatus) {
return false
}
const actualAmount = Number(order.actualAmount ?? order.totalAmount ?? 0)
if (minAmount.value !== undefined && actualAmount < minAmount.value) return false
if (maxAmount.value !== undefined && actualAmount > maxAmount.value) return false
if (!matchText(userKeyword.value, [order.userId, order.userNickname, order.customerName, order.customerPhone])) return false
if (!matchText(artistKeyword.value, (order.items || []).map((item: any) => item.artistName || item.artistId))) return false
if (!matchRange(order.createTime, createRange.value)) return false
if (!matchRange((order.items || [])[0]?.appointmentTime, appointmentRange.value, (order.items || []).map((item: any) => item.appointmentTime))) return false
if (!keywordValue) {
return true
}
const haystack = [
order.orderNo,
order.userId,
order.couponName,
order.customerRemark,
order.quoteStatusText,
...(order.items || []).map((item: any) => `${item.productTitle || ''} ${item.artistName || ''}`)
].join(' ').toLowerCase()
return haystack.includes(keywordValue)
})
})
/**
* Purpose: matchText supports OrdersView.vue by holding or executing the match text page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const matchText = (needle: string, values: any[]) => {
const normalized = needle.trim().toLowerCase()
if (!normalized) return true
return values.some(value => String(value ?? '').toLowerCase().includes(normalized))
}
/**
* Purpose: matchRange supports OrdersView.vue by holding or executing the match range page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const matchRange = (value: string | undefined, range?: [string, string], candidates?: string[]) => {
if (!range?.length) return true
const values = candidates?.length ? candidates : [value]
const start = new Date(range[0]).getTime()
const end = new Date(range[1]).getTime()
return values.some(item => {
if (!item) return false
const time = new Date(item).getTime()
return time >= start && time <= end
})
}
/**
* Purpose: resetFilters supports OrdersView.vue by holding or executing the reset filters page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const resetFilters = () => {
keyword.value = ''
statusFilter.value = 'all'
shopFilter.value = currentUserType.value !== 4 ? normalizeShopId(currentUserInfo?.shopId) : undefined
artistKeyword.value = ''
userKeyword.value = ''
createRange.value = undefined
appointmentRange.value = undefined
minAmount.value = undefined
maxAmount.value = undefined
void loadOrders()
}
/**
* Purpose: columns supports OrdersView.vue by holding or executing the columns page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const columns = [
{ title: '订单编号', dataIndex: 'orderNo', key: 'orderNo' },
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 100 },
{ title: '订单总额', key: 'totalAmount', width: 120 },
{ title: '实付金额', key: 'actualAmount', width: 120 },
{ title: '优惠券', dataIndex: 'couponName', key: 'couponName', width: 140 },
{ title: '状态', key: 'status', width: 100 },
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
{ title: '操作', key: 'actions', width: 180 }
]
/**
* Purpose: itemColumns supports OrdersView.vue by holding or executing the item columns page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const itemColumns = [
{ title: '商品ID', dataIndex: 'productId', key: 'productId', width: 100 },
{ title: '商品名称', dataIndex: 'productTitle', key: 'productTitle' },
{ title: '美甲师', dataIndex: 'artistName', key: 'artistName', width: 120 },
{ title: '预约时间', dataIndex: 'appointmentTime', key: 'appointmentTime', width: 180 },
{ title: '单价', key: 'price', width: 100 },
{ title: '参考价', key: 'referencePrice', width: 100 },
{ title: '报价', key: 'quotedPrice', width: 100 },
{ title: '最终价', key: 'confirmedPrice', width: 100 },
{ title: '数量', dataIndex: 'quantity', key: 'quantity', width: 80 },
{ title: '总价', key: 'totalPrice', width: 100 }
]
/** statusColor is a local helper used by this page script. */
const statusColor = (status: number) => {
const normalized = Number(status)
if (normalized === 0) return 'blue'
if (normalized === 1) return 'orange'
if (normalized === 2) return 'green'
if (normalized === 3) return 'red'
if (normalized === 4) return 'processing'
return 'default'
}
const isQuoteOrder = (order: any) => Number(order?.status) === 0
const orderStatusText = (order: any) => order?.statusText || (isQuoteOrder(order) ? '确认价格中' : '--')
const moneyText = (value?: unknown) => {
const amount = Number(value ?? 0)
return Number.isFinite(amount) ? amount.toFixed(2) : '0.00'
}
const formatMoney = (value?: unknown) => {
if (value === undefined || value === null || value === '') return '--'
const amount = Number(value)
return Number.isFinite(amount) ? `¥${amount.toFixed(2)}` : '--'
}
/**
* Purpose: normalizeUserType supports OrdersView.vue by holding or executing the normalize user type page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const normalizeUserType = (value: unknown) => {
const type = Number(value)
return Number.isFinite(type) ? type : null
}
/** resolveCurrentUserType is a local helper used by this page script. */
const resolveCurrentUserType = () => {
currentUserType.value = normalizeUserType(currentUserInfo?.type)
}
/**
* Purpose: normalizeShopId supports OrdersView.vue by holding or executing the normalize shop id page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const normalizeShopId = (value: unknown) => {
if (value === undefined || value === null || value === '') {
return undefined
}
return String(value)
}
/**
* Purpose: getShopOptionValue supports OrdersView.vue by holding or executing the get shop option value page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const getShopOptionValue = (shop: Shop) => normalizeShopId((shop as any).id) || ''
const belongsToCurrentShop = (order: any) => {
const currentShopId = normalizeShopId(currentUserInfo?.shopId)
const orderShopId = normalizeShopId(order?.shopId)
return !currentShopId || !orderShopId || sameId(orderShopId, currentShopId)
}
const canQuoteOrder = (order: any) => {
return isQuoteOrder(order) && canProcessOrders.value && currentUserType.value !== 4 && belongsToCurrentShop(order)
}
const canQuoteCurrentOrder = computed(() => canQuoteOrder(currentOrder.value))
const canManualConfirmPayment = (order: any) => {
return canManagePayments.value && !isQuoteOrder(order) && order?.paymentStatus !== 'PAID'
}
const canOpenAfterSales = (order: any) => canViewAfterSales.value && !isQuoteOrder(order)
const quoteHistory = (order: any) => Array.isArray(order?.quoteMessages) ? order.quoteMessages : []
const hasQuoteInfo = (order: any) => {
return isQuoteOrder(order) ||
Boolean(order?.customerRemark || order?.quoteStatus || order?.quoteStatusText || order?.quoteExpireTime || quoteHistory(order).length) ||
(order?.items || []).some((item: any) =>
item.referencePrice !== undefined || item.quotedPrice !== undefined || item.confirmedPrice !== undefined
)
}
const quoteStatusText = (order: any) => order?.quoteStatusText || (isQuoteOrder(order) ? '确认价格中' : '--')
const quoteStatusColor = (status?: string) => {
const normalized = String(status || '').toUpperCase()
if (normalized.includes('CONFIRM') || normalized.includes('SUCCESS')) return 'green'
if (normalized.includes('EXPIRE') || normalized.includes('CANCEL') || normalized.includes('REJECT')) return 'red'
if (normalized.includes('WAIT') || normalized.includes('PENDING')) return 'orange'
return 'blue'
}
const confirmationText = (confirmed?: boolean) => confirmed ? '已确认' : '待确认'
const confirmationColor = (confirmed?: boolean) => confirmed ? 'green' : 'orange'
const quoteHistoryKey = (history: any, index: string | number) => String(history?.id || `${history?.createTime || 'quote'}-${index}`)
const quoteHistoryItems = (history: any) => {
const items = Array.isArray(history?.items) ? history.items : []
return items.map((item: any, index: number) => {
const title = item.productTitle || item.productName || item.orderItemTitle || item.orderItemId || `项目 ${index + 1}`
const price = item.quotedPrice ?? item.confirmedPrice ?? item.price
return price === undefined || price === null ? String(title) : `${title}:${formatMoney(price)}`
})
}
const resetQuoteForm = (order: any) => {
quoteForm.remark = ''
Object.keys(quoteForm.items).forEach(key => {
delete quoteForm.items[key]
})
for (const item of order?.items || []) {
if (item?.id === undefined || item?.id === null) continue
quoteForm.items[String(item.id)] = Number(item.quotedPrice ?? item.confirmedPrice ?? item.referencePrice ?? item.price ?? 0)
}
}
const openDetail = (order: any) => {
currentOrder.value = order
resetQuoteForm(order)
}
const quoteInputValue = (item: any) => {
if (item?.id === undefined || item?.id === null) return undefined
return quoteForm.items[String(item.id)]
}
const setQuoteInputValue = (item: any, value: unknown) => {
if (item?.id === undefined || item?.id === null) return
const key = String(item.id)
if (value === undefined || value === null || value === '') {
quoteForm.items[key] = undefined
return
}
quoteForm.items[key] = Number(value)
}
const collectQuoteItems = (order: any) => {
const orderItems = order?.items || []
if (!orderItems.length) return null
const items: Array<{ orderItemId: IdType; quotedPrice: number }> = []
for (const item of orderItems) {
if (item?.id === undefined || item?.id === null) return null
const price = Number(quoteForm.items[String(item.id)])
if (!Number.isFinite(price) || price < 0) return null
items.push({ orderItemId: item.id, quotedPrice: price })
}
return items
}
const syncCurrentOrder = (orderId: IdType, fallback?: any) => {
if (!sameId(currentOrder.value?.id, orderId)) return
currentOrder.value = orders.value.find(order => sameId(order.id, orderId)) || fallback || currentOrder.value
resetQuoteForm(currentOrder.value)
}
const submitQuote = async () => {
const order = currentOrder.value
if (!order || !canQuoteOrder(order)) return
const items = collectQuoteItems(order)
if (!items) {
message.warning('请填写每个项目的有效报价')
return
}
quoteSubmitting.value = true
try {
let updatedOrder: any
await runWithGlobalLoading(async () => {
updatedOrder = await adminOrderApi.submitQuote(order.id, {
remark: quoteForm.remark.trim() || undefined,
items
})
await loadOrders()
})
syncCurrentOrder(order.id, updatedOrder)
message.success('报价已提交')
} catch (error: any) {
console.error('提交报价失败:', error)
message.error(error?.message || '提交报价失败')
} finally {
quoteSubmitting.value = false
}
}
const confirmQuote = async () => {
const order = currentOrder.value
if (!order || !canQuoteOrder(order)) return
quoteConfirming.value = true
try {
let updatedOrder: any
await runWithGlobalLoading(async () => {
updatedOrder = await adminOrderApi.confirmQuote(order.id)
await loadOrders()
})
syncCurrentOrder(order.id, updatedOrder)
message.success('当前价格已确认')
} catch (error: any) {
console.error('确认当前价格失败:', error)
message.error(error?.message || '确认当前价格失败')
} finally {
quoteConfirming.value = false
}
}
/**
* Purpose: loadShopOptions supports OrdersView.vue by holding or executing the load shop options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loadShopOptions = async () => {
shopLoading.value = true
try {
shopList.value = await adminShopApi.listAllShops() as unknown as Shop[]
if (currentUserType.value !== 4 && currentUserInfo?.shopId) {
shopFilter.value = normalizeShopId(currentUserInfo.shopId)
}
} catch (error) {
console.error('获取店铺列表失败:', error)
} finally {
shopLoading.value = false
}
}
/** loadOrders is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const loadOrders = async () => {
loading.value = true
try {
const scopedShopId = shopFilter.value || (currentUserType.value !== 4 ? normalizeShopId(currentUserInfo?.shopId) : undefined)
const result = await adminOrderApi.listOrders({
page: 1,
size: 1000,
keyword: keyword.value || undefined,
status: statusFilter.value === 'all' ? undefined : Number(statusFilter.value),
shopId: scopedShopId
}) as unknown as { list?: any[] }
orders.value = result.list || []
} catch {
message.error('获取订单列表失败')
} finally {
loading.value = false
}
}
const focusRouteOrder = () => {
const routeOrderId = route.query.orderId
const orderId = Array.isArray(routeOrderId) ? routeOrderId[0] : routeOrderId
if (!orderId) return
const matchedOrder = orders.value.find(order => sameId(order.id, orderId))
if (matchedOrder) {
openDetail(matchedOrder)
return
}
message.warning('当前门店未找到这笔询价预约,请确认后台已切换到对应店铺')
}
/** process is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const process = async (orderId: IdType, status: number) => {
try {
await runWithGlobalLoading(async () => {
await adminOrderApi.updateOrderStatus(orderId, status)
await loadOrders()
})
message.success('操作成功')
if (sameId(currentOrder.value?.id, orderId)) {
currentOrder.value = orders.value.find(order => sameId(order.id, orderId)) || null
}
} catch {
message.error('操作失败')
}
}
const openManualPay = (order: any) => {
manualPayOrder.value = order
manualPayRemark.value = ''
manualPayOpen.value = true
}
const closeManualPay = () => {
manualPayOpen.value = false
manualPayOrder.value = null
manualPayRemark.value = ''
}
const submitManualPay = async () => {
if (!manualPayOrder.value) return
manualPayLoading.value = true
try {
await runWithGlobalLoading(async () => {
await adminOrderApi.manualConfirmPayment(manualPayOrder.value.id, manualPayRemark.value.trim() || undefined)
await loadOrders()
})
message.success('支付已确认')
closeManualPay()
} catch (error: any) {
console.error('手动确认支付失败:', error)
message.error(error?.message || '手动确认支付失败')
} finally {
manualPayLoading.value = false
}
}
const openAfterSales = (order: any) => {
router.push({
path: '/admin/after-sales',
query: { orderId: String(order.id) }
})
}
/** noop is a local helper used by this page script. */
const noop = () => {}
onMounted(async () => {
resolveCurrentUserType()
await loadUserPermissions()
await loadShopOptions()
await loadOrders()
focusRouteOrder()
})
watch(
() => route.query.orderId,
async value => {
if (!value) return
await loadOrders()
focusRouteOrder()
}
)
</script>
<style scoped>
.orders {
padding: 0;
}
.detail-items {
display: grid;
gap: 12px;
}
.order-action-alert {
margin-bottom: 16px;
}
.quote-history {
display: grid;
gap: 10px;
}
.quote-history__item {
padding: 12px;
border: 1px solid #f0f0f0;
border-radius: 8px;
background: #fafafa;
}
.quote-history__head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: rgba(0, 0, 0, 0.85);
}
.quote-history__head span,
.quote-history__remark,
.quote-history__prices {
color: rgba(0, 0, 0, 0.45);
font-size: 13px;
}
.quote-history__remark {
margin: 8px 0 0;
}
.quote-history__prices {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
margin-top: 8px;
}
.quote-form {
display: grid;
gap: 12px;
}
.quote-form__items {
display: grid;
gap: 10px;
}
.quote-form__item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px;
border: 1px solid #f0f0f0;
border-radius: 8px;
background: #fff;
}
.quote-form__meta {
display: grid;
gap: 4px;
min-width: 0;
}
.quote-form__meta span {
color: rgba(0, 0, 0, 0.45);
font-size: 13px;
}
.quote-form__actions {
display: flex;
justify-content: flex-end;
gap: 8px;
}
@media (max-width: 767px) {
.quote-form__item,
.quote-form__actions {
align-items: stretch;
flex-direction: column;
}
.quote-form__item :deep(.ant-input-number) {
width: 100% !important;
}
}
</style>