<template>
|
<el-dialog
|
class="gd-dialog"
|
v-model="visible"
|
title="配置"
|
@closed="visible = false"
|
destroy-on-close
|
:close-on-click-modal="false"
|
>
|
<el-form
|
class="gd-dialog-form"
|
ref="formRef"
|
:model="formData"
|
:rules="rules"
|
label-width="98px"
|
v-loading="loading"
|
>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="关联流程" prop="processDefinitionId">
|
<el-select
|
class="gd-select"
|
popper-class="gd-select-popper"
|
v-model="formData.processDefinitionId"
|
placeholder="请选择"
|
clearable
|
filterable
|
>
|
<el-option v-for="item in flowList" :key="item.id" :label="item.name" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="材料" prop="materialIds">
|
<el-select
|
class="gd-select"
|
popper-class="gd-select-popper"
|
v-model="formData.materialIds"
|
placeholder="请选择"
|
clearable
|
filterable
|
multiple
|
collapse-tags
|
collapse-tags-tooltip
|
>
|
<el-option v-for="item in materialsList" :key="item.id" :label="item.materialName" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="结果配置" prop="resultConfig">
|
<el-select
|
class="gd-select"
|
popper-class="gd-select-popper"
|
v-model="formData.resultConfig"
|
placeholder="请选择"
|
clearable
|
|
>
|
<el-option v-for="item in dictObj.resultConfig" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<el-button color="#F2F3F5" @click="visible = false">取消</el-button>
|
<el-button class="save-btn" color="#4C34FF" :loading="submitting" :disabled="submitting" @click="handleSubmit">
|
保存
|
</el-button>
|
</template>
|
</el-dialog>
|
</template>
|
|
<script setup>
|
import { ref, onMounted } from 'vue'
|
import { ElMessage } from 'element-plus'
|
import { fieldRules } from '@ztzf/utils'
|
import { getConfigDetailApi, saveConfigApi } from './inventoryApi'
|
import { managerList } from '@/api/flow/flow'
|
import { materialsPageApi } from '../materials/materialsApi'
|
|
// 初始化表单数据
|
const initForm = () => ({
|
implementListId: null,
|
processDefinitionId: '',
|
processInstanceId: '',
|
materialIds: [],
|
resultConfig:''
|
})
|
|
const emit = defineEmits(['success'])
|
const formRef = ref(null) // 表单实例
|
const formData = ref(initForm()) // 表单数据
|
const visible = defineModel() // 弹框显隐
|
const submitting = ref(false) // 提交中
|
const loading = ref(false) // 加载中
|
const flowList = ref([]) // 流程列表
|
const materialsList = ref([]) // 材料列表
|
const currentRow = ref(null) // 当前操作的行
|
const dictObj = inject('dictObj')
|
|
// 表单校验规则
|
const rules = {
|
processDefinitionId: fieldRules(false),
|
materialIds: fieldRules(false),
|
}
|
|
// 获取流程列表
|
async function getFlowList() {
|
try {
|
const res = await managerList(1, 999, {})
|
flowList.value = res?.data?.data?.records ?? []
|
} catch (error) {
|
console.error('获取流程列表失败:', error)
|
}
|
}
|
|
// 获取材料列表
|
async function getMaterialsList() {
|
try {
|
const res = await materialsPageApi({ current: 1, size: 999 })
|
materialsList.value = res?.data?.data?.records ?? []
|
} catch (error) {
|
console.error('获取材料列表失败:', error)
|
}
|
}
|
|
// 加载配置详情
|
async function loadConfigDetail(id) {
|
loading.value = true
|
try {
|
const res = await getConfigDetailApi({ id })
|
const data = res?.data?.data ?? {}
|
|
// 设置流程定义ID
|
formData.value.processDefinitionId = data.processDefinitionId || ''
|
formData.value.processInstanceId = data.processInstanceId || ''
|
formData.value.resultConfig = data.resultConfig || ''
|
// 从关联材料中提取材料ID列表
|
if (data.thingListMaterialRels && data.thingListMaterialRels.length > 0) {
|
formData.value.materialIds = data.thingListMaterialRels.map(item => item.materialId)
|
} else {
|
formData.value.materialIds = []
|
}
|
} catch (error) {
|
console.error('加载配置详情失败:', error)
|
} finally {
|
loading.value = false
|
}
|
}
|
|
// 提交配置
|
async function handleSubmit() {
|
const isValid = await formRef.value?.validate().catch(() => false)
|
if (!isValid) return
|
submitting.value = true
|
try {
|
const submitData = {
|
implementListId: formData.value.implementListId,
|
processDefinitionId: formData.value.processDefinitionId,
|
processInstanceId: formData.value.processInstanceId || '',
|
materialIds: formData.value.materialIds || [],
|
resultConfig: formData.value.resultConfig || '',
|
}
|
await saveConfigApi(submitData)
|
ElMessage.success('配置保存成功')
|
visible.value = false
|
emit('success')
|
} finally {
|
submitting.value = false
|
}
|
}
|
|
// 打开弹框
|
async function open({ row } = {}) {
|
currentRow.value = row
|
formData.value = initForm()
|
formData.value.implementListId = row?.id
|
|
// 加载流程和材料列表
|
await Promise.all([getFlowList(), getMaterialsList()])
|
|
// 加载已配置的信息
|
if (row?.id) {
|
await loadConfigDetail(row.id)
|
}
|
}
|
|
defineExpose({ open })
|
</script>
|
|
<style scoped lang="scss"></style>
|