Files
estate/src/views/system/inspection/Plan/index.vue
2026-09-10 16:12:22 +08:00

211 lines
6.7 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" label-width="100px" @submit.prevent="handleQuery">
<el-form-item label="巡检计划名称" prop="planName">
<el-input v-model="queryParams.planName" 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:plan:add'])"
:show-delete="checkPermi(['inspection:plan:remove'])"
:show-edit="checkPermi(['inspection:plan:edit'])"
@update:add="handleAdd"
@update:edit="handleUpdate()"
@update:delete="handleDelete()"
></right-toolbar>
</el-row>
</template>
<el-table v-loading="loading" :data="planList" border @selection-change="handleSelectionChange">
<el-table-column align="center" type="selection" width="55" />
<el-table-column align="center" label="巡检计划名称" prop="planName" />
<el-table-column align="center" label="巡检路线名称" prop="routeNames" />
<!-- <el-table-column label="执行周期" align="center" prop="executeCycle" /> -->
<el-table-column align="center" label="执行星期">
<template #default="scope">
<span v-for="(item, index) in scope.row.executeDayNames" :key="index" class="pl-5px">{{ numToWeek(item) }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="任务时间" prop="taskTime" />
<el-table-column align="center" label="状态" prop="status" width="150">
<template #default="scope">
<el-switch
v-model="scope.row.status"
active-value="0"
inactive-value="1"
@change="(val: string) => handleChangeStatus(scope.row.id, val)"
></el-switch>
<!-- 1关闭 0开启 -->
</template>
</el-table-column>
<el-table-column align="center" class-name="small-padding fixed-width" fixed="right" label="操作" width="110">
<template #default="scope">
<el-button v-has-permi="['inspection:plan:edit']" link type="primary" @click="handleUpdate(scope.row)">编辑</el-button>
<el-button v-has-permi="['inspection:plan: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="Plan" setup>
import { listPlan, delPlan, changePlanStatus } from '@/api/system/InspectionPlan';
import { PlanVO, PlanQuery, PlanForm } from '@/api/system/InspectionPlan/type';
import { checkPermi } from '@/utils/permission';
import { numToWeek } from '@/utils/time';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
interface planListType extends PlanVO {
routeNames?: string;
inspectorNames?: string;
executeDayNames?: number[];
}
const planList = ref<planListType[]>([]);
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: PlanForm = {
id: undefined,
planName: undefined,
inspectorIds: undefined,
executeCycle: undefined,
taskTime: undefined,
remindTime: undefined,
inspectSetting: undefined,
routeIds: undefined,
status: undefined,
remark: undefined,
executeDay: undefined
};
const data = reactive<PageData<PlanForm, PlanQuery>>({
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
planName: undefined,
inspectorIds: undefined,
executeCycle: undefined,
taskTime: undefined,
remindTime: undefined,
inspectSetting: undefined,
routeIds: undefined,
status: undefined,
executeDay: undefined
},
rules: {}
});
const { queryParams } = toRefs(data);
/** 查询巡检计划列表 */
const getList = async () => {
loading.value = true;
listPlan(queryParams.value)
.then((res) => {
planList.value = res.rows;
planList.value.forEach((item) => {
item.routeNames = item.routeList.map((item) => item.routeName).join(',');
item.executeDayNames = item.executeDay
.split(',')
.sort((a, b) => Number(a) - Number(b))
.map((item) => Number(item));
});
total.value = res.total;
})
.finally(() => {
loading.value = false;
});
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
handleQuery();
};
/** 多选框选中数据 */
const handleSelectionChange = (selection: PlanVO[]) => {
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/addPlan'
});
};
/** 修改按钮操作 */
const handleUpdate = (row?: PlanVO) => {
const _ids = row?.id || ids.value[0];
router.push({
path: '/inspection/editPlan',
query: {
id: _ids
}
});
};
/** 状态修改 */
function handleChangeStatus(id: string, status: string) {
changePlanStatus(id, status).then(() => {
proxy?.$modal.msgSuccess('操作成功');
getList();
});
}
/** 删除按钮操作 */
const handleDelete = async (row?: PlanVO) => {
const _ids = row?.id || ids.value;
await proxy?.$modal.confirm('是否确认删除该巡检计划?').finally(() => (loading.value = false));
await delPlan(_ids);
proxy?.$modal.msgSuccess('删除成功');
await getList();
};
onMounted(() => {
getList();
});
</script>
<style lang="scss" scoped>
.el-table {
height: calc(100% - 80px);
}
</style>