export const getRFields = (dataList, rFieldList, fieldList) => {
  dataList.forEach(
    (element: { label?: string; field?: string; component: any; itemProps: any }) => {
      if (['InputGuid'].includes(element.component)) {
        rFieldList.push({
          label: element.label,
          // value:element.prop
          value: element.field,
        });
      } else if (
        ![
          'Divider',
          'Grid',
          'Card',
          'CreateUser',
          'CreateTime',
          'ModifyUser',
          'ModifyTime',
          'CardGroup',
        ].includes(element.component) &&
        !element.itemProps.hidden
      ) {
        let obj: any = element;
        obj.required = element.itemProps.required;
        // obj.componentProps.disabled = false;
        obj.disabled = true;
        obj.ifShow = true;
        obj.upShow = false;
        obj.fieldName = element.componentProps.fieldName;
        fieldList.push(obj);
      } else if (['Grid'].includes(element.component) || element.type == 'subTable') {
        console.log('gridtable');
        fieldList.push({
          field: `${element.field}_add`,
          label: `${element.label || '表格'}-添加按钮`,
          required: false,
          disabled: true,
          upShow: false,
          ifShow: false,
          type: 'grid',
        });
        fieldList.push({
          field: `${element.field}_remove`,
          label: `${element.label || '表格'}-删除按钮`,
          required: false,
          disabled: true,
          upShow: false,
          ifShow: false,
          type: 'grid',
        });

        fieldList.push({
          field: `${element.field}_required`,
          label: `${element.label || '表格'}-数据`,
          required: element.itemProps.required,
          disabled: false,
          upShow: false,
          ifShow: false,
          type: 'gridrequired',
        });
        element.columns.forEach((child) => {
          child.children.forEach((t) => {
            fieldList.push({
              gridprop: element.field,
              field: t.field,
              label: `${element.label || '表格'}-${t.label}`,
              required: t.itemProps.required,
              disabled: true,
              upShow: false,
              ifShow: true,
              fieldName: t.componentProps.fieldName,
              ...t,
            });
          });
        });
      } else if (['Card'].includes(element.component)) {
        console.log(3);
        element.columns.forEach((child) => {
          child.children.forEach((t) => {
            fieldList.push({
              gridprop: element.field,
              field: t.field,
              required: t.itemProps.required,
              disabled: true,
              ifShow: true,
              upShow: false,
              fieldName: t.componentProps.fieldName,
              ...t,
            });
          });
        });
      } else if (
        ['CreateUser', 'CreateTime', 'ModifyUser', 'ModifyTime'].includes(element.component) &&
        element.display
      ) {
        let obj: any = element;
        obj.upShow = false;
        obj.required = element.itemProps.required;
        // obj.componentProps.disabled = false;
        obj.disabled = true;
        obj.ifShow = true;
        obj.fieldName = element.componentProps.fieldName;
        fieldList.push(obj);
      } else if (['CardGroup'].includes(element.component)) {
        let obj: any = element;
        obj.upShow = false;
        obj.required = element.itemProps.required;
        // obj.componentProps.disabled = false;
        obj.disabled = true;
        obj.ifShow = true;
        obj.fieldName = element.componentProps.fieldName;
        obj.label = `卡片组-${element.label}`;
        fieldList.push(obj);
        fieldList = cardComponentChild(element.componentProps.options, fieldList);
      }
    },
  );
  return { rFieldList, fieldList };
};
const cardComponentChild = (data, result) => {
  data.forEach((optionsElement) => {
    optionsElement.children.forEach((childrenElement) => {
      let obj: any = childrenElement;
      obj.upShow = false;
      obj.required = childrenElement.itemProps.required;
      obj.disabled = true;
      obj.ifShow = true;
      obj.label = `${optionsElement.label} - ${childrenElement.label}`;
      obj.fieldName = childrenElement.componentProps.fieldName;
      result.push(obj);
      if (childrenElement.component === 'CardGroup') {
        result = cardComponentChild(childrenElement.componentProps.options, result);
      }
    });
  });
  return result;
};
