<template>
|
<div class="app-container">
|
<div class="search_form">
|
<el-form :model="searchForm"
|
:inline="true">
|
<el-form-item label="车间名称:">
|
<el-input v-model="searchForm.name"
|
placeholder="请输入"
|
clearable
|
prefix-icon="Search"
|
style="width: 200px;"
|
@change="handleQuery" />
|
</el-form-item>
|
<el-form-item label="状态:">
|
<el-select v-model="searchForm.status"
|
placeholder="请选择"
|
clearable
|
style="width: 160px;"
|
@change="handleQuery">
|
<el-option v-for="item in statusOptions"
|
:key="item.value"
|
:label="item.label"
|
:value="item.value" />
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary"
|
@click="handleQuery">搜索</el-button>
|
</el-form-item>
|
</el-form>
|
</div>
|
<div class="table_list">
|
<div style="text-align: right"
|
class="mb10">
|
<el-button type="primary"
|
@click="showNewModal">新增车间</el-button>
|
<el-button type="danger"
|
plain
|
:disabled="selectedRows.length === 0"
|
@click="handleDelete">删除车间</el-button>
|
</div>
|
<PIMTable rowKey="id"
|
:column="tableColumn"
|
:tableData="tableData"
|
:page="page"
|
:isSelection="true"
|
:tableLoading="tableLoading"
|
@selection-change="handleSelectionChange"
|
@pagination="pagination">
|
<template #status="{ row }">
|
<el-tag :type="row.status === 0 ? 'success' : 'info'">
|
{{ row.status === 0 ? "启用" : "停用" }}
|
</el-tag>
|
</template>
|
</PIMTable>
|
</div>
|
|
<!-- 新增/编辑弹窗 -->
|
<el-dialog v-model="dialogVisible"
|
:title="form.id ? '编辑车间' : '新增车间'"
|
width="600px">
|
<el-form ref="formRef"
|
:model="form"
|
:rules="rules"
|
label-width="100px">
|
<el-form-item label="车间名称"
|
prop="name">
|
<el-input v-model="form.name"
|
placeholder="请输入车间名称"
|
maxlength="100" />
|
</el-form-item>
|
<el-form-item label="车间编码"
|
prop="code">
|
<el-input v-model="form.code"
|
placeholder="请输入车间编码"
|
maxlength="50" />
|
</el-form-item>
|
<el-form-item label="负责人"
|
prop="principal">
|
<el-input v-model="form.principal"
|
placeholder="请输入负责人"
|
maxlength="50" />
|
</el-form-item>
|
<el-form-item label="联系电话"
|
prop="contactPhone">
|
<el-input v-model="form.contactPhone"
|
placeholder="请输入联系电话"
|
maxlength="20" />
|
</el-form-item>
|
<el-form-item label="状态"
|
prop="status">
|
<el-radio-group v-model="form.status">
|
<el-radio v-for="item in statusOptions"
|
:key="item.value"
|
:value="item.value">{{ item.label }}</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
<el-form-item label="备注"
|
prop="remark">
|
<el-input v-model="form.remark"
|
type="textarea"
|
:rows="3"
|
placeholder="请输入备注"
|
maxlength="500" />
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button type="primary"
|
@click="handleSubmit">确定</el-button>
|
<el-button @click="dialogVisible = false">取消</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { onMounted, ref, reactive, getCurrentInstance } from "vue";
|
import {
|
listPage,
|
add,
|
update,
|
del,
|
} from "@/api/productionScheduling/workshop.js";
|
|
const { proxy } = getCurrentInstance();
|
|
const statusOptions = [
|
{ label: "启用", value: 0 },
|
{ label: "停用", value: 1 },
|
];
|
|
const tableColumn = ref([
|
{
|
label: "车间名称",
|
prop: "name",
|
},
|
{
|
label: "车间编码",
|
prop: "code",
|
width: "120",
|
},
|
{
|
label: "负责人",
|
prop: "principal",
|
width: "100",
|
},
|
{
|
label: "联系电话",
|
prop: "contactPhone",
|
width: "140",
|
},
|
{
|
label: "状态",
|
prop: "status",
|
dataType: "slot",
|
slot: "status",
|
width: "90",
|
},
|
{
|
label: "备注",
|
prop: "remark",
|
},
|
{
|
label: "更新时间",
|
prop: "updateTime",
|
width: "160",
|
},
|
{
|
dataType: "action",
|
label: "操作",
|
align: "center",
|
fixed: "right",
|
width: 100,
|
operation: [
|
{
|
name: "编辑",
|
type: "text",
|
clickFun: row => {
|
showEditModal(row);
|
},
|
},
|
],
|
},
|
]);
|
const tableData = ref([]);
|
const selectedRows = ref([]);
|
const tableLoading = ref(false);
|
const dialogVisible = ref(false);
|
const formRef = ref(null);
|
const page = reactive({
|
current: 1,
|
size: 100,
|
total: 0,
|
});
|
|
const data = reactive({
|
searchForm: {
|
name: "",
|
status: null,
|
},
|
});
|
const { searchForm } = data;
|
|
const form = reactive({
|
id: null,
|
name: "",
|
code: "",
|
principal: "",
|
contactPhone: "",
|
status: 0,
|
remark: "",
|
});
|
|
const rules = {
|
name: [{ required: true, message: "请输入车间名称", trigger: "blur" }],
|
};
|
|
/** 搜索按钮操作 */
|
const handleQuery = () => {
|
page.current = 1;
|
getList();
|
};
|
|
const pagination = obj => {
|
page.current = obj.page;
|
page.size = obj.limit;
|
getList();
|
};
|
|
const getList = () => {
|
tableLoading.value = true;
|
const params = { ...searchForm, ...page };
|
listPage(params)
|
.then(res => {
|
tableLoading.value = false;
|
tableData.value = res.data.records;
|
page.total = res.data.total;
|
})
|
.catch(() => {
|
tableLoading.value = false;
|
});
|
};
|
|
// 表格选择数据
|
const handleSelectionChange = selection => {
|
selectedRows.value = selection;
|
};
|
|
const resetForm = () => {
|
form.id = null;
|
form.name = "";
|
form.code = "";
|
form.principal = "";
|
form.contactPhone = "";
|
form.status = 0;
|
form.remark = "";
|
};
|
|
// 打开新增弹框
|
const showNewModal = () => {
|
resetForm();
|
dialogVisible.value = true;
|
};
|
|
const showEditModal = row => {
|
resetForm();
|
Object.assign(form, JSON.parse(JSON.stringify(row)));
|
dialogVisible.value = true;
|
};
|
|
const handleSubmit = () => {
|
formRef.value.validate(valid => {
|
if (!valid) return;
|
const request = form.id ? update(form) : add(form);
|
request.then(() => {
|
proxy.$modal.msgSuccess(form.id ? "修改成功" : "新增成功");
|
dialogVisible.value = false;
|
getList();
|
});
|
});
|
};
|
|
// 批量删除
|
const handleDelete = () => {
|
const names = selectedRows.value.map(item => item.name);
|
const ids = selectedRows.value.map(item => item.id);
|
proxy.$modal
|
.confirm(
|
`是否确认删除车间"${names[0]}"${names.length > 1 ? `等${names.length}条数据` : ""}?`
|
)
|
.then(function () {
|
return del(ids.join(","));
|
})
|
.then(() => {
|
getList();
|
proxy.$modal.msgSuccess("删除成功");
|
})
|
.catch(() => {});
|
};
|
|
onMounted(() => {
|
getList();
|
});
|
</script>
|
|
<style scoped></style>
|