增加单位功能
This commit is contained in:
@@ -90,8 +90,17 @@
|
||||
<el-table-column label="备注" min-width="120" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.remark || "-" }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="80" align="center" fixed="right">
|
||||
<el-table-column label="操作" width="150" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-if="!row.receipt_url"
|
||||
link
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="openReceipt(row)"
|
||||
>
|
||||
补回执
|
||||
</el-button>
|
||||
<el-tooltip
|
||||
:disabled="Number((planOf(row.payback_id) || {}).status) !== 2"
|
||||
content="所属回款计划已完成(回款已收齐),不允许删除回款记录"
|
||||
@@ -192,6 +201,35 @@
|
||||
<el-button type="primary" :loading="receiveSaving" @click="submitReceive">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 补传回款回执:针对已登记但漏传回执的回款记录 -->
|
||||
<el-dialog v-model="receiptVisible" title="补传回款回执" width="460px">
|
||||
<el-form :model="receiptForm" label-width="90px">
|
||||
<el-form-item label="流水回执">
|
||||
<div class="receipt-block">
|
||||
<el-upload
|
||||
:show-file-list="false"
|
||||
:http-request="handleReceiptFileUpload"
|
||||
:disabled="receiptUploading"
|
||||
accept=".jpg,.jpeg,.png,.pdf,.doc,.docx,.xls,.xlsx"
|
||||
>
|
||||
<el-button :icon="Upload" :loading="receiptUploading" size="small">上传流水回执</el-button>
|
||||
</el-upload>
|
||||
<div v-if="receiptForm.receipt_url" class="receipt-file">
|
||||
<el-link type="primary" :href="receiptForm.receipt_url" target="_blank" :underline="false">
|
||||
<el-icon><Document /></el-icon>
|
||||
<span class="receipt-name">{{ receiptForm.receipt_name || "流水回执" }}</span>
|
||||
</el-link>
|
||||
<el-button link type="danger" size="small" :icon="Delete" @click="clearReceiptForm">移除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="receiptVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="receiptUploading" @click="submitReceipt">保存回执</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -203,6 +241,7 @@ import {
|
||||
getPaybackList,
|
||||
getPaybackRecordList,
|
||||
createPaybackRecord,
|
||||
updatePaybackRecord,
|
||||
deletePaybackRecord,
|
||||
} from "@/api/crmPayback";
|
||||
import { uploadFile } from "@/api/file";
|
||||
@@ -404,6 +443,65 @@ function clearReceipt() {
|
||||
receiveForm.receipt_name = "";
|
||||
}
|
||||
|
||||
/* ---------------------------- 补传回款回执(事后补凭证) ---------------------------- */
|
||||
const receiptVisible = ref(false);
|
||||
const receiptUploading = ref(false);
|
||||
const receiptForm = reactive({ id: null, receipt_url: "", receipt_name: "" });
|
||||
|
||||
/** 打开补回执:仅针对未上传回执的回款记录 */
|
||||
function openReceipt(row) {
|
||||
receiptForm.id = row.id;
|
||||
receiptForm.receipt_url = "";
|
||||
receiptForm.receipt_name = "";
|
||||
receiptVisible.value = true;
|
||||
}
|
||||
|
||||
async function handleReceiptFileUpload(options) {
|
||||
const file = options.file;
|
||||
receiptUploading.value = true;
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
const res = await uploadFile(fd);
|
||||
const data = res?.data || {};
|
||||
receiptForm.receipt_url = data.url || "";
|
||||
receiptForm.receipt_name = data.name || file.name;
|
||||
ElMessage.success("上传成功");
|
||||
} catch (e) {
|
||||
ElMessage.error(e.message || "上传失败");
|
||||
} finally {
|
||||
receiptUploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function clearReceiptForm() {
|
||||
receiptForm.receipt_url = "";
|
||||
receiptForm.receipt_name = "";
|
||||
}
|
||||
|
||||
async function submitReceipt() {
|
||||
if (!receiptForm.id) return;
|
||||
if (!receiptForm.receipt_url) {
|
||||
ElMessage.warning("请先上传回执文件");
|
||||
return;
|
||||
}
|
||||
receiptUploading.value = true;
|
||||
try {
|
||||
await updatePaybackRecord(receiptForm.id, {
|
||||
receipt_url: receiptForm.receipt_url,
|
||||
receipt_name: receiptForm.receipt_name,
|
||||
});
|
||||
ElMessage.success("回执已补传");
|
||||
receiptVisible.value = false;
|
||||
await fetchRecords();
|
||||
emit("saved");
|
||||
} catch (e) {
|
||||
ElMessage.error(e.message || "补传失败");
|
||||
} finally {
|
||||
receiptUploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function submitReceive() {
|
||||
if (!receiveForm.payback_id) {
|
||||
ElMessage.warning("请选择回款计划");
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h2>回款管理</h2>
|
||||
<p>针对于合同的回款计划创建与回款明细跟踪(点击「详情」登记一笔笔回款)</p>
|
||||
<p>针对于合同的回款计划创建与回款明细跟踪</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<el-button :icon="Refresh" @click="fetchList">刷新</el-button>
|
||||
@@ -163,6 +163,15 @@
|
||||
>
|
||||
回执
|
||||
</el-link>
|
||||
<el-button
|
||||
v-else
|
||||
link
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="openReceipt(row)"
|
||||
>
|
||||
补回执
|
||||
</el-button>
|
||||
<el-tooltip
|
||||
:disabled="Number(row.__planStatus) !== 2"
|
||||
content="所属回款计划已完成(回款已收齐),不允许删除回款记录"
|
||||
@@ -210,14 +219,44 @@
|
||||
@delete="handleDetailDelete"
|
||||
@refresh="fetchList"
|
||||
/>
|
||||
|
||||
<!-- 补传回款回执:针对列表里已登记但漏传回执的回款记录 -->
|
||||
<el-dialog v-model="receiptVisible" title="补传回款回执" width="460px">
|
||||
<el-form :model="receiptForm" label-width="90px">
|
||||
<el-form-item label="流水回执">
|
||||
<div class="receipt-block">
|
||||
<el-upload
|
||||
:show-file-list="false"
|
||||
:http-request="handleReceiptFileUpload"
|
||||
:disabled="receiptUploading"
|
||||
accept=".jpg,.jpeg,.png,.pdf,.doc,.docx,.xls,.xlsx"
|
||||
>
|
||||
<el-button :icon="Upload" :loading="receiptUploading" size="small">上传流水回执</el-button>
|
||||
</el-upload>
|
||||
<div v-if="receiptForm.receipt_url" class="receipt-file">
|
||||
<el-link type="primary" :href="receiptForm.receipt_url" target="_blank" :underline="false">
|
||||
<el-icon><Document /></el-icon>
|
||||
<span class="receipt-name">{{ receiptForm.receipt_name || "流水回执" }}</span>
|
||||
</el-link>
|
||||
<el-button link type="danger" size="small" :icon="Delete" @click="clearReceiptForm">移除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="receiptVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="receiptUploading" @click="submitReceipt">保存回执</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from "vue";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { Plus, Search, Refresh } from "@element-plus/icons-vue";
|
||||
import { getPaybackList, deletePayback, deletePaybackRecord } from "@/api/crmPayback";
|
||||
import { Plus, Search, Refresh, Upload, Delete, Document } from "@element-plus/icons-vue";
|
||||
import { getPaybackList, deletePayback, deletePaybackRecord, updatePaybackRecord } from "@/api/crmPayback";
|
||||
import { uploadFile } from "@/api/file";
|
||||
import PaybackCreate from "./components/create.vue";
|
||||
import PaybackDetail from "./components/detail.vue";
|
||||
import {
|
||||
@@ -362,6 +401,64 @@ async function handleDeleteRecord(row) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------- 补传回款回执(事后补凭证) ---------------------------- */
|
||||
const receiptVisible = ref(false);
|
||||
const receiptUploading = ref(false);
|
||||
const receiptForm = reactive({ id: null, receipt_url: "", receipt_name: "" });
|
||||
|
||||
/** 打开补回执:仅针对未上传回执的回款记录 */
|
||||
function openReceipt(row) {
|
||||
receiptForm.id = row.id;
|
||||
receiptForm.receipt_url = "";
|
||||
receiptForm.receipt_name = "";
|
||||
receiptVisible.value = true;
|
||||
}
|
||||
|
||||
async function handleReceiptFileUpload(options) {
|
||||
const file = options.file;
|
||||
receiptUploading.value = true;
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file);
|
||||
const res = await uploadFile(fd);
|
||||
const data = res?.data || {};
|
||||
receiptForm.receipt_url = data.url || "";
|
||||
receiptForm.receipt_name = data.name || file.name;
|
||||
ElMessage.success("上传成功");
|
||||
} catch (e) {
|
||||
ElMessage.error(e.message || "上传失败");
|
||||
} finally {
|
||||
receiptUploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function clearReceiptForm() {
|
||||
receiptForm.receipt_url = "";
|
||||
receiptForm.receipt_name = "";
|
||||
}
|
||||
|
||||
async function submitReceipt() {
|
||||
if (!receiptForm.id) return;
|
||||
if (!receiptForm.receipt_url) {
|
||||
ElMessage.warning("请先上传回执文件");
|
||||
return;
|
||||
}
|
||||
receiptUploading.value = true;
|
||||
try {
|
||||
await updatePaybackRecord(receiptForm.id, {
|
||||
receipt_url: receiptForm.receipt_url,
|
||||
receipt_name: receiptForm.receipt_name,
|
||||
});
|
||||
ElMessage.success("回执已补传");
|
||||
receiptVisible.value = false;
|
||||
fetchList();
|
||||
} catch (e) {
|
||||
ElMessage.error(e.message || "补传失败");
|
||||
} finally {
|
||||
receiptUploading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchList);
|
||||
</script>
|
||||
|
||||
|
||||
@@ -50,8 +50,15 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="单位" prop="unit">
|
||||
<el-select v-model="form.unit" filterable allow-create clearable placeholder="请选择" style="width: 100%">
|
||||
<el-option v-for="i in PRODUCT_UNIT_OPTIONS" :key="i.value" :label="i.label" :value="i.value" />
|
||||
<el-select
|
||||
v-model="form.unit"
|
||||
filterable
|
||||
allow-create
|
||||
clearable
|
||||
placeholder="请选择或输入单位"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option v-for="i in unitOptions" :key="i" :label="i" :value="i" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@@ -65,7 +72,7 @@
|
||||
<el-button type="primary" link @click="devVisible = true">
|
||||
📁 编辑模块树({{ (form.dev_tree || []).length }} 项 · ¥{{ formatMoney(treeSellTotal(form.dev_tree, form.dev_unit_price)) }})
|
||||
</el-button>
|
||||
<div class="dev-tip">叶子模块只填「人天」,人天单价统一;父级自动汇总金额</div>
|
||||
<!-- <div class="dev-tip">叶子模块只填「人天」,人天单价统一;父级自动汇总金额</div> -->
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8" v-if="form.line_type === 'product'">
|
||||
@@ -122,6 +129,7 @@ import { ref, reactive, watch } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { createProduct, updateProduct } from "@/api/crmProduct";
|
||||
import { getProductCategoryList } from "@/api/crmProductCategory";
|
||||
import { getUnitList } from "@/api/crmUnit";
|
||||
import { PRODUCT_STATUS_OPTIONS, PRODUCT_UNIT_OPTIONS, formatMoney } from "../../dict";
|
||||
import { treeSellTotal } from "../../contract/components/utils";
|
||||
import DevModuleTree from "../../contract/components/DevModuleTree.vue";
|
||||
@@ -137,6 +145,7 @@ const submitting = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const internalId = ref(null);
|
||||
const categoryOptions = ref([]);
|
||||
const unitOptions = ref([]);
|
||||
const devVisible = ref(false);
|
||||
|
||||
const defaultForm = () => ({
|
||||
@@ -205,6 +214,7 @@ watch(
|
||||
Object.assign(form, defaultForm());
|
||||
}
|
||||
fetchCategories();
|
||||
fetchUnits();
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -219,6 +229,27 @@ async function fetchCategories() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 单位下拉合并:单位设置中的启用项 + 内置默认单位 + 当前产品的历史单位值 */
|
||||
function mergeUnitOptions(names) {
|
||||
const all = (names || []).filter(Boolean);
|
||||
PRODUCT_UNIT_OPTIONS.forEach((i) => {
|
||||
if (!all.includes(i.value)) all.push(i.value);
|
||||
});
|
||||
if (form.unit && !all.includes(form.unit)) all.push(form.unit);
|
||||
return all;
|
||||
}
|
||||
|
||||
/** 加载计量单位(取自「基本设置 - 单位设置」,取启用中的单位) */
|
||||
async function fetchUnits() {
|
||||
try {
|
||||
const res = await getUnitList({ page: 1, pageSize: 200, status: 1 });
|
||||
const names = (res?.data?.list || []).map((i) => i.name);
|
||||
unitOptions.value = mergeUnitOptions(names);
|
||||
} catch (e) {
|
||||
unitOptions.value = mergeUnitOptions([]);
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
emit("update:visible", false);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<div class="crm-page">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h2>基本设置</h2>
|
||||
<p>维护 CRM 各模块的基础数据,设置后立即在对应业务表单中生效</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-grid">
|
||||
<div class="setting-card" @click="go('/apps/crm/setting/unit')">
|
||||
<div class="card-icon">
|
||||
<el-icon><Box /></el-icon>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="card-title">单位设置</div>
|
||||
<div class="card-desc">维护产品、报价等业务使用的计量单位(套 / 台 / 个 …)</div>
|
||||
</div>
|
||||
<el-icon class="card-arrow"><ArrowRight /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useRouter } from "vue-router";
|
||||
import { Box, ArrowRight } from "@element-plus/icons-vue";
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
function go(path) {
|
||||
router.push(path);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped src="../styles/crm-page.less"></style>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.setting-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.setting-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
background: var(--el-bg-color);
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s, box-shadow 0.2s;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--el-color-primary-light-5);
|
||||
box-shadow: 0 2px 12px 0 var(--el-color-primary-light-9);
|
||||
|
||||
.card-arrow {
|
||||
color: var(--el-color-primary);
|
||||
transform: translateX(2px);
|
||||
}
|
||||
}
|
||||
|
||||
.card-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 6px;
|
||||
font-size: 20px;
|
||||
color: var(--el-color-primary);
|
||||
background: var(--el-color-primary-light-9);
|
||||
}
|
||||
|
||||
.card-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
.card-title {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.card-desc {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.card-arrow {
|
||||
color: var(--el-text-color-placeholder);
|
||||
transition: color 0.2s, transform 0.2s;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,126 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:model-value="visible"
|
||||
:title="isEdit ? '编辑单位' : '新增单位'"
|
||||
width="520px"
|
||||
:close-on-click-modal="false"
|
||||
@update:model-value="handleClose"
|
||||
@opened="handleOpened"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="90px" label-position="right">
|
||||
<el-form-item label="单位名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="如:套 / 台 / 个 / 人天" maxlength="20" />
|
||||
</el-form-item>
|
||||
<el-form-item label="单位编码" prop="code">
|
||||
<el-input v-model="form.code" placeholder="选填,如:SET / PCS" maxlength="50" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序" prop="sort">
|
||||
<el-input-number v-model="form.sort" :min="0" :max="9999" :controls="false" style="width: 140px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="form.status" placeholder="请选择" style="width: 100%">
|
||||
<el-option v-for="i in PRODUCT_STATUS_OPTIONS" :key="i.value" :label="i.label" :value="Number(i.value)" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入备注(选填)" maxlength="255" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="handleClose">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, watch } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { createUnit, updateUnit } from "@/api/crmUnit";
|
||||
import { PRODUCT_STATUS_OPTIONS } from "../../../dict";
|
||||
|
||||
const props = defineProps({
|
||||
visible: { type: Boolean, default: false },
|
||||
editData: { type: Object, default: null },
|
||||
});
|
||||
const emit = defineEmits(["update:visible", "success"]);
|
||||
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentId = ref(null);
|
||||
|
||||
const defaultForm = () => ({
|
||||
name: "",
|
||||
code: "",
|
||||
sort: 0,
|
||||
status: 1,
|
||||
remark: "",
|
||||
});
|
||||
|
||||
const form = reactive(defaultForm());
|
||||
|
||||
const rules = {
|
||||
name: [{ required: true, message: "请输入单位名称", trigger: "blur" }],
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(val) => {
|
||||
if (!val) return;
|
||||
if (props.editData) {
|
||||
isEdit.value = true;
|
||||
currentId.value = props.editData.id;
|
||||
Object.assign(form, defaultForm(), props.editData);
|
||||
form.status = Number(props.editData.status);
|
||||
if (isNaN(form.status)) form.status = 1;
|
||||
form.sort = Number(props.editData.sort) || 0;
|
||||
} else {
|
||||
isEdit.value = false;
|
||||
currentId.value = null;
|
||||
Object.assign(form, defaultForm());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function handleClose() {
|
||||
emit("update:visible", false);
|
||||
}
|
||||
|
||||
function handleOpened() {
|
||||
formRef.value?.clearValidate();
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return;
|
||||
try {
|
||||
await formRef.value.validate();
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
try {
|
||||
const payload = {
|
||||
name: String(form.name || "").trim(),
|
||||
code: String(form.code || "").trim(),
|
||||
sort: Number(form.sort) || 0,
|
||||
status: Number(form.status),
|
||||
remark: form.remark || "",
|
||||
};
|
||||
if (isEdit.value) {
|
||||
await updateUnit(currentId.value, payload);
|
||||
ElMessage.success("更新成功");
|
||||
} else {
|
||||
await createUnit(payload);
|
||||
ElMessage.success("创建成功");
|
||||
}
|
||||
emit("success");
|
||||
handleClose();
|
||||
} catch (e) {
|
||||
ElMessage.error(e.message || "操作失败");
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,175 @@
|
||||
<template>
|
||||
<div class="crm-page">
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h2>单位设置</h2>
|
||||
<p>维护产品、报价等业务使用的计量单位,产品表单的「单位」下拉取自本表</p>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<el-button :icon="Refresh" @click="fetchList">刷新</el-button>
|
||||
<el-button :icon="RefreshLeft" @click="handleInitDefault">恢复默认单位</el-button>
|
||||
<el-button type="primary" :icon="Plus" @click="openCreate">新增单位</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="filter-bar">
|
||||
<el-form :inline="true" :model="filters" @submit.prevent>
|
||||
<el-form-item>
|
||||
<el-input
|
||||
v-model="filters.keyword"
|
||||
clearable
|
||||
placeholder="搜索单位名称 / 编码"
|
||||
:prefix-icon="Search"
|
||||
style="width: 240px"
|
||||
@keyup.enter="handleSearch"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="filters.status" clearable placeholder="全部" style="width: 120px">
|
||||
<el-option v-for="i in PRODUCT_STATUS_OPTIONS" :key="i.value" :label="i.label" :value="i.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :icon="Search" @click="handleSearch">查询</el-button>
|
||||
<el-button :icon="Refresh" @click="resetFilters">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<div class="table-container" v-loading="loading">
|
||||
<el-table :data="tableData" stripe border row-key="id">
|
||||
<el-table-column prop="name" label="单位名称" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="code" label="单位编码" width="140" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.code || "-" }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="sort" label="排序" width="90" align="center" />
|
||||
<el-table-column label="状态" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="productStatusTag(row.status)" size="small">{{ productStatusText(row.status) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="引用数" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.used_count" type="info" size="small" effect="plain">{{ row.used_count }} 个产品</el-tag>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.remark || "-" }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="160" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" size="small" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<template #empty><el-empty description="暂无单位" :image-size="80" /></template>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSearch"
|
||||
@current-change="fetchList"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UnitEdit v-model:visible="dialogVisible" :edit-data="currentRow" @success="fetchList" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from "vue";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { Plus, Search, Refresh, RefreshLeft } from "@element-plus/icons-vue";
|
||||
import { getUnitList, deleteUnit, initDefaultUnits } from "@/api/crmUnit";
|
||||
import UnitEdit from "./components/edit.vue";
|
||||
import { PRODUCT_STATUS_OPTIONS, productStatusText, productStatusTag } from "../../dict";
|
||||
|
||||
const loading = ref(false);
|
||||
const tableData = ref([]);
|
||||
const dialogVisible = ref(false);
|
||||
const currentRow = ref(null);
|
||||
|
||||
const filters = reactive({ keyword: "", status: "" });
|
||||
const pagination = reactive({ page: 1, pageSize: 20, total: 0 });
|
||||
|
||||
onMounted(() => {
|
||||
fetchList();
|
||||
});
|
||||
|
||||
async function fetchList() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await getUnitList({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
...filters,
|
||||
});
|
||||
tableData.value = res?.data?.list || [];
|
||||
pagination.total = res?.data?.total || 0;
|
||||
} catch (e) {
|
||||
tableData.value = [];
|
||||
pagination.total = 0;
|
||||
ElMessage.error(e.message || "查询失败");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
pagination.page = 1;
|
||||
fetchList();
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
filters.keyword = "";
|
||||
filters.status = "";
|
||||
handleSearch();
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
currentRow.value = null;
|
||||
dialogVisible.value = true;
|
||||
}
|
||||
|
||||
function openEdit(row) {
|
||||
currentRow.value = { ...row };
|
||||
dialogVisible.value = true;
|
||||
}
|
||||
|
||||
/** 补齐缺失的系统默认单位(已存在的不会被覆盖) */
|
||||
async function handleInitDefault() {
|
||||
try {
|
||||
await ElMessageBox.confirm("将补充缺失的默认单位(套 / 台 / 个 …),已存在的单位不会被修改。", "恢复默认单位", {
|
||||
type: "warning",
|
||||
});
|
||||
const res = await initDefaultUnits();
|
||||
const added = res?.data?.added || 0;
|
||||
ElMessage.success(added ? `已补充 ${added} 个单位` : "默认单位已齐全");
|
||||
fetchList();
|
||||
} catch (e) {
|
||||
if (e !== "cancel") ElMessage.error(e.message || "操作失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(row) {
|
||||
const used = Number(row.used_count) || 0;
|
||||
const tip = used ? `该单位已被 ${used} 个产品引用,删除后产品中的历史单位不受影响。` : "删除后不可恢复。";
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除单位「${row.name}」吗?${tip}`, "删除确认", { type: "warning" });
|
||||
await deleteUnit(row.id);
|
||||
ElMessage.success("删除成功");
|
||||
fetchList();
|
||||
} catch (e) {
|
||||
if (e !== "cancel") ElMessage.error(e.message || "删除失败");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped src="../../styles/crm-page.less"></style>
|
||||
Reference in New Issue
Block a user