DeviceConfigurationStep.vue
5.4 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
<template>
<div class="step1">
<BasicForm @register="register">
<template #categoryName="{ model }">
<div class="flex">
<Input
v-model:value="model.categoryName"
:placeholder="t('deviceManagement.product.productCategoryPlaceholderText')"
style="width: 300px"
:disabled="cateGoryDisabled"
@focus="handleFocus"
/>
<Button type="link" :disabled="!model.categoryName" @click="handleCategoryId">
{{ t('deviceManagement.product.viewFunctionText') }}
</Button>
</div>
</template>
</BasicForm>
<CategoryList
@register="registerDrawer"
@handleOpenListDrawer="handleOpenListDrawer"
@handleSelectCategory="handleSelectCategory"
@handleClose="handleClose"
/>
<CategoryListDrawer @register="registerListDrawer" :cateforyListInfo="cateforyListInfo" />
</div>
</template>
<script lang="ts" setup>
import { nextTick, ref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { step1Schemas } from '../device.profile.data';
import { buildUUID } from '/@/utils/uuid';
import { Input, Button } from 'ant-design-vue';
import { useDrawer } from '/@/components/Drawer';
import CategoryList from '../components/CategoryList.vue';
import CategoryListDrawer from '../components/CategoryListDrawer.vue';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();
const emits = defineEmits(['next', 'emitDeviceType']);
const props = defineProps({
ifShowBtn: { type: Boolean, default: true },
});
const [registerDrawer, { openDrawer, closeDrawer }] = useDrawer();
const [registerListDrawer, { openDrawer: openListDrawer, closeDrawer: closeListDrawer }] =
useDrawer();
const [register, { validate, setFieldsValue, resetFields, updateSchema, getFieldsValue }] =
useForm({
labelWidth: 140,
schemas: step1Schemas,
actionColOptions: {
span: 14,
},
showResetButton: false,
showActionButtonGroup: props.ifShowBtn ? true : false,
submitButtonOptions: {
text: t('deviceManagement.product.nextStepText'),
},
submitFunc: customSubmitFunc,
});
const cateGoryDisabled = ref<boolean>(false);
const editOrAddNameStatus = (nameStatus) =>
updateSchema({
field: 'name',
componentProps: {
disabled: nameStatus,
},
});
const setFieldsdefaultRuleChainId = async (id) => {
await nextTick();
setFieldsValue({ defaultRuleChainId: id });
};
async function customSubmitFunc() {
const values = await validate();
if (!values) return;
emits('next', true, null);
emits('emitDeviceType', values?.deviceType);
}
const imageUrl = ref('');
//回显数据
const setFormData = async (v) => {
if (v.image) {
setFieldsValue({
image: [{ uid: buildUUID(), name: 'name', url: v.image } as FileItem],
});
}
// 不能把image字段回显进去,页面会显示大量警告
const { image, ...params } = v;
imageUrl.value = image;
setFieldsValue({
...params,
category: params?.categoryId ? 1 : 2,
isUpdate: true,
profileId: v?.tbProfileId,
});
};
//获取数据
async function getFormData() {
await validate();
const values = getFieldsValue();
if (!values) return;
if (Reflect.has(values, 'image')) {
const file = (values.image || []).at(0) || {};
values.image = file.url || null;
}
return values;
}
//清空数据
const resetFormData = () => {
resetFields();
};
const editOrAddDeviceTypeStatus = (status: boolean) => {
updateSchema([
{
field: 'deviceType',
componentProps: {
disabled: status,
},
},
{
field: 'category',
componentProps({ formModel }) {
return {
options: [
{ label: t('deviceManagement.product.customCategoryText'), value: 2 },
{ label: t('deviceManagement.product.standardCategoryText'), value: 1 },
],
onChange() {
formModel.categoryId = null;
formModel.categoryName = undefined;
},
disabled: status,
};
},
},
]);
cateGoryDisabled.value = status;
};
// 查看功能
const handleCategoryId = () => {
const { categoryId } = getFieldsValue() || {};
if (!categoryId) return;
cateforyListInfo.value = { record: { id: categoryId }, isRight: false };
openListDrawer(true);
};
// 获取焦点
const handleFocus = () => {
const { categoryId } = getFieldsValue() || {};
openDrawer(true, { categoryId });
};
//打开品类名称
const cateforyListInfo = ref<any>({});
const handleOpenListDrawer = (record?: any) => {
cateforyListInfo.value = { record, isRight: true };
openListDrawer(true);
};
// 选择产品品类
const handleSelectCategory = (item) => {
closeDrawer();
closeListDrawer();
item.id && setFieldsValue({ categoryId: item.id, categoryName: item?.name });
};
// 关闭抽屉
const handleClose = () => {
closeListDrawer();
};
defineExpose({
editOrAddNameStatus,
setFormData,
resetFormData,
getFormData,
editOrAddDeviceTypeStatus,
getFieldsValue,
setFieldsdefaultRuleChainId,
});
</script>
<style lang="less" scoped>
@import url('./common/DeviceConfigurationSetp.less');
</style>