approve.ts 2.81 KB
import { find, isEmpty } from 'lodash-es';
import { defHttp } from '/@/utils/http/axios';
import {
  FIELDS_BASE_INFO,
  FIELDS_PROFIT_INFO,
  FIELDS_REPORT_INFO,
} from '/@/views/project/order/tableData';

enum Api {
  APPROVE = '/order/erp/audit/wait_audit_list',
  APPROVE_ED = '/order/erp/audit/audit_list',
  AUDIT = '/order/erp/audit/do_audit',
}

export const approveAuditApi = async (params: any) =>
  defHttp.post<any>(
    {
      url: Api.AUDIT,
      params,
    },
    { message: '操作成功' },
  );

export const getWaitListApi = async (params: DemoParams) => {
  const res = await defHttp.post({
    url: Api.APPROVE,
    params,
  });

  res.records = res.records.map((item) => {
    item.fields = [];
    !isEmpty(item.fieldInfos.baseFields) &&
      Object.entries(item.fieldInfos.baseFields).map(([key, value]) => {
        if (value === 'UN_LOCKED') {
          const obj = find(FIELDS_BASE_INFO, { field: key });
          item.fields.push(obj?.label);
        }
      });
    !isEmpty(item.fieldInfos.reportFields) &&
      Object.entries(item.fieldInfos.reportFields).map(([key, value]) => {
        if (value === 'UN_LOCKED') {
          const obj = find(FIELDS_REPORT_INFO, { field: key });
          item.fields.push(obj?.label);
        }
      });
    !isEmpty(item.fieldInfos.reportFields) &&
      Object.entries(item.fieldInfos.reportFields).map(([key, value]) => {
        if (value === 'UN_LOCKED') {
          const obj = find(FIELDS_PROFIT_INFO, { field: key });
          item.fields.push(obj?.label);
        }
      });

    item.fields = item.fields.join(',');
    return item;
  });

  return new Promise((resolve) => {
    resolve(res.records);
  });
};

export const getApprovedListApi = async (params: any) => {
  const res = await defHttp.post({
    url: Api.APPROVE_ED,
    params,
  });

  res.records = res.records.map((item) => {
    item.fields = [];
    !isEmpty(item.fieldInfos.baseFields) &&
      Object.entries(item.fieldInfos.baseFields).map(([key, value]) => {
        if (value === 'UN_LOCKED') {
          const obj = find(FIELDS_BASE_INFO, { field: key });
          item.fields.push(obj?.label);
        }
      });
    !isEmpty(item.fieldInfos.reportFields) &&
      Object.entries(item.fieldInfos.reportFields).map(([key, value]) => {
        if (value === 'UN_LOCKED') {
          const obj = find(FIELDS_REPORT_INFO, { field: key });
          item.fields.push(obj?.label);
        }
      });
    !isEmpty(item.fieldInfos.reportFields) &&
      Object.entries(item.fieldInfos.reportFields).map(([key, value]) => {
        if (value === 'UN_LOCKED') {
          const obj = find(FIELDS_PROFIT_INFO, { field: key });
          item.fields.push(obj?.label);
        }
      });
    item.fields = item.fields.join(',');
    return item;
  });

  return new Promise((resolve) => {
    resolve(res.records);
  });
};