import { doFetch } from './doFetch';

export default async (fieldscolumns, setdrawer, row, formId, detailpath) => {
  let newfieldscolumns = [];
  const selectValueType = (type, options) => {
    switch (type) {
      case 1:
        return {
          valueType: 'input',
        };
      case 2:
        return {
          valueType: 'select',
          options,
        };
      case 3:
        return {
          valueType: 'radio',
          options,
        };
      case 4:
        return {
          valueType: 'select',
          options,
        };
      default:
        break;
    }
  };

  const selectextendField = (type) => {
    switch (Number(type)) {
      case 1:
        return 'userCharList';
      case 2:
        return 'equipmentCharList';
      case 3:
        return 'equipmentSupplierCharList';
      default:
        break;
    }
  };
  let res = await doFetch({
    url: '/base/paFormField/queryList',
    params: {
      formId,
    },
  });
  if (res?.data?.dataList) {
    let column = [
      {
        title: '扩展字段',
        valueType: 'split',
      },
    ];
    res?.data?.dataList?.forEach?.((el) => {
      column.push({
        ...selectValueType(el.fieldChar, el.valueList),
        title: el.fieldName,
        dataIndex: el.id,
        key: el.id,
      });
    });
    newfieldscolumns = fieldscolumns.concat(column);
    //console.log('fieldscolumns', newfieldscolumns);
  }
  setdrawer((s) => ({
    ...s,
    visible: true,
    item: row,
    title: '详情',
    fields: newfieldscolumns,
    extendField: selectextendField(formId),
    detailpath,
    params: { id: row.id },
    val: 'detail',
    title: row.fullName + '的详细信息',
  }));
};
