Commit ed849db8a184f08e085b7f3fad8f79676085d670

Authored by dev001
1 parent 263238de

fix: 任务中心所属组织选择后,下面的设备组织就只能选择所属组织及以下

@@ -108,6 +108,19 @@ export const formSchemas: FormSchema[] = [ @@ -108,6 +108,19 @@ export const formSchemas: FormSchema[] = [
108 label: '所属组织', 108 label: '所属组织',
109 colProps: { span: 24 }, 109 colProps: { span: 24 },
110 component: 'OrgTreeSelect', 110 component: 'OrgTreeSelect',
  111 + componentProps: ({ formActionType }) => {
  112 + const { setFieldsValue } = formActionType;
  113 + return {
  114 + onChange(key: string) {
  115 + setFieldsValue({
  116 + [FormFieldsEnum.EXECUTE_TARGET_DATA]: {
  117 + paramsOrg: key, //传递组织id到DevicePicker组件里进行组织过滤
  118 + },
  119 + });
  120 + },
  121 + getPopupContainer: () => document.body,
  122 + };
  123 + },
111 }, 124 },
112 { 125 {
113 field: FormFieldsEnum.TARGET_TYPE, 126 field: FormFieldsEnum.TARGET_TYPE,
@@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
19 value?: Recordable; 19 value?: Recordable;
20 multiple?: boolean; 20 multiple?: boolean;
21 max?: 3; 21 max?: 3;
  22 + paramsOrg?: string;
22 }>(), 23 }>(),
23 { 24 {
24 value: () => ({}), 25 value: () => ({}),
@@ -74,7 +75,7 @@ @@ -74,7 +75,7 @@
74 handleChange(key, value, option); 75 handleChange(key, value, option);
75 emit('update:value', { ..._value }); 76 emit('update:value', { ..._value });
76 }; 77 };
77 - const [register, { setFieldsValue, getFieldsValue, resetFields }] = useForm({ 78 + const [register, { setFieldsValue, getFieldsValue, resetFields, updateSchema }] = useForm({
78 schemas: [ 79 schemas: [
79 { 80 {
80 field: FormFieldsEnum.DEVICE_TYPE, 81 field: FormFieldsEnum.DEVICE_TYPE,
@@ -206,12 +207,41 @@ @@ -206,12 +207,41 @@
206 watch( 207 watch(
207 () => props.value, 208 () => props.value,
208 () => { 209 () => {
  210 + if (Reflect.has(props.value, 'paramsOrg')) {
  211 + const { paramsOrg } = props.value;
  212 + updateOrgSchema(paramsOrg);
  213 + }
209 setValue(); 214 setValue();
210 }, 215 },
211 { 216 {
212 immediate: true, 217 immediate: true,
213 } 218 }
214 ); 219 );
  220 +
  221 + //更新组织,只能选择层级以下
  222 + const getOrganizationLevelList = async (organizationId) => {
  223 + const data = await getOrganizationList({ organizationId });
  224 + copyTransFun(data as any);
  225 + return data;
  226 + };
  227 +
  228 + const updateOrgSchema = async (organizationId: string) => {
  229 + const data = await getOrganizationLevelList(organizationId);
  230 + setFieldsValue({
  231 + [FormFieldsEnum.ORGANIZATION]: null,
  232 + [FormFieldsEnum.DEVICE]: [],
  233 + });
  234 + updateSchema({
  235 + field: FormFieldsEnum.ORGANIZATION,
  236 + componentProps: {
  237 + treeData: data,
  238 + onChange(value: string, option: Recordable) {
  239 + handleEmit(FormFieldsEnum.ORGANIZATION, value, option);
  240 + },
  241 + },
  242 + });
  243 + };
  244 + //
215 </script> 245 </script>
216 246
217 <template> 247 <template>