Files
estate/src/views/system/inspection/Item/index2.vue
2026-09-20 08:57:53 +08:00

207 lines
6.3 KiB
Vue

<template>
<div class="h-full flex flex-col p-2">
<Pageheader></Pageheader>
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :inline="true" :model="queryParams" @submit.prevent="handleQuery">
<el-form-item label="项目名称" prop="itemName">
<el-input v-model="queryParams.itemName" clearable maxlength="20" placeholder="请输入项目名称" @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleQuery">搜索</el-button>
<el-button @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</transition>
<el-card class="flex-1" shadow="never">
<template #header>
<el-row :gutter="10" class="mb8">
<right-toolbar
:disable-delete="multiple"
:disable-edit="single"
:show-add="checkPermi(['inspection:item:add'])"
:show-delete="checkPermi(['inspection:item:remove'])"
:show-edit="checkPermi(['inspection:item:edit'])"
@update:add="handleAdd"
@update:edit="handleUpdate()"
@update:delete="handleDelete()"
></right-toolbar>
</el-row>
</template>
<el-table v-loading="loading" :data="itemList" border @selection-change="handleSelectionChange">
<el-table-column align="center" type="selection" width="55" />
<el-table-column align="center" label="项目名称" prop="itemName" width="200" />
<el-table-column align="center" label="巡检标准" prop="inspectionStandard" />
<el-table-column align="center" label="状态" prop="status" width="200">
<template #default="scope">
<el-switch
v-model="scope.row.status"
active-value="0"
inactive-value="1"
@change="(val: string) => handleChange(val, scope.row.id)"
></el-switch>
</template>
</el-table-column>
<el-table-column align="center" label="添加人" prop="createByName" width="150" />
<el-table-column align="center" label="添加时间" prop="createTime" width="180" />
<el-table-column align="center" class-name="small-padding fixed-width" label="操作">
<template #default="scope">
<el-button v-has-permi="['inspection:item:edit']" link type="primary" @click="handleUpdate(scope.row)">编辑</el-button>
<el-button v-has-permi="['inspection:item:remove']" link type="primary" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" v-model:limit="queryParams.pageSize" v-model:page="queryParams.pageNum" :total="total" @pagination="getList" />
</el-card>
</div>
</template>
<script lang="ts" name="Item" setup>
import { listItem, delItem, updateItemStatus } from '@/api/system/InspectionItem';
import { ItemVO, ItemQuery, ItemForm } from '@/api/system/InspectionItem/type';
import { checkPermi } from '@/utils/permission';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const itemList = ref<ItemVO[]>([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const initFormData: ItemForm = {
id: undefined,
itemName: undefined,
itemCode: undefined,
inspectionStandard: undefined,
category: undefined,
description: undefined,
defaultValue: undefined,
inputType: undefined,
options: undefined,
isRequired: undefined,
status: undefined,
remark: undefined
};
const data = reactive<PageData<ItemForm, ItemQuery>>({
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
itemName: undefined,
itemCode: undefined,
inspectionStandard: undefined,
category: undefined,
description: undefined,
defaultValue: undefined,
inputType: undefined,
options: undefined,
isRequired: undefined,
status: undefined,
params: {}
},
rules: {
id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }],
itemName: [{ required: true, message: '项目名称不能为空', trigger: 'blur' }]
}
});
const { queryParams } = toRefs(data);
/** 查询巡检项目列表 */
const getList = async () => {
loading.value = true;
listItem(queryParams.value)
.then((res) => {
itemList.value = res.rows;
total.value = res.total;
})
.finally(() => {
loading.value = false;
});
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
handleQuery();
};
/** 多选框选中数据 */
const handleSelectionChange = (selection: ItemVO[]) => {
ids.value = selection.map((item) => item.id);
single.value = selection.length != 1;
multiple.value = !selection.length;
};
const router = useRouter();
/** 新增按钮操作 */
const handleAdd = () => {
router.push({
path: '/inspection/addItem'
});
};
/** 修改按钮操作 */
const handleUpdate = (row?: ItemVO) => {
const _ids = row?.id || ids.value[0];
router.push({
path: '/inspection/editItem',
query: {
id: _ids
}
});
};
const handleChange = (value: string, id: string) => {
updateItemStatus({
id,
status: value
})
.then(() => {
proxy?.$modal.msgSuccess('状态修改成功');
getList();
})
.catch(() => {
proxy?.$modal.msgError('状态修改失败,请稍后再试');
getList();
});
};
/** 删除按钮操作 */
const handleDelete = async (row?: ItemVO) => {
const _ids = row?.id || ids.value;
await proxy?.$modal.confirm('是否确认删除?').finally(() => (loading.value = false));
await delItem(_ids);
proxy?.$modal.msgSuccess('删除成功');
await getList();
};
onMounted(() => {
getList();
});
</script>
<style lang="scss" scoped>
.el-table {
height: calc(100% - 80px);
}
</style>