/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2023-04-20 14:06:17
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2024-06-28 14:47:20
 * @FilePath: /BudgetManaSystem/src/services/getDic.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */







import { request } from "@umijs/max"


//根据系统id+字典类型获取字典数据
export const getDicDataBySysId =  (systemId:string,dictType?:string) => {
    
  return request('/centerSys/sysdictdata/getDictByDictType', {
      method: 'GET',
      params:{systemId,dictType}
  });    
}


//根据系统id+参数code获取制定参数数据
export const getParamsDataBySysId =  (systemId:string,parameterCode?:string) => {
    
  return request('/centerSys/parameter/getParameterByCode', {
      method: 'GET',
      params:{systemId,parameterCode}
  });    
}


//从公共字典获取数据
export const getPubDicData =  () => {
    
    return request('/performance/dict', {
        method: 'GET',
    });    
}

// 筛选指定的字典数据

export const getDataByKeyFromDic = (dicData:any[],key: string) => {

    let result = dicData.filter((t: any) => (t.code == key));

    if (result.length > 0) {

      let dataArr = result[0].dataVoList;

      let defaultValue = dataArr.filter((t:any) => t.defaultValue == 1);

      dataArr.sort((prev:any, next:any) => {
        return prev.sort - next.sort;
      });

      return {
        defaultvalue: defaultValue[0] ? defaultValue[0].value : '',
        list: dataArr.map((t:any) => {
          return ({ label: t.name, value: t.code })
        })
      }
    }

    return {
      defaultvalue: '',
      list: []
    };
  }
