import {http} from './service.js'


const uploadBase64=p => http.post('common/file/uploadBase64', p)



// 权限管理
let permissionsUrl={
	login:'/permissions/authentication/login',
	menuList: "/permissions/account/getMyPermissionsTreeList",
	orgList:"/permissions/org/pagingQuery",
	orgListByName: "/permissions/org/getListByLikeName",
	getById: "/permissions/org/get/",
	carList:"/permissions/xq/device/admin/user/pagingQuery",
	subList:"/permissions/org/getSubListByPid"
}
const permissions = {
	login:(params,header) => http.post(permissionsUrl.login,params,{header: header}),
	menuList:(params,header) => http.get(permissionsUrl.menuList,{params:params,header: header}),
	orgList:(params,header) => http.get(permissionsUrl.orgList,{params:params,header: header}),
	orgListByName:(params,header) => http.get(permissionsUrl.orgListByName,{params:params,header: header}),
	getById: (params,header) => http.get(permissionsUrl.getById+params,{header: header}),
	getCarList:(params,header)=>http.get(permissionsUrl.carList,{params:params,header:header}),
	getSubListByPid:(params)=>http.get(permissionsUrl.subList,{params:params,header:header})
}

//登录
//获取token
const getToken=p => http.post(`blade-auth/oauth/token?tenant_id=${p.tenant_id}&username=${p.username}&password=${p.password}&grant_type=${p.grant_type}`,{},{header: {"Authorization": "Basic c2FiZXI6c2FiZXJfc2VjcmV0"}})
//字典
const dict=(params,header) => http.get('/blade-system/dict-biz/dictionary?code='+params,{params:{},header})

//获取当前登录用户的身份
const getCurrentAccount=(params,header) => http.get('/permissions/authentication/getCurrentAccount',{params,header})
//修改密码
const updatePsw= (params,header) => http.post('/permissions/account/modifyPassword',params,{header})


//机构列表
const agency={
	page:(params,header) => http.get("/cyzh-community/agency/list",{params:params,header:header})
}

//数据统计
let dataStatisticsUrl={
	//小区数
	getResidentialAccount:"home/getResidentialAccount",
	//单元数
	getUnitAccount:"home/getUnitAccount",
	//住户数
	getUserAccount:"home/getUserAccount",
	//住户待审核
	getApplyUserAccountWithCheckState:"/cyzh-estate/applyuser/list"
}
const dataStatistics={
	getResidentialAccount:(params,header) => http.get(dataStatisticsUrl.getResidentialAccount,{params:{'_':new Date().getTime()},header}),
	getUnitAccount:(params,header) => http.get(dataStatisticsUrl.getUnitAccount,{params:{'_':new Date().getTime()},header}),
	getUserAccount:(params,header) => http.get(dataStatisticsUrl.getUserAccount,{params:{'_':new Date().getTime()},header}),
	getApplyUserAccountWithCheckState:(params,header) => http.get(dataStatisticsUrl.getApplyUserAccountWithCheckState,{params:{'checkState':'0'},header})
}


//小区管理
let residentialUrl={
	page:"/cyzh-community/residential/list",
	pageBycondition: "/cyzh-community/residential/list",
	add: "/estate/residential/addResidential",
	update: "/cyzh-community/residential/submit",
	del: "/estate/residential/deleteResidential",
	findListByPosition:"/estate/unit/findListByPosition",
	pageByconditionNew:"/community/residential/listByAgencyId",//条件获取小区列表
}
const residential={
	page:(params,header) => http.get(residentialUrl.page,{params:params,header: header}),
	pageBycondition:(params,header) => http.get(residentialUrl.pageBycondition,{params:params,header: header}),
	add: (params,header) => http.post(residentialUrl.add,params,{header: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}}),
	update: (params,header) => http.post(residentialUrl.update,params),
	del: (params,header) => http.post(residentialUrl.del,params,{header: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}}),
	findListByPosition:(params,header) => http.get(residentialUrl.findListByPosition,{params:params,header: header}),
	pageByconditionNew:(params,header) => http.get(residentialUrl.pageByconditionNew,{params:params,header:header})
}

//楼栋管理
let buildingUrl={
	page:'/cyzh-community/building/list',
	update:'/cyzh-community/building/submit',
	del:'/cyzh-community/building/remove',
	add:'/cyzh-community/building/submit'
}
const building={
	page:(params,header) => http.get(buildingUrl.page,{params:params,header: header}),
	update: (params,header) => http.post(buildingUrl.update,params),
	del: (params,header) => http.post(buildingUrl.del,params),
	add: (params,header) => http.post(buildingUrl.add,params),
}

//单元管理
let unitUrl={
	page:"/cyzh-community/unit/list",
	update:'/cyzh-community/unit/submit'
}
const unit={
	page:(params,header) => http.get(unitUrl.page,{params:params,header:header}),
	update: (params,header) => http.post(unitUrl.update,params),
}


