import { FormProps, FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table';
import { uploadApi } from '/@/api/sys/upload';

export const searchFormSchema: FormSchema[] = [
  {
    field: 'cpmc',
    label: '产品名称',
    defaultValue: undefined,
    component: 'Input',
  },
  {
    field: 'cpbh',
    label: '产品编号',
    defaultValue: undefined,
    component: 'Input',
  },
  {
    field: 'cplx',
    label: '产品类别',
    defaultValue: undefined,
    component: 'ApiCascader',
    componentProps: {
      apiConfig: {
        path: '/jcxx/cplx/getAllCPLXTree_zujian',
        method: 'GET',
        apiId: 'copy1770283483454d34933',
        apiParams: [
          {
            key: '1',
            title: 'Query Params',
            tableInfo: [
              {
                name: 'code',
                value: null,
                description: null,
                required: false,
                dataType: 'String',
                type: null,
                defaultValue: null,
                validateType: null,
                error: null,
                expression: null,
                children: null,
                bindType: '',
              },
            ],
          },
          { key: '2', title: 'Header', tableInfo: [] },
          { key: '3', title: 'Body' },
        ],
        script:
          'var sql = ""\r\n    + "select id,"\r\n    + " pid as \'parentId\', "\r\n    + " id as \'value\', "\r\n    + " cm as \'label\' "\r\n    + "from mes_base_cplx "\r\n    + "where delete_mark = 0 "\r\n    + "order by pid, id";\r\nvar list = db.select(sql);\r\n\r\nif (list == null || list.size() == 0) {\r\n    return [];\r\n}\r\nvar map = new HashMap();\r\nvar idx = 0;\r\nwhile (idx < list.size()) {\r\n    var itemNode = list.get(idx);\r\n    itemNode.children = [];\r\n    map.put(itemNode.id, itemNode);\r\n    idx = idx + 1;\r\n}\r\nvar dataList = [];\r\nidx = 0;\r\nwhile (idx < list.size()) {\r\n    var itemNode = list.get(idx);\r\n    if (itemNode.parentId == null || itemNode.parentId == \'0\' || itemNode.parentId == \'\') {\r\n        dataList.add(itemNode);\r\n    } else {\r\n        var pid = null;\r\n        if (itemNode.parentId.contains(",")){\r\n            var arr = itemNode.parentId.split(",");\r\n            pid=arr[arr.length-1]\r\n        }else{\r\n            pid=itemNode.parentId;\r\n        }\r\n        var parentNode = map.get(pid);\r\n        if (parentNode != null) {\r\n            parentNode.children.add(itemNode);\r\n        } else {\r\n            dataList.add(itemNode);\r\n        }\r\n    }\r\n    idx = idx + 1;\r\n}\r\nreturn dataList\r\n',
      },
      showFormat: 'all',
      separator: '/',
      selectedConfig: 'any',
    },
  },
];

export const columns: BasicColumn[] = [
  {
    resizable: true,
    dataIndex: 'cpmc',
    title: '产品名称',
    componentType: 'input',

    fixed: false,
    sorter: true,

    styleConfig: undefined,
    listStyle: '',
  },

  {
    resizable: true,
    dataIndex: 'cpbh',
    title: '产品编号',
    componentType: 'input',

    fixed: false,
    sorter: true,

    styleConfig: undefined,
    listStyle: '',
  },

  {
    resizable: true,
    dataIndex: 'gg',
    title: '规格',
    componentType: 'input',

    fixed: false,
    sorter: true,

    styleConfig: undefined,
    listStyle: '',
  },

  {
    resizable: true,
    dataIndex: 'xh',
    title: '型号',
    componentType: 'input',

    fixed: false,
    sorter: true,

    styleConfig: undefined,
    listStyle: '',
  },

  {
    resizable: true,
    dataIndex: 'cplx',
    title: '产品类别',
    componentType: 'cascader',

    fixed: false,
    sorter: true,

    styleConfig: undefined,
    listStyle: undefined,
  },

  {
    resizable: true,
    dataIndex: 'bzzl',
    title: '标准重量',
    componentType: 'number',

    fixed: false,
    sorter: true,

    styleConfig: undefined,
    listStyle: undefined,
  },
];
//表头合并配置
export const headerMergingData = [];
//表单事件
export const formEventConfigs = {
  0: [
    {
      type: 'circle',
      color: '#2774ff',
      text: '开始节点',
      icon: '#icon-kaishi',
      bgcColor: '#D8E5FF',
      isUserDefined: false,
    },
    {
      color: '#F6AB01',
      icon: '#icon-chushihua',
      text: '初始化表单',
      bgcColor: '#f9f5ea',
      isUserDefined: false,
      nodeInfo: { processEvent: [] },
    },
  ],
  1: [
    {
      color: '#B36EDB',
      icon: '#icon-shujufenxi',
      text: '获取表单数据',
      detail: '(新增无此操作)',
      bgcColor: '#F8F2FC',
      isUserDefined: false,
      nodeInfo: { processEvent: [] },
    },
  ],
  2: [
    {
      color: '#F8625C',
      icon: '#icon-jiazai',
      text: '加载表单',
      bgcColor: '#FFF1F1',
      isUserDefined: false,
      nodeInfo: { processEvent: [] },
    },
  ],
  3: [
    {
      color: '#6C6AE0',
      icon: '#icon-jsontijiao',
      text: '提交表单',
      bgcColor: '#F5F4FF',
      isUserDefined: false,
      nodeInfo: { processEvent: [] },
    },
  ],
  4: [
    {
      type: 'circle',
      color: '#F8625C',
      text: '结束节点',
      icon: '#icon-jieshuzhiliao',
      bgcColor: '#FFD6D6',
      isLast: true,
      isUserDefined: false,
    },
  ],
};
export const formProps: FormProps = {
  labelCol: { span: 3, offset: 0 },
  labelAlign: 'right',
  layout: 'horizontal',
  size: 'default',
  schemas: [
    {
      key: '1f1fb7bd2e914b399e728160b594bc33',
      field: '',
      label: '',
      type: 'grid',
      colProps: { span: 24 },
      component: 'Grid',
      children: [
        {
          span: 2,
          list: [
            {
              key: '4e15f120f3ee4d9fbe0a1a0ae9e2f97e',
              field: 'cptp',
              label: '',
              type: 'image',
              component: 'Image',
              colProps: { span: 24 },
              defaultValue: '',
              componentProps: {
                span: 2,
                defaultValue: '',
                showLabel: true,
                isShow: true,
                isUpload: true,
                sourceType: 'album,camera',
                events: {},
                tooltipConfig: { visible: false, title: '提示文本' },
                style: {},
              },
            },
          ],
        },
        {
          span: 4,
          list: [
            {
              key: 'a460a8af25d04694a22bd64a032030e0',
              field: 'cpmc',
              label: '产品名称',
              type: 'input',
              component: 'Input',
              colProps: { span: 24 },
              defaultValue: '',
              componentProps: {
                width: '100%',
                span: 9,
                defaultValue: '',
                placeholder: '请输入产品名称',
                prefix: '',
                suffix: '',
                addonBefore: '',
                addonAfter: '',
                disabled: false,
                allowClear: false,
                showLabel: true,
                required: false,
                rules: [],
                events: {},
                listStyle: '',
                isSave: false,
                isShow: true,
                scan: false,
                bordered: true,
                isShowAi: false,
                tooltipConfig: { visible: false, title: '提示文本' },
                style: { width: '100%' },
              },
            },
            {
              key: 'dc527027d15944a9b6b09232f0cd4789',
              field: 'cpbh',
              label: '产品编号',
              type: 'input',
              component: 'Input',
              colProps: { span: 24 },
              defaultValue: '',
              componentProps: {
                width: '100%',
                span: 9,
                defaultValue: '',
                placeholder: '请输入产品编号',
                prefix: '',
                suffix: '',
                addonBefore: '',
                addonAfter: '',
                disabled: false,
                allowClear: false,
                showLabel: true,
                required: false,
                rules: [],
                events: {},
                listStyle: '',
                isSave: false,
                isShow: true,
                scan: false,
                bordered: true,
                isShowAi: false,
                tooltipConfig: { visible: false, title: '提示文本' },
                style: { width: '100%' },
              },
            },
          ],
        },
        { span: 1, list: [] },
        {
          span: 8,
          list: [
            {
              key: '8b4babad12cb4d669d171a78abbd8175',
              field: '',
              label: '',
              type: 'grid',
              colProps: { span: 24 },
              component: 'Grid',
              children: [
                {
                  span: 4,
                  list: [
                    {
                      key: '229a158148af45808c1527cc7dc76677',
                      field: 'kxs',
                      label: '',
                      type: 'checkbox',
                      component: 'ApiCheckboxGroup',
                      colProps: { span: 24 },
                      componentProps: {
                        span: 7,
                        showLabel: true,
                        disabled: false,
                        staticOptions: [{ key: 1, label: '可销售', value: '1' }],
                        datasourceType: 'staticData',
                        defaultSelect: '1',
                        labelField: 'label',
                        valueField: 'value',
                        apiConfig: {
                          path: 'CodeGeneration/selection',
                          method: 'GET',
                          apiId: '93d735dcb7364a0f8102188ec4d77ac7',
                        },
                        dicOptions: [],
                        required: false,
                        rules: [],
                        events: {},
                        isShow: true,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        listStyle: "return 'margin-left:30px;'",
                        style: {},
                      },
                    },
                  ],
                },
                {
                  span: 4,
                  list: [
                    {
                      key: '858413cbade048248b39abd7ee1b9641',
                      field: 'kcg',
                      label: '',
                      type: 'checkbox',
                      component: 'ApiCheckboxGroup',
                      colProps: { span: 24 },
                      componentProps: {
                        span: 7,
                        showLabel: true,
                        disabled: false,
                        staticOptions: [{ key: 1, label: '可采购', value: '1' }],
                        datasourceType: 'staticData',
                        defaultSelect: '1',
                        labelField: 'label',
                        valueField: 'value',
                        apiConfig: {
                          path: 'CodeGeneration/selection',
                          method: 'GET',
                          apiId: '93d735dcb7364a0f8102188ec4d77ac7',
                        },
                        dicOptions: [],
                        required: false,
                        rules: [],
                        events: {},
                        isShow: true,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        listStyle: "return 'margin-left:30px;'",
                        style: {},
                      },
                    },
                  ],
                },
                { span: 4, list: [] },
              ],
              componentProps: {
                gutter: 0,
                justify: 'start',
                align: 'bottom',
                isShow: true,
                showBorder: false,
                bordercolor: '#d9d9d9',
                bordershowtype: [true, true, true, true],
                borderwidth: 1,
                padding: '0',
                margin: '0',
                span: 0,
              },
            },
            {
              key: '64df29de9dfa47bfba8cb389db383c2d',
              field: 'wllx',
              label: '',
              type: 'radio',
              component: 'ApiRadioGroup',
              colProps: { span: 24 },
              componentProps: {
                span: 0,
                showLabel: true,
                disabled: false,
                optionType: 'default',
                staticOptions: [
                  { key: 1, label: '半成品', value: '半成品' },
                  { key: 2, label: '成品', value: '成品' },
                  { key: 3, label: '原材料', value: '原材料' },
                  { key: 4, label: '其它', value: '其它' },
                ],
                datasourceType: 'staticData',
                labelField: 'label',
                valueField: 'value',
                defaultSelect: '',
                apiConfig: {
                  path: 'CodeGeneration/selection',
                  method: 'GET',
                  apiId: '93d735dcb7364a0f8102188ec4d77ac7',
                },
                dicOptions: [],
                required: false,
                rules: [],
                events: {},
                isShow: true,
                tooltipConfig: { visible: false, title: '提示文本' },
                style: {},
              },
            },
          ],
        },
      ],
      componentProps: {
        justify: 'start',
        align: 'bottom',
        isShow: true,
        showBorder: false,
        bordercolor: '#d9d9d9',
        bordershowtype: [true, true, true, true],
        borderwidth: 1,
        padding: '10px',
        margin: '10px',
      },
    },
    {
      key: 'aa875806550d4c22b12a5aa8e82495f1',
      field: '',
      label: '',
      type: 'tab',
      colProps: { span: 24 },
      component: 'Tab',
      children: [
        {
          span: 24,
          name: '基础信息',
          prefix: '',
          suffix: '',
          activeColor: '#1c8dff',
          folderId: '',
          imageUrl: '',
          conFolderId: '',
          conImageUrl: '',
          list: [
            {
              key: '9973c1c91dd94ae3a1f5f1f97816ced5',
              field: '',
              label: '文本',
              type: 'text',
              component: 'Text',
              colProps: { span: 24 },
              defaultValue: '基础',
              componentProps: {
                defaultValue: '基础',
                color: '',
                align: 'left',
                fontSize: 16,
                fontWeight: 'bold',
                fontFamily: '黑体',
                fontStyle: 'normal',
                isShow: true,
                padding: '0',
                margin: '0',
                style: {},
              },
            },
            {
              key: '07a43f641ec5454487ace5f117bb98a0',
              field: '',
              label: '',
              type: 'grid',
              colProps: { span: 24 },
              component: 'Grid',
              children: [
                {
                  span: 6,
                  list: [
                    {
                      key: '2c05765e50b44fa8be4aec443066f781',
                      field: 'cplx',
                      label: '产品类别',
                      type: 'cascader',
                      component: 'ApiCascader',
                      colProps: { span: 24 },
                      componentProps: {
                        width: '100%',
                        span: 7,
                        placeholder: '请选择产品类别',
                        showFormat: 'all',
                        separator: '/',
                        selectedConfig: 'any',
                        disabled: false,
                        allowClear: false,
                        showLabel: true,
                        apiConfig: {
                          path: '/jcxx/cplx/getAllCPLXTree_zujian',
                          method: 'GET',
                          apiId: 'copy1770283483454d34933',
                          apiParams: [
                            {
                              key: '1',
                              title: 'Query Params',
                              tableInfo: [
                                {
                                  name: 'code',
                                  value: null,
                                  description: null,
                                  required: false,
                                  dataType: 'String',
                                  type: null,
                                  defaultValue: null,
                                  validateType: null,
                                  error: null,
                                  expression: null,
                                  children: null,
                                  bindType: '',
                                },
                              ],
                            },
                            { key: '2', title: 'Header', tableInfo: [] },
                            { key: '3', title: 'Body' },
                          ],
                          script:
                            'var sql = ""\r\n    + "select id,"\r\n    + " pid as \'parentId\', "\r\n    + " id as \'value\', "\r\n    + " cm as \'label\' "\r\n    + "from mes_base_cplx "\r\n    + "where delete_mark = 0 "\r\n    + "order by pid, id";\r\nvar list = db.select(sql);\r\n\r\nif (list == null || list.size() == 0) {\r\n    return [];\r\n}\r\nvar map = new HashMap();\r\nvar idx = 0;\r\nwhile (idx < list.size()) {\r\n    var itemNode = list.get(idx);\r\n    itemNode.children = [];\r\n    map.put(itemNode.id, itemNode);\r\n    idx = idx + 1;\r\n}\r\nvar dataList = [];\r\nidx = 0;\r\nwhile (idx < list.size()) {\r\n    var itemNode = list.get(idx);\r\n    if (itemNode.parentId == null || itemNode.parentId == \'0\' || itemNode.parentId == \'\') {\r\n        dataList.add(itemNode);\r\n    } else {\r\n        var pid = null;\r\n        if (itemNode.parentId.contains(",")){\r\n            var arr = itemNode.parentId.split(",");\r\n            pid=arr[arr.length-1]\r\n        }else{\r\n            pid=itemNode.parentId;\r\n        }\r\n        var parentNode = map.get(pid);\r\n        if (parentNode != null) {\r\n            parentNode.children.add(itemNode);\r\n        } else {\r\n            dataList.add(itemNode);\r\n        }\r\n    }\r\n    idx = idx + 1;\r\n}\r\nreturn dataList\r\n',
                        },
                        required: false,
                        rules: [],
                        events: {},
                        isShow: true,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                    {
                      key: '844afd05cb5048449fb49670df62bfdb',
                      field: 'fpl',
                      label: '废品率（%）',
                      type: 'number',
                      component: 'InputNumber',
                      colProps: { span: 24 },
                      defaultValue: 0,
                      componentProps: {
                        width: '100%',
                        span: 7,
                        defaultValue: 0,
                        min: 0,
                        max: 100,
                        step: 0.1,
                        disabled: false,
                        showLabel: true,
                        controls: true,
                        required: false,
                        subTotal: false,
                        isShow: true,
                        rules: [],
                        events: {},
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                    {
                      key: 'adc48bfeb4ec40c982b4b6c40c07a8e1',
                      field: 'sfyx',
                      label: '有效的',
                      type: 'switch',
                      component: 'Switch',
                      colProps: { span: 24 },
                      defaultValue: 1,
                      componentProps: {
                        span: 7,
                        defaultValue: 1,
                        checkedChildren: '',
                        unCheckedChildren: '',
                        checkedColor: '#1C8DFF',
                        unCheckedColor: '#bbbdbf',
                        showLabel: true,
                        disabled: false,
                        events: {},
                        isShow: true,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: {},
                      },
                    },
                  ],
                },
                {
                  span: 6,
                  list: [
                    {
                      key: 'ddeda11a238e4e0b9b18006c0202b511',
                      field: 'gg',
                      label: '规格',
                      type: 'input',
                      component: 'Input',
                      colProps: { span: 24 },
                      defaultValue: '',
                      componentProps: {
                        width: '100%',
                        span: 7,
                        defaultValue: '',
                        placeholder: '请输入规格',
                        prefix: '',
                        suffix: '',
                        addonBefore: '',
                        addonAfter: '',
                        disabled: false,
                        allowClear: false,
                        showLabel: true,
                        required: false,
                        rules: [],
                        events: {},
                        listStyle: '',
                        isSave: false,
                        isShow: true,
                        scan: false,
                        bordered: true,
                        isShowAi: false,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                    {
                      key: 'e0a69ab733de4819bc02c8305de3521e',
                      field: 'bzzl',
                      label: '标准重量',
                      type: 'number',
                      component: 'InputNumber',
                      colProps: { span: 24 },
                      defaultValue: 0,
                      componentProps: {
                        width: '100%',
                        span: 7,
                        defaultValue: 0,
                        min: 0,
                        step: 1,
                        disabled: false,
                        showLabel: true,
                        controls: true,
                        required: false,
                        subTotal: false,
                        isShow: true,
                        rules: [],
                        events: {},
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                  ],
                },
                {
                  span: 6,
                  list: [
                    {
                      key: '8f188c8662e54061b2943d5fb896bc8f',
                      field: 'xh',
                      label: '型号',
                      type: 'input',
                      component: 'Input',
                      colProps: { span: 24 },
                      defaultValue: '',
                      componentProps: {
                        width: '100%',
                        span: 7,
                        defaultValue: '',
                        placeholder: '请输入型号',
                        prefix: '',
                        suffix: '',
                        addonBefore: '',
                        addonAfter: '',
                        disabled: false,
                        allowClear: false,
                        showLabel: true,
                        required: false,
                        rules: [],
                        events: {},
                        listStyle: '',
                        isSave: false,
                        isShow: true,
                        scan: false,
                        bordered: true,
                        isShowAi: false,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                    {
                      key: '19b87c1f6faf41588c18aa15647c2026',
                      field: 'hjzt',
                      label: '合金状态',
                      type: 'input',
                      component: 'Input',
                      colProps: { span: 24 },
                      defaultValue: '',
                      componentProps: {
                        width: '100%',
                        span: 7,
                        defaultValue: '',
                        placeholder: '请输入合金状态',
                        prefix: '',
                        suffix: '',
                        addonBefore: '',
                        addonAfter: '',
                        disabled: false,
                        allowClear: false,
                        showLabel: true,
                        required: false,
                        rules: [],
                        events: {},
                        listStyle: '',
                        isSave: false,
                        isShow: true,
                        scan: false,
                        bordered: true,
                        isShowAi: false,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                  ],
                },
                {
                  span: 6,
                  list: [
                    {
                      key: 'b3565aaf26f140b4943dd3a8fbb83e06',
                      field: 'nbdm',
                      label: '内部代码',
                      type: 'input',
                      component: 'Input',
                      colProps: { span: 24 },
                      defaultValue: '',
                      componentProps: {
                        width: '100%',
                        span: 7,
                        defaultValue: '',
                        placeholder: '请输入内部代码',
                        prefix: '',
                        suffix: '',
                        addonBefore: '',
                        addonAfter: '',
                        disabled: false,
                        allowClear: false,
                        showLabel: true,
                        required: false,
                        rules: [],
                        events: {},
                        listStyle: '',
                        isSave: false,
                        isShow: true,
                        scan: false,
                        bordered: true,
                        isShowAi: false,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                    {
                      key: '9cd3ae5314614be5b1929c3503a54841',
                      field: 'erpid',
                      label: 'ERP ID',
                      type: 'input',
                      component: 'Input',
                      colProps: { span: 24 },
                      defaultValue: '',
                      componentProps: {
                        width: '100%',
                        span: 7,
                        defaultValue: '',
                        placeholder: '请输入ERP ID',
                        prefix: '',
                        suffix: '',
                        addonBefore: '',
                        addonAfter: '',
                        disabled: false,
                        allowClear: false,
                        showLabel: true,
                        required: false,
                        rules: [],
                        events: {},
                        listStyle: '',
                        isSave: false,
                        isShow: true,
                        scan: false,
                        bordered: true,
                        isShowAi: false,
                        tooltipConfig: { visible: false, title: '提示文本' },
                        style: { width: '100%' },
                      },
                    },
                  ],
                },
              ],
              componentProps: {
                gutter: 0,
                justify: 'start',
                align: 'top',
                isShow: true,
                showBorder: false,
                bordercolor: '#d9d9d9',
                bordershowtype: [true, true, true, true],
                borderwidth: 1,
                padding: '10px',
                margin: '0',
              },
            },
          ],
        },

      ],
      componentProps: { tabPosition: 'top', size: 'default', type: 'line', isShow: true },
    },
  ],
  showActionButtonGroup: false,
  buttonLocation: 'center',
  actionColOptions: { span: 24 },
  showResetButton: false,
  showSubmitButton: false,
  hiddenComponent: [],
};

export const treeConfig = {
  id: '2019350969972043778',
  isMultiple: true,
  name: '产品类型',
  type: 2,
  configTip: '已配置',
  config: [{ bindFiled: 'cplx', name: '类型名称', value: 'value' }],
};
