123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <template>
- <div class="quality-project-container layout-pd">
- <el-card shadow="never">
- <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
- <el-form-item label="质检项名称" prop="Name">
- <el-input v-model="state.queryParams.Name" placeholder="请输入质检项目名称" clearable @keyup.enter="handleQuery" class="keyword-input" />
- </el-form-item>
- <el-form-item label="质检项分组" prop="GroupingName">
- <el-select v-model="state.queryParams.GroupingName" placeholder="请选择质检项目分组" @change="handleQuery">
- <el-option v-for="item in qualityItemGrouping" :value="item.dicDataValue" :key="item.dicDataValue" :label="item.dicDataName" />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
- <el-button @click="resetQuery(ruleFormRef)" v-waves class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
- </el-form-item>
- </el-form>
- </el-card>
- <el-card shadow="never">
- <ProTable
- ref="proTableRef"
- :columns="columns"
- :data="state.tableData"
- @updateTable="queryList"
- :loading="state.loading"
- :total="state.total"
- v-model:page-index="state.queryParams.PageIndex"
- v-model:page-size="state.queryParams.PageSize"
- >
- <!-- 表格 header 按钮 -->
- <template #tableHeader="scope">
- <el-button type="primary" @click="onProjectAdd" v-waves v-auth="'quality:project:add'">
- <SvgIcon name="ele-Plus" class="mr5" />新增
- </el-button>
- <el-button type="primary" @click="onProjectDelete" v-waves v-auth="'quality:project:delete'" :disabled="!scope.isSelected">
- <SvgIcon name="ele-Delete" class="mr5" />删除
- </el-button>
- </template>
- <template #type="{ row }">
- {{ row.isIntelligent === 1 ? '是' : '否' }}
- </template>
- <!-- 表格操作 -->
- <template #operation="{ row }">
- <el-button link type="primary" @click="onProjectEdit(row)" v-auth="'quality:project:edit'" title="编辑质检项目"> 编辑 </el-button>
- </template>
- </ProTable>
- </el-card>
- <!-- 质检项目新增 -->
- <project-add ref="projectAddRef" @updateList="queryList" :qualityItemGrouping="qualityItemGrouping" />
- <!-- 质检项目编辑 -->
- <project-edit ref="projectEditRef" @updateList="queryList" :qualityItemGrouping="qualityItemGrouping" />
- </div>
- </template>
- <script lang="tsx" setup name="qualityProject">
- import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
- import { ElMessage, ElMessageBox, FormInstance } from 'element-plus';
- import { formatDate } from '@/utils/formatTime';
- import { auth } from '@/utils/authFunction';
- import { projectBaseData, projectDelete, projectList, projectUpdate } from '@/api/quality/project';
- // 引入组件
- const ProjectAdd = defineAsyncComponent(() => import('@/views/quality/project/components/Project-add.vue')); // 质检项目新增
- const ProjectEdit = defineAsyncComponent(() => import('@/views/quality/project/components/Project-edit.vue')); // 质检项目编辑
- const proTableRef = ref<RefType>(); // 表格ref
- // 表格配置项
- const columns = ref<any[]>([
- { type: 'selection', fixed: 'left', width: 55,align: 'center' },
- { prop: 'name', label: '质检项名称' },
- { prop: 'describe', label: '质检项描述', width: 130 },
- { prop: 'groupingName', label: '质检项分组' },
- { prop: 'type', label: '是否智能质检' },
- { prop: 'grade', label: '分值(分)' },
- {
- prop: 'isEnable',
- label: '是否启用',
- render: (scope) => {
- return (
- <>
- {auth('quality:project:edit') ? (
- <el-switch
- model-value={scope.row.isEnable}
- active-text="启用"
- inactive-text="禁用"
- active-value={1}
- inactive-value={0}
- onClick={() => changeIsEnable(scope.row)}
- inline-prompt
- />
- ) : (
- <span>{scope.row.isEnable === 1 ? '启用' : '禁用'}</span>
- )}
- </>
- );
- },
- },
- { prop: 'creatorName', label: '创建人' },
- {
- prop: 'creationTime',
- label: '创建时间',
- width: 170,
- render: (scope) => {
- return <span>{formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
- },
- },
- { prop: 'lastModificationName', label: '更新人' },
- {
- prop: 'lastModificationTime',
- label: '更新时间',
- width: 170,
- render: (scope) => {
- return <span>{formatDate(scope.row.lastModificationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
- },
- },
- { prop: 'operation', label: '操作', fixed: 'right', width: 120, align: 'center' },
- ]);
- // 定义变量内容
- const state = reactive({
- loading: false, // 加载状态
- queryParams: {
- // 查询参数
- PageIndex: 1,
- PageSize: 10,
- GroupingName: null,
- Type: null,
- Name: null,
- },
- total: 0, // 总条数
- tableData: [], // 表格数据
- });
- const ruleFormRef = ref<RefType>(null); // 表单ref
- const qualityItemGrouping = ref<EmptyArrayType>([]); // 质检项目分组
- const getBaseData = async () => {
- try {
- const res = await projectBaseData();
- qualityItemGrouping.value = res.result?.qualityItemGrouping ?? [];
- } catch (error) {
- console.log(error);
- }
- };
- // 手动查询,将页码设置为1
- const handleQuery = () => {
- state.queryParams.PageIndex = 1;
- queryList();
- };
- // 获取参数列表
- const queryList = () => {
- state.loading = true;
- projectList(state.queryParams)
- .then((res) => {
- state.loading = false;
- state.tableData = res.result.items ?? [];
- state.total = res.result.total ?? 0;
- })
- .finally(() => {
- state.loading = false;
- });
- };
- // 重置表单
- const resetQuery = (formEl: FormInstance | undefined) => {
- if (!formEl) return;
- formEl.resetFields();
- queryList();
- };
- // 新增质检项目
- const projectAddRef = ref<RefType>();
- const onProjectAdd = () => {
- projectAddRef.value.openDialog();
- };
- // 编辑质检项目
- const projectEditRef = ref<RefType>();
- const onProjectEdit = (row: any) => {
- projectEditRef.value.openDialog(row);
- };
- // 删除质检项目
- const onProjectDelete = () => {
- const names = proTableRef.value.selectedList.map((item: any) => item.name).join('、');
- const ids = proTableRef.value.selectedList.map((item: any) => item.id);
- ElMessageBox.confirm(`您确定要删除:【${names}】质检项目,是否继续?`, '提示', {
- confirmButtonText: '确认',
- cancelButtonText: '取消',
- type: 'warning',
- draggable: true,
- cancelButtonClass: 'default-button',
- autofocus: false,
- })
- .then(() => {
- projectDelete({ ids }).then(() => {
- ElMessage.success('操作成功');
- queryList();
- });
- })
- .catch(() => {});
- };
- // 修改是否启用
- const changeIsEnable = (row: any) => {
- ElMessageBox.confirm(`您确定要${row.isEnable === 1 ? '禁用' : '启用'}:【${row.name}】质检项,是否继续?`, '提示', {
- confirmButtonText: '确认',
- cancelButtonText: '取消',
- type: 'warning',
- draggable: true,
- cancelButtonClass: 'default-button',
- autofocus: false,
- })
- .then(() => {
- const isEnable = row.isEnable === 1 ? 0 : 1;
- const request = {
- ...row,
- isEnable: isEnable,
- };
- projectUpdate(request)
- .then(() => {
- ElMessage.success('操作成功');
- queryList();
- })
- .catch(() => {
- queryList();
- });
- })
- .catch(() => {
- queryList();
- });
- };
- // 页面加载时
- onMounted(() => {
- getBaseData();
- queryList();
- });
- </script>
- <style lang="scss" scoped>
- .quality-project-container {
- }
- </style>
|