import { BasicColumn, FormSchema } from '/@/components/Table';
import { getDictItemsByCode } from '/@/utils/dict';

let metrictype_map_flag = true
let metrictype_map = {}
let collectCode_map = {}
let collectRateCode_map = {}
if(metrictype_map_flag){
  let data = getDictItemsByCode('metrictype')
  if(data && data instanceof Array){
    data.forEach((item) => {metrictype_map[item.value] =item.text})
  }
  let dataway = getDictItemsByCode('colletway')
  if(dataway && dataway instanceof Array){
    dataway.forEach((item) => {collectCode_map[item.value] =item.text})
  }
  let datarate = getDictItemsByCode('colletrate')
  if(datarate && datarate instanceof Array){
    datarate.forEach((item) => {collectRateCode_map[item.value] =item.text})
  }
  metrictype_map_flag = true
}
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '指标编号',
    align:"center",
    dataIndex: 'metricNo',
    width:100
   },
   {
    title: '指标名称',
    align:"left",
    dataIndex: 'metricName',
    width:300
   },
   {
    title: '指标类型',
    align:"center",
    dataIndex: 'metricTypeCode',
    width:100,
    customRender:({text}) =>{
      return !metrictype_map[text]?'-':metrictype_map[text]
    },
   },
   {
    title: '采集方式',
    align:"center",
    dataIndex: 'collectCode',
    width:100,
    customRender:({text}) =>{
      return !collectCode_map[text]?'-':collectCode_map[text]
    },
   },
   {
    title: '采集频率',
    align:"center",
    dataIndex: 'collectRateCode',
    width:100,
    customRender:({text}) =>{
      return !collectRateCode_map[text]?'-':collectRateCode_map[text]
    },
   },
   {
    title: '指标说明',
    align:"left",
    dataIndex: 'metricDesc',
    width:400
   },
   {
    title: '更新日期',
    align:"left",
    dataIndex: 'updatedTime',
    width:140
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '指标名称',
    field: 'metricName',
    component: 'Input',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '指标类型',
    field: 'metricTypeCode',
    component: 'Select',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '采集方式',
    field: 'collectCode',
    component: 'Select',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '指标编号',
    field: 'metricNo',
    component: 'Input',
    dynamicDisabled: true,
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
  },
  {
    label: '指标名称',
    field: 'metricName',
    component: 'Input',
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({model,schema}) => {
      return [
             { required: true, message: '请输入指标名称!'},
      ];
    },
  },
  {
    label: '指标类型',
    field: 'metricTypeCode',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'metrictype',
      placeholder: '请选择指标类型',
     },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择指标类型!'},
      ];
    },
  },
  {
    label: '采集方式',
    field: 'collectCode',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'colletway',
      placeholder: '请选择采集方式',
     },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择采集方式!'},
      ];
    },
  },
  {
    label: '采集频率',
    field: 'collectRateCode',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'colletrate',
      placeholder: '请选择采集频率率',
     },
    colProps: {lg: 12},
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 6},},wrapperCol:{xs: {span: 24},sm: {span: 18},}},
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请选择采集频率!'},
      ];
    },
  },
  {
    label: '指标说明',
    field: 'metricDesc',
    component: 'InputTextArea',
    itemProps:{labelCol:{xs: {span: 24},sm: {span: 3},},wrapperCol:{xs: {span: 24},sm: {span: 21},}},
    componentProps: {
      rows: 5
    }
  },
  {
	  label: '',
	  field: 'caNo',
	  component: 'Input',
	  show: false
	},
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}