补齐项目组负责人审批、费用信息、合作客户、生产出库菜单、申请单号 LCKY 前缀及配套 SQL 迁移,并同步相关前后端与单测。 Co-authored-by: Cursor <cursoragent@cursor.com>
434 lines
13 KiB
Vue
434 lines
13 KiB
Vue
<!-- 合作客户基础信息 -->
|
|
<!-- eslint-disable vue/no-v-model-argument -->
|
|
<template>
|
|
<div class="partner-customer-tab">
|
|
<div class="filter-block">
|
|
<el-form :model="searchForm" class="filter-form" @submit.prevent>
|
|
<div class="filter-grid">
|
|
<el-form-item label="关键词">
|
|
<el-input
|
|
v-model="searchForm.keyword"
|
|
placeholder="客户名称/联系人/联系方式"
|
|
clearable
|
|
@keyup.enter="handleSearch"
|
|
/>
|
|
</el-form-item>
|
|
</div>
|
|
<div class="filter-actions-row">
|
|
<div class="filter-actions-end">
|
|
<el-button class="btn-ghost" @click="handleReset">
|
|
<el-icon><RefreshLeft /></el-icon>重置
|
|
</el-button>
|
|
<el-button class="btn-main" type="primary" @click="handleSearch">
|
|
<el-icon><Search /></el-icon>搜索
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</el-form>
|
|
</div>
|
|
|
|
<div class="list-toolbar">
|
|
<div class="list-toolbar-row">
|
|
<div class="list-toolbar-selected">
|
|
已选 <span class="sel-num">{{ selectedRows.length }}</span> 项
|
|
</div>
|
|
<el-button class="btn-main" type="primary" @click="handleAdd">
|
|
<el-icon><Plus /></el-icon>
|
|
新增合作客户
|
|
</el-button>
|
|
<el-button
|
|
class="btn-ghost"
|
|
type="danger"
|
|
:disabled="selectedRows.length === 0"
|
|
@click="handleBatchDelete"
|
|
>
|
|
<el-icon><Delete /></el-icon>
|
|
批量删除
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="list-body list-wrap">
|
|
<el-table
|
|
class="list-table"
|
|
:data="tableData"
|
|
v-loading="loading"
|
|
stripe
|
|
row-key="id"
|
|
@selection-change="handleSelectionChange"
|
|
@row-dblclick="handleView"
|
|
>
|
|
<el-table-column type="selection" min-width="55" align="center" header-align="center" />
|
|
<el-table-column
|
|
type="index"
|
|
label="序号"
|
|
min-width="68"
|
|
align="center"
|
|
header-align="center"
|
|
:index="(index: number) => (pagination.page - 1) * pagination.pageSize + index + 1"
|
|
/>
|
|
<el-table-column
|
|
prop="customerName"
|
|
label="客户名称"
|
|
min-width="160"
|
|
align="center"
|
|
header-align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
prop="customerContact"
|
|
label="客户联系人"
|
|
min-width="140"
|
|
align="center"
|
|
header-align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
prop="customerPhone"
|
|
label="客户联系方式"
|
|
min-width="140"
|
|
align="center"
|
|
header-align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
prop="remark"
|
|
label="备注"
|
|
min-width="160"
|
|
show-overflow-tooltip
|
|
>
|
|
<template #default="{ row }">{{ row.remark || '—' }}</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
prop="createTime"
|
|
label="创建时间"
|
|
min-width="180"
|
|
align="center"
|
|
header-align="center"
|
|
>
|
|
<template #default="{ row }">{{ formatDisplayOrDash(row.createTime) }}</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
label="操作"
|
|
min-width="120"
|
|
fixed="right"
|
|
align="center"
|
|
header-align="center"
|
|
>
|
|
<template #default="{ row }">
|
|
<div style="display: flex; justify-content: center; gap: 8px">
|
|
<el-button class="btn-op-item" @click="handleView(row)">
|
|
<el-icon><View /></el-icon>查看
|
|
</el-button>
|
|
<el-dropdown
|
|
trigger="hover"
|
|
@command="(cmd: string) => handleDropdownCommand(cmd, row)"
|
|
>
|
|
<el-button class="btn-op-item">
|
|
<el-icon><More /></el-icon>
|
|
</el-button>
|
|
<template #dropdown>
|
|
<el-dropdown-menu>
|
|
<el-dropdown-item command="edit">
|
|
<el-icon><Edit /></el-icon>编辑
|
|
</el-dropdown-item>
|
|
<el-dropdown-item command="delete" divided>
|
|
<el-icon><Delete /></el-icon>删除
|
|
</el-dropdown-item>
|
|
</el-dropdown-menu>
|
|
</template>
|
|
</el-dropdown>
|
|
</div>
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
|
|
<div class="pagination list-pager-bar">
|
|
<el-pagination
|
|
:current-page="pagination.page"
|
|
:page-size="pagination.pageSize"
|
|
:total="pagination.total"
|
|
:page-sizes="[10, 20, 50]"
|
|
layout="total, sizes, prev, pager, next"
|
|
@size-change="
|
|
(val: number) => ((pagination.page = 1), (pagination.pageSize = val), loadData())
|
|
"
|
|
@current-change="(val: number) => ((pagination.page = val), loadData())"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<el-dialog
|
|
v-model="dialogVisible"
|
|
:title="dialogTitle"
|
|
width="640px"
|
|
class="dialog-form-layout"
|
|
align-center
|
|
append-to-body
|
|
modal-class="protocol-dialog-mask"
|
|
destroy-on-close
|
|
:close-on-click-modal="false"
|
|
>
|
|
<el-form
|
|
ref="formRef"
|
|
:model="formData"
|
|
:rules="formRules"
|
|
label-position="top"
|
|
class="biz-dialog-form"
|
|
scroll-to-error
|
|
:scroll-into-view-options="{ behavior: 'smooth', block: 'center' }"
|
|
>
|
|
<div class="form-grid-2">
|
|
<el-form-item label="客户名称" prop="customerName">
|
|
<el-input v-model="formData.customerName" placeholder="必填" />
|
|
</el-form-item>
|
|
<el-form-item label="客户联系人" prop="customerContact">
|
|
<el-input v-model="formData.customerContact" placeholder="必填" />
|
|
</el-form-item>
|
|
<el-form-item label="客户联系方式" prop="customerPhone" class="form-col-span-2">
|
|
<el-input v-model="formData.customerPhone" placeholder="必填" />
|
|
</el-form-item>
|
|
<el-form-item label="备注" class="form-col-span-2">
|
|
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="可选" />
|
|
</el-form-item>
|
|
</div>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button class="btn-ghost" @click="dialogVisible = false">
|
|
<el-icon><Close /></el-icon>
|
|
取消
|
|
</el-button>
|
|
<el-button class="btn-main" type="primary" :loading="submitLoading" @click="handleSubmit">
|
|
<el-icon><Check /></el-icon>
|
|
确定
|
|
</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
|
|
<SystemViewDialog
|
|
v-model:visible="viewVisible"
|
|
:title="viewRow?.customerName || '合作客户详情'"
|
|
:icon="User"
|
|
:meta="viewRow?.createTime ? `创建时间:${viewRow.createTime}` : ''"
|
|
:sections="viewSections"
|
|
width="720px"
|
|
:grid-columns="2"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, reactive, ref } from 'vue'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import {
|
|
Check,
|
|
Close,
|
|
Delete,
|
|
Edit,
|
|
More,
|
|
Plus,
|
|
RefreshLeft,
|
|
Search,
|
|
User,
|
|
View
|
|
} from '@element-plus/icons-vue'
|
|
import {
|
|
fetchCreatePartnerCustomer,
|
|
fetchDeletePartnerCustomer,
|
|
fetchPartnerCustomerList,
|
|
fetchUpdatePartnerCustomer
|
|
} from '@/api/admin'
|
|
import SystemViewDialog from '@/components/business/system-view-dialog/index.vue'
|
|
import { formatDisplayOrDash } from '@/utils/datetime-display'
|
|
import { withFullscreenLoading, fullscreenLoadingText } from '@/utils/fullscreen-loading'
|
|
|
|
defineOptions({ name: 'PartnerCustomerTab' })
|
|
|
|
type PartnerRow = Api.PartnerCustomer.Item
|
|
|
|
const searchForm = reactive({ keyword: '' })
|
|
const tableData = ref<PartnerRow[]>([])
|
|
const selectedRows = ref<PartnerRow[]>([])
|
|
const loading = ref(false)
|
|
const pagination = reactive({ page: 1, pageSize: 10, total: 0 })
|
|
|
|
const dialogVisible = ref(false)
|
|
const dialogTitle = ref('新增合作客户')
|
|
const isEdit = ref(false)
|
|
const submitLoading = ref(false)
|
|
const formRef = ref()
|
|
const editingId = ref<string | null>(null)
|
|
const formData = reactive({
|
|
customerName: '',
|
|
customerContact: '',
|
|
customerPhone: '',
|
|
remark: ''
|
|
})
|
|
const formRules = {
|
|
customerName: [{ required: true, message: '请填写客户名称', trigger: 'blur' }],
|
|
customerContact: [{ required: true, message: '请填写客户联系人', trigger: 'blur' }],
|
|
customerPhone: [{ required: true, message: '请填写客户联系方式', trigger: 'blur' }]
|
|
}
|
|
|
|
const viewVisible = ref(false)
|
|
const viewRow = ref<PartnerRow | null>(null)
|
|
const viewSections = computed(() => {
|
|
const row = viewRow.value
|
|
if (!row) return []
|
|
return [
|
|
{
|
|
title: '基本信息',
|
|
fields: [
|
|
{ label: '客户名称', value: row.customerName },
|
|
{ label: '客户联系人', value: row.customerContact },
|
|
{ label: '客户联系方式', value: row.customerPhone },
|
|
{ label: '创建时间', value: row.createTime },
|
|
{ label: '备注', value: row.remark, span: true }
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
async function loadData() {
|
|
loading.value = true
|
|
try {
|
|
const res: any = await fetchPartnerCustomerList({
|
|
page: pagination.page,
|
|
pageSize: pagination.pageSize,
|
|
keyword: searchForm.keyword || undefined
|
|
})
|
|
const data = res?.data ?? res
|
|
tableData.value = data?.list ?? []
|
|
pagination.total = data?.total ?? 0
|
|
} catch (e) {
|
|
console.error(e)
|
|
tableData.value = []
|
|
pagination.total = 0
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function handleSearch() {
|
|
pagination.page = 1
|
|
loadData()
|
|
}
|
|
|
|
function handleReset() {
|
|
searchForm.keyword = ''
|
|
pagination.page = 1
|
|
loadData()
|
|
}
|
|
|
|
function handleSelectionChange(rows: PartnerRow[]) {
|
|
selectedRows.value = rows
|
|
}
|
|
|
|
function resetForm() {
|
|
formData.customerName = ''
|
|
formData.customerContact = ''
|
|
formData.customerPhone = ''
|
|
formData.remark = ''
|
|
editingId.value = null
|
|
}
|
|
|
|
function handleAdd() {
|
|
isEdit.value = false
|
|
dialogTitle.value = '新增合作客户'
|
|
resetForm()
|
|
dialogVisible.value = true
|
|
}
|
|
|
|
function handleEdit(row: PartnerRow) {
|
|
isEdit.value = true
|
|
dialogTitle.value = '编辑合作客户'
|
|
editingId.value = row.id
|
|
formData.customerName = row.customerName || ''
|
|
formData.customerContact = row.customerContact || ''
|
|
formData.customerPhone = row.customerPhone || ''
|
|
formData.remark = row.remark || ''
|
|
dialogVisible.value = true
|
|
}
|
|
|
|
function handleView(row: PartnerRow) {
|
|
viewRow.value = row
|
|
viewVisible.value = true
|
|
}
|
|
|
|
function handleDropdownCommand(cmd: string, row: PartnerRow) {
|
|
if (cmd === 'edit') handleEdit(row)
|
|
if (cmd === 'delete') handleDelete(row)
|
|
}
|
|
|
|
async function handleSubmit() {
|
|
await formRef.value?.validate()
|
|
submitLoading.value = true
|
|
try {
|
|
const payload = {
|
|
customerName: formData.customerName.trim(),
|
|
customerContact: formData.customerContact.trim(),
|
|
customerPhone: formData.customerPhone.trim(),
|
|
remark: formData.remark.trim() || undefined
|
|
}
|
|
if (isEdit.value && editingId.value) {
|
|
await fetchUpdatePartnerCustomer(editingId.value, payload)
|
|
ElMessage.success('更新成功')
|
|
} else {
|
|
await fetchCreatePartnerCustomer(payload)
|
|
ElMessage.success('创建成功')
|
|
}
|
|
dialogVisible.value = false
|
|
loadData()
|
|
} catch (e: any) {
|
|
if (e !== false && e?.message) {
|
|
// request util already toasts most errors
|
|
}
|
|
} finally {
|
|
submitLoading.value = false
|
|
}
|
|
}
|
|
|
|
async function handleDelete(row: PartnerRow) {
|
|
try {
|
|
await ElMessageBox.confirm(`确定删除合作客户「${row.customerName}」吗?`, '提示', {
|
|
type: 'warning'
|
|
})
|
|
await withFullscreenLoading(() => fetchDeletePartnerCustomer(row.id), {
|
|
text: fullscreenLoadingText.delete
|
|
})
|
|
ElMessage.success('已删除')
|
|
loadData()
|
|
} catch (e) {
|
|
if (e !== 'cancel') console.error(e)
|
|
}
|
|
}
|
|
|
|
async function handleBatchDelete() {
|
|
if (!selectedRows.value.length) return
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
`确定删除选中的 ${selectedRows.value.length} 个合作客户吗?`,
|
|
'提示',
|
|
{ type: 'warning' }
|
|
)
|
|
await withFullscreenLoading(
|
|
async () => {
|
|
for (const row of selectedRows.value) {
|
|
await fetchDeletePartnerCustomer(row.id)
|
|
}
|
|
},
|
|
{ text: fullscreenLoadingText.delete }
|
|
)
|
|
ElMessage.success('已删除')
|
|
selectedRows.value = []
|
|
loadData()
|
|
} catch (e) {
|
|
if (e !== 'cancel') console.error(e)
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
loadData()
|
|
})
|
|
</script>
|