// import request from '@/utils/request'
// import key from '@/constant/key'
// import { model } from '@/model'
import key from '../../constant/key'
import request from '../../utils/request'
import { model } from '../../model'

//=== 接口：WORKFLOW管理 START ===
// 初始化一览页面信息
export function getWorkFlowListInit() {
	return request({
		url: '/workflowList/init',
		method: key.POST,
	})
}

// 取得WORKFLOW一览
export interface IGetWorkFlowList extends model.basisRequest {
	i_perpage: string
	i_pageindex: string
	i_sch_form_name: string
	i_sch_status: string
	i_sch_use_s_ymd: string
	i_sch_use_e_ymd: string
}

export function getWorkFlowList(data: IGetWorkFlowList) {
	return request({
		url: '/workflowList/getList',
		data,
		method: key.POST,
	})
}

// 导出WORKFLOW一览
export function exportWorkFlowList(data: IGetWorkFlowList) {
	return request({
		url: '/workflowList/export',
		data,
		method: key.POST,
		responseType: 'blob'
	})
}

// 删除WorkFlow
export function delWorkFlow(i_form_id: string) {
	return request({
		url: '/workflowList/delete',
		data:{i_form_id:i_form_id},
		method: key.DELETE
	})
}

// 初始化表单设计页面信息
export function getWorkFlowInit(data: any) {
	return request({
		url: '/workflow/init',
		method: key.POST,
		data
	})
}

// 取得WorkFlow详情
export function getDetail(i_form_id: string) {
	return request({
		url: '/workflow/detail',
		data:{i_form_id: i_form_id},
		method: key.POST,
	})
}
// 保存WorkFlow（新增，变更）
export function saveWorkFlowConfig(data: any) {
	return request({
		url: '/workflow/saveForm',
		method: key.POST,
		data,
	})
}

// 取得字典类型列表
export function getDictSelectList(data: any) {
	return request({
		url: '/workflow/dict',
		method: key.POST,
		data
	})
}
//=== 接口：WORKFLOW管理 END ===

//=== 接口：新增申请 START ===
// 取得WORKFLOW申请管理-新增申请一览初始化
export function getWorkFlowNewListInit() {
	return request({
		url: '/newApply/init',
		method: key.POST,
	})
}

export interface IGetWorkFlowNewList extends model.basisRequest {
	i_perpage: number
	i_pageindex: number
	i_is_applicant?: boolean, 
	i_sch_form_name?: string
	i_sch_field?: string
	i_sch_dept?: string
}

// 取得WORKFLOW申请管理-新增申请一览
export function getWorkFlowNewList(data: IGetWorkFlowNewList) {
	return request({
		url: '/newApply/getList',
		method: key.POST,
		data,
	})
}

// 导出WORKFLOW申请管理-新增申请一览
export function exportWorkFlowNewList(data: IGetWorkFlowNewList) {
	return request({
		url: '/newApply/export',
		method: key.POST,
		data,
		responseType: 'blob'
	})
}

// WORKFLOW申请管理-新增申请-保存申请
export function saveApply(data: any) {
	return request({
		url: '/newApply/save',
		method: key.POST,
		data,
		setTimeout: 20000
	})
}
//=== 接口：新增申请 END ===

//=== 接口：我的申请 START ===
// 取得WORKFLOW申请管理-我的申请一览初始化
export function getWorkFlowMyListInit() {
	return request({
		url: '/myApply/init',
		method: key.POST,
	})
}

export interface IGetWorkFlowMyList extends model.basisRequest {
	i_perpage: string
	i_pageindex: string
	i_sch_form_name: string
	i_sch_field: string
	i_sch_dept: string
}

// WORKFLOW申请管理-我的申请一览
export function getWorkFlowMyList(data:IGetWorkFlowMyList) {
	return request({
		url: '/myApply/getList',
		method: key.POST,
		data,
	})
}

// WORKFLOW申请管理-我的申请导出
export function exportWorkFlowMyList(data:IGetWorkFlowMyList) {
	return request({
		url: '/myApply/export',
		method: key.POST,
		data,
		responseType: 'blob'
	})
}

// 取得WORKFLOW申请管理-我的申请-详情
export function getMyDetail(i_apply_id : string, i_is_copy:boolean) {
	return request({
		url: '/myApply/detail',
		method: key.POST,
		data: { i_apply_no : i_apply_id, i_is_copy : i_is_copy}
	})
}

// WORKFLOW申请管理-我的申请-修改申请
export function modifyApply(data: any) {
	return request({
		url: '/myApply/save',
		method: key.POST,
		data,
	})
}

// 取得WORKFLOW申请管理-我的申请-删除申请
export function deleteApply(i_apply_id : string) {
	return request({
		url: '/myApply/delete',
		method: key.DELETE,
		data:{i_apply_id : i_apply_id}
	})
}

