user.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { getMobileUserInfo } from '@/api/index';
  2. import { selectAllocationPermission } from '@/api/week';
  3. const user = {
  4. state: {
  5. userInfo: null,
  6. activaTypeStore: null,
  7. isAssignFlag: false, //是否有客资分配权限
  8. },
  9. mutations: {
  10. SET_USER_INFO: (state, userInfo) => {
  11. state.userInfo = userInfo;
  12. },
  13. SET_ACTIVA_TYPE_STORE: (state, value) => {
  14. state.activaTypeStore = value;
  15. },
  16. SET_ASSIGN_FLAG: (state, value) => {
  17. state.isAssignFlag = value;
  18. },
  19. },
  20. actions: {
  21. // 获取用户信息
  22. getUserInfo({ dispatch, commit, state }) {
  23. dispatch('getAssignPermission');
  24. return new Promise((resolve, reject) => {
  25. getMobileUserInfo()
  26. .then((res) => {
  27. commit('SET_USER_INFO', res.data);
  28. localStorage.setItem('nickName', res.data.nickName);
  29. localStorage.setItem('postName', res.data.postName);
  30. localStorage.setItem('zipPhoto', res.data.zipPhoto);
  31. localStorage.setItem('deptLevel', res.data.depts[0].deptLevel);
  32. localStorage.setItem('userId', res.data.userId);
  33. dispatch('getAssignPermission');
  34. resolve();
  35. })
  36. .catch((error) => {
  37. reject(error);
  38. });
  39. });
  40. },
  41. // 查询当前用户是否存在家装客资分配权限
  42. getAssignPermission({ commit }) {
  43. selectAllocationPermission()
  44. .then((res) => {
  45. console.log(res);
  46. commit('SET_ASSIGN_FLAG', res.data.isAllocationPermission);
  47. })
  48. .catch((error) => {
  49. console.log(error);
  50. });
  51. },
  52. // 储存提示类-未拜访-从那个店铺类型进入未拜访列表
  53. setActivaTypeStore({ commit }, value) {
  54. commit('SET_ACTIVA_TYPE_STORE', value);
  55. },
  56. },
  57. };
  58. export default user;