import request from '@/utils/request'
import upload from '@/utils/upload'

const preUrl = '/clientServices.do?iscrypt=1'

// 获取流程 宫格 列表
export function getProcessList(staffId, unitId) {
	return request({
		url: preUrl,
		method: 'post',
		data: {
			serviceId: 'bpm_20150319001GetFlowList',
			params: {
				staffId: staffId,
				unitid: unitId
			}
		}
	})
}

// 获取流程信息
export function getProcessInfo({ modelId, control }) {
	return request({
		url: preUrl,
		method: 'post',
		data: {
			serviceId: 'bpm_20150319002GetStartFlowInfo',
			params: {
				modelId: modelId,
				control: control
			}
		}
	})
}

// 获取流程 表单
export function getProcessForm(user, process) {
	return request({
		url: preUrl,
		method: 'post',
		data: {
			serviceId: 'bpm_20180525getflowform',
			params: {
				staffId: user.useId, // user.useId
				formId: process.formId,
				tmodelId: process.tmodelId,
				modelId: process.modelId, // 流程模板
				control: process.control, // 流程类型

				loginID: user.useId, // user.useId
				groupName: user.deptName, // user.deptName
				name: user.name, // user.name
				currentPosition: user.positionName, // user.positionName
				id: user.unitId, // user.unitId
			}
		}
	})
}

// 提交流程 表单
export function submitProcessForm(user, process, fileIds) {
	return request({
		url: preUrl,
		method: 'post',
		data: {
			serviceId: 'bpm_20150325001FlowStart',
			params: {
				flow: {
					staffId: user.useId, // user.useId
					staffName: user.name,  // user.name
					gxId: user.gxId, // user.gxId
					insName: user.name + process.modelName, // user.name + modelName
					groupId: user.groupid, // user.groupid
					usesNames: "[]",
					tmodelId: process.tmodelId, // process.tmodelId
					modelId: process.modelId, // process.modelId
					// 附件id 为空时设置值为''
					fileIds: fileIds.length==0?'':fileIds 
				},
				form: {
					formId: process.formId, // process.formId
					formElements: process.form
				},
				control: '1'
			}
		}
	})
}

export function uploadFile(data) {
	return upload({
    url: '/MiniAppUploadFileAction.do',
    name: data.name,
    filePath: data.filePath
  })
}