import http from "@/utils/http";
import { AppDispatch } from "..";
/**
 * 获取 问卷管理列表
 */
export const A6Q_APIgetList = (data: any) => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post("cms/questionnaire/pageList", data);
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total,
      };
      dispatch({ type: "A6Q/getList", payload: obj });
    }
  };
};

/**
 * 删除
 */
export const A6Q_APIdel = (id: number) => {
  return http.get(`cms/questionnaire/remove/${id}`);
};

/**
 * 新增/编辑
 */
export const A6Q_APIsave = (data: any) => {
  return http.post("cms/questionnaire/save", data);
};

/**
 * 通过id获取详情
 */
export const A6Q_APIgetInfo = (id: number) => {
  return http.get(`cms/questionnaire/detail/${id}`);
};

/**
 * 结果明细
 */
export const A6Q_APIresList = (id: number) => {
  return http.get(`cms/questionnaire/submit/getList/${id}`);
};

/**
 * 结果统计
 */
export const A6Q_APIresTabList = (id: number) => {
  return http.get(`cms/questionnaire/report/${id}`);
};

/**
 * 结果明细-查看
 */
export const A6Q_APIresListLook = (
  questionnaireId: number,
  answerPcsId: number
) => {
  return http.get(
    `cms/questionnaire/submit/detail/${questionnaireId}/${answerPcsId}`
  );
};

// ------------------------题目管理-----------------------

/**
 * 获取列表
 */
export const A6Q_API_TgetList = (id: number) => {
  return http.get(`cms/question/getList/${id}`);
};

/**
 * 列表排序
 */
export const A6Q_API_Tsort = (id1: number, id2: number) => {
  return http.get(`cms/question/sort/${id1}/${id2}`);
};

/**
 * 删除
 */
export const A6Q_API_Tdel = (id: number) => {
  return http.get(`cms/question/removes/${id}`);
};

/**
 * 删除选项
 */
export const A6Q_API_Tdels2 = (ids: string) => {
  return http.get(`cms/question/option/removes/${ids}`);
};

/**
 * 批量新增
 */
export const A6Q_API_Tadds = (data: any) => {
  return http.post("cms/question/addBatch", data);
};

/**
 * 单个编辑
 */
export const A6Q_API_Tedit = (data: any) => {
  return http.post("cms/question/edit", data);
};

/**
 * 获取详情
 */
export const A6Q_API_TgetInfo = (id: number) => {
  return http.get(`cms/question/detail/${id}`);
};
