templateModal.vue
5.76 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
<!--
* 功能:报表-新增、编辑
* 作者:闫李壮
* 日期:2024-6-6
-->
<template>
<div>
<a-modal v-if="visible" :visible="visible" :title="id ? '编辑模板' : '新增模板'" width="50%" @ok="handleOk"
@cancel="handleCancel" :mask-closable="false">
<a-form class="basic-report-template-form" ref="formRef" :model="form" :rules="formRules" auto-label-width>
<a-form-item field="reportName" label="报表名称">
<a-input v-model="form.reportName" placeholder="请输入字母或数字,最多20个字符" :max-length="20"/>
</a-form-item>
<a-form-item field="visibilityType" label="可见类型">
<a-radio-group v-model="form.visibilityType" :disabled="form.systemFlag === 0">
<a-radio :value="1">公有</a-radio>
<a-radio :value="2">私有</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item field="remark" label="报表描述">
<a-textarea v-model="form.remark" placeholder="请输入报表描述,最多不超过200字." allow-clear
:max-length="200"/>
</a-form-item>
<a-form-item field="headConfig" label="表头配置">
<a-table :columns="columns" :data="form.headConfig" :pagination="false" bordered style="width:100%">
<template #deviceName="{ record }">
<a-input v-model="record.deviceName" readonly></a-input>
</template>
<template #deviceVarId="{ record }">
<a-input v-model="record.deviceVarId" readonly></a-input>
</template>
<template #deviceVarName="{ record }">
<a-input v-model="record.deviceVarName" allow-clear/>
</template>
<template #operation="{ rowIndex }">
<a-button type="primary" :status="'danger'" size="mini" @click="handleDeleteTableItem(rowIndex)">
删除
</a-button>
</template>
</a-table>
</a-form-item>
<a-form-item>
<a-button type="primary" @click="handleAddTableItem">新增一行</a-button>
</a-form-item>
</a-form>
<select-var-modal :visible="selectVarVisible" @cancel="handleModalClose" @add="handleDeviceVarSelect"/>
</a-modal>
</div>
</template>
<script setup lang="ts">
import SelectVarModal from "@/views/manage/station/components/select-var-modal/index.vue";
import {ref, watch} from "vue";
import {Notification} from '@arco-design/web-vue'
import {
addReportTemplates,
editReportTemplates,
getReportTemplateDetail
} from "@/api/power/energy/search/report-templates";
import {useRoute} from "vue-router";
const props = defineProps({
visible: {
type: Boolean,
default: false,
},
id: {
type: Number,
default: 0
}
});
const emit = defineEmits(["confirm", 'cancel']);
const formRef = ref<any>(null);
const route = useRoute();
const {stationType, reportType} = route.query;
/**
* @desc 表单
*/
const form = ref<any>({
reportName: '',
remark: '',
visibilityType: 1,
multiLevelHeader: 1,
headConfig: []
});
const formRules = {
reportName: [
{
required: true,
message: '报表名称不得为空',
},
]
}
/**
* @desc 表头
*/
const columns: any[] = [
{
title: '设备',
dataIndex: 'deviceName',
slotName: 'deviceName',
align: 'center'
},
{
title: '变量',
dataIndex: 'deviceVarId',
slotName: 'deviceVarId',
align: 'center'
},
{
title: '显示名称',
dataIndex: 'deviceVarName',
slotName: 'deviceVarName',
align: 'center'
},
{
title: '操作',
dataIndex: 'operation',
slotName: 'operation',
align: 'center'
},
];
/**
* @desc 选择变量弹窗
*/
const selectVarVisible = ref(false);
// 新增一行
const handleAddTableItem = () => {
selectVarVisible.value = true;
};
/**
* @desc 选择变量弹窗确认
* @param record
*/
const handleDeviceVarSelect = (record: any) => {
const {deviceName, deviceId, varName: deviceVarName, varSn: deviceVarId} = record;
const item: any = {
deviceName,
deviceId,
deviceVarName,
deviceVarId
};
form.value.headConfig.push(item);
selectVarVisible.value = false;
};
/**
* @desc 关闭变量弹窗确认
*/
const handleModalClose = () => {
selectVarVisible.value = false;
};
/**
* @desc 移除
*/
const handleDeleteTableItem = (index: number) => {
form.value.headConfig.splice(index, 1);
}
// 确定提交
const handleOk = async () => {
formRef.value.validate(async (valid: boolean) => {
if (valid) return
try {
const params = {
...form.value,
headConfig: JSON.stringify(form.value.headConfig),
reportType,
stationType
}
let res: any;
if (props.id) {
res = await editReportTemplates(params)
} else {
res = await addReportTemplates(params);
}
if (res.code === 200) {
Notification.success(`${props.id ? '编辑' : '新增'}成功`)
emit("confirm");
resetFields()
} else {
Notification.error(res.msg)
}
} catch (e) {
}
})
};
/**
* 关闭当前弹窗
*/
const handleCancel = () => {
resetFields()
emit("cancel");
};
const getTemplateDetail = async () => {
const res = await getReportTemplateDetail(props.id);
if (res.code === 200) {
form.value = {
...res.data,
headConfig: JSON.parse(res.data.headConfig)
};
console.log(form.value,'form')
}
};
/**
* @desc 重置表单
*/
const resetFields = () => {
form.value = {
reportName: '',
remark: '',
visibilityType: 1,
multiLevelHeader: 1,
headConfig: []
}
}
/**
* @desc 监听id变化
*/
watch(
() => props.id,
(id) => {
if (id) {
getTemplateDetail()
}
}
)
</script>
<style lang="less" scoped>
</style>