//房间管理
let roomUrl={
	del:'/cyzh-community/room/remove',
	add:'/cyzh-community/room/submit',
	page: "/cyzh-community/room/list",
	pageBycondition:  "/cyzh-community/room/list",
	update:'/cyzh-community/room/submit',
}
const room = {
	del: (params,header) => http.post(roomUrl.del,params),
	add: (params,header) => http.post(roomUrl.add,params,{header: header}),
	page:(params,header) => http.get(roomUrl.page,{params:params,header: header}),
	pageBycondition: (params,header) => http.get(roomUrl.pageBycondition,{params:params,header: header}),
	update: (params,header) => http.post(roomUrl.update,params),
}

//住户管理
let userUrl={
	page:'/cyzh-person/houseuser/list',
	del:'/cyzh-person/houseuser/remove',
	add:'/cyzh-person/houseuser/submit',
	update:'/cyzh-person/houseuser/submit',
	detail: "/cyzh-person/houseuser/detail"
}
let user={
	page:(params,header) => http.get(userUrl.page,{params:params,header: header}),
	del: (params,header) => http.post(userUrl.del,params),
	add: (params,header) => http.post(userUrl.add,params),
	update: (params,header) => http.post(userUrl.update,params),
	detail: (params,header) => http.get(userUrl.detail+"?id="+params.id)
}

//住户审核
let userAuthUrl={
	//审核列表
	page:'/cyzh-estate/applyuser/list',
	//认证审核
	updateCheckState:'/cyzh-estate/applyuser/updateCheckState',
}
const userAuth={
	page: (params,header) => http.get(userAuthUrl.page,{params:params,header:header}),
	updateCheckState: (params,header) => http.post(userAuthUrl.updateCheckState,params),
}



//用户反馈
let userFeedBackUrl={
	page:'/cyzh-estate/feedback/list',
}
const userFeedBack={
	page:(params,header) => http.get(userFeedBackUrl.page,{params:params,header: header}),
}

//物业报修
let estateRepairUrl={
	page:'/cyzh-estate/repair/list',
	submit:'/estate/estateRepair/addOrEditEstateRepair',//新增修改
	detail:'/cyzh-estate/repair/detail',
	userFeedback:'/cyzh-estate/feedback/list',//用户反馈
}
const estateRepair={
	page:(params,header) => http.get(estateRepairUrl.page,{params:params,header: header}),
	submit: (params,header) => http.post(estateRepairUrl.submit,params,{header: header}),
	detail:(params,header) => http.get(estateRepairUrl.detail,{params:params,header: header}),
}

//车辆管理
let carManageUrl={
	page:"/permissions/xq/device/admin/user/pagingQuery",
	pageBycondition:"/cyzh-estate/car/list",
	submit:"/cyzh-estate/car/submit",
	del:"/cyzh-estate/car/remove",
	audit: "/cyzh-estate/car/audit"
}
const carManage={
	page:(params,header) => http.get(carManageUrl.pageBycondition,{params:params,header: header}),
	pageBycondition:(params,header) => http.get(carManageUrl.pageBycondition,{params:params,header:header}),
	submit:(params,header) => http.post(carManageUrl.submit,params,{header:header}),
	del:(params,header) => http.post(carManageUrl.del,params),
	update:(params,header) => http.post(carManageUrl.submit,params),
	audit: (params,header) => http.post(carManageUrl.audit,params)
}

//服务人员管理
const serverUser={
	page:(params,header) => http.get('/cyzh-person/serveruser/list',{params:params,header:header}),
	submit:(params,header) => http.post('/cyzh-person/serveruser/submit',params),
	addOrEditOpenPermission:(params,header) => http.post('estate/serverUser/addOrEditOpenPermission',params),
	accessDevicesManualPush:(params,header) => http.post('estate/serverUser/accessDevicesManualPush',params),
	deleteServerUser:(params,header) => http.post('/cyzh-person/serveruser/remove?id='+params.id),
}

//公告管理
const notice={
	page:(params,header) => http.get('/cyzh-estate/noticepushrecord/listReturnNotice',{params:params,header:header}),
	submit:(params,header) => http.post('estate/notice/addOrEditNotice',params,{header: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}}),
	remove:(params,header) => http.post('estate/notice/deleteNotice/'+params,{},{header: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}}),
}


export const api={
	//登录时获取token
	getToken,
	//上传base64文件
	uploadBase64,
	//权限管理
	permissions,
	//字典
	dict,
	//获取当前用户的身份信息
	getCurrentAccount,
	//修改密码
	updatePsw,
	//机构列表
	agency,
	//数据统计
	dataStatistics,
	//小区管理
	residential,
	//楼栋管理
	building,
	//单元管理
	unit,
	//房间管理
	room,
	//住户管理
	user,
	//住户审核
	userAuth,
	//用户反馈
	userFeedBack,
	//物业报修
	estateRepair,
	//车辆管理
	carManage,
	//服务人员管理
	serverUser,
	//公告管理
	notice
}