home.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import http from '@/request/index.js';
  2. export const state = {
  3. houseData: [], //库房数据
  4. houseSelectData: {
  5. houseName: "",
  6. houseId: ""
  7. },
  8. homeAwaitData: {},
  9. userData: {},
  10. messData: []
  11. };
  12. export const mutations = {
  13. setHouseData(state, data) {
  14. state.houseData = data
  15. },
  16. setHouseName(state, data) {
  17. state.houseSelectData = data
  18. },
  19. setUserData(state, data) {
  20. state.userData = data
  21. },
  22. setAwaitData(state, data) {
  23. state.homeAwaitData = data
  24. },
  25. setMessData(state, data) {
  26. state.messData = data
  27. },
  28. }
  29. export const actions = {
  30. getHomeAwaitData({
  31. commit,
  32. rootState
  33. }, data) {
  34. return new Promise((resolve, reject) => {
  35. http('home.getAwaitData', data, '加载中').then(res => {
  36. if (res.success == true) {
  37. commit('setAwaitData', res.data);
  38. }
  39. }).catch(e => {
  40. reject(e)
  41. })
  42. })
  43. },
  44. getHouseData({
  45. dispatch,
  46. commit,
  47. rootState
  48. }, data) {
  49. return new Promise((resolve, reject) => {
  50. http('home.getRoomData', data, '加载中').then(res => {
  51. if (res.success == true) {
  52. res.data.length > 0 && res.data.forEach((item) => {
  53. item['text'] = item.stroomName;
  54. item['value'] = item.id;
  55. })
  56. commit('setHouseName', {
  57. houseName: res.data[0].stroomName,
  58. houseId: res.data[0].id
  59. });
  60. dispatch('getHomeAwaitData', {
  61. stroomId: res.data[0].id
  62. })
  63. commit('setHouseData', res.data);
  64. } else {
  65. commit('setHouseData', []);
  66. }
  67. }).catch(e => {
  68. reject(e)
  69. })
  70. })
  71. },
  72. getUserData({
  73. commit,
  74. rootState
  75. }, data) {
  76. return new Promise((resolve, reject) => {
  77. http('home.getUserData', data, '加载中').then(res => {
  78. if (res.success == true) {
  79. commit('setUserData', res.data.userContext);
  80. }
  81. }).catch(e => {
  82. reject(e)
  83. })
  84. })
  85. },
  86. getMessData({
  87. commit,
  88. rootState
  89. }, data) {
  90. return new Promise((resolve, reject) => {
  91. http('home.getMessageData', data, '加载中').then(res => {
  92. if (res.success == true) {
  93. resolve(res);
  94. commit('setMessData', res.data.records);
  95. }
  96. }).catch(e => {
  97. reject(e)
  98. })
  99. })
  100. },
  101. }