// 取得WORKFLOW申请管理-我的申请-取消申请
export function cancelApply(i_apply_id : string) {
	return request({
		url: '/myApply/cancel',
		method: key.POST,
		data:{ i_apply_id : i_apply_id},
		setTimeout: 20000
	})
}

export interface INoticeReferenceUser extends model.basisRequest {
	i_apply_id: string              //申请ID
	i_notice_readers: string        //选择的通知者
}

// 取得WORKFLOW申请管理-我的申请-通知
export function noticeReferenceUser(data : INoticeReferenceUser) {
	return request({
		url: '/myApply/noticeReference',
		method: key.POST,
		data,
	})
}

// 推送
export function sendMessage(data: any) {
	return request({
		url: '/myApply/pushMessage',
		method: key.POST,
		data,
		setTimeout: 20000
	})
}
//=== 接口：我的申请 END ===

//=== 接口：待审批申请 START ===
// 取得WORKFLOW申请管理-待审批申请一览初始化
export function getWorkFlowWaitListInit() {
	return request({
		url: '/pending/init',
		method: key.POST,
	})
}

export interface IGetWorkFlowWaitList extends model.basisRequest {
	i_perpage: string
	i_pageindex: string
	i_sch_field: string
	i_sch_apply_user: string
	i_sch_dept_no: string
}

// WORKFLOW申请管理-待审批申请一览
export function getWorkFlowWaitList(data:IGetWorkFlowWaitList) {
	return request({
		url: '/pending/getList',
		method: key.POST,
		data,
	})
}

// WORKFLOW申请管理-待审批申请导出
export function exportWorkFlowWaitList(data:IGetWorkFlowWaitList) {
	return request({
		url: '/pending/export',
		method: key.POST,
		data,
		responseType: 'blob'
	})
}

export interface IAudit extends model.basisRequest {
	i_apply_id: string           //申请ID
	i_comment: string            //审批意见
	i_audit_result: string       //审批结果
}

// 取得WORKFLOW申请管理-待审批申请-审批
export function Audit(data:IAudit) {
	return request({
		url: '/pending/audit',
		method: key.POST,
		data,
		setTimeout: 20000
	})
}

// 代理人设定初期化
export function getAgentListInit() {
	return request({
		url: '/pending/proxyDetail',
		method: key.POST,
	})
}

// 代理人设定保存
export function saveAgentList(data:any) {
	return request({
		url: '/pending/saveProxy',
		method: key.POST,
		data
	})
}
//=== 接口：待审批申请 END ===

//=== 接口：可查阅申请 START ===
// 取得WORKFLOW申请管理-可查阅申请初始化
export function getWorkFlowSearchableListInit() {
	return request({
		url: '/approve/init',
		method: key.POST,
	})
}

export interface IGetWorkFlowSearchableList extends model.basisRequest {
	i_perpage: string
	i_pageindex: string
	i_sch_field: string
	i_sch_apply_user: string
	i_sch_dept: string
}

// WORKFLOW申请管理-可查阅申请一览
export function getWorkFlowSearchableList(data:IGetWorkFlowSearchableList) {
	return request({
		url: '/approve/getList',
		method: key.POST,
		data,
	})
}

// WORKFLOW申请管理-可查阅申请导出
export function exportWorkFlowSearchableList(data:IGetWorkFlowSearchableList) {
	return request({
		url: '/approve/export',
		method: key.POST,
		data,
		responseType: 'blob'
	})
}
//=== 接口：可查阅申请 END ===

//=== 接口：无效申请 START ===
// 取得WORKFLOW申请管理-无效申请初始化
export function getWorkFlowInvalidListInit() {
	return request({
		url: '/invalid/init',
		method: key.POST,
	})
}

export interface IGetWorkFlowInvalidList extends model.basisRequest {
	i_perpage: string
	i_pageindex: string
	i_sch_field: string
	i_sch_apply_user: string
	i_sch_dept_no: string
}

// WORKFLOW申请管理-无效申请一览
export function getWorkFlowInvalidList(data:IGetWorkFlowInvalidList) {
	return request({
		url: '/invalid/getList',
		method: key.POST,
		data,
	})
}

// WORKFLOW申请管理-无效申请导出
export function exportWorkFlowInvalidList(data:IGetWorkFlowInvalidList) {
	return request({
		url: '/invalid/export',
		method: key.POST,
		data,
		responseType: 'blob'
	})
}
//=== 接口：无效申请 END ===

//=== 接口：分组管理 START ===
// 初始化一览页面信息
export function getGroupListInit() {
	return request({
		url: '/groupManage/init',
		method: key.POST,
	})
}

export interface IGetGroupList extends model.basisRequest {
	i_perpage: string
	i_pageindex: string
	i_sch_field_role: string
	i_sch_field_head: string
	i_enable: string
}

