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

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

const getHospitalId = ({ colProps }) => {
  return {
    field: 'hospitalId',
    label: '医院',
    defaultValue: undefined,
    form: {
      itemProps: {
        validateTrigger: 'blur',
      },
      componentProps: {
        labelInValue: true,
        api: HospitalApi.all,
        params: {},
        resultField: 'records',
        labelField: 'name',
        valueField: 'id',
        allowClear: false,
        placeholder: '医院',
        optionFilterProp: 'label',
        showSearch: true,
      },
      colProps,
      component: 'ApiSelect',
      rules: [{ required: true, type: 'object', message: '请选择医院！' }],
    },
    table: {
      customRender: ({ text, record }) => get(record, 'hospital.name') || text,
    },
  };
};

export { getDistributorId, getHospitalId };
