吉安感知网项目-前端
shuishen
5 days ago 6e88705bd5b443a259b24c17c8a299765d059d96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<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>