import { axios } from "@/configue/http";

// 获取内容列表
export function getList(type, data, cb) {
  let params = {
    ...data,
    startTime: data.date ? data.date[0] + " 00:00:00" : "",
    endTime: data.date ? data.date[1] + " 23:59:59" : "",
  };

  axios({
    method: "post",
    data: params,
    url: `cms/${type}/list`,
  }).then((res) => {
    cb(res);
  });
}


export function getMuseumAllList(cb) {
  axios({
    method: "get",
    url: `cms/museum/all`,
  }).then((res) => {
    cb(res);
  });
}

// 获取字典列表
export function getDictList(type,cb) {
  axios({
    method: "post",
    data: {
      "searchKey": "",
      type
    },
    url: `cms/dict/list`,
  }).then((res) => {
    cb(res);
  });
}

// 获取字典列表全部
export function getDictListAll(type,cb) {
  axios({
    method: "post",
    data: {
      "searchKey": "",
      type
    },
    url: `cms/dict/all`,
  }).then((res) => {
    cb(res);
  });
}


//获取系统配置
export function getConfigDetail(cb) {
  axios({
    method: "get",
    url: `cms/config/detail`,
  }).then((res) => {
    cb(res);
  });
}



//获取统计数据
export function getReportDetail(cb) {
  axios({
    method: "get",
    url: `cms/report/detail`,
  }).then((res) => {
    cb(res);
  });
}


// 获取系统设置列表
export function getSysList(type, data, cb) {
  let tmp = {}
  if (data.date) {
    tmp = {
      startTime: data.date ? data.date[0] + " 00:00:00" : "",
      endTime: data.date ? data.date[1] + " 23:59:59" : "",
    }
  }
  let params = {
    ...data,
    ...tmp
  };

  axios({
    method: "post",
    data: params,
    url: `sys/${type}/list`,
  }).then((res) => {
    cb(res);
  });
}



// 获取用户设置的权限列表
export function getRoleList(cb) {

  axios({
    method: "get",
    url: `sys/user/getRole`,
  }).then((res) => {
    cb(res);
  });
}



// 保存

export function saveSys(type, data, cb) {
  let params = {
    ...data,
  };
  axios({
    method: "post",
    data: params,
    url: `sys/${type}/save`,
  }).then((res) => {
    cb(res);
  });
}

// 保存

export function save(type, data, cb) {
  let params = {
    ...data,
  };
  axios({
    method: "post",
    data: params,
    url: `cms/${type}/save`,
  }).then((res) => {
    cb(res);
  });
}

//删除
export function del(type, data, cb) {
  console.log(type,data);
  axios({
    method: "get",
    url: `cms/${type}/remove/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}

//获取cms详情

export function getDetail(type, data, cb) {
  axios({
    method: "get",
    url: `cms/${type}/detail/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}

//获取sys详情
export function getSysDetail(type, data, cb) {
  axios({
    method: "get",
    url: `sys/${type}/detail/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}

//设置图片封面
export function setCover(data, cb) {
  axios({
    method: "get",
    url: `cms/goods/setIndex/${data.fileId}`,
  }).then((res) => {
    cb(res);
  });
}

//删除图库图片
export function delImg(data, cb) {
  axios({
    method: "get",
    url: `cms/goods/remove/file/${data.fileId}`,
  }).then((res) => {
    cb(res);
  });
}


//更新图库图片
export function refreshImg(data, cb) {
  axios({
    method: "get",
    url: `cms/goods/afresh/uploadImg/${data.fileId}/${data.code}`,
  }).then((res) => {
    cb(res);
  });
}



//提审
export function apply(type,data, cb) {
  axios({
    method: "get",
    url: `cms/${type}/apply/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}


// 审核
export function audit(type, data, cb) {
  let params = {
    ...data
  };
  axios({
    method: "post",
    data: params,
    url: `cms/${type}/audit`,
  }).then((res) => {
    cb(res);
  });
}


//审核详情
export function applyDetail(type,data, cb) {
  axios({
    method: "get",
    url: `cms/${type}/auditDetail/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}

// 是否显示
export function handleDisplay(type, data, cb) {
  axios({
    method: "get",
    url: `cms/${type}/display/${data.id}/${data.display}`,
  }).then((res) => {
    cb(res);
  });
}

// 是否启用
export function handleDisable(type, data, cb) {
  axios({
    method: "get",
    url: `sys/${type}/editStatus/${data.id}/${data.isEnabled}`,
  }).then((res) => {
    cb(res);
  });
}


// 新建修改问题
export function saveQuestion(data, cb) {
  axios({
    method: "post",
    data: {
      answer:data
    },
    url: `cms/questionGroup/questionAnswer/save`,
  }).then((res) => {
    cb(res);
  });
}

// 修改问题
export function updateQuestion( data, cb) {
  let params = {
    ...data
  };
  axios({
    method: "post",
    data: params,
    url: `cms/questionGroup/questionAnswer/update`,
  }).then((res) => {
    cb(res);
  });
}

//删除问题
export function delQuestion(data, cb) {
  axios({
    method: "get",
    url: `cms/questionGroup/remove/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}



//删除场景
export function delscene(data, cb) {
  axios({
    method: "get",
    url: `cms/scene/removes/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}


//删除(sys)
export function delSys(type, data, cb) {
  axios({
    method: "get",
    url: `sys/${type}/removes/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}

//删除(sys)
export function delSysSingle(type, data, cb) {
  axios({
    method: "get",
    url: `sys/${type}/remove/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}


//修改密码
export function updatePwd(data, cb) {
  axios({
    method: "post",
    data,
    url: `sys/user/updatePwd`,
  }).then((res) => {
    cb(res);
  });
}


//重置密码
export function resetPass(data, cb) {
  axios({
    method: "get",
    url: `sys/user/resetPass/${data.id}`,
  }).then((res) => {
    cb(res);
  });
}


//导出数据
export function exportExcel(type, data, cb) {
  axios({
    method: "post",
    data,
    url: `cms/${type}/exportExcel`,
  }).then((res) => {
    cb(res);
  });
}



// 精品排序
export function goodsSort(data, cb) {
  axios({
    method: "post",
    data,
    url: `cms/goods/sort`,
  }).then((res) => {
    cb(res);
  });
}


// 获取城市列表
export const museumGetCity = () => {
  return axios({
    url: 'cms/museum/getCity',
  })
}