import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/showlist/okkiShowlist/list',
  save='/showlist/okkiShowlist/add',
  edit='/showlist/okkiShowlist/edit',
  changeStatus='/showlist/okkiShowlist/status',
  deleteOne = '/showlist/okkiShowlist/delete',
  deleteBatch = '/showlist/okkiShowlist/deleteBatch',
  importExcel = '/showlist/okkiShowlist/importExcel',
  exportXls = '/showlist/okkiShowlist/exportXls',
  okkiOverviewList = '/showlist/okkiShowlist/queryOkkiOverviewByMainId',
  okkiProductListList = '/showlist/okkiShowlist/queryOkkiProductListByMainId',
  okkiAdvantageList = '/showlist/okkiShowlist/queryOkkiAdvantageByMainId',
  okkiKeywordsList = '/showlist/okkiShowlist/queryOkkiKeywordsByMainId',
  okkiFaqList = '/showlist/okkiShowlist/queryOkkiFaqByMainId',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;

/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 查询子表数据
 * @param params
 */
export const okkiOverviewList = Api.okkiOverviewList;
/**
 * 查询子表数据
 * @param params
 */
export const okkiProductListList = Api.okkiProductListList;
/**
 * 查询子表数据
 * @param params
 */
export const okkiAdvantageList = Api.okkiAdvantageList;
/**
 * 查询子表数据
 * @param params
 */
export const okkiKeywordsList = Api.okkiKeywordsList;
/**
 * 查询子表数据
 * @param params
 */
export const okkiFaqList = Api.okkiFaqList;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
/**
 * 同步给小满
 */
export const changeStatus = (params,handleSuccess) => {
  return defHttp.post({url: Api.changeStatus, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
