import { cloneDeep, random } from 'lodash';

export const formConf = {
  formRef: 'elForm',
  formModel: 'formData',
  size: 'medium',
  labelPosition: 'right',
  labelWidth: 100,
  formRules: 'rules',
  gutter: 15,
  disabled: false,
  span: 24,
  formBtns: true,
};
export const drawingListDefault = [];

export const inputComponents = [
  {
    type: 'default',
    tag: 'solverName',
    tagType: 'INPUT',
    justify: 'start',
    align: 'top',
    label: '求解器名称',
    layoutTree: true,
    children: [],
    document: 'https://element.eleme.cn/#/zh-CN/component/layout',
    readonly: false,
    required: true,
    defaultValue: undefined,
    englishLabel: 'solverName',
    specialWidget: true,
    solverNumber: 1,
    hiddenDefaultValue: true,
    widgetViewType: 'SOLVER',
    englishLabelReadOnly: false,
    options: [
      {
        value: null,
      },
    ],
    solverNames: [],
    solverNameIndex: 0,
    coreNodeInfo: [
      {
        minCore: 12,
        maxCore: 24,
        defaultCore: 12,
        minNode: 1,
        maxNode: 1,
        defaultNode: 1,
      },
    ],
  },
  {
    type: 'default',
    tag: 'script',
    tagType: 'script',
    justify: 'start',
    align: 'top',
    label: '执行脚本',
    children: [],
    document: 'https://element.eleme.cn/#/zh-CN/component/layout',
    readonly: true,
    englishLabel: 'script',
    specialWidget: true,
    otherParam: null,
    value: null,
    required: true,
  },
];

