增加供应商智能添加功能
This commit is contained in:
1 parent
d8936d9730
commit
20be7f4817
29 files changed
+4317
-1476
No files matched your search
@@ -50,6 +50,47 @@
|
||||
<el-input v-model="form.name" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" v-if="type === 'customer'">
|
||||
<el-form-item label="客户类型">
|
||||
<el-select v-model="form.customer_type" placeholder="请选择" style="width: 100%">
|
||||
<el-option label="企业" value="1" />
|
||||
<el-option label="政府机构" value="2" />
|
||||
<el-option label="国企" value="3" />
|
||||
<el-option label="教育机构" value="4" />
|
||||
<el-option label="个人" value="5" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" v-if="type === 'supplier'">
|
||||
<el-form-item label="供应商类型">
|
||||
<el-select v-model="form.supplier_type" placeholder="请选择" style="width: 100%">
|
||||
<el-option label="原材料供应商" value="1" />
|
||||
<el-option label="设备供应商" value="2" />
|
||||
<el-option label="服务供应商" value="3" />
|
||||
<el-option label="其他" value="4" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" v-if="type === 'customer'">
|
||||
<el-form-item label="客户等级">
|
||||
<el-select v-model="form.customer_level" placeholder="请选择" style="width: 100%">
|
||||
<el-option label="核心客户" value="1" />
|
||||
<el-option label="重要客户" value="2" />
|
||||
<el-option label="普通客户" value="3" />
|
||||
<el-option label="潜在客户" value="4" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12" v-if="type === 'supplier'">
|
||||
<el-form-item label="供应商等级">
|
||||
<el-select v-model="form.supplier_level" placeholder="请选择" style="width: 100%">
|
||||
<el-option label="核心供应商" value="1" />
|
||||
<el-option label="重要供应商" value="2" />
|
||||
<el-option label="普通供应商" value="3" />
|
||||
<el-option label="潜在供应商" value="4" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="所属行业">
|
||||
<el-input v-model="form.industry" />
|
||||
@@ -57,7 +98,16 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="企业类型">
|
||||
<el-input v-model="form.enterprise_type" placeholder="如:有限责任公司" />
|
||||
<el-select v-model="form.enterprise_type" placeholder="请选择" style="width: 100%">
|
||||
<el-option label="有限责任公司" value="有限责任公司" />
|
||||
<el-option label="股份有限公司" value="股份有限公司" />
|
||||
<el-option label="合伙企业" value="合伙企业" />
|
||||
<el-option label="个人独资企业" value="个人独资企业" />
|
||||
<el-option label="国有企业" value="国有企业" />
|
||||
<el-option label="集体企业" value="集体企业" />
|
||||
<el-option label="外商投资企业" value="外商投资企业" />
|
||||
<el-option label="其他" value="其他" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
@@ -65,17 +115,32 @@
|
||||
<el-select v-model="form.taxpayer_qualification" placeholder="请选择" style="width: 100%">
|
||||
<el-option label="一般纳税人" value="一般纳税人" />
|
||||
<el-option label="小规模纳税人" value="小规模纳税人" />
|
||||
<el-option label="其他" value="其他" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="form.status" placeholder="请选择" style="width: 100%">
|
||||
<el-option label="正常" value="1" />
|
||||
<el-option label="禁用" value="0" />
|
||||
<el-option label="冻结" value="2" />
|
||||
<el-option label="已注销" value="3" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="注册资本">
|
||||
<el-input v-model="form.registered_capital" placeholder="如:100万元" />
|
||||
<el-input v-model="form.registered_capital" placeholder="万元">
|
||||
<template #append>万元</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="实缴资本">
|
||||
<el-input v-model="form.paid_capital" placeholder="如:50万元" />
|
||||
<el-input v-model="form.paid_capital" placeholder="万元">
|
||||
<template #append>万元</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
@@ -157,12 +222,21 @@
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" />
|
||||
</el-form-item>
|
||||
|
||||
<!-- 显示原始AI响应数据 -->
|
||||
<el-divider content-position="left">AI响应数据</el-divider>
|
||||
<el-form-item label="详细数据">
|
||||
<div class="ai-data-box">
|
||||
<pre>{{ formattedAiData }}</pre>
|
||||
</div>
|
||||
<div class="form-tip">此数据为AI返回的原始响应,仅作查看参考,已自动填充可编辑字段到上方表单</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button v-if="step === 2" @click="step = 1">返回修改名称</el-button>
|
||||
<el-button @click="emit('update:visible', false)">取消</el-button>
|
||||
<!-- <el-button @click="emit('update:visible', false)">取消</el-button> -->
|
||||
<el-button
|
||||
v-if="step === 2"
|
||||
type="primary"
|
||||
@@ -174,7 +248,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { ref, reactive, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Cpu } from '@element-plus/icons-vue'
|
||||
import { smartGenerateCompany } from '@/api/ai'
|
||||
@@ -194,8 +268,41 @@ const generating = ref(false)
|
||||
const saving = ref(false)
|
||||
const formRef = ref()
|
||||
|
||||
// 从文本中提取JSON对象
|
||||
function extractJSON(text) {
|
||||
text = text.trim()
|
||||
|
||||
// 方法1: 直接解析整个文本
|
||||
try {
|
||||
JSON.parse(text)
|
||||
return text
|
||||
} catch (e) {
|
||||
// 继续尝试其他方法
|
||||
}
|
||||
|
||||
// 方法2: 查找第一个 { 和最后一个 }
|
||||
const start = text.indexOf('{')
|
||||
const end = text.lastIndexOf('}')
|
||||
if (start !== -1 && end !== -1 && end > start) {
|
||||
const jsonStr = text.substring(start, end + 1)
|
||||
try {
|
||||
JSON.parse(jsonStr)
|
||||
return jsonStr
|
||||
} catch (e) {
|
||||
// 继续尝试其他方法
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
const defaultForm = () => ({
|
||||
name: '',
|
||||
customer_type: '',
|
||||
supplier_type: '',
|
||||
customer_level: '3',
|
||||
supplier_level: '3',
|
||||
status: '1',
|
||||
industry: '',
|
||||
enterprise_type: '',
|
||||
taxpayer_qualification: '',
|
||||
@@ -219,6 +326,15 @@ const defaultForm = () => ({
|
||||
|
||||
const form = reactive(defaultForm())
|
||||
|
||||
// 原始AI响应数据(JSON格式字符串)
|
||||
const rawAiData = ref('')
|
||||
|
||||
// formattedAiData 直接显示 rawAiData 的内容(后端已返回格式化好的JSON或原始文本)
|
||||
const formattedAiData = ref('')
|
||||
watch(rawAiData, (newVal) => {
|
||||
formattedAiData.value = newVal
|
||||
}, { immediate: true })
|
||||
|
||||
async function handleGenerate() {
|
||||
if (!companyName.value.trim()) {
|
||||
ElMessage.warning('请输入公司名称')
|
||||
@@ -236,6 +352,14 @@ async function handleGenerate() {
|
||||
const data = res.data.data
|
||||
const nameField = props.type === 'supplier' ? 'supplier_name' : 'customer_name'
|
||||
form.name = data[nameField] || data.name || companyName.value.trim()
|
||||
if (props.type === 'customer') {
|
||||
form.customer_type = data.customer_type || '1'
|
||||
form.customer_level = data.customer_level || '3'
|
||||
} else {
|
||||
form.supplier_type = data.supplier_type || ''
|
||||
form.supplier_level = data.supplier_level || '3'
|
||||
}
|
||||
form.status = data.status || '1'
|
||||
form.industry = data.industry || ''
|
||||
form.enterprise_type = data.enterprise_type || ''
|
||||
form.taxpayer_qualification = data.taxpayer_qualification || ''
|
||||
@@ -255,10 +379,28 @@ async function handleGenerate() {
|
||||
form.registered_address = data.registered_address || ''
|
||||
form.registered_phone = data.registered_phone || ''
|
||||
form.remark = data.remark || ''
|
||||
// 保存原始AI响应数据(使用后端返回的原始数据)
|
||||
if (res.data.raw) {
|
||||
rawAiData.value = res.data.raw
|
||||
} else {
|
||||
rawAiData.value = JSON.stringify(data, null, 2)
|
||||
}
|
||||
} else {
|
||||
// 解析失败,只填名称
|
||||
// 解析失败,显示AI原始返回内容
|
||||
let rawContent = res.data.raw || '无原始数据'
|
||||
let errorMsg = res.data.error || '未知错误'
|
||||
// 保存原始AI响应数据
|
||||
rawAiData.value = rawContent
|
||||
// 限制显示长度
|
||||
if (rawContent.length > 1500) {
|
||||
rawContent = rawContent.substring(0, 1500) + '...'
|
||||
}
|
||||
ElMessage.error({
|
||||
message: `AI生成失败:${errorMsg}\n\n原始响应:\n${rawContent}`,
|
||||
showClose: true,
|
||||
duration: 0 // 不自动关闭
|
||||
})
|
||||
form.name = companyName.value.trim()
|
||||
ElMessage.warning('AI返回格式异常,请手动填写其他信息')
|
||||
}
|
||||
step.value = 2
|
||||
}
|
||||
@@ -280,6 +422,11 @@ async function handleSave() {
|
||||
const payload = {
|
||||
supplier_name: form.name,
|
||||
customer_name: form.name,
|
||||
customer_type: form.customer_type,
|
||||
supplier_type: form.supplier_type,
|
||||
customer_level: form.customer_level,
|
||||
supplier_level: form.supplier_level,
|
||||
status: form.status,
|
||||
industry: form.industry,
|
||||
enterprise_type: form.enterprise_type,
|
||||
taxpayer_qualification: form.taxpayer_qualification,
|
||||
@@ -299,7 +446,6 @@ async function handleSave() {
|
||||
registered_address: form.registered_address,
|
||||
registered_phone: form.registered_phone,
|
||||
remark: form.remark,
|
||||
status: '1',
|
||||
is_draft: 0
|
||||
}
|
||||
|
||||
@@ -323,6 +469,8 @@ function handleClosed() {
|
||||
step.value = 1
|
||||
companyName.value = ''
|
||||
Object.assign(form, defaultForm())
|
||||
rawAiData.value = ''
|
||||
formattedAiData.value = ''
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -347,5 +495,16 @@ function handleClosed() {
|
||||
overflow-y: auto;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.ai-data-box {
|
||||
background: var(--el-fill-color-lighter);
|
||||
border: 1px solid var(--el-border-color);
|
||||
border-radius: 4px;
|
||||
padding: 12px;
|
||||
font-family: 'Consolas', 'Monaco', monospace;
|
||||
font-size: 12px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -63,7 +63,6 @@
|
||||
|
||||
<div class="table-container" v-loading="loading">
|
||||
<el-table :data="tableData" stripe border>
|
||||
<el-table-column type="index" label="#" width="60" align="center" />
|
||||
<el-table-column prop="customer_name" label="客户名称" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<div class="name-cell-wrapper">
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
|
||||
<div class="table-container" v-loading="loading">
|
||||
<el-table :data="tableData" stripe border>
|
||||
<el-table-column type="index" label="#" width="60" align="center" />
|
||||
<el-table-column prop="supplier_name" label="供应商名称" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<div class="name-cell-wrapper">
|
||||
|
||||
Reference in new issue
Block a user