822 lines
28 KiB
Vue
822 lines
28 KiB
Vue
<template>
|
||
<div class="order-sub-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="afterSale-list"
|
||
width="220px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:available-fields="availableFields"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<order-toolbar-button-group
|
||
:buttons="toolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="split-stack">
|
||
<div class="upper-wrapper">
|
||
<upper-table
|
||
ref="upperTable"
|
||
:title="'售后审计列表'"
|
||
default-align="center"
|
||
table-id="afterSale-list"
|
||
:data="tableData"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="upperPagination"
|
||
:show-index="true"
|
||
:show-selection="true"
|
||
:show-actions="true"
|
||
:enable-column-config="true"
|
||
:column-config-schema-version="1"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
row-key="id"
|
||
@current-change="handleRowClick"
|
||
@selection-change="handleSelectionChange"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@sort-change="handleSortChange"
|
||
@refresh="handleRefresh"
|
||
>
|
||
<!-- 售后类型 -->
|
||
<template #column-type="{ row }">
|
||
<span :class="getStatusTextClass(typeTagType(row.type))">
|
||
{{ typeLabel(row.type) }}
|
||
</span>
|
||
</template>
|
||
|
||
<!-- 子类型 -->
|
||
<template #column-sub_type="{ row }">
|
||
{{ subTypeLabel(row.sub_type) }}
|
||
</template>
|
||
|
||
<!-- 状态 -->
|
||
<template #column-status="{ row }">
|
||
<span :class="getStatusTextClass(statusTagType(row.status))">
|
||
{{ statusLabel(row.status) }}
|
||
</span>
|
||
</template>
|
||
|
||
<!-- 角色组 -->
|
||
<template #column-role_group="{ row }">
|
||
<span v-if="row.role_group" :class="getStatusTextClass(roleGroupTagType(row.role_group))">
|
||
{{ roleGroupLabel(row.role_group) }}
|
||
</span>
|
||
<span v-else>-</span>
|
||
</template>
|
||
|
||
<!-- 仓库理赔 -->
|
||
<template #column-claim_status="{ row }">
|
||
<span v-if="row.claim_status" :class="getStatusTextClass(claimStatusTagType(row.claim_status))">
|
||
{{ claimStatusLabel(row.claim_status) }}
|
||
</span>
|
||
<span v-else>-</span>
|
||
</template>
|
||
|
||
<!-- 运方理赔 -->
|
||
<template #column-carrier_claim_status="{ row }">
|
||
<span v-if="row.carrier_claim_status" :class="getStatusTextClass(claimStatusTagType(row.carrier_claim_status))">
|
||
{{ claimStatusLabel(row.carrier_claim_status) }}
|
||
</span>
|
||
<span v-else>-</span>
|
||
</template>
|
||
|
||
<!-- 操作列 -->
|
||
<template #column-actions="{ row }">
|
||
<div class="wave-operation-actions">
|
||
<el-button size="small" type="primary" link @click.stop="handleViewDetail(row)">详情</el-button>
|
||
</div>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无售后审计记录</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ========== 弹窗 ========== -->
|
||
|
||
<!-- 创建/编辑售后单弹窗 -->
|
||
<el-dialog
|
||
v-model="formDialogVisible"
|
||
:title="isEditMode ? '编辑售后单' : '创建售后单'"
|
||
width="650px"
|
||
align-center
|
||
destroy-on-close
|
||
@closed="resetForm"
|
||
>
|
||
<el-form ref="formRef" :model="formData" :rules="formRules" label-width="110px" size="small">
|
||
<el-form-item label="售后类型" prop="type">
|
||
<el-select v-model="formData.type" placeholder="请选择售后类型" style="width: 100%" @change="onTypeChange">
|
||
<el-option v-for="(label, value) in typeOptions" :key="value" :label="label" :value="value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="子类型" prop="sub_type">
|
||
<el-select v-model="formData.sub_type" placeholder="请选择子类型" style="width: 100%">
|
||
<el-option v-for="(label, value) in currentSubTypeOptions" :key="value" :label="label" :value="value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="标题" prop="title">
|
||
<el-input v-model="formData.title" placeholder="请输入售后标题" maxlength="200" show-word-limit />
|
||
</el-form-item>
|
||
<el-form-item label="详细描述">
|
||
<el-input v-model="formData.description" type="textarea" :rows="3" placeholder="请输入详细描述" maxlength="1000" show-word-limit />
|
||
</el-form-item>
|
||
<el-form-item label="优先级">
|
||
<el-input-number v-model="formData.priority" :min="0" :max="10" placeholder="0-10,默认0" style="width: 120px" />
|
||
</el-form-item>
|
||
<el-form-item label="关联运单号">
|
||
<el-input v-model="formData.waybill_no" placeholder="输入运单号" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="关联发货订单号">
|
||
<el-input v-model="formData.order_delivery_no" placeholder="输入发货订单号" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="关联入库单号">
|
||
<el-input v-model="formData.entry_order_no" placeholder="输入入库单号" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="关联出库单号">
|
||
<el-input v-model="formData.order_stockout_no" placeholder="输入出库单号" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="关联收货单号">
|
||
<el-input v-model="formData.receiving_no" placeholder="输入收货单号" clearable />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button size="small" @click="formDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" size="small" :loading="formLoading" @click="handleSubmitForm">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 转单弹窗 -->
|
||
<el-dialog
|
||
v-model="transferDialogVisible"
|
||
title="转单"
|
||
width="500px"
|
||
align-center
|
||
destroy-on-close
|
||
>
|
||
<el-form ref="transferFormRef" :model="transferForm" :rules="transferRules" label-width="110px" size="small">
|
||
<el-form-item label="售后单号">
|
||
<el-input :model-value="transferForm.after_sale_no" disabled />
|
||
</el-form-item>
|
||
<el-form-item label="目标角色组" prop="role_group">
|
||
<el-select v-model="transferForm.role_group" placeholder="请选择目标角色组" style="width: 100%">
|
||
<el-option label="客服组" value="customer_service" />
|
||
<el-option label="仓库组" value="warehouse" />
|
||
<el-option label="财务组" value="finance" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="转单备注">
|
||
<el-input v-model="transferForm.remark" type="textarea" :rows="2" placeholder="请输入转单备注" />
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button size="small" @click="transferDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" size="small" :loading="transferLoading" @click="handleSubmitTransfer">确认转单</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 导出进度弹窗 -->
|
||
<AsyncExportProgressDialog
|
||
v-model:visible="exportDialogVisible"
|
||
:loading="exportLoading"
|
||
:progress-percent="exportProgressPercent"
|
||
:progress-status="exportProgressStatus"
|
||
:status-label="exportStatusLabel"
|
||
:task-id="exportTaskProgress.taskId"
|
||
:message="exportTaskProgress.message"
|
||
:error="exportTaskProgress.error"
|
||
:update-time="exportTaskProgress.updateTime"
|
||
/>
|
||
|
||
<!-- 售后明细弹窗 -->
|
||
<AfterSaleDetailDialog
|
||
v-model:visible="detailDialogVisible"
|
||
:after-sale-id="detailAfterSaleId"
|
||
@success="fetchData"
|
||
/>
|
||
|
||
<!-- 跳转路由(用于查看详情) -->
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { onMounted, onUnmounted, reactive, ref, computed, watch } from 'vue'
|
||
import { useRouter } from 'vue-router'
|
||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||
import {
|
||
afterSaleAuditList,
|
||
afterSaleCreate,
|
||
afterSaleUpdate,
|
||
afterSaleTransfer,
|
||
afterSaleBatchSetPendingFeedback,
|
||
afterSaleBatchClose,
|
||
afterSaleExport,
|
||
afterSaleExportTaskProgress,
|
||
type AfterSaleListParams,
|
||
type AfterSaleCreateParams,
|
||
type AfterSaleUpdateParams,
|
||
type AfterSaleTransferParams,
|
||
} from '@/api/aftersale/index'
|
||
import {
|
||
getAfterSaleAvailableFields,
|
||
afterSaleAvailableFields,
|
||
afterSaleColumns,
|
||
afterSaleToolbarButtons,
|
||
AFTER_SALE_TYPE_MAP,
|
||
AFTER_SALE_TYPE_TAG_MAP,
|
||
AFTER_SALE_SUB_TYPE_MAP,
|
||
AFTER_SALE_STATUS_MAP,
|
||
AFTER_SALE_STATUS_TAG_MAP,
|
||
AFTER_SALE_ROLE_GROUP_MAP,
|
||
AFTER_SALE_ROLE_GROUP_TAG_MAP,
|
||
CLAIM_STATUS_MAP,
|
||
CLAIM_STATUS_TAG_MAP,
|
||
} from './afterSale-config'
|
||
import { loadStores } from '@/api/index/index'
|
||
import { extractStoreListFromResponse, fillStoreScanFieldOptions, getStatusTextClass } from '@/views/order/orderManagement/config/order-common-config'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||
import AfterSaleDetailDialog from '@/views/afterSale/detail/AfterSaleDetailDialog.vue'
|
||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
|
||
// ==================== 工具函数 ====================
|
||
|
||
function typeLabel(t: string) { return AFTER_SALE_TYPE_MAP[t] ?? t ?? '-' }
|
||
function typeTagType(t: string) { return AFTER_SALE_TYPE_TAG_MAP[t] ?? 'info' }
|
||
function subTypeLabel(s: string) { return AFTER_SALE_SUB_TYPE_MAP[s] ?? s ?? '-' }
|
||
function statusLabel(s: string) { return AFTER_SALE_STATUS_MAP[s] ?? s ?? '-' }
|
||
function statusTagType(s: string) { return AFTER_SALE_STATUS_TAG_MAP[s] ?? 'info' }
|
||
function roleGroupLabel(r: string) { return AFTER_SALE_ROLE_GROUP_MAP[r] ?? r ?? '-' }
|
||
function roleGroupTagType(r: string) { return AFTER_SALE_ROLE_GROUP_TAG_MAP[r] ?? 'info' }
|
||
function claimStatusLabel(c: string) { return CLAIM_STATUS_MAP[c] ?? c ?? '-' }
|
||
function claimStatusTagType(c: string) { return CLAIM_STATUS_TAG_MAP[c] ?? 'info' }
|
||
|
||
// ==================== 子类型映射(按 type 分组) ====================
|
||
const subTypeOptionsByType: Record<string, Record<string, string>> = {
|
||
order: {
|
||
damage: '破损', missing_item: '少发', mis_shipment: '错发', wrong_sku: '错品',
|
||
quality_issue: '质量问题', delivery_delay: '发货延迟', logistics_issue: '物流异常',
|
||
rejected: '客户拒收', intercept: '拦截', verify_delivery: '核实签收', urge: '催件',
|
||
extra_item: '多发', change_address: '改地址', change_carrier: '换快递',
|
||
weight_issue: '重量异常', freight_issue: '运费争议', other: '其他',
|
||
},
|
||
receiving: {
|
||
shortage: '少货', damage: '破损', wrong_sku: '错品', quality_issue: '质量问题', other: '其他',
|
||
},
|
||
entry: {
|
||
shortage: '少货', damage: '破损', wrong_sku: '错品', quality_issue: '质量问题', other: '其他',
|
||
},
|
||
stockout: {
|
||
return_issue: '退货异常', wrong_outbound: '错发', shortage: '少发', other: '其他',
|
||
},
|
||
}
|
||
|
||
const typeOptions = AFTER_SALE_TYPE_MAP
|
||
|
||
// ==================== 布局 ====================
|
||
|
||
const settingsStore = useSettingsStore()
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() => shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)')
|
||
|
||
const router = useRouter()
|
||
|
||
// ==================== 配置 ====================
|
||
|
||
const availableFields = computed(() => {
|
||
const typeVal = currentConditions.value.type?.value
|
||
return getAfterSaleAvailableFields(typeVal || undefined)
|
||
})
|
||
const columns = afterSaleColumns
|
||
const tableSize = 'small'
|
||
const toolbarButtons = afterSaleToolbarButtons
|
||
|
||
// ==================== 按钮状态 ====================
|
||
|
||
const buttonLoadingMap = computed(() => ({
|
||
loading: loading.value,
|
||
exportLoading: exportLoading.value,
|
||
batchPendingFeedbackLoading: batchPendingFeedbackLoading.value,
|
||
batchCompleteLoading: batchCompleteLoading.value,
|
||
batchCloseLoading: batchCloseLoading.value,
|
||
}))
|
||
|
||
const buttonDisabledMap = computed(() => ({
|
||
batchPendingFeedbackDisabled: selectedRows.value.length === 0,
|
||
}))
|
||
|
||
const buttonLabelMap = computed(() => ({}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.value,
|
||
labels: buttonLabelMap.value,
|
||
})
|
||
)
|
||
|
||
function resolveButtonLoading(loadingKey?: string) {
|
||
if (!loadingKey) return false
|
||
return Boolean((buttonLoadingMap.value as Record<string, boolean>)[loadingKey])
|
||
}
|
||
|
||
function resolveButtonDisabled(disabledKey?: string) {
|
||
if (!disabledKey) return false
|
||
return Boolean((buttonDisabledMap.value as Record<string, boolean>)[disabledKey])
|
||
}
|
||
|
||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||
if (!dynamicLabelKey) return defaultLabel
|
||
return (buttonLabelMap.value as Record<string, string>)[dynamicLabelKey] || defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
refresh: () => handleRefresh(),
|
||
batchSetPendingFeedback: () => handleBatchSetPendingFeedback(),
|
||
batchComplete: () => handleBatchStatus('completed', '批量完成', batchCompleteLoading),
|
||
batchClose: () => handleBatchStatus('closed', '批量关闭', batchCloseLoading),
|
||
handleExport: () => handleExport(),
|
||
openColumnConfigPanel: () => { upperTable.value?.openColumnConfig?.() },
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: string) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
// ==================== 数据状态 ====================
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
const loading = ref(false)
|
||
const queryTime = ref(0)
|
||
const tableData = ref<any[]>([])
|
||
const currentConditions = ref<Record<string, any>>({})
|
||
const selectedRow = ref<any>(null)
|
||
const selectedRows = ref<any[]>([])
|
||
const batchPendingFeedbackLoading = ref(false)
|
||
const batchCompleteLoading = ref(false)
|
||
const batchCloseLoading = ref(false)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const upperPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
|
||
// ==================== 导出 ====================
|
||
|
||
const {
|
||
exportLoading,
|
||
exportDialogVisible,
|
||
exportTaskProgress,
|
||
exportProgressPercent,
|
||
exportProgressStatus,
|
||
exportStatusLabel,
|
||
submitExportTask,
|
||
} = useAsyncExportTask({
|
||
storageKey: 'afterSale:list:exportTaskId',
|
||
submitExport: (payload) => afterSaleExport(payload as any),
|
||
queryProgress: (params) => afterSaleExportTaskProgress(params as any),
|
||
})
|
||
|
||
function handleExport() {
|
||
const where = buildWhereFromConditions(currentConditions.value)
|
||
submitExportTask({ where, sort: {} })
|
||
}
|
||
|
||
// ==================== ScanBox 事件 ====================
|
||
|
||
function handleConditionChange(conditions: Record<string, any>) {
|
||
currentConditions.value = conditions ?? {}
|
||
pagination.currentPage = 1
|
||
upperPagination.currentPage = 1
|
||
fetchData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
currentConditions.value = {}
|
||
pagination.currentPage = 1
|
||
upperPagination.currentPage = 1
|
||
fetchData()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
currentConditions.value = {}
|
||
pagination.currentPage = 1
|
||
upperPagination.currentPage = 1
|
||
fetchData()
|
||
}
|
||
|
||
function handleRowClick(row: any) {
|
||
selectedRow.value = row
|
||
}
|
||
|
||
function handleSelectionChange(rows: any[]) {
|
||
selectedRows.value = rows
|
||
}
|
||
|
||
async function handleBatchSetPendingFeedback() {
|
||
if (selectedRows.value.length === 0) {
|
||
ElMessage.warning('请先勾选需要设为待反馈的工单')
|
||
return
|
||
}
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认将 ${selectedRows.value.length} 个工单设为"待反馈"状态?`,
|
||
'批量设待反馈',
|
||
{ confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', buttonSize: 'small' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchPendingFeedbackLoading.value = true
|
||
try {
|
||
const ids = selectedRows.value.map((r: any) => r.id)
|
||
const res: any = await afterSaleBatchSetPendingFeedback({ ids })
|
||
if (res && (res.flag === 'success' || res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||
const data = res.data ?? res
|
||
const total = data.total ?? 0
|
||
const success = data.success ?? 0
|
||
const failed = data.failed ?? []
|
||
if (failed.length > 0) {
|
||
ElMessage.warning(`成功 ${success}/${total} 个,失败 ${failed.length} 个,详见控制台`)
|
||
console.warn('批量设待反馈失败项:', failed)
|
||
} else {
|
||
ElMessage.success(`成功将 ${success} 个工单设为待反馈`)
|
||
}
|
||
upperTable.value?.clearSelection?.()
|
||
selectedRows.value = []
|
||
fetchData()
|
||
} else {
|
||
ElMessage.error(res?.message || '批量操作失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('批量设待反馈失败:', error)
|
||
ElMessage.error('批量操作失败')
|
||
} finally {
|
||
batchPendingFeedbackLoading.value = false
|
||
}
|
||
}
|
||
|
||
/** 通用批量状态操作:completed(完成) / closed(关闭) */
|
||
async function handleBatchStatus(status: 'completed' | 'closed', label: string, loadingRef: ReturnType<typeof ref<boolean>>) {
|
||
if (selectedRows.value.length === 0) {
|
||
ElMessage.warning('请先勾选需要操作的工单')
|
||
return
|
||
}
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认将 ${selectedRows.value.length} 个工单${label}?`,
|
||
label,
|
||
{ confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', buttonSize: 'small' }
|
||
)
|
||
} catch { return }
|
||
|
||
loadingRef.value = true
|
||
try {
|
||
const ids = selectedRows.value.map((r: any) => r.id)
|
||
const res: any = await afterSaleBatchClose({ ids, status })
|
||
if (res && (res.flag === 'success' || res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||
const data = res.data ?? res
|
||
const total = data.total ?? 0
|
||
const success = data.success ?? 0
|
||
const failed = data.failed ?? []
|
||
if (failed.length > 0) {
|
||
ElMessage.warning(`成功 ${success}/${total} 个,失败 ${failed.length} 个,详见控制台`)
|
||
console.warn(`${label}失败项:`, failed)
|
||
} else {
|
||
ElMessage.success(`成功${label} ${success} 个工单`)
|
||
}
|
||
upperTable.value?.clearSelection?.()
|
||
selectedRows.value = []
|
||
fetchData()
|
||
} else {
|
||
ElMessage.error(res?.message || `${label}失败`)
|
||
}
|
||
} catch (error) {
|
||
console.error(`${label}失败:`, error)
|
||
ElMessage.error(`${label}失败`)
|
||
} finally {
|
||
loadingRef.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 数据查询 ====================
|
||
|
||
function buildWhereFromConditions(conditions: Record<string, any>): Record<string, any> {
|
||
const where: Record<string, any> = {}
|
||
for (const [key, cond] of Object.entries(conditions)) {
|
||
if (cond === undefined || cond === null || cond === '') continue
|
||
if (typeof cond === 'object' && cond.value !== undefined) {
|
||
const val = cond.value
|
||
const op = cond.operator || 'eq'
|
||
if (val === undefined || val === null || val === '' || (Array.isArray(val) && val.length === 0)) continue
|
||
where[key] = { operator: op, value: val }
|
||
} else {
|
||
where[key] = { operator: 'eq', value: cond }
|
||
}
|
||
}
|
||
return where
|
||
}
|
||
|
||
async function fetchData() {
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const where = buildWhereFromConditions(currentConditions.value)
|
||
const params: AfterSaleListParams = {
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
where,
|
||
}
|
||
const res: any = await afterSaleAuditList(params)
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
const data = res.data ?? res
|
||
tableData.value = data.list ?? []
|
||
const total = data.total ?? (data.pagination?.total ?? 0)
|
||
pagination.total = total
|
||
upperPagination.total = total
|
||
} else {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
upperPagination.total = 0
|
||
ElMessage.error(res?.message || '获取售后列表失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('获取售后列表失败:', error)
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
upperPagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
function handleRefresh() {
|
||
upperPagination.currentPage = 1
|
||
fetchData()
|
||
}
|
||
|
||
function handleSortChange(_sort: { prop: string; order: string }) {
|
||
// 预留排序事件处理
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
upperPagination.currentPage = page
|
||
fetchData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
upperPagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
upperPagination.currentPage = 1
|
||
fetchData()
|
||
}
|
||
|
||
// ==================== 创建 / 编辑 ====================
|
||
|
||
const formDialogVisible = ref(false)
|
||
const isEditMode = ref(false)
|
||
const formLoading = ref(false)
|
||
const formRef = ref<FormInstance>()
|
||
|
||
const defaultFormData = () => ({
|
||
id: null as number | null,
|
||
type: 'order' as string,
|
||
sub_type: '' as string,
|
||
title: '' as string,
|
||
description: '' as string,
|
||
priority: 0 as number,
|
||
waybill_no: '' as string,
|
||
order_delivery_no: '' as string,
|
||
entry_order_no: '' as string,
|
||
order_stockout_no: '' as string,
|
||
receiving_no: '' as string,
|
||
})
|
||
|
||
const formData = reactive(defaultFormData())
|
||
|
||
const formRules: FormRules = {
|
||
type: [{ required: true, message: '请选择售后类型', trigger: 'change' }],
|
||
sub_type: [{ required: true, message: '请选择子类型', trigger: 'change' }],
|
||
title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
|
||
}
|
||
|
||
const currentSubTypeOptions = computed(() => {
|
||
return subTypeOptionsByType[formData.type] || {}
|
||
})
|
||
|
||
function onTypeChange() {
|
||
formData.sub_type = ''
|
||
}
|
||
|
||
function showCreateDialog() {
|
||
isEditMode.value = false
|
||
Object.assign(formData, defaultFormData())
|
||
formDialogVisible.value = true
|
||
}
|
||
|
||
function handleEdit(row: any) {
|
||
isEditMode.value = true
|
||
formData.id = row.id
|
||
formData.type = row.type
|
||
formData.sub_type = row.sub_type
|
||
formData.title = row.title
|
||
formData.description = row.description ?? ''
|
||
formData.priority = row.priority ?? 0
|
||
formData.waybill_no = row.waybill_no ?? ''
|
||
formData.order_delivery_no = row.order_delivery_no ?? ''
|
||
formData.entry_order_no = row.entry_order_no ?? ''
|
||
formData.order_stockout_no = row.order_stockout_no ?? ''
|
||
formData.receiving_no = row.receiving_no ?? ''
|
||
formDialogVisible.value = true
|
||
}
|
||
|
||
function resetForm() {
|
||
formRef.value?.resetFields()
|
||
}
|
||
|
||
async function handleSubmitForm() {
|
||
const valid = await formRef.value?.validate().catch(() => false)
|
||
if (!valid) return
|
||
|
||
formLoading.value = true
|
||
try {
|
||
let res: any
|
||
if (isEditMode.value && formData.id) {
|
||
const updateParams: AfterSaleUpdateParams = {
|
||
id: formData.id,
|
||
type: formData.type as any,
|
||
sub_type: formData.sub_type,
|
||
title: formData.title,
|
||
description: formData.description || undefined,
|
||
priority: formData.priority,
|
||
waybill_id: formData.waybill_no ? Number(formData.waybill_no) : undefined,
|
||
order_delivery_no: formData.order_delivery_no || undefined,
|
||
entry_order_no: formData.entry_order_no || undefined,
|
||
order_stockout_no: formData.order_stockout_no || undefined,
|
||
receiving_no: formData.receiving_no || undefined,
|
||
}
|
||
res = await afterSaleUpdate(updateParams)
|
||
} else {
|
||
const createParams: AfterSaleCreateParams = {
|
||
type: formData.type as any,
|
||
sub_type: formData.sub_type,
|
||
title: formData.title,
|
||
description: formData.description || undefined,
|
||
priority: formData.priority,
|
||
waybill_id: formData.waybill_no ? Number(formData.waybill_no) : undefined,
|
||
order_delivery_no: formData.order_delivery_no || undefined,
|
||
entry_order_no: formData.entry_order_no || undefined,
|
||
order_stockout_no: formData.order_stockout_no || undefined,
|
||
receiving_no: formData.receiving_no || undefined,
|
||
}
|
||
res = await afterSaleCreate(createParams)
|
||
}
|
||
if (res && (res.flag === 'success' || res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||
ElMessage.success(isEditMode.value ? '更新成功' : '创建成功')
|
||
formDialogVisible.value = false
|
||
fetchData()
|
||
} else {
|
||
ElMessage.error(res?.message || '操作失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('提交售后单失败:', error)
|
||
ElMessage.error('操作失败')
|
||
} finally {
|
||
formLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 转单 ====================
|
||
|
||
const transferDialogVisible = ref(false)
|
||
const transferLoading = ref(false)
|
||
const transferFormRef = ref<FormInstance>()
|
||
|
||
const transferForm = reactive({
|
||
id: null as number | null,
|
||
after_sale_no: '' as string,
|
||
role_group: '' as string,
|
||
remark: '' as string,
|
||
})
|
||
|
||
const transferRules: FormRules = {
|
||
role_group: [{ required: true, message: '请选择目标角色组', trigger: 'change' }],
|
||
}
|
||
|
||
function handleTransfer(row: any) {
|
||
transferForm.id = row.id
|
||
transferForm.after_sale_no = row.after_sale_no
|
||
transferForm.role_group = ''
|
||
transferForm.remark = ''
|
||
transferDialogVisible.value = true
|
||
}
|
||
|
||
async function handleSubmitTransfer() {
|
||
const valid = await transferFormRef.value?.validate().catch(() => false)
|
||
if (!valid || !transferForm.id) return
|
||
|
||
transferLoading.value = true
|
||
try {
|
||
const params: AfterSaleTransferParams = {
|
||
id: transferForm.id,
|
||
role_group: transferForm.role_group as any,
|
||
remark: transferForm.remark || undefined,
|
||
}
|
||
const res: any = await afterSaleTransfer(params)
|
||
if (res && (res.flag === 'success' || res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||
ElMessage.success(res.message || '转单成功')
|
||
transferDialogVisible.value = false
|
||
fetchData()
|
||
} else {
|
||
ElMessage.error(res?.message || '转单失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('转单失败:', error)
|
||
ElMessage.error('转单失败')
|
||
} finally {
|
||
transferLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 查看详情 ====================
|
||
|
||
const detailDialogVisible = ref(false)
|
||
const detailAfterSaleId = ref<number | null>(null)
|
||
|
||
// 关闭弹窗时重置 ID,确保再次打开同一记录也能触发加载
|
||
watch(detailDialogVisible, (v) => {
|
||
if (!v) detailAfterSaleId.value = null
|
||
})
|
||
|
||
function handleViewDetail(row: any) {
|
||
detailAfterSaleId.value = row.id
|
||
detailDialogVisible.value = true
|
||
}
|
||
|
||
// ==================== 生命周期 ====================
|
||
|
||
// ==================== 货主列表加载 ====================
|
||
|
||
async function loadStoreOptions() {
|
||
try {
|
||
const storesRes: any = await loadStores()
|
||
fillStoreScanFieldOptions(afterSaleAvailableFields, extractStoreListFromResponse(storesRes))
|
||
} catch {
|
||
fillStoreScanFieldOptions(afterSaleAvailableFields, [])
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadStoreOptions()
|
||
fetchData()
|
||
})
|
||
|
||
// 清理导出定时器
|
||
onUnmounted(() => {
|
||
// useAsyncExportTask 内部会自动清理
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "../../order/orderManagement/styles/order-sub.scss";
|
||
|
||
.wave-operation-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px;
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
color: #909399;
|
||
padding: 16px;
|
||
}
|
||
</style>
|