export const selectComponents = [
  {
    id: '0',
    label: '单行文本',
    englishLabel: null,
    tag: 'el-input',
    tagType: 'INPUT',
    tagIcon: 'input',
    placeholder: '请输入',
    defaultValue: undefined,
    span: 24,
    labelWidth: null,
    style: { width: '100%' },
    clearable: true,
    prepend: '',
    append: '',
    'prefix-icon': '',
    'suffix-icon': '',
    maxlength: null,
    'show-word-limit': false,
    readonly: false,
    disabled: false,
    required: true,
    regList: [],
    changeTag: true,
    document: 'https://element.eleme.cn/#/zh-CN/component/input',
    needLabel: false,
    total: 1,
    column: 1,
    englishLabelReadOnly: false,
    widgetViewType: '',
    specialWidget: false,
  },
  {
    id: '0',
    label: '显示行',
    englishLabel: null,
    tag: 'displayText',
    tagType: 'VIEW',
    tagIcon: 'input',
    placeholder: '请输入',
    defaultValue: undefined,
    span: 24,
    labelWidth: null,
    style: { width: '100%' },
    clearable: true,
    prepend: '',
    append: '',
    'prefix-icon': '',
    'suffix-icon': '',
    maxlength: null,
    'show-word-limit': false,
    readonly: false,
    disabled: false,
    required: true,
    regList: [],
    changeTag: true,
    document: 'https://element.eleme.cn/#/zh-CN/component/input',
    needLabel: false,
    total: 1,
    column: 1,
    englishLabelReadOnly: false,
    widgetViewType: '',
    specialWidget: false,
  },
  // {
  //   id: '1',
  //   label: '多行文本',
  //   englishLabel: null,
  //   tag: 'el-input',
  //   tagIcon: 'textarea',
  //   type: 'textarea',
  //   placeholder: '请输入',
  //   defaultValue: undefined,
  //   span: 24,
  //   labelWidth: null,
  //   autosize: {
  //     minRows: 4,
  //     maxRows: 4,
  //   },
  //   style: { width: '100%' },
  //   maxlength: null,
  //   'show-word-limit': false,
  //   readonly: false,
  //   disabled: false,
  //   required: true,
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/input',
  // },
  // {
  //   id: '2',
  //   label: '密码',
  //   englishLabel:null,
  //   tag: 'el-input',
  //   tagIcon: 'password',
  //   placeholder: '请输入',
  //   defaultValue: undefined,
  //   span: 24,
  //   'show-password': true,
  //   labelWidth: null,
  //   style: { width: '100%' },
  //   clearable: true,
  //   prepend: '',
  //   append: '',
  //   'prefix-icon': '',
  //   'suffix-icon': '',
  //   maxlength: null,
  //   'show-word-limit': false,
  //   readonly: false,
  //   disabled: false,
  //   required: true,
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/input',
  // },
  {
    id: '3',
    label: '计数器',
    englishLabel: null,
    tag: 'el-input-number',
    tagType: 'NUMBER',
    tagIcon: 'number',
    placeholder: '',
    defaultValue: undefined,
    span: 24,
    labelWidth: null,
    min: undefined,
    max: undefined,
    step: undefined,
    'step-strictly': false,
    precision: undefined,
    'controls-position': 'right',
    disabled: false,
    required: true,
    regList: [],
    changeTag: true,
    unit: null,
    document: 'https://element.eleme.cn/#/zh-CN/component/input-number',
    englishLabelReadOnly: false,
    widgetViewType: '',
    specialWidget: false,
  },
  {
    label: '下拉选择',
    englishLabel: null,
    tag: 'el-select',
    tagType: 'SELECT',
    tagIcon: 'select',
    placeholder: '请选择',
    defaultValue: undefined,
    span: 24,
    labelWidth: null,
    style: { width: '100%' },
    clearable: true,
    disabled: false,
    required: true,
    filterable: false,
    multiple: false,
    options: [
      {
        label: '选项一',
        value: 1,
      },
      {
        label: '选项二',
        value: 2,
      },
    ],
    regList: [],
    changeTag: true,
    document: 'https://element.eleme.cn/#/zh-CN/component/select',
    englishLabelReadOnly: false,
    widgetViewType: 'SOLVER',
    specialWidget: true,
  },
  // {
  //   label: '级联选择',
  //   tag: 'el-cascader',
  //   tagIcon: 'cascader',
  //   placeholder: '请选择',
  //   defaultValue: [],
  //   span: 24,
  //   labelWidth: null,
  //   style: { width: '100%' },
  //   props: {
  //     props: {
  //       multiple: false,
  //     },
  //   },
  //   'show-all-levels': true,
  //   disabled: false,
  //   clearable: true,
  //   filterable: false,
  //   required: true,
  //   options: [
  //     {
  //       id: 1,
  //       value: 1,
  //       label: '选项1',
  //       children: [
  //         {
  //           id: 2,
  //           value: 2,
  //           label: '选项1-1',
  //         },
  //       ],
  //     },
  //   ],
  //   dataType: 'dynamic',
  //   labelKey: 'label',
  //   valueKey: 'value',
  //   childrenKey: 'children',
  //   separator: '/',
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/cascader',
  // },
  // {
  //   label: '单选框组',
  //   englishLabel: null,
  //   tag: 'el-radio-group',
  //   tagIcon: 'radio',
  //   tagType: 'RADIO',
  //   defaultValue: undefined,
  //   span: 24,
  //   labelWidth: null,
  //   style: {},
  //   optionType: 'default',
  //   border: false,
  //   size: 'medium',
  //   disabled: false,
  //   required: true,
  //   options: [
  //     {
  //       label: '选项一',
  //       value: 1,
  //     },
  //     {
  //       label: '选项二',
  //       value: 2,
  //     },
  //   ],
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/radio',
  // },
  {
    label: '单选框',
    englishLabel: null,
    tag: 'el-checkbox',
    tagIcon: 'checkbox',
    tagType: 'CHECKBOX',
    defaultValue: undefined,
    span: 24,
    labelWidth: null,
    style: {},
    optionType: 'default',
    border: false,
    size: 'medium',
    disabled: false,
    required: true,
    regList: [],
    changeTag: true,
    document: 'https://element.eleme.cn/#/zh-CN/component/radio',
  },
  {
    label: '多选框组',
    englishLabel: null,
    tag: 'el-checkbox-group',
    tagIcon: 'checkboxs',
    tagType: 'CHECKBOXS',
    defaultValue: [],
    selectList: [],
    span: 24,
    labelWidth: null,
    style: {},
    optionType: 'default',
    border: false,
    size: 'medium',
    disabled: false,
    required: true,
    options: [
      {
        label: '选项一',
        value: 1,
      },
      {
        label: '选项二',
        value: 2,
      },
    ],
    regList: [],
    changeTag: true,
    document: 'https://element.eleme.cn/#/zh-CN/component/checkbox',
    englishLabelReadOnly: false,
    widgetViewType: '',
    specialWidget: false,
  },
  // {
  //   label: '开关',
  //   tag: 'el-switch',
  //   tagIcon: 'switch',
  //   defaultValue: false,
  //   span: 24,
  //   labelWidth: null,
  //   style: {},
  //   disabled: false,
  //   required: true,
  //   'active-text': '',
  //   'inactive-text': '',
  //   'active-color': null,
  //   'inactive-color': null,
  //   'active-value': true,
  //   'inactive-value': false,
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/switch',
  // },
  {
    label: '滑块',
    englishLabel: null,
    tag: 'el-slider',
    tagIcon: 'slider',
    tagType: 'SLIDER',
    defaultValue: 8,
    span: 24,
    labelWidth: null,
    disabled: false,
    required: true,
    min: 1,
    max: 12,
    step: 1,
    'show-stops': false,
    range: false,
    regList: [],
    changeTag: true,
    document: 'https://element.eleme.cn/#/zh-CN/component/slider',
    englishLabelReadOnly: false,
    widgetViewType: 'SOLVER',
    specialWidget: false,
  },
  // {
  //   label: '时间选择',
  //   tag: 'el-time-picker',
  //   tagIcon: 'time',
  //   placeholder: '请选择',
  //   defaultValue: null,
  //   span: 24,
  //   labelWidth: null,
  //   style: { width: '100%' },
  //   disabled: false,
  //   clearable: true,
  //   required: true,
  //   'picker-options': {
  //     selectableRange: '00:00:00-23:59:59',
  //   },
  //   format: 'HH:mm:ss',
  //   'value-format': 'HH:mm:ss',
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/time-picker',
  // },
  // {
  //   label: '时间范围',
  //   tag: 'el-time-picker',
  //   tagIcon: 'time-range',
  //   defaultValue: null,
  //   span: 24,
  //   labelWidth: null,
  //   style: { width: '100%' },
  //   disabled: false,
  //   clearable: true,
  //   required: true,
  //   'is-range': true,
  //   'range-separator': '至',
  //   'start-placeholder': '开始时间',
  //   'end-placeholder': '结束时间',
  //   format: 'HH:mm:ss',
  //   'value-format': 'HH:mm:ss',
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/time-picker',
  // },
  // {
  //   label: '日期选择',
  //   tag: 'el-date-picker',
  //   tagIcon: 'date',
  //   placeholder: '请选择',
  //   defaultValue: null,
  //   type: 'date',
  //   span: 24,
  //   labelWidth: null,
  //   style: { width: '100%' },
  //   disabled: false,
  //   clearable: true,
  //   required: true,
  //   format: 'yyyy-MM-dd',
  //   'value-format': 'yyyy-MM-dd',
  //   readonly: false,
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/date-picker',
  // },
  // {
  //   label: '日期范围',
  //   tag: 'el-date-picker',
  //   tagIcon: 'date-range',
  //   defaultValue: null,
  //   span: 24,
  //   labelWidth: null,
  //   style: { width: '100%' },
  //   type: 'daterange',
  //   'range-separator': '至',
  //   'start-placeholder': '开始日期',
  //   'end-placeholder': '结束日期',
  //   disabled: false,
  //   clearable: true,
  //   required: true,
  //   format: 'yyyy-MM-dd',
  //   'value-format': 'yyyy-MM-dd',
  //   readonly: false,
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/date-picker',
  // },
  // {
  //   label: '评分',
  //   tag: 'el-rate',
  //   tagIcon: 'rate',
  //   defaultValue: 0,
  //   span: 24,
  //   labelWidth: null,
  //   style: {},
  //   max: 5,
  //   'allow-half': false,
  //   'show-text': false,
  //   'show-score': false,
  //   disabled: false,
  //   required: true,
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/rate',
  // },
  // {
  //   label: '颜色选择',
  //   tag: 'el-color-picker',
  //   tagIcon: 'color',
  //   defaultValue: null,
  //   labelWidth: null,
  //   'show-alpha': false,
  //   'color-format': '',
  //   disabled: false,
  //   required: true,
  //   size: 'medium',
  //   regList: [],
  //   changeTag: true,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/color-picker',
  // },
  {
    label: '上传',

    englishLabel: null,
    tag: 'el-upload',
    tagIcon: 'upload',
    tagType: 'FILE',
    action: 'https://jsonplaceholder.typicode.com/posts/',
    defaultValue: null,
    labelWidth: null,
    disabled: false,
    required: true,
    accept: '',
    name: 'file',
    'auto-upload': true,
    showTip: false,
    buttonText: '点击上传',
    fileSize: 2,
    sizeUnit: 'MB',
    'list-type': 'text',
    multiple: false,
    regList: [],
    changeTag: true,
    fileType: '2',
    document: 'https://element.eleme.cn/#/zh-CN/component/upload',
    englishLabelReadOnly: false,
    widgetViewType: '',
    specialWidget: false,
    chooseType: '1',
    fromType: '2',
    isServer: true,
  },
  {
    layout: 'rowFormItem',
    englishLabel: null,
    tagIcon: 'row',
    type: 'default',
    tagType: 'VIEW',
    justify: 'start',
    align: 'top',
    label: '行容器',
    layoutTree: true,
    children: [],
    document: 'https://element.eleme.cn/#/zh-CN/component/layout',
    layoutType: '1',
    readonly: false,
    required: true,
    defaultValue: null,
    hiddenDefaultValue: true,
  },
  // {
  //   layout: 'colFormItem',
  //   label: '按钮',
  //   changeTag: true,
  //   labelWidth: null,
  //   tag: 'el-button',
  //   tagIcon: 'button',
  //   span: 24,
  //   default: '主要按钮',
  //   type: 'primary',
  //   icon: 'el-icon-search',
  //   size: 'medium',
  //   disabled: false,
  //   document: 'https://element.eleme.cn/#/zh-CN/component/button',
  // },
];
export const layoutComponents = [
  {
    layout: 'rowFormItem',
    englishLabel: null,
    tagIcon: 'row',
    type: 'default',
    tagType: 'VIEW',
    justify: 'start',
    align: 'top',
    label: '行容器',
    layoutTree: true,
    children: [],
    document: 'https://element.eleme.cn/#/zh-CN/component/layout',
    layoutType: '1',
    readonly: false,
    required: true,
    defaultValue: null,
  },
];
export function makeMap(str: any, expectsLowerCase: any) {
  const map = Object.create(null);
  const list = str.split(',');
  for (let i = 0; i < list.length; i++) {
    map[list[i]] = true;
  }
  return expectsLowerCase ? (val: any) => map[val.toLowerCase()] : (val: any) => map[val];
}