// 取得Group一览
export function getGroupList(data:IGetGroupList) {
	return request({
		url: '/groupManage/getList',
		data,
		method: key.POST,
	})
}

// 导出Group一览
export function exportGroupList(data: IGetGroupList) {
	return request({
		url: '/groupManage/export',
		data,
		method: key.POST,
		responseType: 'blob'
	})
}

// 删除Group
export function delGroup(i_group_id: string) {
	return request({
		url: '/groupManage/delete',
		data:{i_group_id:i_group_id},
		method: key.POST,
	})
}

// 取得Group详情
export function getGroupDetail(data: any) {
	return request({
		url: '/groupManage/getDetail',
		data,
		method: key.POST,
	})
}
// 保存Group（新增，变更）
export function saveGroupConfig(data: any) {
	return request({
		url: '/groupManage/save',
		data,
		method: key.POST,
	})
}
//=== 接口：角色管理 END ===
//用户选择器个人
export function getAllUser(data) {
	return request({
		url: '/userDept/getUserDept',
		data,
		method: key.POST,
	})
}

//用户选择器列表
export function getAllUserList(data) {
	return request({
		url: '/userDept/getUserDeptList',
		data,
		method: key.POST,
	})
}


//字典类主表
export function getAllDict(data) {
	return request({
		url: '/alldict/getDict',
		data,
		method: key.POST,
	})
}

//公司
export function getAllDept(data) {
	return request({
		url: '/userDept/getAllCompany',
		data,
		method: key.POST,
	})
}

//公司树
export function getAllDeptTree(data) {
	return request({
		url: '/userDept/getAllDept',
		data,
		method: key.POST,
	})
}

export function getDeptName(data) {
	return request({
		url: '/userDept/getDeptName',
		data,
		method: key.POST,
	})
}

export function getAllGroup(data) {
	return request({
		url: '/groupManage/allRole',
		data,
		method: key.POST,
	})
}

//业务选择
export function getAllForm(data) {
	return request({
		url: '/workflowList/allForm',
		data,
		method: key.POST,
	})
}

export interface IDownloadApplyFile extends model.basisRequest {
	i_file_name_new: string
	i_form_id: string
	i_apply_id: string
}

//保存印章
export function uploadSeal(data) {
	return request({
		url: '/fileTransfer/saveSeal',
		method: key.POST,
		data: data,
	})
}

//删除印章
export function deleteSeal(fileName) {
	return request({
		url: '/fileTransfer/deleteSeal',
		method: key.DELETE,
		data: {fileName : fileName, i_language:''},
	})
}

//取得印章
export function getSeal(data : model.basisRequest) {
	return request({
		url: '/fileTransfer/detail',
		method: key.POST,
		data: data,
	})
}

// 文件上传
export function uploadFile(data:FormData) {
	return request({
		url: 'fileTransfer/upload',
		method: key.POST,
		data,
	})
}

// 导出下载
export function downloadApplyFile(params: IDownloadApplyFile) {
	return request({
		url: 'fileTransfer/downLoad',
		method: key.POST,
		data: {
			...params,
		},
		responseType: 'blob',
	})
}

interface ILanguage extends model.basisRequest {
	i_func_id: string
}
// 获取页面翻译
export function getLanguage(ILanguage) {
	return request({
		url: '/language/getList',
		method: key.POST,
		data: ILanguage
	})
}

// 获取字典类型名
export function getDictName(params: ILanguage) {
	return request({
		url: '/language/getDictName',
		method: key.POST,
		data: {
			...params,
		},
	})
}

// 取得全部字典分类或指定字典分类
export function getAllDictType(params: ILanguage) {
	return request({
		url: '/language/getAllDictType',
		method: key.POST,
		data: {
			...params,
		},
	})
}

interface IField extends model.basisRequest {
	i_sch_field: string
}

// 取得全部岗位分类
export function getAllPost(data : IField) {
	return request({
		url: '/postPart/getAllPost',
		method: key.POST,
		data: data
	})
}

// 取得岗位
export function getPost(data : IField) {
	return request({
		url: '/postPart/getPost',
		method: key.POST,
		data: data
	})
}

// 取得全部角色
export function getAllRole(data : IField) {
	return request({
		url: '/postPart/getAllRole',
		method: key.POST,
		data: data
	})
}

// 取得角色
export function getRole(data : IField) {
	return request({
		url: '/postPart/getRole',
		method: key.POST,
		data: data
	})
}

// 取得ALL部门|岗位
export function getAllDeptPost(data : IField) {
	return request({
		url: '/postPart/getAllDeptPost',
		method: key.POST,
		data: data
	})
}

// 取得部门|岗位
export function getDeptPost(data : IField) {
	return request({
		url: '/postPart/getDeptPost',
		method: key.POST,
		data: data
	})
}








