Commit ed7a9b0826ea3f30b73143d6a1293194e9f067b5

Authored by fengtao
1 parent e9015aa1

fix: 任务中心选择组织,再选择产品时,组织也只能在任务中心下进行选择

@@ -117,6 +117,10 @@ export const formSchemas: FormSchema[] = [ @@ -117,6 +117,10 @@ export const formSchemas: FormSchema[] = [
117 paramsOrg: key, //传递组织id到DevicePicker组件里进行组织过滤 117 paramsOrg: key, //传递组织id到DevicePicker组件里进行组织过滤
118 change: true, 118 change: true,
119 }, 119 },
  120 + [FormFieldsEnum.DEVICE_PROFILE]: {
  121 + paramsOrg: key, //传递组织id到DevicePicker组件里进行组织过滤
  122 + change: true,
  123 + },
120 }); 124 });
121 }, 125 },
122 getPopupContainer: () => document.body, 126 getPopupContainer: () => document.body,
@@ -46,6 +46,11 @@ @@ -46,6 +46,11 @@
46 paramsOrg: res.organizationId, //传递组织id到DevicePicker组件里进行组织过滤 46 paramsOrg: res.organizationId, //传递组织id到DevicePicker组件里进行组织过滤
47 change: false, 47 change: false,
48 }, 48 },
  49 + [FormFieldsEnum.DEVICE_PROFILE]: {
  50 + ...res.executeTargetData,
  51 + paramsOrg: res.organizationId, //传递组织id到DevicePicker组件里进行组织过滤
  52 + change: false,
  53 + },
49 }); 54 });
50 } 55 }
51 } 56 }
@@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
14 const props = withDefaults( 14 const props = withDefaults(
15 defineProps<{ 15 defineProps<{
16 value?: Recordable; 16 value?: Recordable;
  17 + paramsOrg?: string;
17 }>(), 18 }>(),
18 { 19 {
19 value: () => ({}), 20 value: () => ({}),
@@ -42,7 +43,7 @@ @@ -42,7 +43,7 @@
42 emit('update:value', { ..._value }); 43 emit('update:value', { ..._value });
43 }; 44 };
44 45
45 - const [register, { setFieldsValue, getFieldsValue, resetFields }] = useForm({ 46 + const [register, { setFieldsValue, getFieldsValue, resetFields, updateSchema }] = useForm({
46 schemas: [ 47 schemas: [
47 { 48 {
48 field: FormFieldsEnum.DEVICE_TYPE, 49 field: FormFieldsEnum.DEVICE_TYPE,
@@ -135,12 +136,45 @@ @@ -135,12 +136,45 @@
135 watch( 136 watch(
136 () => props.value, 137 () => props.value,
137 () => { 138 () => {
  139 + if (Reflect.has(props.value, 'paramsOrg')) {
  140 + nextTick(() => {
  141 + const { paramsOrg, change } = props.value;
  142 + updateOrgSchema(paramsOrg, change);
  143 + });
  144 + }
138 setValue(); 145 setValue();
139 }, 146 },
140 { 147 {
141 immediate: true, 148 immediate: true,
142 } 149 }
143 ); 150 );
  151 +
  152 + //更新组织,只能选择层级以下
  153 + const getOrganizationLevelList = async (organizationId) => {
  154 + const data = await getOrganizationList({ organizationId });
  155 + copyTransFun(data as any);
  156 + return data;
  157 + };
  158 +
  159 + const updateOrgSchema = async (organizationId: string, change?: boolean) => {
  160 + const data = await getOrganizationLevelList(organizationId);
  161 + if (change) {
  162 + setFieldsValue({
  163 + [FormFieldsEnum.ORGANIZATION]: null,
  164 + [FormFieldsEnum.DEVICE_PROFILE]: [],
  165 + });
  166 + }
  167 + updateSchema({
  168 + field: FormFieldsEnum.ORGANIZATION,
  169 + componentProps: {
  170 + treeData: data,
  171 + onChange(value: string, option: Recordable) {
  172 + handleEmit(FormFieldsEnum.ORGANIZATION, value, option);
  173 + },
  174 + },
  175 + });
  176 + };
  177 + //
144 </script> 178 </script>
145 179
146 <template> 180 <template>