export function isNumberStr(str: any) {
  return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str);
}

const convertMap = [
  {
    drag: 'label',
    preview: 'chineseLabel',
  },
  {
    drag: 'englishLabel',
    preview: 'englishLabel',
  },

  {
    drag: 'tagType',
    preview: 'type',
  },
  {
    drag: 'multiple',
    preview: 'isMultiple',
  },
  {
    drag: 'fileType',
    preview: 'fileType',
  },
];

const draggableJsonToPreviewJson = (item: any) => {
  item.typeList = [item.tagType];
  item.required = item.required ? '1' : '2';
  if (item.type === 'script') {
  } else if (item.type === 'CHECKBOXS') {
    item.total = item.options.length;
    item.column = item.options.length;
    item.labelList = item.options.map((item_2: any) => item_2.label);
    item.list = item.options.map((item_2: any) => {
      if (item.selectList.includes(item_2.value)) {
        return '1';
      } else {
        return '0';
      }
    });
  } else if (item.type === 'INPUT' || item.type === 'INPUTS') {
    if (item.englishLabel === 'solverName') {
      if (item.options?.length) {
        item.value = item.options[item.solverNameIndex]?.value;
        item.defaultValue = item.value;
        item.solverType = item.value;
        item.solverName = item.value;
        item.solverNames = item.options.map((item_1: any) => item_1.value);
        item.list = item.solverNames;
      }
    }
    item.labelList = [''];
    // item.list = [!item.defaultValue ? '' : item.defaultValue];
    item.list = [];
    item.total = 0;
    item.value = item.defaultValue;
  } else if (item.type === 'CHECKBOX') {
    item.value = item.defaultValue;
  } else if (item.type === 'VIEW') {
    item.chineseLabel = item.componentName;
    item.value = item.defaultValue;
    if (item.tag === 'displayText') {
      item.labelList = [''];
      item.list = [!item.defaultValue ? '' : item.defaultValue];
      item.total = 1;
    } else if (item.layoutType === '2') {
      try {
        item.labelList = item.children.map((item_1: any) => {
          return item_1.label;
        });

        item.list = item.children.map((item_1: any) => {
          return item_1.defaultValue;
        });
        item.units = item.children.map((item_1: any) => {
          return item_1.unit;
        });
        item.total = item.children.length;
        item.column = item.children.length;
        const childType = item.children?.length ? item.children[0].tagType : '';
        item.type = childType === 'INPUT' ? 'INPUTS' : childType === 'NUMBER' ? 'NUMBERS' : '';
        item.typeList = [item.type];
        item.needLabel = item.labelList.every((item_2: any) => {
          return item_2;
        });
        if (item.children) {
          delete item.children;
        }
      } catch {}
    }
  } else if (item.type === 'SLIDER') {
    item.minValue = item.min;
    item.maxValue = item.max;
    item.value = item.defaultValue;
  } else if (item.type === 'SELECT') {
    item.value = item.defaultValue ? item.defaultValue + '' : null;
    item.labelList = item.options
      .map((item: any) => {
        return item.label;
      })
      .join(';');
    item.mapList = item.options
      .map((item: any) => {
        return item.value;
      })
      .join(';');
  } else if (item.type === 'NUMBER' || item.type === 'NUMBERS') {
    item.value = item.defaultValue;
    item.units = [item.unit || ''];
    // item.list = [!item.defaultValue ? '' : item.defaultValue];
    item.list = [];
    item.total = 0;
    item.column = 1;
  } else if (item.type === 'RADIO') {
    item.value = item.defaultValue;
  }
  if (!item.value === null || item.value === undefined) {
    item.value = '';
  }
};

