/**
 * long description for the file
 *
 * @summary 角色/权限管理
 * @author wu <308822989@qq.com>
 *
 * Created at     : 2018-08-01 18:01:57
 * Last modified  : 2018-08-29 09:13:13
 */

import axios from '@/config/axios.js';
import { proPath } from '@/config/config.js';

const state = {
  //  机构类别
  roleTypeEnum: [
    {
      label: '功能角色',
      value: '1'
    },
    {
      label: '数据角色',
      value: '2'
    }
  ]
}

const getters = {
}

const mutations = {
  // //  更新list
  // treeItem (state, treeItem) {
  //   state.treeItem = treeItem;
  // }
}
const actions = {
  //  角色树列表
  list ({ commit, state }, form) {
    let res = axios.get(proPath + 'v1/sysroles/getRootRole');
    return res;
  },
  //  删除
  delRoles ({ commit, state }, idArr) {
    if (!(idArr && idArr.length > 0)) {
      return false;
    }
    let arr = [];
    for (let item of idArr) {
      arr.push(item.id);
    }
    idArr = arr.join(',');
    let res = axios.delete(proPath + 'v1/sysroles/' + idArr);
    return res;
  },
  //  添加
  addRoles ({ commit, state }, form) {
    let res = axios.post(proPath + 'v1/sysroles/', form);
    return res;
  },
  //  修改
  editRoles ({ commit, state }, obj) {
    let res = axios.put(proPath + 'v1/sysroles/' + obj.id, obj.form);
    return res;
  },
  // //  岗位查找用户列表
  // userList ({ commit, state }, postId) {
  //   let res = axios.get('v1/sysusers/getUsersByPostId/' + postId);
  //   return res;
  // }
  //  数据权限列表
  dataRolesList ({ commit, state }, form) {
    let res = axios.get(proPath + 'v1/sysdatablepolicys/', {
      params: form
    });
    return res;
  },
  //  用户查询菜单选中项
  sysauthorizes ({ commit, state }, form) {
    let res = axios.get(proPath + 'v1/sysauthorizes/', {
      params: form
    });
    return res;
  },
  //  设置用户菜单数据权限
  setSysauthorizes ({ commit, state }, obj) {
    let res = axios.post(proPath + 'v1/sysauthorizes/batchInsert', obj);
    return res;
  }
}

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