初始化项目
This commit is contained in:
commit
60c416e553
79 files changed
+5609
No files matched your search
@@ -0,0 +1,348 @@
|
||||
<template>
|
||||
<div class="report-page">
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>报备管理</span>
|
||||
<el-button type="primary" @click="handleAdd" v-if="!userStore.isAdmin">
|
||||
<el-icon><Plus /></el-icon>
|
||||
提交报备
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 查询表单 -->
|
||||
<el-form :inline="true" :model="queryForm" class="query-form">
|
||||
<el-form-item label="客户名称">
|
||||
<el-input v-model="queryForm.customerName" placeholder="请输入客户名称" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="queryForm.status" placeholder="请选择状态" clearable>
|
||||
<el-option label="待审核" :value="0" />
|
||||
<el-option label="已通过" :value="1" />
|
||||
<el-option label="已驳回" :value="2" />
|
||||
<el-option label="已失效" :value="3" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery">
|
||||
<el-icon><Search /></el-icon>
|
||||
查询
|
||||
</el-button>
|
||||
<el-button @click="handleReset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<el-table :data="tableData" border stripe v-loading="loading">
|
||||
<el-table-column prop="dealerName" label="经销商" />
|
||||
<el-table-column prop="customerName" label="客户名称" />
|
||||
<el-table-column prop="customerPhone" label="联系电话" />
|
||||
<el-table-column prop="description" label="报备说明" show-overflow-tooltip />
|
||||
<el-table-column prop="status" label="状态">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.status === 0" type="warning">待审核</el-tag>
|
||||
<el-tag v-else-if="row.status === 1" type="success">已通过</el-tag>
|
||||
<el-tag v-else-if="row.status === 2" type="danger">已驳回</el-tag>
|
||||
<el-tag v-else type="info">已失效</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="protectEndDate" label="保护期截止" width="180">
|
||||
<template #default="{ row }">
|
||||
{{ row.protectEndDate || '-' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createdAt" label="创建时间" width="180" />
|
||||
<el-table-column label="操作" width="200" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="handleView(row)">查看</el-button>
|
||||
<el-button
|
||||
v-if="userStore.isAdmin && row.status === 0"
|
||||
link
|
||||
type="success"
|
||||
@click="handleAudit(row)"
|
||||
>
|
||||
审核
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="!userStore.isAdmin && row.status === 0"
|
||||
link
|
||||
type="danger"
|
||||
@click="handleWithdraw(row)"
|
||||
>
|
||||
撤回
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<el-pagination
|
||||
v-model:current-page="queryForm.current"
|
||||
v-model:page-size="queryForm.size"
|
||||
:total="total"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="fetchData"
|
||||
@current-change="fetchData"
|
||||
style="margin-top: 20px; justify-content: flex-end"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 提交报备对话框 -->
|
||||
<el-dialog v-model="dialogVisible" title="提交报备" width="600px" @close="handleDialogClose">
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="100px">
|
||||
<el-form-item label="客户" prop="customerId">
|
||||
<el-select
|
||||
v-model="formData.customerId"
|
||||
placeholder="请选择客户"
|
||||
filterable
|
||||
remote
|
||||
:remote-method="searchCustomer"
|
||||
:loading="searchLoading"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in customerOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="报备说明" prop="description">
|
||||
<el-input
|
||||
v-model="formData.description"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请输入报备说明"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 审核对话框 -->
|
||||
<el-dialog v-model="auditDialogVisible" title="审核报备" width="600px">
|
||||
<el-form ref="auditFormRef" :model="auditForm" label-width="100px">
|
||||
<el-form-item label="审核结果">
|
||||
<el-radio-group v-model="auditForm.approved">
|
||||
<el-radio :label="true">通过</el-radio>
|
||||
<el-radio :label="false">驳回</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="驳回原因" prop="rejectReason" v-if="!auditForm.approved">
|
||||
<el-input
|
||||
v-model="auditForm.rejectReason"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请输入驳回原因"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="auditDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleAuditSubmit">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { getReportPage, createReport, auditReport, withdrawReport } from '@/api/report'
|
||||
import { searchCustomerByName } from '@/api/customer'
|
||||
import type { Report, ReportForm } from '@/types'
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const tableData = ref<Report[]>([])
|
||||
const total = ref(0)
|
||||
const dialogVisible = ref(false)
|
||||
const auditDialogVisible = ref(false)
|
||||
const auditReportId = ref<number>()
|
||||
const formRef = ref<FormInstance>()
|
||||
const auditFormRef = ref<FormInstance>()
|
||||
const searchLoading = ref(false)
|
||||
const customerOptions = ref<Array<{ id: number; name: string }>>([])
|
||||
|
||||
const queryForm = reactive({
|
||||
current: 1,
|
||||
size: 10,
|
||||
customerName: '',
|
||||
status: undefined as number | undefined
|
||||
})
|
||||
|
||||
const formData = reactive<ReportForm>({
|
||||
customerId: 0,
|
||||
description: ''
|
||||
})
|
||||
|
||||
const auditForm = reactive({
|
||||
approved: true,
|
||||
rejectReason: ''
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
customerId: [{ required: true, message: '请选择客户', trigger: 'change' }]
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
const fetchData = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await getReportPage(queryForm)
|
||||
tableData.value = res.records
|
||||
total.value = res.total
|
||||
} catch (error) {
|
||||
console.error('查询失败', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索客户
|
||||
const searchCustomer = async (query: string) => {
|
||||
if (!query) return
|
||||
searchLoading.value = true
|
||||
try {
|
||||
const res = await searchCustomerByName(query)
|
||||
customerOptions.value = res
|
||||
} catch (error) {
|
||||
console.error('搜索客户失败', error)
|
||||
} finally {
|
||||
searchLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 查询按钮
|
||||
const handleQuery = () => {
|
||||
queryForm.current = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 重置按钮
|
||||
const handleReset = () => {
|
||||
queryForm.customerName = ''
|
||||
queryForm.status = undefined
|
||||
queryForm.current = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 新增按钮
|
||||
const handleAdd = () => {
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// 查看详情
|
||||
const handleView = (row: Report) => {
|
||||
ElMessageBox.alert(
|
||||
`
|
||||
<div style="line-height: 2;">
|
||||
<p><strong>经销商:</strong>${row.dealerName}</p>
|
||||
<p><strong>客户名称:</strong>${row.customerName}</p>
|
||||
<p><strong>联系电话:</strong>${row.customerPhone || '-'}</p>
|
||||
<p><strong>报备说明:</strong>${row.description || '-'}</p>
|
||||
<p><strong>状态:</strong>${row.statusDesc}</p>
|
||||
<p><strong>驳回原因:</strong>${row.rejectReason || '-'}</p>
|
||||
<p><strong>保护期:</strong>${row.protectStartDate || '-'} ~ ${row.protectEndDate || '-'}</p>
|
||||
</div>
|
||||
`,
|
||||
'报备详情',
|
||||
{
|
||||
dangerouslyUseHTMLString: true,
|
||||
confirmButtonText: '关闭'
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// 审核按钮
|
||||
const handleAudit = (row: Report) => {
|
||||
auditReportId.value = row.id
|
||||
auditForm.approved = true
|
||||
auditForm.rejectReason = ''
|
||||
auditDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 撤回按钮
|
||||
const handleWithdraw = async (row: Report) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要撤回该报备吗?', '提示', { type: 'warning' })
|
||||
await withdrawReport(row.id)
|
||||
ElMessage.success('撤回成功')
|
||||
fetchData()
|
||||
} catch (error) {
|
||||
// 取消撤回
|
||||
}
|
||||
}
|
||||
|
||||
// 提交报备
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
try {
|
||||
await createReport(formData)
|
||||
ElMessage.success('提交成功')
|
||||
dialogVisible.value = false
|
||||
fetchData()
|
||||
} catch (error) {
|
||||
console.error('提交失败', error)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 审核提交
|
||||
const handleAuditSubmit = async () => {
|
||||
if (!auditReportId.value) return
|
||||
if (!auditForm.approved && !auditForm.rejectReason) {
|
||||
ElMessage.warning('请输入驳回原因')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await auditReport(auditReportId.value, auditForm)
|
||||
ElMessage.success('审核成功')
|
||||
auditDialogVisible.value = false
|
||||
fetchData()
|
||||
} catch (error) {
|
||||
console.error('审核失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 对话框关闭
|
||||
const handleDialogClose = () => {
|
||||
formRef.value?.resetFields()
|
||||
Object.assign(formData, {
|
||||
customerId: 0,
|
||||
description: ''
|
||||
})
|
||||
customerOptions.value = []
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.report-page {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.query-form {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user