insPlanModal.vue
8.04 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<template>
<a-modal
v-model:visible="visible"
:title="modalTitle"
width="80vw"
@ok="handleOk"
@cancel="handleCancel"
>
<a-form :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 14 }" style="margin-top: 32px" :rules="rules">
<a-row :gutter="16">
<a-col :span="12">
<a-form-item label="计划编号" name="code">
<a-input v-model:value="form.code" :disabled="isViewMode" />
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="计划名称" name="name">
<a-input v-model:value="form.name" :disabled="isViewMode" />
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :span="12">
<a-form-item label="开始时间" name="startTime">
<a-date-picker
v-model:value="form.startTime"
:disabled="isViewMode"
placeholder="请选择"
style="width: 100%"
/>
</a-form-item>
</a-col>
<a-col :span="12">
<a-form-item label="结束时间" name="endTime">
<a-date-picker
v-model:value="form.endTime"
:disabled="isViewMode"
placeholder="请选择"
style="width: 100%"
/>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :span="12">
<a-form-item label="计划状态" name="status">
<a-select
v-model:value="form.status"
:disabled="isViewMode"
placeholder="请选择"
:options="[
{label:'未开始',value:'NOT_START'},
{label:'进行中',value:'UNDERWAY'},
{label:'已完成',value:'FINISH'},
{label:'停用',value:'STOP'},
]"
>
</a-select>
</a-form-item>
</a-col>
</a-row>
<a-row :gutter="16">
<a-col :span="24">
<a-form-item label="计划备注" name="remark">
<a-textarea
v-model:value="form.remark"
:disabled="isViewMode"
>
</a-textarea>
</a-form-item>
</a-col>
</a-row>
<a-form-item label="巡检明细" name="tkCheckDetailsDTOList">
<div style="text-align: end">
<a-button class="editable-add-btn" type="primary" @click="handleAdd" style="margin-bottom: 8px" :disabled="isViewMode">
<template #icon>
<PlusOutlined/>
</template>
新增
</a-button>
<a-table bordered :data-source="tableData" :columns="columns">
<template #code="{ text, record, index }">
<div>
<a-input v-model:value="record.code" :disabled="isViewMode"/>
</div>
</template>
<template #checkDeviceId="{ text, record, index }">
<div>
<a-select
v-model:value="record.checkDeviceId"
:options="Options"
:disabled="isViewMode"
:field-names="{ label: 'name', value: 'id' }"
placeholder="请选择"
/>
</div>
</template>
<template #checkPlanId="{ text, record, index }">
<div>
<a-select
v-model:value="record.checkPlanId"
:options="planOptions"
:disabled="isViewMode"
:fieldNames="{ label: 'name', value: 'id' }"
placeholder="请选择"
/>
</div>
</template>
<template #planDetails="{ text, record, index }">
<div>
<a-textarea v-model:value="record.planDetails" :disabled="isViewMode"/>
</div>
</template>
<template #operation="{ text, record, index }">
<div>
<a-button type="link" @click="handleDelete(index)" :disabled="isViewMode">删除</a-button>
</div>
</template>
</a-table>
</div>
</a-form-item>
</a-form>
</a-modal>
</template>
<script setup lang="ts">
// 定义 props
import {onMounted, ref, watch} from "vue";
import {getLedgerList} from "/@/api/equipment/ledger";
import {getPlanList} from "/@/api/equipment/chenkPlan";
const Options = ref([]);
const planOptions = ref([]);
const props = defineProps({
initialData: {
type: Object,
default: () => ({
form: {
code: '',
name: '',
status: '',
enabled: '',
startTime: '',
endTime: '',
remark: '',
},
tableData: [],
}),
},
visible: {
type: Boolean,
default: false,
},
isViewMode: {
type: Boolean,
default: false,
},
modalTitle: {
type: String,
default: '',
},
});
const columns = [
{
title: '明细编号',
dataIndex: 'code',
slots: { customRender: 'code' },
width: '160px'
},
{
title: '巡检设备',
dataIndex: 'checkDeviceId',
slots: { customRender: 'checkDeviceId' },
width: '180px'
},
{
title: '巡检方案',
dataIndex: 'checkPlanId',
slots: { customRender: 'checkPlanId' },
width: '180px'
},
{
title: '方案明细',
dataIndex: 'planDetails',
slots: { customRender: 'planDetails' },
width: '160px'
},
{
title: '操作',
dataIndex: 'operation',
slots: { customRender: 'operation' },
width: '120px'
}
];
const rules = {
code: [
{ required: true, message: '请输入', trigger: 'blur' },
],
name: [
{ required: true, message: '请输入', trigger: 'blur' },
],
remark: [
{ required: true, message: '请输入', trigger: 'blur' },
],
status: [{ required: true, message: '请选择', trigger: 'change' }],
};
const visible = ref(props.visible);
const isViewMode = ref(props.isViewMode);
const modalTitle = ref(props.modalTitle);
const form = ref({ ...props.initialData.form });
const tableData = ref([...props.initialData.tableData]);
const emit = defineEmits(['update:visible', 'submit']);
// 监听 visible 的变化
watch(
() => props.visible,
(newVal) => {
visible.value = newVal;
}
);
watch(
() => props.isViewMode,
(newVal) => {
isViewMode.value = newVal;
}
);
// 监听 visible 的变化并通知父组件
watch(
() => visible.value,
(newVal) => {
emit('update:visible', newVal);
}
);
// 监听 initialData 的变化
watch(
() => props.initialData,
(newVal) => {
form.value = { ...newVal.form };
tableData.value = [...newVal.tableData];
},
{ deep: true }
);
onMounted(() => {
fetchAgeOptions();
});
const fetchAgeOptions = async () => {
try {
const response = await getLedgerList({ page: 1, pageSize: 999 }); // 调用接口
const response1 = await getPlanList({ page: 1, pageSize: 999, type: 'INSPECTION' }); // 调用接口
Options.value = response.items?.map((item: any) => {
return {
value: item?.id,
label: item?.name
}
})
planOptions.value = response1.items?.map((item: any) => {
return {
value: item?.id,
label: item?.name
}
});
} catch (error) {
console.error('失败:', error);
}
};
const handleAdd = () => {
tableData.value.push({
code: '',
checkDeviceId: undefined,
checkPlanId: undefined,
planDetails: '',
});
};
const handleDelete = (index) => {
tableData.value.splice(index, 1);
};
const handleOk = () => {
if (isViewMode.value) {
visible.value = false;
return;
}
const objData = { ...form.value, tkCheckDetailsDTOList: tableData.value };
emit('submit', objData); // 将数据提交给父组件
resetForm();
}
const handleCancel = () => {
resetForm();
visible.value = false;
};
// 清空表单和表格数据
const resetForm = () => {
form.value = {
code: '',
name: '',
status: '',
enabled: '',
startTime: '',
endTime: '',
remark: '',
};
tableData.value = [];
isViewMode.value = false;
};
</script>