// 事项api
import local from "@/utils/local";
import request from "@/utils/request";
import store from "@/store";
let PHP_URL = process.env.VUE_APP_API_PHP_URL;
// 首页数据展示
export const homeInfo = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let siteId = local.getLocal("siteId");
  let deviceCode = local.getLocal("devicenum");
  return request({
    url: `${baseUrl}basics_api/sampleform/home/info`,
    method: "post",
    data: {
      siteId,
      deviceCode,
      ...data,
    },
  });
};

// 获取部门列表
export const deptList = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let siteId = local.getLocal("siteId");
  // let deviceCode = local.getLocal("devicenum");
  return request({
    url: `${baseUrl}basics_api/sampleform/home/depts`,
    method: "post",
    data: {
      siteId,
      deviceCode: store.getters.deviceCode,
      ...data,
    },
  });
};

// 查询事项列表
export const sampleformMatterList = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let siteId = local.getLocal("siteId");
  return request({
    url: `${baseUrl}basics_api/sampleform/matter/interlist`,
    method: "post",
    data: {
      siteId,
      ...data,
    },
  });
};

// 查询事项详情
export const sampleformMatterInfo = (params) => {
  let baseUrl = local.getLocal("serverUrl");
  return request({
    url: `${baseUrl}basics_api/sampleform/matter/interinfo`,
    method: "get",
    params,
  });
};

// 查询设备关联事项列表
export const deviceMatterList = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let siteId = local.getLocal("siteId");
  // let deviceCode = local.getLocal("devicenum");
  return request({
    url: `${baseUrl}basics_api/sampleform/device/matter/datum/interlist`,
    method: "post",
    data: {
      siteId,
      deviceCode: store.getters.deviceCode,
      ...data,
    },
  });
};

//   查询材料列表
export const materialsList = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let siteId = local.getLocal("siteId");
  return request({
    url: `${baseUrl}basics_api/sampleform/matter/datum/interlist`,
    method: "post",
    data: {
      siteId,
      ...data,
    },
  });
};

// 获取事项文件夹（分类）列表
export const matterFolderList = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  return request({
    url: `${baseUrl}basics_api/sampleform/matter/category/interlist`,
    method: "post",
    data,
  });
};

// 表单合成
export const mergeFormToDocx = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let siteId = local.getLocal("siteId");
  return request({
    url: `${baseUrl}basics_api/sampleform/home/mergeFormToDocx`,
    method: "post",
    data: {
      siteId,
      ...data,
    },
  });
};
// 查看样表
export const checkMaterials = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let siteId = local.getLocal("siteId");
  let deviceCode = local.getLocal("devicenum");
  return request({
    url: `${baseUrl}basics_api/sampleform/sample/bill/save`,
    method: "post",
    data: {
      siteId,
      deviceCode,
      ...data,
    },
  });
};
// 查询使用皮肤
export const skinList = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  // let siteId = local.getLocal("siteId");
  return request({
    url: `${baseUrl}basics_api/sampleform/skin/interlist`,
    method: "post",
    data,
  });
};
// 排队编号查询对应事项
export const matterForFlownum = (params) => {
  // let baseUrl = local.getLocal("serverUrl");
  return request({
    url: `${PHP_URL}api/matter/matterForFlownum`,
    method: "get",
    params,
  });
};
//获取设备信息（按设备编码）
export const deviceInfo = (data) => {
  let baseUrl = local.getLocal("serverUrl");
  let deviceCode = local.getLocal("devicenum");
  return request({
    url: `${baseUrl}basics_api/sampleform/device/check`,
    method: "post",
    data: {
      deviceCode,
      ...data,
    },
  });
};
//热力图背景图上传
export function screenSave(params = {}) {
  let deviceInfo = {};
  try {
    let { productId, productName } = local.getLocal("deviceInfo");
    deviceInfo = { productId, productName };
  } catch (error) {}
  let javaBase = local.getLocal("serverUrl");
  params["deviceNum"] = local.getLocal("devicenum");
  return request({
    url: `${javaBase}basics_api/zwfw/page/bury/screen/save`,
    method: "post",
    data: {
      ...deviceInfo,
      ...params,
    },
  });
}
//java数据埋点
export function burySave(params = {}) {
  let deviceInfo = {};
  try {
    let { productId, productName } = local.getLocal("deviceInfo");
    deviceInfo = { productId, productName };
  } catch (error) {}
  let javaBase = local.getLocal("serverUrl");
  params["deviceNum"] = local.getLocal("devicenum");
  return request({
    url: `${javaBase}basics_api/zwfw/page/bury/save`,
    method: "post",
    data: {
      ...deviceInfo,
      ...params,
    },
  });
}
