/**
 * @file 通用表单schema字段
 */
import * as DistributorApi from '/@/api/system/distributorApi';
import get from 'lodash.get';

const getDistributorId = ({ colProps }) => {
  return {
    field: 'distributorId',
    label: '经销商',
    defaultValue: undefined,
    form: {
      componentProps: {
        labelInValue: true,
        api: DistributorApi.all,
        params: {},
        resultField: 'records',
        labelField: 'name',
        valueField: 'id',
        allowClear: false,
        placeholder: '经销商',
      },
      colProps,
      component: 'ApiSelect',
      rules: [{ required: true, type: 'object', message: '请选择经销商！' }],
    },
    table: {
      customRender: ({ text, record }) => get(record, 'distributor.name') || text,
    },
  };
};

export { getDistributorId };
