import {getAdminIndex} from '@/api/public'
import {getInfo,changePassword} from '@/api/user'
import {getDepartmentList,delDepartment,getDepartmentMain,
  getAllDepartment,addDepartment,upDepartment
} from '@/api/system'
import {login,logoutapi} from '@/api/unifiedLogin'

const state = {

}

const mutations = {

}

const actions = {
  //单点登录 start ---------------------------------------->
  login({commit},data) {
    return new Promise((resolve, reject) => {
      login(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  logoutapi({commit},data) {
    return new Promise((resolve, reject) => {
      logoutapi(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //单点登录 end ---------------------------------------->
  
  //公共api start ---------------------------------------->
  //首页数据
  getAdminIndex({commit},data) {
    return new Promise((resolve, reject) => {
      getAdminIndex(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //公共api end ---------------------------------------->
  
  //用户中心 start ---------------------------------------->
  //获取用户身份信息
  getInfo({commit},data) {
    return new Promise((resolve, reject) => {
      getInfo(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //修改用户密码
  changePassword({commit},data) {
    return new Promise((resolve, reject) => {
      changePassword(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //用户中心 end ---------------------------------------->

  //职能部门 start ---------------------------------------->
  //获取职能部门列表
  getDepartmentList({commit},data) {
    return new Promise((resolve, reject) => {
      getDepartmentList(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //删除部门
  delDepartment({commit},data) {
    return new Promise((resolve, reject) => {
      delDepartment(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //获取职能部门详情
  getDepartmentMain({commit},data) {
    return new Promise((resolve, reject) => {
      getDepartmentMain(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //获得上一级职能部门列表
  getAllDepartment({commit},data) {
    return new Promise((resolve, reject) => {
      getAllDepartment(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //添加职能部门列表
  addDepartment({commit},data) {
    return new Promise((resolve, reject) => {
      addDepartment(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  //编辑职能部门
  upDepartment({commit},data) {
    return new Promise((resolve, reject) => {
      upDepartment(data).then(response => {
        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  }
  //职能部门 end ---------------------------------------->
}


export default {
  namespaced: true,
  state,
  mutations,
  actions
}
