843 lines
29 KiB
Vue
843 lines
29 KiB
Vue
<template>
|
||
<div class="after-sale-detail-container">
|
||
<!-- 顶部标题栏 -->
|
||
<div class="detail-header-bar">
|
||
<el-button size="small" @click="goBack">
|
||
<el-icon><ArrowLeft /></el-icon>
|
||
返回列表
|
||
</el-button>
|
||
<span class="detail-title">售后明细 - {{ detail?.after_sale_no || '加载中...' }}</span>
|
||
<div class="header-actions">
|
||
<el-button
|
||
v-if="detail && (detail.status === 'pending' || detail.status === 'processing')"
|
||
size="small"
|
||
type="warning"
|
||
@click="showTransferDialog"
|
||
>
|
||
转单
|
||
</el-button>
|
||
<el-button
|
||
v-if="detail && detail.status !== 'completed' && detail.status !== 'cancelled' && detail.status !== 'closed'"
|
||
size="small"
|
||
type="primary"
|
||
@click="showHandleDialog"
|
||
>
|
||
处理工单
|
||
</el-button>
|
||
<el-button
|
||
v-if="detail"
|
||
size="small"
|
||
type="success"
|
||
@click="showClaimDialog"
|
||
>
|
||
登记理赔
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-loading="loading" class="detail-body">
|
||
<template v-if="detail">
|
||
<!-- 基本信息卡片 -->
|
||
<el-card class="info-card" shadow="never">
|
||
<template #header>
|
||
<div class="card-header">
|
||
<span class="card-title">基本信息</span>
|
||
<el-tag :type="statusTagType(detail.status)" size="small">
|
||
{{ statusLabel(detail.status) }}
|
||
</el-tag>
|
||
</div>
|
||
</template>
|
||
<el-descriptions :column="3" border size="small">
|
||
<el-descriptions-item label="售后单号">{{ detail.after_sale_no }}</el-descriptions-item>
|
||
<el-descriptions-item label="售后类型">
|
||
<el-tag size="small" :type="typeTagType(detail.type)">{{ typeLabel(detail.type) }}</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="子类型">{{ subTypeLabel(detail.sub_type) }}</el-descriptions-item>
|
||
<el-descriptions-item label="标题" :span="2">{{ detail.title }}</el-descriptions-item>
|
||
<el-descriptions-item label="优先级">{{ detail.priority }}</el-descriptions-item>
|
||
<el-descriptions-item v-if="detail.description" label="详细描述" :span="3">
|
||
{{ detail.description }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="角色组">
|
||
<el-tag v-if="detail.role_group" size="small" :type="roleGroupTagType(detail.role_group)">
|
||
{{ roleGroupLabel(detail.role_group) }}
|
||
</el-tag>
|
||
<span v-else>-</span>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="处理结果">
|
||
{{ detail.resolution || '-' }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="完结时间">
|
||
{{ detail.resolved_at || '-' }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="创建时间">{{ detail.created_at }}</el-descriptions-item>
|
||
<el-descriptions-item label="更新时间">{{ detail.updated_at }}</el-descriptions-item>
|
||
</el-descriptions>
|
||
</el-card>
|
||
|
||
<!-- 关联单据 -->
|
||
<el-card v-if="hasRelatedDocs" class="info-card" shadow="never">
|
||
<template #header><span class="card-title">关联单据</span></template>
|
||
<el-descriptions :column="3" border size="small">
|
||
<el-descriptions-item v-if="detail.waybill_no" label="运单号">
|
||
{{ detail.waybill_no }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="detail.order_delivery_no" label="发货订单号">
|
||
{{ detail.order_delivery_no }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="detail.entry_order_no" label="入库单号">
|
||
{{ detail.entry_order_no }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="detail.order_stockout_no" label="出库单号">
|
||
{{ detail.order_stockout_no }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="detail.receiving_no" label="收货单号">
|
||
{{ detail.receiving_no }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
</el-card>
|
||
|
||
<!-- 理赔信息 -->
|
||
<el-card v-if="detail.claim_needed || detail.carrier_claim_needed" class="info-card" shadow="never">
|
||
<template #header><span class="card-title">理赔信息</span></template>
|
||
<el-row :gutter="20">
|
||
<!-- 仓库理赔 -->
|
||
<el-col v-if="detail.claim_needed" :span="12">
|
||
<div class="claim-section">
|
||
<h4>🏭 仓库理赔</h4>
|
||
<el-descriptions :column="1" border size="small">
|
||
<el-descriptions-item label="金额">¥{{ detail.claim_amount ?? '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="状态">
|
||
<el-tag size="small" :type="claimStatusTagType(detail.claim_status!)">
|
||
{{ claimStatusLabel(detail.claim_status!) }}
|
||
</el-tag>
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
</div>
|
||
</el-col>
|
||
<!-- 运方理赔 -->
|
||
<el-col v-if="detail.carrier_claim_needed" :span="12">
|
||
<div class="claim-section">
|
||
<h4>🚚 运方理赔</h4>
|
||
<el-descriptions :column="1" border size="small">
|
||
<el-descriptions-item label="金额">¥{{ detail.carrier_claim_amount ?? '-' }}</el-descriptions-item>
|
||
<el-descriptions-item label="状态">
|
||
<el-tag size="small" :type="claimStatusTagType(detail.carrier_claim_status!)">
|
||
{{ claimStatusLabel(detail.carrier_claim_status!) }}
|
||
</el-tag>
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
</div>
|
||
</el-col>
|
||
</el-row>
|
||
</el-card>
|
||
|
||
<!-- 处理步骤 / 时间线 -->
|
||
<el-card v-if="steps && steps.length > 0" class="info-card" shadow="never">
|
||
<template #header><span class="card-title">处理记录</span></template>
|
||
<el-timeline>
|
||
<el-timeline-item
|
||
v-for="step in steps"
|
||
:key="step.id"
|
||
:timestamp="step.completed_at || step.started_at || step.created_at"
|
||
placement="top"
|
||
:type="stepTimelineType(step.step_status)"
|
||
>
|
||
<div class="step-item">
|
||
<div class="step-header">
|
||
<el-tag size="small" :type="stepStatusTagType(step.step_status)">
|
||
{{ stepStatusLabel(step.step_status) }}
|
||
</el-tag>
|
||
<span class="step-action">{{ step.action || '未指定操作' }}</span>
|
||
</div>
|
||
<div v-if="step.remark" class="step-remark">{{ step.remark }}</div>
|
||
<div v-if="step.operator_snapshot" class="step-operator">
|
||
操作人: {{ parseOperatorName(step.operator_snapshot) }}
|
||
</div>
|
||
<div v-if="step.attachments && step.attachments.length > 0" class="step-attachments">
|
||
<span v-for="(att, idx) in step.attachments" :key="idx" class="att-item">
|
||
<el-image
|
||
v-if="att.mime_type?.startsWith('image/')"
|
||
:src="att.file_url"
|
||
:preview-src-list="[att.file_url]"
|
||
fit="cover"
|
||
style="width:60px;height:60px;border-radius:4px;cursor:pointer"
|
||
:title="att.file_name"
|
||
/>
|
||
<a v-else :href="att.file_url" target="_blank">{{ att.file_name || `文件${(att as any).id || att.file_id}` }}</a>
|
||
</span>
|
||
</div>
|
||
</div>
|
||
</el-timeline-item>
|
||
</el-timeline>
|
||
</el-card>
|
||
|
||
<!-- 暂无步骤 -->
|
||
<el-empty v-if="!steps || steps.length === 0" description="暂无处理记录" />
|
||
</template>
|
||
</div>
|
||
|
||
<!-- ========== 弹窗 ========== -->
|
||
|
||
<!-- 处理工单弹窗 -->
|
||
<el-dialog
|
||
v-model="handleDialogVisible"
|
||
title="处理工单"
|
||
width="550px"
|
||
align-center
|
||
destroy-on-close
|
||
>
|
||
<el-form ref="handleFormRef" :model="handleForm" :rules="handleRules" label-width="110px" size="small">
|
||
<el-form-item label="售后单号">
|
||
<el-input :model-value="detail?.after_sale_no" disabled />
|
||
</el-form-item>
|
||
<el-form-item label="更新状态" prop="status">
|
||
<el-select v-model="handleForm.status" placeholder="请选择状态" style="width: 100%">
|
||
<el-option label="待处理" value="pending" />
|
||
<el-option label="处理中" value="processing" />
|
||
<el-option label="已完成" value="completed" />
|
||
<el-option label="已关闭" value="closed" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="处理备注">
|
||
<el-input v-model="handleForm.remark" type="textarea" :rows="3" placeholder="请输入处理备注" />
|
||
</el-form-item>
|
||
<el-form-item label="附件">
|
||
<el-upload
|
||
ref="handleUploadRef"
|
||
action="#"
|
||
:auto-upload="false"
|
||
:file-list="handleFileList"
|
||
:limit="10"
|
||
:on-change="(file: any) => onHandleFileChange(file)"
|
||
:on-remove="(file: any) => onHandleFileRemove(file)"
|
||
:before-upload="() => false"
|
||
accept="image/*"
|
||
list-type="text"
|
||
>
|
||
<el-button size="small" type="primary" plain>选择文件</el-button>
|
||
<template #tip>
|
||
<span class="upload-tip">支持图片格式,单张不超过10MB,选完后点击"确认处理"时自动上传</span>
|
||
</template>
|
||
</el-upload>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button size="small" @click="handleDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" size="small" :loading="handleLoading" @click="handleSubmitHandle">
|
||
确认处理
|
||
</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="detail?.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>
|
||
|
||
<!-- 登记理赔弹窗 -->
|
||
<el-dialog
|
||
v-model="claimDialogVisible"
|
||
title="登记理赔"
|
||
width="600px"
|
||
align-center
|
||
destroy-on-close
|
||
>
|
||
<el-form ref="claimFormRef" :model="claimForm" :rules="claimRules" label-width="120px" size="small">
|
||
<el-form-item label="售后单号">
|
||
<el-input :model-value="detail?.after_sale_no" disabled />
|
||
</el-form-item>
|
||
<el-divider content-position="left">🏭 仓库理赔</el-divider>
|
||
<el-form-item label="是否需要理赔">
|
||
<el-switch v-model="claimForm.claim_needed" :active-value="1" :inactive-value="0" />
|
||
</el-form-item>
|
||
<template v-if="claimForm.claim_needed">
|
||
<el-form-item label="理赔金额" prop="claim_amount">
|
||
<el-input-number v-model="claimForm.claim_amount" :min="0" :precision="2" style="width: 180px" />
|
||
</el-form-item>
|
||
<el-form-item label="理赔状态" prop="claim_status">
|
||
<el-select v-model="claimForm.claim_status" placeholder="请选择" style="width: 180px">
|
||
<el-option v-for="(label, value) in claimStatusOptions" :key="value" :label="label" :value="value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
<el-divider content-position="left">🚚 运方理赔</el-divider>
|
||
<el-form-item label="是否需要理赔">
|
||
<el-switch v-model="claimForm.carrier_claim_needed" :active-value="1" :inactive-value="0" />
|
||
</el-form-item>
|
||
<template v-if="claimForm.carrier_claim_needed">
|
||
<el-form-item label="理赔金额" prop="carrier_claim_amount">
|
||
<el-input-number v-model="claimForm.carrier_claim_amount" :min="0" :precision="2" style="width: 180px" />
|
||
</el-form-item>
|
||
<el-form-item label="理赔状态" prop="carrier_claim_status">
|
||
<el-select v-model="claimForm.carrier_claim_status" placeholder="请选择" style="width: 180px">
|
||
<el-option v-for="(label, value) in claimStatusOptions" :key="value" :label="label" :value="value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</template>
|
||
<el-divider content-position="left">📝 操作信息</el-divider>
|
||
<el-form-item label="操作动作" prop="claim_action">
|
||
<el-input v-model="claimForm.claim_action" placeholder="如:登记仓库理赔" />
|
||
</el-form-item>
|
||
<el-form-item label="备注">
|
||
<el-input v-model="claimForm.claim_remark" type="textarea" :rows="2" placeholder="请输入备注" />
|
||
</el-form-item>
|
||
<el-form-item label="附件">
|
||
<el-upload
|
||
ref="claimUploadRef"
|
||
action="#"
|
||
:auto-upload="false"
|
||
:file-list="claimFileList"
|
||
:limit="10"
|
||
:on-change="(file: any) => onClaimFileChange(file)"
|
||
:on-remove="(file: any) => onClaimFileRemove(file)"
|
||
:before-upload="() => false"
|
||
accept="image/*"
|
||
list-type="text"
|
||
>
|
||
<el-button size="small" type="primary" plain>选择文件</el-button>
|
||
<template #tip>
|
||
<span class="upload-tip">支持图片格式,单张不超过10MB,选完后点击"确认登记"时自动上传</span>
|
||
</template>
|
||
</el-upload>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button size="small" @click="claimDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" size="small" :loading="claimLoading" @click="handleSubmitClaim">
|
||
确认登记
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, computed, onMounted } from 'vue'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||
import { ArrowLeft } from '@element-plus/icons-vue'
|
||
import {
|
||
afterSaleDetail,
|
||
afterSaleHandleWorkOrder,
|
||
afterSaleTransfer,
|
||
afterSaleRegisterClaim,
|
||
type AfterSale,
|
||
type AfterSaleStep,
|
||
type AfterSaleHandleWorkOrderParams,
|
||
type AfterSaleTransferParams,
|
||
type AfterSaleRegisterClaimParams,
|
||
} from '@/api/aftersale/index'
|
||
import { getCOSUploadConfig, uploadSuccessNotify } from '@/api/index/index'
|
||
import {
|
||
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,
|
||
STEP_STATUS_MAP,
|
||
STEP_STATUS_TAG_MAP,
|
||
} from '@/views/afterSale/list/afterSale-config'
|
||
|
||
// ==================== 工具函数 ====================
|
||
|
||
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' }
|
||
function stepStatusLabel(s: number) { return STEP_STATUS_MAP[s] ?? String(s) }
|
||
function stepStatusTagType(s: number) { return STEP_STATUS_TAG_MAP[s] ?? 'info' }
|
||
function stepTimelineType(s: number): 'primary' | 'success' | 'warning' | 'danger' | 'info' {
|
||
const map: Record<number, 'primary' | 'success' | 'warning' | 'danger' | 'info'> = {
|
||
0: 'info', 1: 'primary', 2: 'success', 3: 'warning',
|
||
}
|
||
return map[s] ?? 'info'
|
||
}
|
||
|
||
function parseOperatorName(snapshot: string): string {
|
||
try {
|
||
const obj = JSON.parse(snapshot)
|
||
return obj.name || obj.id || '-'
|
||
} catch {
|
||
return snapshot || '-'
|
||
}
|
||
}
|
||
|
||
const claimStatusOptions = CLAIM_STATUS_MAP
|
||
|
||
// ==================== 路由 ====================
|
||
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
|
||
function goBack() {
|
||
router.push({ name: 'afterSale.list' })
|
||
}
|
||
|
||
// ==================== 数据 ====================
|
||
|
||
const loading = ref(false)
|
||
const detail = ref<AfterSale | null>(null)
|
||
const steps = ref<AfterSaleStep[]>([])
|
||
|
||
const hasRelatedDocs = computed(() => {
|
||
if (!detail.value) return false
|
||
return !!(detail.value.waybill_no || detail.value.order_delivery_no ||
|
||
detail.value.entry_order_no || detail.value.order_stockout_no || detail.value.receiving_no)
|
||
})
|
||
|
||
// ==================== 附件上传 ====================
|
||
|
||
/** 处理工单附件 */
|
||
const handleFileList = ref<any[]>([])
|
||
const handleUploadedIds = ref<number[]>([])
|
||
const handleUploadRef = ref<any>()
|
||
|
||
/** 登记理赔附件 */
|
||
const claimFileList = ref<any[]>([])
|
||
const claimUploadedIds = ref<number[]>([])
|
||
const claimUploadRef = ref<any>()
|
||
|
||
/** 上传单个文件到COS并注册 */
|
||
async function uploadSingleFile(rawFile: File): Promise<number | null> {
|
||
try {
|
||
// 1. 获取COS上传配置
|
||
const configRes: any = await getCOSUploadConfig({
|
||
fileName: rawFile.name,
|
||
fileType: rawFile.type,
|
||
fileSize: rawFile.size,
|
||
})
|
||
const cosConfig = configRes?.data ?? configRes
|
||
if (cosConfig?.isNew === false) {
|
||
// 文件已存在,直接返回已有 file_id
|
||
return cosConfig?.fileId ?? cosConfig?.file_id ?? null
|
||
}
|
||
if (cosConfig?.error) {
|
||
console.error('获取上传配置失败:', cosConfig.msg)
|
||
return null
|
||
}
|
||
|
||
// 2. 上传到COS
|
||
const formData = new FormData()
|
||
if (cosConfig.data) {
|
||
Object.keys(cosConfig.data).forEach((key) => {
|
||
formData.append(key, cosConfig.data[key])
|
||
})
|
||
}
|
||
formData.append('file', rawFile)
|
||
const uploadUrl = cosConfig.uploadUrl || cosConfig.upload_url
|
||
const uploadHeaders = cosConfig.headers || {}
|
||
const uploadRes = await fetch(uploadUrl, {
|
||
method: 'POST',
|
||
headers: uploadHeaders,
|
||
body: formData,
|
||
})
|
||
if (!uploadRes.ok) {
|
||
throw new Error(`上传失败: ${uploadRes.status}`)
|
||
}
|
||
|
||
// 3. 通知上传成功,获取 file_id
|
||
const notifyRes: any = await uploadSuccessNotify(cosConfig.fileInfo || cosConfig)
|
||
const fileId = notifyRes?.data?.file_id ?? notifyRes?.file_id ?? notifyRes?.data?.fileId
|
||
return fileId ?? null
|
||
} catch (error) {
|
||
console.error('文件上传失败:', error)
|
||
return null
|
||
}
|
||
}
|
||
|
||
/** 批量上传文件,返回成功上传的 file_id 列表 */
|
||
async function uploadFilesBatch(fileList: any[]): Promise<number[]> {
|
||
const ids: number[] = []
|
||
for (const file of fileList) {
|
||
const rawFile = file.raw || file
|
||
if (rawFile instanceof File) {
|
||
const fileId = await uploadSingleFile(rawFile)
|
||
if (fileId != null) {
|
||
ids.push(fileId)
|
||
}
|
||
}
|
||
}
|
||
return ids
|
||
}
|
||
|
||
// 处理工单附件 - 选择文件
|
||
function onHandleFileChange(_file: any) {
|
||
// el-upload v-model 自动同步 fileList
|
||
}
|
||
|
||
// 处理工单附件 - 移除文件
|
||
function onHandleFileRemove(_file: any) {
|
||
// el-upload v-model 自动同步 fileList
|
||
}
|
||
|
||
// 登记理赔附件 - 选择文件
|
||
function onClaimFileChange(_file: any) {
|
||
// el-upload v-model 自动同步 fileList
|
||
}
|
||
|
||
// 登记理赔附件 - 移除文件
|
||
function onClaimFileRemove(_file: any) {
|
||
// el-upload v-model 自动同步 fileList
|
||
}
|
||
|
||
/** 清空处理工单附件 */
|
||
function resetHandleAttachments() {
|
||
handleFileList.value = []
|
||
handleUploadedIds.value = []
|
||
}
|
||
|
||
/** 清空登记理赔附件 */
|
||
function resetClaimAttachments() {
|
||
claimFileList.value = []
|
||
claimUploadedIds.value = []
|
||
}
|
||
|
||
async function fetchDetail() {
|
||
const id = Number(route.query.id)
|
||
if (!id) {
|
||
ElMessage.error('缺少售后单ID')
|
||
goBack()
|
||
return
|
||
}
|
||
|
||
loading.value = true
|
||
try {
|
||
const res: any = await afterSaleDetail(id)
|
||
if (res && (res.flag === 'success' || res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||
const data = res.data ?? res
|
||
detail.value = data.after_sale ?? null
|
||
steps.value = data.steps ?? []
|
||
} else {
|
||
ElMessage.error(res?.message || '获取售后明细失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('获取售后明细失败:', error)
|
||
ElMessage.error('获取售后明细失败')
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 处理工单 ====================
|
||
|
||
const handleDialogVisible = ref(false)
|
||
const handleLoading = ref(false)
|
||
const handleFormRef = ref<FormInstance>()
|
||
|
||
const handleForm = reactive({
|
||
status: '' as string,
|
||
remark: '' as string,
|
||
})
|
||
|
||
const handleRules: FormRules = {
|
||
status: [{ required: true, message: '请选择更新状态', trigger: 'change' }],
|
||
}
|
||
|
||
function showHandleDialog() {
|
||
handleForm.status = detail.value?.status || 'processing'
|
||
handleForm.remark = ''
|
||
resetHandleAttachments()
|
||
handleDialogVisible.value = true
|
||
}
|
||
|
||
async function handleSubmitHandle() {
|
||
const valid = await handleFormRef.value?.validate().catch(() => false)
|
||
if (!valid || !detail.value) return
|
||
|
||
handleLoading.value = true
|
||
try {
|
||
// 先上传附件
|
||
const attachmentIds = await uploadFilesBatch(handleFileList.value)
|
||
|
||
const params: AfterSaleHandleWorkOrderParams = {
|
||
id: detail.value.id,
|
||
status: handleForm.status as any,
|
||
remark: handleForm.remark || undefined,
|
||
attachment_ids: attachmentIds.length > 0 ? attachmentIds : undefined,
|
||
}
|
||
const res: any = await afterSaleHandleWorkOrder(params)
|
||
if (res && (res.flag === 'success' || res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||
ElMessage.success(res.message || '处理成功')
|
||
handleDialogVisible.value = false
|
||
resetHandleAttachments()
|
||
fetchDetail()
|
||
} else {
|
||
ElMessage.error(res?.message || '处理失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('处理工单失败:', error)
|
||
ElMessage.error('处理失败')
|
||
} finally {
|
||
handleLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 转单 ====================
|
||
|
||
const transferDialogVisible_ = ref(false)
|
||
const transferLoading = ref(false)
|
||
const transferFormRef = ref<FormInstance>()
|
||
|
||
const transferForm = reactive({
|
||
role_group: '' as string,
|
||
remark: '' as string,
|
||
})
|
||
|
||
const transferRules: FormRules = {
|
||
role_group: [{ required: true, message: '请选择目标角色组', trigger: 'change' }],
|
||
}
|
||
|
||
function showTransferDialog() {
|
||
transferForm.role_group = ''
|
||
transferForm.remark = ''
|
||
transferDialogVisible_.value = true
|
||
}
|
||
|
||
async function handleSubmitTransfer() {
|
||
const valid = await transferFormRef.value?.validate().catch(() => false)
|
||
if (!valid || !detail.value) return
|
||
|
||
transferLoading.value = true
|
||
try {
|
||
const params: AfterSaleTransferParams = {
|
||
id: detail.value.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
|
||
fetchDetail()
|
||
} else {
|
||
ElMessage.error(res?.message || '转单失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('转单失败:', error)
|
||
ElMessage.error('转单失败')
|
||
} finally {
|
||
transferLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 登记理赔 ====================
|
||
|
||
const claimDialogVisible = ref(false)
|
||
const claimLoading = ref(false)
|
||
const claimFormRef = ref<FormInstance>()
|
||
|
||
const claimForm = reactive({
|
||
claim_needed: 0 as 0 | 1,
|
||
claim_amount: undefined as number | undefined,
|
||
claim_status: '' as string,
|
||
carrier_claim_needed: 0 as 0 | 1,
|
||
carrier_claim_amount: undefined as number | undefined,
|
||
carrier_claim_status: '' as string,
|
||
claim_action: '' as string,
|
||
claim_remark: '' as string,
|
||
})
|
||
|
||
const claimRules: FormRules = {
|
||
claim_action: [{ required: true, message: '请输入操作动作', trigger: 'blur' }],
|
||
}
|
||
|
||
function showClaimDialog() {
|
||
claimForm.claim_needed = detail.value?.claim_needed ?? 0
|
||
claimForm.claim_amount = detail.value?.claim_amount ?? undefined
|
||
claimForm.claim_status = detail.value?.claim_status ?? ''
|
||
claimForm.carrier_claim_needed = detail.value?.carrier_claim_needed ?? 0
|
||
claimForm.carrier_claim_amount = detail.value?.carrier_claim_amount ?? undefined
|
||
claimForm.carrier_claim_status = detail.value?.carrier_claim_status ?? ''
|
||
claimForm.claim_action = ''
|
||
claimForm.claim_remark = ''
|
||
resetClaimAttachments()
|
||
claimDialogVisible.value = true
|
||
}
|
||
|
||
async function handleSubmitClaim() {
|
||
const valid = await claimFormRef.value?.validate().catch(() => false)
|
||
if (!valid || !detail.value) return
|
||
|
||
claimLoading.value = true
|
||
try {
|
||
// 先上传附件
|
||
const attachmentIds = await uploadFilesBatch(claimFileList.value)
|
||
|
||
const params: AfterSaleRegisterClaimParams = {
|
||
id: detail.value.id,
|
||
claim_needed: claimForm.claim_needed,
|
||
claim_amount: claimForm.claim_needed ? claimForm.claim_amount : undefined,
|
||
claim_status: claimForm.claim_needed ? (claimForm.claim_status as any) : undefined,
|
||
carrier_claim_needed: claimForm.carrier_claim_needed,
|
||
carrier_claim_amount: claimForm.carrier_claim_needed ? claimForm.carrier_claim_amount : undefined,
|
||
carrier_claim_status: claimForm.carrier_claim_needed ? (claimForm.carrier_claim_status as any) : undefined,
|
||
action: claimForm.claim_action,
|
||
remark: claimForm.claim_remark || undefined,
|
||
attachment_ids: attachmentIds.length > 0 ? attachmentIds : undefined,
|
||
}
|
||
const res: any = await afterSaleRegisterClaim(params)
|
||
if (res && (res.flag === 'success' || res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||
ElMessage.success('理赔登记成功')
|
||
claimDialogVisible.value = false
|
||
resetClaimAttachments()
|
||
fetchDetail()
|
||
} else {
|
||
ElMessage.error(res?.message || '理赔登记失败')
|
||
}
|
||
} catch (error) {
|
||
console.error('登记理赔失败:', error)
|
||
ElMessage.error('理赔登记失败')
|
||
} finally {
|
||
claimLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ==================== 生命周期 ====================
|
||
|
||
onMounted(() => {
|
||
fetchDetail()
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
.after-sale-detail-container {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 8px 16px;
|
||
}
|
||
|
||
.detail-header-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
padding: 8px 0;
|
||
border-bottom: 1px solid #ebeef5;
|
||
margin-bottom: 16px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.detail-title {
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
flex: 1;
|
||
}
|
||
|
||
.header-actions {
|
||
display: flex;
|
||
gap: 8px;
|
||
}
|
||
|
||
.detail-body {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.info-card {
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.card-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.card-title {
|
||
font-size: 15px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.claim-section h4 {
|
||
margin: 0 0 12px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.step-item {
|
||
padding: 4px 0;
|
||
}
|
||
|
||
.step-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
margin-bottom: 4px;
|
||
}
|
||
|
||
.step-action {
|
||
font-weight: 500;
|
||
}
|
||
|
||
.step-remark {
|
||
color: #606266;
|
||
font-size: 13px;
|
||
margin-top: 4px;
|
||
}
|
||
|
||
.step-operator {
|
||
color: #909399;
|
||
font-size: 12px;
|
||
margin-top: 4px;
|
||
}
|
||
|
||
.step-attachments {
|
||
margin-top: 4px;
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
.att-label {
|
||
margin-right: 4px;
|
||
}
|
||
|
||
.att-item {
|
||
display: inline-block;
|
||
background: #f0f2f5;
|
||
padding: 1px 6px;
|
||
border-radius: 3px;
|
||
margin-right: 4px;
|
||
}
|
||
|
||
.upload-tip {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
margin-left: 8px;
|
||
}
|
||
</style>
|