import { FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';
import { getSkyInspectionPage } from '../../method/api';
import { getPage } from '/@/api/datamanager/groundDisasterId/muSourceData';
export const accountFormSchema: FormSchema[] = [

  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
    },
  },
  {
    field: 'jclx',
    label: '监测类型:',
    colProps: { span: 8 },
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'disaster_monitoring_type',
      },
      labelField: 'itemText',
      valueField: 'id',
      resultField: 'items',
    },
  },
  {
    field: 'sjlx',
    label: '数据类型:',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'disaster_data_type',
      },
      labelField: 'itemText',
      valueField: 'id',
      resultField: 'items',
    },
  },
  {
    field: 'tcid',
    label: '图层选择:',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: getPage,
      params: {
        pages: 1,
        size: 9999,
      },
      labelField: 'zymc',
      valueField: 'id',
      resultField: 'result.records',
      showSearch: true,
    },
  },
  {
    field: 'tcmc',
    label: '图层名称:',
    component: 'Input',
    colProps: { span: 24 },
    componentProps: {
      maxLength: 50,
    },
  },
  {
    field: 'sjtcid',
    label: '上级图层:',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: getSkyInspectionPage,
      params: {
        pages: 1,
        size: 9999,
      },
      labelField: 'tcmc',
      valueField: 'id',
      resultField: 'result.records',
      showSearch: true,

    },
  },
  {
    field: 'xh',
    label: '排序:',
    component: 'InputNumber',
    colProps: { span: 8 },
    componentProps: {
      style: 'width:100%',
      min: 0,
      max: 1000,
    },
  },
  {
    field: 'tmd',
    label: '透明度:',
    component: 'Slider',
    colProps: { span: 8 },
    slot: 'slider',
    componentProps: {
      min: 0,
      max: 100,
    },
  },
  {
    field: 'map',
    label: '',
    component: 'Input',
    slot: 'map',
  },
  {
    field: 'bz',
    label: '备注:',
    component: 'InputTextArea',
    colProps: { span: 24 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入备注',
    },
  },
];
export const accountFormSchemaT: FormSchema[] = [

  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
    componentProps: {
      disabled: true,
      maxLength: 36,
    },
  },
  {
    field: 'jclx',
    label: '监测类型:',
    colProps: { span: 8 },
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'disaster_monitoring_type',
      },
      labelField: 'itemText',
      valueField: 'id',
      disabled: true,
      resultField: 'items',
    },
  },
  {
    field: 'sjlx',
    label: '数据类型:',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: findDictItemByCode ,
      params: {
        dictCode: 'disaster_data_type',
      },
      labelField: 'itemText',
      valueField: 'id',
      disabled: true,
      resultField: 'items',
    },
  },
  {
    field: 'tcid',
    label: '图层选择:',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: getPage,
      params: {
        pages: 1,
        size: 9999,
      },
      labelField: 'zymc',
      valueField: 'id',
      resultField: 'result.records',
      disabled: true,
      showSearch: true,
    },
  },
  {
    field: 'tcmc',
    label: '图层名称:',
    component: 'Input',
    colProps: { span: 24 },
    componentProps: {
      disabled: true,
      maxLength: 50,
    },
  }, 
  {
    field: 'sjtcid',
    label: '上级图层:',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: getSkyInspectionPage,
      params: {
        pages: 1,
        size: 9999,
      },
      labelField: 'tcmc',
      valueField: 'id',
      resultField: 'result.records',
      disabled: true,
      showSearch: true,

    },
  },
  {
    field: 'xh',
    label: '排序:',
    component: 'InputNumber',
    colProps: { span: 8 },
    componentProps: {
      style: 'width:100%',
      min: 0,
      disabled: true,
      max: 1000,
    },
  },
  {
    field: 'tmd',
    label: '透明度:',
    component: 'Slider',
    colProps: { span: 8 },
    slot: 'slider',
    componentProps: {
      min: 0,
      disabled: true,
      max: 100,
    },
  },
  {
    field: 'map',
    label: '',
    component: 'Input',
    slot: 'map',
  },
  {
    field: 'bz',
    label: '备注:',
    component: 'InputTextArea',
    colProps: { span: 24 },
    componentProps: {
      maxLength: 150,
      disabled: true,
      placeholder: '请输入备注',
    },
  },
];
export const searchFormSchema: FormSchema[] = [
  {
    field: 'searchStr',
    label: '关键字',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 32,
      placeholder: '请输入图层名称',
    },
  },


  {
    field: 'jclx',
    label: '监测类型',
    component: 'ApiSelect',
    componentProps: (formActionType) => {
 
      
      const { setFieldsValue } = formActionType;
      console.log(formActionType);
      
      return {
        labelField: 'itemText',
        valueField: 'id',
        placeholder: '请选择监测类型',
        params: {
          dictCode: 'disaster_monitoring_type',
        },
        api: findDictItemByCode,
        onChange(
          _value: string,
          option: { deviceType: string; transportType: string; id: string }
        ) {
          console.log(_value,option);
          
          // const { deviceType, transportType, id } = option;
          // setFieldsValue({
          //   deviceType: deviceType,
          //   transportType,
          //   deviceProfileId: id,
          //   gatewayId: null,
          // });
        },
      };
      
    },
    colProps: { span: 6 },
  },
  {
    field: 'sjlx',
    label: '数据类型',
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'disaster_data_type',
      },
      labelField: 'itemText',
      valueField: 'id',
      placeholder: '请选择数据类型',
    },
    colProps: { span: 6 },
  },

];
let getSjlx;
let getJclx;
let getSjtc;

async function formatTextFunc () {
  getSjlx = await findDictItemByCode({ dictCode: 'disaster_monitoring_type' });
  getJclx = await findDictItemByCode({ dictCode: 'disaster_data_type' });
  getSjtc = await getSkyInspectionPage({ pages: 1, size: 9999, });
 
}
formatTextFunc();
export const columns = [
  {
    title: '图层名称',
    dataIndex: 'tcmc',
    width: 160,
  },
  {
    title: '监测类型',
    dataIndex: 'jclx',
    width: 160,
    format: (_, record) => {
      if(record.jclx){

        const text = getSjlx.find((f) => {
  
          if (f.id.trim() == record.jclx.trim()) {
            return f.itemText;
          }
        });
        return text?.itemText;
      }else{
        return ''
      }
    },
  },
  {
    title: '数据类型',
    dataIndex: 'sjlx',
    width: 160,
    format: (_, record) => {
      if(record.sjlx){

        const text = getJclx.find((f) => {
          if (f.id.trim() == record.sjlx.trim()) {
            return f.itemText;
          }
        });
        return text?.itemText;
      }else{
        return ''
      }
    },
  },
  {
    title: '透明度(%)',
    dataIndex: 'tmd',
    width: 160,
  }, {
    title: '图层级别',
    dataIndex: 'tcjb',
 
    slots: { customRender: 'tcjb' },
    width: 160,
  },
  {
    title: '上级图层',
    dataIndex: 'sjtcid',
    width: 160,
    format: (_, record) => {
  
      if(getSjtc?.result){

        const text = getSjtc.result.records.find((f) => {
          if (f.id == record.sjtcid) {
            return f.tcmc;
          }
        });
        return text?.tcmc;
      }
    },
  },
  {
    title: '排序',
    dataIndex: 'xh',

    width: 160,
  },
];

