export function initRenders(titleTab) {
  const cols = [
    {
      title: "序号",
      key: "num_key",
      render: (text, record, index) => {
        return index + 1;
      }
    }
  ];
  let columns = [];
  if (titleTab) {
    columns = titleTab.map(field => ({
      title: field.displayName,
      dataIndex: field.field,
      key: field.field,
      renderType: field.renderType,
      enumSource: field.enumSource
    }));
  }

  for (let i = 0; i < columns.length; i++) {
    if (columns[i].renderType == "enum") {
      const { enumSource } = columns[i];
      columns[i].render = (text, record, index) => {
        return enumRender(text, enumSource);
      };
    }
  }
  return cols.concat(columns);
}

export function enumRender(value, enumSource) {
  for (let i = 0; i < enumSource.length; i++) {
    if (value == enumSource[i].value) {
      return enumSource[i].text;
    }
  }
  return value;
}
