✨ feat(mes): 新增点检记录明细的项目类型字段及批量创建功能
新增项目类型字段到点检记录明细响应对象,并在控制器和服务层中实现批量创建点检记录明细的功能。此变更提升了点检记录的灵活性和可扩展性。pull/871/MERGE
parent
0c0de1eb45
commit
b5063758e5
|
|
@ -6,6 +6,7 @@
|
|||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
:disabled="isDetail"
|
||||
>
|
||||
<el-row>
|
||||
<el-col :span="8">
|
||||
|
|
@ -47,11 +48,21 @@
|
|||
<!-- 编辑时展示点检项目明细 -->
|
||||
<template v-if="formData.id">
|
||||
<el-divider content-position="center">点检项目明细</el-divider>
|
||||
<CheckRecordLineList :record-id="formData.id" />
|
||||
<CheckRecordLineList :record-id="formData.id" :disabled="isDetail" />
|
||||
</template>
|
||||
<template #footer>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
<el-button v-if="isEditable" :disabled="formLoading" type="primary" @click="submitForm">
|
||||
保 存
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="isEditable && formData.status === MesDvCheckRecordStatusEnum.DRAFT"
|
||||
:disabled="formLoading"
|
||||
type="warning"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
提 交
|
||||
</el-button>
|
||||
<el-button @click="dialogVisible = false">关 闭</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
|
@ -62,22 +73,33 @@ import DvMachinerySelect from '@/views/mes/dv/machinery/components/DvMachinerySe
|
|||
import DvCheckPlanSelect from '@/views/mes/dv/checkplan/components/DvCheckPlanSelect.vue'
|
||||
import UserSelect from '@/views/system/user/components/UserSelect.vue'
|
||||
import CheckRecordLineList from './CheckRecordLineList.vue'
|
||||
import { MesDvCheckRecordStatusEnum } from '@/views/mes/utils/constants'
|
||||
|
||||
defineOptions({ name: 'CheckRecordForm' })
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formLoading = ref(false) // 表单的加载中
|
||||
const formType = ref<string>('create') // 表单的类型:create / update / detail
|
||||
const isEditable = computed(() => ['create', 'update'].includes(formType.value)) // 是否为编辑模式
|
||||
const isDetail = computed(() => formType.value === 'detail') // 是否为详情模式
|
||||
const dialogTitle = computed(() => {
|
||||
const titles: Record<string, string> = {
|
||||
create: '新增点检记录',
|
||||
update: '编辑点检记录',
|
||||
detail: '点检记录详情'
|
||||
}
|
||||
return titles[formType.value] || formType.value
|
||||
})
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
id: undefined as number | undefined,
|
||||
planId: undefined,
|
||||
machineryId: undefined,
|
||||
checkTime: undefined,
|
||||
userId: undefined,
|
||||
status: undefined as number | undefined,
|
||||
remark: ''
|
||||
})
|
||||
const formRules = reactive({
|
||||
|
|
@ -85,14 +107,14 @@ const formRules = reactive({
|
|||
checkTime: [{ required: true, message: '点检时间不能为空', trigger: 'blur' }]
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
const originalFormData = ref<string>('') // 原始表单数据快照,用于脏检查
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
// 修改时,设置数据
|
||||
// 修改/详情时,加载数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
|
|
@ -101,28 +123,31 @@ const open = async (type: string, id?: number) => {
|
|||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
// 保存原始数据快照
|
||||
originalFormData.value = JSON.stringify(formData.value)
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
/** 提交表单(create/update 模式) */
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
if (!formRef) return
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
await formRef.value.validate()
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as any
|
||||
if (formType.value === 'create') {
|
||||
await DvCheckRecordApi.createCheckRecord(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
const res = await DvCheckRecordApi.createCheckRecord(data)
|
||||
message.success('新增成功')
|
||||
// 创建成功后,更新表单数据和状态为编辑模式
|
||||
formData.value.id = res
|
||||
formData.value.status = MesDvCheckRecordStatusEnum.DRAFT
|
||||
formType.value = 'update'
|
||||
} else {
|
||||
await DvCheckRecordApi.updateCheckRecord(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
message.success('修改成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 更新快照
|
||||
originalFormData.value = JSON.stringify(formData.value)
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
|
|
@ -130,6 +155,29 @@ const submitForm = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
/** 提交操作:表单修改过则先保存,再提交 */
|
||||
const handleSubmit = async () => {
|
||||
// 校验表单
|
||||
await formRef.value.validate()
|
||||
try {
|
||||
await message.confirm('确认提交该点检记录?【提交后将不能修改】')
|
||||
formLoading.value = true
|
||||
// 1. 表单有修改时,先保存
|
||||
if (JSON.stringify(formData.value) !== originalFormData.value) {
|
||||
const data = formData.value as any
|
||||
await DvCheckRecordApi.updateCheckRecord(data)
|
||||
}
|
||||
// 2. 提交记录
|
||||
await DvCheckRecordApi.submitCheckRecord(formData.value.id!)
|
||||
message.success('提交成功')
|
||||
dialogVisible.value = false
|
||||
emit('success')
|
||||
} catch {
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
|
|
@ -138,8 +186,11 @@ const resetForm = () => {
|
|||
machineryId: undefined,
|
||||
checkTime: undefined,
|
||||
userId: undefined,
|
||||
status: undefined,
|
||||
remark: ''
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -65,11 +65,18 @@
|
|||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||
<el-table-column label="设备编码" align="center" prop="machineryCode" />
|
||||
<el-table-column label="设备名称" align="center" prop="machineryName" />
|
||||
<el-table-column label="设备编码" align="center" prop="machineryCode" min-width="140">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" @click="openForm('detail', scope.row.id)">
|
||||
{{ scope.row.machineryCode }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="设备名称" align="center" prop="machineryName" min-width="120" />
|
||||
<el-table-column label="品牌" align="center" prop="machineryBrand" />
|
||||
<el-table-column label="规格型号" align="center" prop="machinerySpec" />
|
||||
<el-table-column label="计划名称" align="center" prop="planName" />
|
||||
<el-table-column label="规格型号" align="center" prop="machinerySpec" min-width="120" />
|
||||
<el-table-column label="计划编码" align="center" prop="planCode" min-width="120" />
|
||||
<el-table-column label="计划名称" align="center" prop="planName" min-width="120" />
|
||||
<el-table-column
|
||||
label="点检时间"
|
||||
align="center"
|
||||
|
|
@ -83,32 +90,24 @@
|
|||
<dict-tag :type="DICT_TYPE.MES_DV_CHECK_RECORD_STATUS" :value="scope.row.status" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<el-table-column label="操作" align="center" width="200" fixed="right">
|
||||
<template #default="scope">
|
||||
<!-- 草稿:编辑、删除 -->
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
v-if="scope.row.status === MesDvCheckRecordStatusEnum.DRAFT"
|
||||
v-hasPermi="['mes:dv-check-record:update']"
|
||||
v-if="scope.row.status === MesDvCheckRecordStatusEnum.DRAFT"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="success"
|
||||
@click="handleSubmit(scope.row)"
|
||||
v-if="scope.row.status === MesDvCheckRecordStatusEnum.DRAFT"
|
||||
v-hasPermi="['mes:dv-check-record:update']"
|
||||
>
|
||||
提交
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
v-if="scope.row.status === MesDvCheckRecordStatusEnum.DRAFT"
|
||||
v-hasPermi="['mes:dv-check-record:delete']"
|
||||
v-if="scope.row.status === MesDvCheckRecordStatusEnum.DRAFT"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
|
|
@ -130,8 +129,8 @@
|
|||
|
||||
<script setup lang="ts">
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
|
||||
import download from '@/utils/download'
|
||||
import { DvCheckRecordApi } from '@/api/mes/dv/checkrecord'
|
||||
import CheckRecordForm from './CheckRecordForm.vue'
|
||||
import DvMachinerySelect from '@/views/mes/dv/machinery/components/DvMachinerySelect.vue'
|
||||
|
|
@ -147,6 +146,7 @@ const { t } = useI18n() // 国际化
|
|||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
|
|
@ -157,7 +157,7 @@ const queryParams = reactive({
|
|||
checkTime: []
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
const formRef = ref() // 表单弹窗
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
|
|
@ -184,21 +184,10 @@ const resetQuery = () => {
|
|||
}
|
||||
|
||||
/** 添加/修改操作 */
|
||||
const formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 提交按钮操作 */
|
||||
const handleSubmit = async (row: any) => {
|
||||
try {
|
||||
await message.confirm('确认提交该点检记录吗?')
|
||||
await DvCheckRecordApi.submitCheckRecord(row.id)
|
||||
message.success('提交成功')
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
|
|
@ -222,7 +211,7 @@ const handleExport = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
/** 初始化 */
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue