import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { TemplateInfoForm, TemplateInfoQuery, TemplateInfoVO } from '@/api/print/template/templateInfotypes';
import { TemplateParametersForm } from '@/api/print/template/templateParameterstypes';
import { ParameterPreviewValuesForm } from '@/api/print/template/PreviewValuesTypes';
import { TemplateAttachmentsForm } from '@/api/print/template/templateAttachmentstypes';
import { TemplateParametersExcelsubQuery } from '@/api/print/template/ExcelSubtypes';

/**
 * 查询模版定义列表
 * @param query
 * @returns {*}
 */

export const listTemplateInfo = (query?: TemplateInfoQuery): AxiosPromise<TemplateInfoVO[]> => {
  return request({
    url: '/print/templateInfo/list',
    method: 'get',
    params: query
  });
};

export const templateInfoDelete = (query?: TemplateInfoVO) => {
  return request({
    url: '/print/templateInfo/delete',
    method: 'post',
    data: query
  });
};
/**
 * 新增打印模版
 * @param data
 */
export const addTemplateInfo = (data: TemplateInfoForm) => {
  return request({
    url: '/print/templateInfo/add',
    method: 'post',
    data: data
  });
};
/**
 * 修改
 * @param data
 */
export const editTemplateInfo = (data: TemplateInfoForm) => {
  return request({
    url: '/print/templateInfo/edit',
    method: 'post',
    data: data
  });
};
/**
 * 查询打印模版
 */
export const quryTemplateInfo = (data: TemplateInfoForm) => {
  return request({
    url: '/print/templateInfo/qurytemplate',
    method: 'post',
    data: data
  });
};

/**
 * 上传打印模版附件
 */
export const uploadTempFile = (ossId: string, templateId: string | number) => {
  const data = {
    ossId,
    templateId
  };
  return request({
    url: '/print/templateInfo/uploadTempFile',
    method: 'post',
    data: data
  });
};

export const queryFileList = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/print/templateInfo/queryUploadFiles',
    method: 'post',
    data: data
  });
};

export const deleteFile = (attachmentId: string | number) => {
  const data = {
    attachmentId
  };
  return request({
    url: '/print/templateInfo/deleteFile',
    method: 'post',
    data: data
  });
};

export const paramsParsing = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/print/templateInfo/paramsParsing',
    method: 'post',
    data: data
  });
};

export const paramsUpdate = (data: TemplateParametersForm) => {
  return request({
    url: '/print/templateInfo/paramsUpdate',
    method: 'post',
    data: data
  });
};

export const quryPrintViews = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/print/parameterPreviewValues/quryPrintViews',
    method: 'post',
    data: data
  });
};

export const saveTemplateViewsValue = (data: ParameterPreviewValuesForm) => {
  return request({
    url: '/print/parameterPreviewValues/add',
    method: 'post',
    data: data
  });
};

export const saveTemplateViewsTableValues = (
  templateId: string | number,
  previewId: string | number,
  rowValue: string,
  attachmentId: string | number,
  tableValues: any
) => {
  const data = {
    templateId,
    previewId,
    rowValue,
    attachmentId,
    tableValues
  };
  return request({
    url: '/print/parameterPreviewValues/addTableValues',
    method: 'post',
    data: data
  });
};

export const saveTemplateViewsListValues = (
  templateId: string | number,
  previewId: string | number,
  rowValue: string,
  attachmentId: string | number,
  tableValues: any
) => {
  const data = {
    templateId,
    previewId,
    rowValue,
    attachmentId,
    tableValues
  };
  return request({
    url: '/print/parameterPreviewValues/addListValues',
    method: 'post',
    data: data
  });
};

export const quryTemplateViewsTableValues = (previewId: string | number) => {
  const data = {
    previewId
  };
  return request({
    url: '/print/parameterPreviewValues/quryTableValues',
    method: 'post',
    data: data
  });
};

export const templetPreview = (templateId: string | number) =>{
  const data = {
    templateId
  };
  return request({
    url: '/print/parameterPreviewValues/templetPreview',
    method: 'post',
    data: data
  });
};

export const templetCompleted = (templateId: string | number) =>{
  const data = {
    templateId
  };
  return request({
    url: '/print/templateInfo/templetCompleted',
    method: 'post',
    data: data
  });
};

export const updateTempFile = (data: TemplateAttachmentsForm) => {
  return request({
    url: '/print/templateInfo/updateTempFile',
    method: 'post',
    data: data
  });
};
export const templetToTest = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/print/templateInfo/templetToTest',
    method: 'post',
    data: data
  });
};
/**
 * 查询打印模版
 */
export const quryTemplateInfoByTempId = (templateId: string | number) => {
  const data = {
    templateId
  };
  return request({
    url: '/print/templateInfo/quryTempletById',
    method: 'post',
    data: data
  });
};

export const quryTemplateExcelSubTables = (data: TemplateParametersExcelsubQuery) => {
  return request({
    url: '/print/parameterPreviewValues/quryTemplateExcelSubTables',
    method: 'post',
    data: data
  });
};

/**
 * 查询版本管理列表
 * @param query
 * @returns {*}
 */
export const queryControversialList = (query?: TemplateInfoQuery): AxiosPromise<TemplateInfoVO[]> => {
  return request({
    url: '/print/templateInfo/queryControversialList',
    method: 'get',
    params: query
  });
};

export const changeTemplateVsersionStatus = (templateId: string | number, versionActiveStatus: string) => {
  const data = {
    templateId,
    versionActiveStatus
  };
  return request({
    url: '/print/templateInfo/changeTemplateVsersionStatus',
    method: 'post',
    data: data
  });
};

export const queryTemplateList = () => {
  return request({
    url: '/print/templateInfo/queryTemplateList',
    method: 'post'
  });
};

export const selectTempByTempCode = (data: TemplateInfoForm) => {
  return request({
    url: '/print/templateInfo/qurytemplateByTempCode',
    method: 'post',
    data: data
  });
};

export const quryTemplateListSub = (data) => {
  return request({
    url: '/print/parameterPreviewValues/quryTemplateListSub',
    method: 'post',
    data: data
  });
};


export const quryTemplateViewsListValues = (previewId: string | number) => {
  const data = {
    previewId
  };
  return request({
    url: '/print/parameterPreviewValues/quryListValues',
    method: 'post',
    data: data
  });
};

export const quryTemplateImageSub = (previewId: string | number) => {
  const data = {
    previewId
  };
  return request({
    url: '/print/parameterPreviewValues/quryTemplateImageSub',
    method: 'post',
    data: data
  });
};

export const addImageSub = (data) => {
  return request({
    url: '/print/parameterPreviewValues/addImageSub',
    method: 'post',
    data: data
  });
};

export const reUploadTempFile = (data) => {
  return request({
    url: '/print/templateInfo/reUploadTempFile',
    method: 'post',
    data: data
  });
};

export const getVersionLogList = (templateCode: string | number) => {
  return request({
    url: '/print/templateInfo/versionLog',
    method: 'get',
    params: templateCode
  });
};
export const quryTemplateBlockContent = (data) => {
  return request({
    url: '/print/parameterPreviewValues/quryTemplateBlockContent',
    method: 'post',
    data: data
  });
};
export const quryBlockPreviewValues = (data) => {
  return request({
    url: '/print/parameterPreviewValues/quryBlockValues',
    method: 'post',
    data: data
  });
};
export const saveTemplateViewsBlockValues = (data) => {
  return request({
    url: '/print/parameterPreviewValues/addBlockPreviewValues',
    method: 'post',
    data: data
  });
};
