<template>
|
<div class="app-container">
|
<el-form :model="filters" :inline="true">
|
<el-form-item label="申请单号:">
|
<el-input v-model="filters.applyCode" placeholder="请输入申请单号" clearable style="width: 200px;" />
|
</el-form-item>
|
<el-form-item label="客户:">
|
<el-select v-model="filters.customerId" placeholder="请选择客户" clearable style="width: 200px;">
|
<el-option v-for="item in customerList" :key="item.id" :label="item.name" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="状态:">
|
<el-select v-model="filters.status" placeholder="请选择状态" clearable style="width: 150px;">
|
<el-option label="待审核" value="pending" />
|
<el-option label="已审核" value="approved" />
|
<el-option label="已驳回" value="rejected" />
|
<el-option label="已开票" value="invoiced" />
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="getTableData">搜索</el-button>
|
<el-button @click="resetFilters">重置</el-button>
|
</el-form-item>
|
</el-form>
|
<div class="table_list">
|
<div class="actions">
|
<div></div>
|
<div>
|
<el-button type="primary" @click="add" icon="Plus">新增申请</el-button>
|
<el-button @click="handleBatchApply" icon="Document" :disabled="selectedRows.length === 0">批量申请</el-button>
|
</div>
|
</div>
|
<PIMTable
|
rowKey="id"
|
isSelection
|
:column="columns"
|
:tableData="dataList"
|
:page="{
|
current: pagination.currentPage,
|
size: pagination.pageSize,
|
total: pagination.total,
|
}"
|
@selection-change="handleSelectionChange"
|
@pagination="changePage"
|
>
|
<template #amount="{ row }">
|
<span class="text-primary">¥{{ formatMoney(row.amount) }}</span>
|
</template>
|
<template #taxRate="{ row }">
|
<span>{{ row.taxRate }}%</span>
|
</template>
|
<template #status="{ row }">
|
<el-tag :type="getStatusType(row.status)">{{ getStatusLabel(row.status) }}</el-tag>
|
</template>
|
<template #operation="{ row }">
|
<el-button type="primary" link @click="view(row)">查看</el-button>
|
<el-button type="primary" link @click="edit(row)" v-if="row.status === 'pending'">编辑</el-button>
|
<el-button type="success" link @click="handleAudit(row)" v-if="row.status === 'pending'">审核</el-button>
|
<el-button type="warning" link @click="handleInvoice(row)" v-if="row.status === 'approved'">开票</el-button>
|
</template>
|
</PIMTable>
|
</div>
|
|
<FormDialog :title="dialogTitle" v-model="dialogVisible" width="800px" @confirm="submitForm" @cancel="dialogVisible = false">
|
<el-form :model="form" :rules="rules" ref="formRef" label-width="120px">
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="申请单号" prop="applyCode">
|
<el-input v-model="form.applyCode" placeholder="系统自动生成" disabled />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="客户" prop="customerId">
|
<el-select v-model="form.customerId" placeholder="请选择客户" style="width: 100%;" :disabled="isEdit">
|
<el-option v-for="item in customerList" :key="item.id" :label="item.name" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="开票金额" prop="amount">
|
<el-input-number v-model="form.amount" :min="0" :precision="2" style="width: 100%;" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="税率" prop="taxRate">
|
<el-select v-model="form.taxRate" placeholder="请选择税率" style="width: 100%;">
|
<el-option
|
v-for="dict in tax_rate"
|
:key="dict.value"
|
:label="dict.label"
|
:value="Number(dict.value)"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="发票类型" prop="invoiceType">
|
<el-select v-model="form.invoiceType" placeholder="请选择发票类型" style="width: 100%;">
|
<el-option label="增值税专用发票" value="special" />
|
<el-option label="增值税普通发票" value="normal" />
|
<el-option label="电子发票" value="electronic" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="申请日期" prop="applyDate">
|
<el-date-picker v-model="form.applyDate" type="date" placeholder="选择日期" value-format="YYYY-MM-DD" style="width: 100%;" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-form-item label="发票内容" prop="content">
|
<el-input v-model="form.content" type="textarea" :rows="3" placeholder="请输入发票内容" />
|
</el-form-item>
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="请输入备注" />
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<el-button type="primary" @click="submitForm">确定</el-button>
|
<el-button @click="dialogVisible = false">取消</el-button>
|
</template>
|
</FormDialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, onMounted, getCurrentInstance } from "vue";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
import FormDialog from "@/components/Dialog/FormDialog.vue";
|
|
defineOptions({
|
name: "开票申请",
|
});
|
|
const { proxy } = getCurrentInstance();
|
const { tax_rate } = proxy.useDict("tax_rate");
|
|
const filters = reactive({
|
applyCode: "",
|
customerId: "",
|
status: "",
|
});
|
|
const pagination = reactive({
|
currentPage: 1,
|
pageSize: 10,
|
total: 0,
|
});
|
|
const columns = [
|
{ label: "申请单号", prop: "applyCode", width: "150" },
|
{ label: "客户名称", prop: "customerName", width: "180" },
|
{ label: "开票金额", prop: "amount", slot: "amount" },
|
{ label: "税率", prop: "taxRate", slot: "taxRate" },
|
{ label: "发票类型", prop: "invoiceTypeLabel", width: "130" },
|
{ label: "申请日期", prop: "applyDate", width: "120" },
|
{ label: "状态", prop: "status", slot: "status" },
|
{ label: "操作", prop: "operation", slot: "operation", width: "200", fixed: "right" },
|
];
|
|
const dataList = ref([]);
|
const selectedRows = ref([]);
|
const dialogVisible = ref(false);
|
const dialogTitle = ref("");
|
const formRef = ref(null);
|
const isEdit = ref(false);
|
const currentId = ref(null);
|
|
const customerList = [
|
{ id: 1, name: "北京科技有限公司" },
|
{ id: 2, name: "上海贸易公司" },
|
{ id: 3, name: "广州实业有限公司" },
|
{ id: 4, name: "深圳电子公司" },
|
];
|
|
const form = reactive({
|
applyCode: "",
|
customerId: "",
|
amount: 0,
|
taxRate: 13,
|
invoiceType: "special",
|
applyDate: "",
|
content: "",
|
remark: "",
|
});
|
|
const rules = {
|
customerId: [{ required: true, message: "请选择客户", trigger: "change" }],
|
amount: [{ required: true, message: "请输入开票金额", trigger: "blur" }],
|
taxRate: [{ required: true, message: "请选择税率", trigger: "change" }],
|
invoiceType: [{ required: true, message: "请选择发票类型", trigger: "change" }],
|
applyDate: [{ required: true, message: "请选择申请日期", trigger: "change" }],
|
};
|
|
const mockData = [
|
{ id: 1, applyCode: "KP2024001", customerId: 1, customerName: "北京科技有限公司", amount: 5000, taxRate: 13, invoiceType: "special", invoiceTypeLabel: "增值税专用发票", applyDate: "2024-01-15", status: "pending", content: "软件服务费", remark: "" },
|
{ id: 2, applyCode: "KP2024002", customerId: 2, customerName: "上海贸易公司", amount: 8000, taxRate: 13, invoiceType: "normal", invoiceTypeLabel: "增值税普通发票", applyDate: "2024-01-16", status: "approved", content: "商品销售", remark: "" },
|
{ id: 3, applyCode: "KP2024003", customerId: 3, customerName: "广州实业有限公司", amount: 12000, taxRate: 6, invoiceType: "electronic", invoiceTypeLabel: "电子发票", applyDate: "2024-01-18", status: "invoiced", content: "技术服务费", remark: "" },
|
];
|
|
const formatMoney = (value) => {
|
if (value === undefined || value === null) return "0.00";
|
return Number(value).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
};
|
|
const getStatusLabel = (status) => {
|
const map = { pending: "待审核", approved: "已审核", rejected: "已驳回", invoiced: "已开票" };
|
return map[status] || status;
|
};
|
|
const getStatusType = (status) => {
|
const map = { pending: "warning", approved: "success", rejected: "danger", invoiced: "primary" };
|
return map[status] || "";
|
};
|
|
const getTableData = () => {
|
let result = [...mockData];
|
if (filters.applyCode) {
|
result = result.filter(item => item.applyCode.includes(filters.applyCode));
|
}
|
if (filters.customerId) {
|
result = result.filter(item => item.customerId === filters.customerId);
|
}
|
if (filters.status) {
|
result = result.filter(item => item.status === filters.status);
|
}
|
pagination.total = result.length;
|
dataList.value = result.slice((pagination.currentPage - 1) * pagination.pageSize, pagination.currentPage * pagination.pageSize);
|
};
|
|
const resetFilters = () => {
|
filters.applyCode = "";
|
filters.customerId = "";
|
filters.status = "";
|
pagination.currentPage = 1;
|
getTableData();
|
};
|
|
const changePage = ({ current, size }) => {
|
pagination.currentPage = current;
|
pagination.pageSize = size;
|
getTableData();
|
};
|
|
const handleSelectionChange = (selection) => {
|
selectedRows.value = selection;
|
};
|
|
const add = () => {
|
isEdit.value = false;
|
dialogTitle.value = "新增开票申请";
|
Object.assign(form, {
|
applyCode: "KP" + Date.now().toString().slice(-8),
|
customerId: "",
|
amount: 0,
|
taxRate: 13,
|
invoiceType: "special",
|
applyDate: new Date().toISOString().split('T')[0],
|
content: "",
|
remark: "",
|
});
|
dialogVisible.value = true;
|
};
|
|
const edit = (row) => {
|
isEdit.value = true;
|
currentId.value = row.id;
|
dialogTitle.value = "编辑开票申请";
|
Object.assign(form, row);
|
dialogVisible.value = true;
|
};
|
|
const view = (row) => {
|
ElMessage.info(`查看申请单: ${row.applyCode}`);
|
};
|
|
const handleAudit = (row) => {
|
ElMessageBox.confirm("确认审核通过该开票申请吗?", "提示", {
|
confirmButtonText: "通过",
|
cancelButtonText: "驳回",
|
distinguishCancelAndClose: true,
|
type: "warning",
|
}).then(() => {
|
const index = mockData.findIndex(item => item.id === row.id);
|
if (index !== -1) {
|
mockData[index].status = "approved";
|
}
|
ElMessage.success("审核通过");
|
getTableData();
|
}).catch((action) => {
|
if (action === "cancel") {
|
const index = mockData.findIndex(item => item.id === row.id);
|
if (index !== -1) {
|
mockData[index].status = "rejected";
|
}
|
ElMessage.warning("已驳回");
|
getTableData();
|
}
|
});
|
};
|
|
const handleInvoice = (row) => {
|
ElMessageBox.confirm("确认已开具发票?", "提示", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "info",
|
}).then(() => {
|
const index = mockData.findIndex(item => item.id === row.id);
|
if (index !== -1) {
|
mockData[index].status = "invoiced";
|
}
|
ElMessage.success("开票完成");
|
getTableData();
|
});
|
};
|
|
const handleBatchApply = () => {
|
ElMessage.success(`批量申请 ${selectedRows.value.length} 条记录`);
|
};
|
|
const submitForm = () => {
|
formRef.value.validate((valid) => {
|
if (valid) {
|
const customer = customerList.find(item => item.id === form.customerId);
|
const invoiceTypeMap = { special: "增值税专用发票", normal: "增值税普通发票", electronic: "电子发票" };
|
if (isEdit.value) {
|
const index = mockData.findIndex(item => item.id === currentId.value);
|
if (index !== -1) {
|
mockData[index] = { ...mockData[index], ...form, customerName: customer?.name, invoiceTypeLabel: invoiceTypeMap[form.invoiceType] };
|
}
|
ElMessage.success("编辑成功");
|
} else {
|
const newId = mockData.length > 0 ? Math.max(...mockData.map(item => item.id)) + 1 : 1;
|
mockData.push({ id: newId, ...form, customerName: customer?.name, invoiceTypeLabel: invoiceTypeMap[form.invoiceType], status: "pending" });
|
ElMessage.success("新增成功");
|
}
|
dialogVisible.value = false;
|
getTableData();
|
}
|
});
|
};
|
|
onMounted(() => {
|
getTableData();
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.actions {
|
display: flex;
|
justify-content: space-between;
|
margin-bottom: 15px;
|
}
|
|
.text-primary {
|
color: #409eff;
|
font-weight: bold;
|
}
|
</style>
|