/**
 * long description for the file
 *
 * @summary short description for the file
 * @author wu <308822989@qq.com>
 *
 * Created at     : 2018-08-27 14:56:02
 * Last modified  : 2018-10-26 16:05:14
 */

import axios from '@/config/axios.js';
import { setCookie, getCookie, dgTree } from '@/utils/util.js';
import moment from 'moment';
import { proPath } from '@/config/config.js';

const state = {
  //  岗位类型 1-主岗位 2-兼岗位
  postType: [
    {
      label: '主岗位',
      value: '1'
    },
    {
      label: '兼岗位',
      value: '2'
    }
  ]
}

const getters = {
}

const mutations = {
}
const actions = {
  //  取用户列表
  list ({ commit, state }, form) {
    let thisParams = {};
    for (let i in form) {
      if (form[i] !== '' && form[i] !== null && typeof (form[i]) !== 'undefined') {
        thisParams[i] = form[i]
      }
    }
    let res = axios.get(proPath + 'v1/sysusers/getUsersByOrgCode/', {
      params: thisParams
    });
    return res;
  },
  //  添加
  addUser ({ commit, state }, form) {
    let res = axios.post(proPath + 'v1/sysusers/', form, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
    return res;
  },
  //  修改
  editUser ({ commit, state }, obj) {
    let res = axios.post(proPath + 'v1/sysusers/updateUser/' + obj.id, obj.form, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    });
    return res;
  },
  //  删除
  delUser ({ commit, state }, items) {
    if (!(items && items.length > 0)) {
      return false;
    }
    let arr = [];
    for (let item of items) {
      arr.push(item.userId);
    }
    items = arr.join(',');
    let res = axios.delete(proPath + 'v1/sysusers/' + items);
    return res;
  },
  //  取用户中间表列表
  postUser ({ commit, state }, form) {
    let res = axios.get(proPath + 'v1/sysuserposts/', {
      params: form
    });
    return res;
  },
  //  用户绑定岗位
  inserUserPost ({ commit, state }, obj) {
    let res = axios.put(proPath + 'v1/sysuserposts/inserUserPost/' + obj.userId, obj.form);
    return res;
  },
  //  修改密码
  updpsw ({ commit, state }, form) {
    let res = axios.post(proPath + 'v1/sysusers/updpsw', form);
    return res;
  }
}

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