admin-vue3/src/views/infra/autocode/data/index.vue

186 lines
5.2 KiB
Vue

<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="组成编码" prop="partCode">
<el-input
v-model="queryParams.partCode"
placeholder="请输入组成编码"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item label="组成名称" prop="partName">
<el-input
v-model="queryParams.partName"
placeholder="请输入组成名称"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['infra:auto-code-part:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
<el-button type="warning" plain @click="handleClose">
<Icon icon="ep:close" class="mr-5px" /> 关闭
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true">
<el-table-column label="组成编码" align="center" prop="partCode" />
<el-table-column label="组成名称" align="center" prop="partName" />
<el-table-column label="分段序号" align="center" prop="partIndex" />
<el-table-column label="分段类型" align="center" prop="partType">
<template #default="scope">
<dict-tag :type="DICT_TYPE.INFRA_AUTOCODE_PARTTYPE" :value="scope.row.partType" />
</template>
</el-table-column>
<el-table-column label="分段长度" align="center" prop="partLength" />
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column label="操作" align="center" min-width="120px">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.partId)"
v-hasPermi="['infra:auto-code-part:update']"
>
修改
</el-button>
<el-button
link
type="danger"
@click="handleDelete(scope.row.partId)"
v-hasPermi="['infra:auto-code-part:delete']"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗:添加/修改 -->
<AutoCodePartForm ref="formRef" :ruleId="ruleId" @success="getList" />
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { AutoCodePartApi, AutoCodePartVO } from '@/api/infra/autocode/part'
import AutoCodePartForm from './AutoCodePartForm.vue'
/** */
defineOptions({ name: 'AutoCodePart' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const list = ref<AutoCodePartVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const router = useRouter() // 路由
const route = useRoute()
const ruleId = ref(Number(route.params.ruleId) || 0)
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
ruleId: ruleId.value,
partCode: undefined,
partName: undefined,
createTime: []
})
const queryFormRef = ref() // 搜索的表单
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
queryParams.ruleId = ruleId.value
const data = await AutoCodePartApi.getAutoCodePartPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, partId?: number) => {
formRef.value.open(type, partId)
}
/** 删除按钮操作 */
const handleDelete = async (partId: number) => {
try {
// 删除的二次确认
await message.delConfirm()
// 发起删除
await AutoCodePartApi.deleteAutoCodePart(partId)
message.success(t('common.delSuccess'))
// 刷新列表
await getList()
} catch {}
}
/** 处理关闭操作 */
const handleClose = async () => {
const obj = { path: '/infra/autocode' }
router.push(obj)
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>