const previewJsonToDraggableJson = (item: any) => {
  if (!item?.typeList) return;
  item.tagType = item.typeList[0] || item.type;
  item.required = item.required == 1 ? true : false;
  if (item.englishLabel === 'script') {
    item.tag = 'script';
    item.layout = 'colFormItem';
    item.changeTag = true;
    item.renderKey = +new Date();
  } else if (item.widgetViewType === 'SOLVER' && item.englishLabel === 'solverName') {
    item.tag = 'solverName';
    item.layout = 'colFormItem';
    item.changeTag = true;
    item.renderKey = +new Date();
    if (item.solverNames?.length) {
      item.options = item.solverNames.map((item_1: any) => {
        return {
          value: item_1,
          label: item_1,
        };
      });
      item.solverNames = [item.options[item.solverNameIndex]?.value];
      item.list = item.solverNames;
      item.solverName = item.options[item.solverNameIndex]?.value;
      item.solverType = item.solverName;
    } else {
      item.options = [];
      item.solverNames = [];
      item.solverName = '';
      item.solverType = item.solverName;
      item.list = item.solverNames;
    }
  } else if (item.type === 'CHECKBOXS') {
    item.tag = 'el-checkbox-group';
    item.layout = 'colFormItem';
    item.changeTag = true;
    item.tagIcon = 'checkboxs';
    item.renderKey = +new Date();
    item.options = [];
    item.options =
      item.labelList
        ?.map((item_1: any, index_1: any) => {
          if (index_1 < item.total) {
            return {
              label: item_1,
              value: item_1,
            };
          }
        })
        .filter((item_1: any) => item_1) || [];
    item.selectList =
      item.labelList?.filter((item_1: any, index_1: any) => {
        return item.list[index_1] === '1';
      }) || [];
  } else if (item.type === 'INPUT' || item.type === 'INPUTS') {
    if (item.labelList?.length === 1) {
      item.tagIcon = 'input';
      item.tag = 'el-input';
      item.layoutType = '1';
      item.defaultValue = item.value;
      item.layout = 'colFormItem';
      item.changeTag = true;
      item.renderKey = +new Date();
    } else if (item.type === 'VIEW') {
      item.tagIcon = 'input';
      item.tag = 'displayText';
      item.layoutType = '1';
      item.defaultValue = item.value;
      item.layout = 'colFormItem';
      item.changeTag = true;
      item.renderKey = +new Date();
    } else if (item.labelList?.length > 1) {
      item.layoutType = '2';
      item.type = 'VIEW';
      item.tagType = 'VIEW';
      item.typeList = ['VIEW'];
      item.layout = 'rowFormItem';
      item.componentName = item.chineseLabel;
      item.defaultValue = item.value;
      item.children = item.labelList.map((item_1: any, index_1: any) => {
        const formId = random(0, 1, true);
        return {
          label: item_1,
          defaultValue: item.list[index_1],
          tag: 'el-input',
          tagIcon: 'input',
          tagType: 'INPUT',
          layout: 'colFormItem',
          list: [item.list[index_1]],
          labelList: [item_1],
          chineseLabel: item_1,
          formId: formId,
          vModel: `field${formId}`,
          typeList: ['INPUT'],
          changeTag: true,
          renderKey: +new Date(),
        };
      });
      item.value = '';
    } else {
      item.layout = 'colFormItem';
      item.changeTag = true;
      item.renderKey = +new Date();
      item.tag = 'el-input';
      item.typeList = ['INPUT'];
      item.tagIcon = 'input';
      item.defaultValue = item.value;
    }
  } else if (item.type === 'VIEW') {
    if (!item.isSpecialBox) {
      item.layout = 'rowFormItem';
      item.componentName = item.chineseLabel;
      item.defaultValue = item.value;
      item.layoutType = item.layoutType || '1';
      item.changeTag = true;
      item.renderKey = +new Date();
    } else {
      item.layout = 'colFormItem';
      item.defaultValue = item.value;
      item.tag = 'displayText';
      item.tagIcon = 'input';
    }
  } else if (item.type === 'CHECKBOX') {
    item.tag = 'el-checkbox';
    item.tagIcon = 'checkbox';
    item.defaultValue = item.value;
    item.layout = 'colFormItem';
    item.changeTag = true;
    item.renderKey = +new Date();
  } else if (item.type === 'SLIDER') {
    item.tag = 'el-slider';
    item.tagIcon = 'slider';
    item.min = item.minValue;
    item.max = item.maxValue;
    item.defaultValue = item.value;
    item.layout = 'colFormItem';
    item.changeTag = true;
    item.renderKey = +new Date();
  } else if (item.type === 'SELECT') {
    item.tag = 'el-select';
    item.tagIcon = 'select';
    item.defaultValue = item.value + '';
    item.layout = 'colFormItem';

    item.renderKey = +new Date();
    item.changeTag = true;

    item.selectList = item.labelList
      ? item.labelList.split(';')?.map((item_1: any, index_1: any) => {
          return {
            label: item_1,
            value: item.mapList ? item.mapList.split(';')[index_1] : item_1,
          };
        })
      : [];
    item.options = item.selectList;
  } else if (item.type === 'FILE') {
    item.tag = 'el-upload';
    item.tagIcon = 'upload';
    item.tagType = 'FILE';
    item.layout = 'colFormItem';
    item.renderKey = +new Date();
  } else if (item.type === 'NUMBER' || item.type === 'NUMBERS') {
    if (item.labelList?.length === 1) {
      item.defaultValue = item.value;
      item.unit = item.units?.length ? item.units[0] : null;
      item.tag = 'el-input-number';
      item.tagIcon = 'number';
      item.tagType = 'NUMBER';
      item.layout = 'colFormItem';
      item.renderKey = +new Date();
    } else if (item.labelList?.length > 1) {
      item.layoutType = '2';
      item.type = 'VIEW';
      item.tagType = 'VIEW';
      item.typeList = ['VIEW'];
      item.layout = 'rowFormItem';
      item.componentName = item.chineseLabel;
      item.defaultValue = item.value;
      item.children = item.labelList.map((item_1: any, index_1: any) => {
        const formId = random(0, 1, true);
        return {
          label: item_1,
          defaultValue: item.list[index_1],
          tag: 'el-input-number',
          tagIcon: 'number',
          tagType: 'NUMBER',
          layout: 'colFormItem',
          list: [item.list[index_1]],
          labelList: [item_1],
          chineseLabel: item_1,
          formId: formId,
          vModel: `field${formId}`,
          typeList: ['NUMBER'],
          changeTag: true,
          renderKey: +new Date(),
          unit: item.units[index_1],
        };
      });
      item.value = '';
    }
  }
};
/**
 *
 * @param list
 * @param type 1是拖拽json转预览json,2是预览json转拖拽json
 */
