364 lines
11 KiB
Vue
364 lines
11 KiB
Vue
<template>
|
|
<div class="panel dialog-list-panel invoice-info-container">
|
|
<div class="list-toolbar">
|
|
<div class="list-toolbar-row">
|
|
<div class="list-toolbar-selected">
|
|
<el-button class="btn-main" type="primary" @click="handleAdd">
|
|
<el-icon><Plus /></el-icon>添加开票信息
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="list-body list-wrap">
|
|
<ListTable table-key="crm-customer-components-invoice-info"
|
|
:data="invoiceInfoList"
|
|
v-loading="loading"
|
|
stripe
|
|
class="list-table"
|
|
empty-text=""
|
|
>
|
|
<el-table-column type="index" label="序号" min-width="68" align="center" header-align="center" />
|
|
<el-table-column
|
|
label="单位名称(章)"
|
|
prop="companyName"
|
|
min-width="180"
|
|
align="center"
|
|
header-align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
label="税号"
|
|
prop="taxNo"
|
|
min-width="180"
|
|
align="center"
|
|
header-align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
label="单位地址"
|
|
prop="companyAddress"
|
|
min-width="200"
|
|
align="center"
|
|
header-align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
label="法定代表人"
|
|
prop="legalRepresentative"
|
|
min-width="120"
|
|
align="center"
|
|
header-align="center"
|
|
/>
|
|
<el-table-column
|
|
label="代理人"
|
|
prop="agent"
|
|
min-width="100"
|
|
align="center"
|
|
header-align="center"
|
|
/>
|
|
<el-table-column
|
|
label="电话/传真"
|
|
prop="phoneFax"
|
|
min-width="130"
|
|
align="center"
|
|
header-align="center"
|
|
/>
|
|
<el-table-column
|
|
label="开户银行"
|
|
prop="bankName"
|
|
min-width="150"
|
|
align="center"
|
|
header-align="center"
|
|
show-overflow-tooltip
|
|
/>
|
|
<el-table-column
|
|
label="账号"
|
|
prop="bankAccount"
|
|
min-width="200"
|
|
align="center"
|
|
header-align="center"
|
|
/>
|
|
<el-table-column label="默认" min-width="80" align="center" header-align="center">
|
|
<template #default="{ row }">
|
|
<el-tag v-if="row.isDefault === '1'" type="success" size="small">是</el-tag>
|
|
<el-tag v-else type="info" size="small">否</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column
|
|
label="操作"
|
|
min-width="260"
|
|
align="center"
|
|
header-align="center"
|
|
fixed="right"
|
|
class-name="col-actions"
|
|
>
|
|
<template #default="{ row }">
|
|
<el-button v-if="row.isDefault !== '1'" link type="primary" @click="handleSetDefault(row)">
|
|
<el-icon><Star /></el-icon>设为默认
|
|
</el-button>
|
|
<el-button link type="primary" @click="handleEdit(row)">
|
|
<el-icon><Edit /></el-icon>编辑
|
|
</el-button>
|
|
<el-button
|
|
link
|
|
type="danger"
|
|
:disabled="!canDeleteByCreator(row)"
|
|
:title="canDeleteByCreator(row) ? '' : CREATOR_DELETE_TIP"
|
|
@click="handleDelete(row)"
|
|
>
|
|
<el-icon><Delete /></el-icon>删除
|
|
</el-button>
|
|
</template>
|
|
</el-table-column>
|
|
</ListTable>
|
|
</div>
|
|
|
|
<el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" class="dialog-form-layout" align-center append-to-body @close="handleClose">
|
|
<el-form ref="formRef" :model="form" :rules="rules" label-position="right" label-width="100px" class="crm-dialog-form">
|
|
<div class="form-grid-2">
|
|
<el-form-item label="单位名称(章)" prop="companyName" class="form-col-span-2">
|
|
<el-input v-model="form.companyName" placeholder="请输入单位名称" maxlength="200" />
|
|
</el-form-item>
|
|
<el-form-item label="税号" prop="taxNo" class="form-col-span-2">
|
|
<el-input v-model="form.taxNo" placeholder="请输入税号" maxlength="50" />
|
|
</el-form-item>
|
|
<el-form-item label="单位地址" prop="companyAddress" class="form-col-span-2">
|
|
<el-input v-model="form.companyAddress" placeholder="请输入单位地址" maxlength="500" />
|
|
</el-form-item>
|
|
<el-form-item label="法定代表人" prop="legalRepresentative">
|
|
<el-input v-model="form.legalRepresentative" placeholder="请输入法定代表人" maxlength="100" />
|
|
</el-form-item>
|
|
<el-form-item label="代理人" prop="agent">
|
|
<el-input v-model="form.agent" placeholder="请输入代理人" maxlength="100" />
|
|
</el-form-item>
|
|
<el-form-item label="电话/传真" prop="phoneFax">
|
|
<el-input v-model="form.phoneFax" placeholder="请输入电话/传真" maxlength="100" />
|
|
</el-form-item>
|
|
<el-form-item label="开户银行" prop="bankName">
|
|
<el-input v-model="form.bankName" placeholder="请输入开户银行" maxlength="200" />
|
|
</el-form-item>
|
|
<el-form-item label="账号" prop="bankAccount" class="form-col-span-2">
|
|
<el-input v-model="form.bankAccount" placeholder="请输入账号" maxlength="100" />
|
|
</el-form-item>
|
|
<el-form-item label="是否默认" prop="isDefault">
|
|
<el-radio-group v-model="form.isDefault">
|
|
<el-radio value="1">是</el-radio>
|
|
<el-radio value="0">否</el-radio>
|
|
</el-radio-group>
|
|
</el-form-item>
|
|
<el-form-item label="备注" prop="remark" class="form-col-span-2">
|
|
<el-input v-model="form.remark" type="textarea" placeholder="请输入备注" maxlength="500" :rows="3" />
|
|
</el-form-item>
|
|
</div>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button @click="handleClose">
|
|
<el-icon><Close /></el-icon>取消
|
|
</el-button>
|
|
<el-button type="primary" :loading="submitLoading" @click="submitForm">
|
|
<el-icon><Check /></el-icon>确定
|
|
</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, watch } from 'vue'
|
|
import { Plus, Edit, Delete, Star, Close, Check } from '@element-plus/icons-vue'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import request from '@/utils/http'
|
|
import { canDeleteByCreator, CREATOR_DELETE_TIP } from '@/utils/creator-delete'
|
|
|
|
interface InvoiceInfoVO {
|
|
id: string | number
|
|
customerId: string | number
|
|
companyName: string
|
|
taxNo?: string
|
|
companyAddress?: string
|
|
legalRepresentative?: string
|
|
agent?: string
|
|
phoneFax?: string
|
|
bankName?: string
|
|
bankAccount?: string
|
|
isDefault: string
|
|
remark?: string
|
|
}
|
|
|
|
interface InvoiceInfoForm {
|
|
id?: string | number
|
|
customerId: string | number | undefined
|
|
companyName: string
|
|
taxNo?: string
|
|
companyAddress?: string
|
|
legalRepresentative?: string
|
|
agent?: string
|
|
phoneFax?: string
|
|
bankName?: string
|
|
bankAccount?: string
|
|
isDefault: string
|
|
remark?: string
|
|
}
|
|
|
|
const props = defineProps<{
|
|
customerId?: number | string
|
|
}>()
|
|
|
|
const loading = ref(false)
|
|
const submitLoading = ref(false)
|
|
const invoiceInfoList = ref<InvoiceInfoVO[]>([])
|
|
|
|
const dialog = ref({
|
|
visible: false,
|
|
title: '',
|
|
})
|
|
|
|
const formRef = ref()
|
|
const form = ref<InvoiceInfoForm>({
|
|
id: undefined,
|
|
customerId: '',
|
|
companyName: '',
|
|
taxNo: '',
|
|
companyAddress: '',
|
|
legalRepresentative: '',
|
|
agent: '',
|
|
phoneFax: '',
|
|
bankName: '',
|
|
bankAccount: '',
|
|
isDefault: '0',
|
|
remark: '',
|
|
})
|
|
|
|
const rules = ref({
|
|
companyName: [{ required: true, message: '单位名称不能为空', trigger: 'blur' }],
|
|
})
|
|
|
|
const getList = async () => {
|
|
if (!props.customerId) return
|
|
loading.value = true
|
|
try {
|
|
const res = await request.post({ url: '/web/crm/invoice-info/by-customer', data: { customerId: props.customerId } })
|
|
const raw = (res as { data?: InvoiceInfoVO[] })?.data ?? res
|
|
invoiceInfoList.value = Array.isArray(raw) ? raw : []
|
|
} catch (error) {
|
|
console.error('获取开票信息失败:', error)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
watch(
|
|
() => props.customerId,
|
|
(newVal) => {
|
|
if (newVal) getList()
|
|
},
|
|
{ immediate: true },
|
|
)
|
|
|
|
const handleAdd = () => {
|
|
reset()
|
|
dialog.value.visible = true
|
|
dialog.value.title = '添加开票信息'
|
|
}
|
|
|
|
const handleEdit = (row: InvoiceInfoVO) => {
|
|
reset()
|
|
form.value = {
|
|
id: row.id,
|
|
customerId: row.customerId,
|
|
companyName: row.companyName,
|
|
taxNo: row.taxNo,
|
|
companyAddress: row.companyAddress,
|
|
legalRepresentative: row.legalRepresentative,
|
|
agent: row.agent,
|
|
phoneFax: row.phoneFax,
|
|
bankName: row.bankName,
|
|
bankAccount: row.bankAccount,
|
|
isDefault: row.isDefault,
|
|
remark: row.remark,
|
|
}
|
|
dialog.value.visible = true
|
|
dialog.value.title = '修改开票信息'
|
|
}
|
|
|
|
const submitForm = () => {
|
|
formRef.value?.validate(async (valid: boolean) => {
|
|
if (valid) {
|
|
submitLoading.value = true
|
|
try {
|
|
form.value.customerId = props.customerId
|
|
if (form.value.id) {
|
|
await request.post({ url: '/web/crm/invoice-info/update', data: form.value })
|
|
ElMessage.success('修改成功')
|
|
} else {
|
|
await request.post({ url: '/web/crm/invoice-info/add', data: form.value })
|
|
ElMessage.success('新增成功')
|
|
}
|
|
dialog.value.visible = false
|
|
await getList()
|
|
} catch (error) {
|
|
console.error('保存失败:', error)
|
|
} finally {
|
|
submitLoading.value = false
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
const handleDelete = async (row: InvoiceInfoVO) => {
|
|
try {
|
|
await ElMessageBox.confirm('是否确认删除该开票信息?', '提示', { type: 'warning' })
|
|
await request.post({ url: '/web/crm/invoice-info/delete', data: { id: String(row.id) } })
|
|
ElMessage.success('删除成功')
|
|
await getList()
|
|
} catch (error) {
|
|
console.error('删除失败:', error)
|
|
}
|
|
}
|
|
|
|
const handleSetDefault = async (row: InvoiceInfoVO) => {
|
|
try {
|
|
await request.post({
|
|
url: '/web/crm/invoice-info/set-default',
|
|
data: { id: String(row.id), customerId: String(row.customerId) },
|
|
})
|
|
ElMessage.success('设置成功')
|
|
await getList()
|
|
} catch (error) {
|
|
console.error('设置失败:', error)
|
|
}
|
|
}
|
|
|
|
const handleClose = () => {
|
|
dialog.value.visible = false
|
|
reset()
|
|
}
|
|
|
|
const reset = () => {
|
|
form.value = {
|
|
id: undefined,
|
|
customerId: props.customerId != null ? String(props.customerId) : '',
|
|
companyName: '',
|
|
taxNo: '',
|
|
companyAddress: '',
|
|
legalRepresentative: '',
|
|
agent: '',
|
|
phoneFax: '',
|
|
bankName: '',
|
|
bankAccount: '',
|
|
isDefault: '0',
|
|
remark: '',
|
|
}
|
|
formRef.value?.resetFields()
|
|
}
|
|
|
|
defineExpose({ getList })
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.invoice-info-container {
|
|
margin: 0;
|
|
}
|
|
</style>
|