import config from "@/config"
import http from "@/utils/request"

export default {
	filter: {
		list: {
			url: `${config.API_URL}tools/filter/index`,
			name: "获得过滤数据",
			get: async function(params){
				return await http.get(this.url, params);
			}
		},
		insert:{
			url: `${config.API_URL}tools/filter/insert`,
			name: "导入过滤数据",
			post: async function(data={}){
				return await http.post(this.url, data);
			}
		},
		search: {
			url: `${config.API_URL}/tools/filter/search`,
			name: "过滤数据",
			get: async function(params){
				return await http.get(this.url, params);
			}
		},
		delete:{
			url: `${config.API_URL}/tools/filter/delete`,
			name: "删除过滤数据",
			post: async function(data={}){
				return await http.post(this.url, data);
			}
		},
		edit:{
			url: `${config.API_URL}/tools/filter/edit`,
			name: "更新过滤数据",
			post: async function(data={}){
				return await http.post(this.url, data);
			}
		},
		task: {
			url: `${config.API_URL}/tools/filter/task`,
			name: "任务单数据",
			get: async function(params){
				return await http.get(this.url, params);
			}
		},
		batch:{
			url: `${config.API_URL}/tools/filter/batch`,
			name: "条件删除",
			post: async function(data={}){
				return await http.post(this.url, data);
			}
		}
	},
	inspect:{
		list: {
			url: `${config.API_URL}/tools/inspect/index`,
			name: "获得质检数据",
			get: async function(data){
				let params = Object.assign({}, data);
				let users = params.user || {}, uids = [];
				if(users.length > 0){
					users.map((item) => {
						uids.push(item.uid);
					})
				}
				params.user = uids;
				return await http.get(this.url, params);
			}
		},
		insert:{
			url: `${config.API_URL}/tools/inspect/insert`,
			name: "导入质检数据",
			post: async function(data={}){
				return await http.post(this.url, data);
			}
		},
		edit:{
			url: `${config.API_URL}/tools/inspect/edit`,
			name: "质检数据操作",
			post: async function(data={}){
				return await http.post(this.url, data);
			}
		},
		delete:{
			url: `${config.API_URL}/tools/inspect/delete`,
			name: "删除过滤数据",
			post: async function(data={}){
				let params = Object.assign({}, data);
				let users = params.user || {}, uids = [];
				if(users.length > 0){
					users.map((item) => {
						uids.push(item.uid);
					})
				}
				params.user = uids;
				return await http.post(this.url, params);
			}
		},
		average:{
			url: `${config.API_URL}/tools/inspect/average`,
			name: "质检数据操作",
			post: async function(data={}){
				let params = Object.assign({}, data);
				let users = params.users || {}, uids = [], user = params.user || {}, uid = [];
				if(users.length > 0){
					users.map((item) => {
						uids.push(item.uid);
					})
				}
				if(user.length > 0){
					user.map((item) => {
						uid.push(item.uid);
					})
				}
				params.users = uids;
				params.user = uid;
				return await http.post(this.url, params);
			}
		}
	}
}