/**
 * long description for the file
 *
 * @summary 岗位管理
 * @author wu <308822989@qq.com>
 *
 * Created at     : 2018-08-01 18:01:57
 * Last modified  : 2018-08-27 14:55:32
 */

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

const state = {
  //  树选中项
  treeItem: {}
}

const getters = {
}

const mutations = {
  //  更新list
  treeItem (state, treeItem) {
    state.treeItem = treeItem;
  }
}
const actions = {
  //  取岗位列表
  list ({ commit, state }, form) {
    let res = axios.get(proPath + 'v1/sysposts/getPostByOrgCode', {
      params: form
    });
    return res;
  },
  //  删除
  delPost ({ commit, state }, idArr) {
    if (!(idArr && idArr.length > 0)) {
      return false;
    }
    let arr = [];
    for (let item of idArr) {
      arr.push(item.postId);
    }
    idArr = arr.join(',');
    let res = axios.delete(proPath + 'v1/sysposts/' + idArr);
    return res;
  },
  //  添加
  addPost ({ commit, state }, form) {
    let res = axios.post(proPath + 'v1/sysposts/', form);
    return res;
  },
  //  修改
  editPost ({ commit, state }, obj) {
    let res = axios.put(proPath + 'v1/sysposts/' + obj.id, obj.form);
    return res;
  },
  //  岗位查找用户列表
  userList ({ commit, state }, form) {
    let res = axios.get(proPath + 'v1/sysusers/getUsersByPostId/' + form.postId);
    return res;
  },
  //  岗位添加多用户
  insertPostUser ({ commit, state }, obj) {
    let res = axios.put(proPath + 'v1/sysuserposts/insertPostUser/' + obj.id, obj.form);
    return res;
  }
}

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