export const convertDragList = (list: any, type: string = '1', depth: number = 1) => {
  list?.forEach((item: any) => {
    item.level = depth;
    convertMap.forEach((item_1: any) => {
      if (type === '1') {
        item[item_1.preview] = item[item_1.drag];
      } else {
        item[item_1.drag] = item[item_1.preview];
      }
    });
    if (type === '1') {
      draggableJsonToPreviewJson(item);
    }

    if (type === '2') {
      item.formId = random(0, 1, true);
      item.vModel = `field${item.formId}`;
      item.id = item.formId;
      if (!item.englishLabel) {
        item.englishLabel = null;
      }
      previewJsonToDraggableJson(item);
    }
    if (item.children?.length) {
      if (type === '2' && (!item.layoutType || item.layoutType === '1')) {
        const itemClone: any = cloneDeep(item);
        item.layout = 'rowFormItem';
        item.componentName = item.chineseLabel;
        item.defaultValue = item.value;
        item.layoutType = item.layoutType || '1';
        item.changeTag = true;
        item.renderKey = +new Date();

        itemClone.changeTag = true;
        itemClone.renderKey = +new Date();
        delete itemClone.children;
        if (item.type === 'VIEW') {
          itemClone.isSpecialBox = true;
        }
        item.children.unshift(itemClone);
      }

      convertDragList(item.children, type, depth + 1);
      if (type === '1') {
        const displayItemClone = item.children.shift();
        for (const key in displayItemClone) {
          if (key !== 'chineseLabel') {
            item[key] = displayItemClone[key];
          }
        }
      }
    } else if (item.type === 'VIEW' && item.layoutType === '1') {
      item.tagIcon = 'input';
      item.tag = 'displayText';
      item.layoutType = '1';
      item.defaultValue = item.list?.length ? item.list[0] : null;
      item.layout = 'colFormItem';
      item.changeTag = true;
      item.renderKey = +new Date();
    }
  });
};
