tea-plan.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import _ from 'lodash';
  4. import axios from 'axios';
  5. Vue.use(Vuex);
  6. const api = {
  7. interface: `/api/train/apply`,
  8. apply: `/api/train/apply/queryteacher`,
  9. divide: `/api/train/teaplan/divide`, //query: trainplanid
  10. findTeacher: `/api/train/teaplan/findteacher`, //planid termid batchid
  11. arrange: `/api/train/apply/arrange`, //计划-安排教师
  12. sendmsg: `/api/train/apply/sendmsg`, //计划,给指定期安排的教师发送通知
  13. confirm: `/api/train/apply/confirm`, //计划,给指定期安排的教师变更为确认状态
  14. };
  15. const state = () => ({});
  16. const mutations = {};
  17. const actions = {
  18. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  19. const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
  20. return res;
  21. },
  22. async create({ commit }, payload) {
  23. const res = await this.$axios.$post(`${api.interface}`, payload);
  24. return res;
  25. },
  26. async fetch({ commit }, payload) {
  27. const res = await this.$axios.$get(`${api.interface}/${payload}`);
  28. return res;
  29. },
  30. async update({ commit }, { id, ...data }) {
  31. const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
  32. return res;
  33. },
  34. async delete({ commit }, payload) {
  35. const res = await this.$axios.$delete(`${api.interface}/${payload}`);
  36. return res;
  37. },
  38. async applyQuery({ commit }, { skip = 0, limit, ...info } = {}) {
  39. const res = await this.$axios.$get(`${api.apply}`, { skip, limit, ...info });
  40. return res;
  41. },
  42. async divide({ commit }, payload) {
  43. //payload是trainplanid
  44. const res = await this.$axios.$get(`${api.divide}`, payload);
  45. return res;
  46. },
  47. async findTeacher({ commit }, payload) {
  48. //payload是trainplanid
  49. const res = await this.$axios.$get(`${api.findTeacher}`, payload);
  50. return res;
  51. },
  52. // 计划-安排教师
  53. async arrangeTeacher({ commit }, payload) {
  54. const res = await this.$axios.$post(`${api.arrange}`, payload);
  55. return res;
  56. },
  57. // 计划-给指定期安排的教师发送通知
  58. async sendMsg({ commit }, { planid, ...info }) {
  59. const res = await this.$axios.$post(`${api.sendmsg}/${planid}`, info);
  60. return res;
  61. },
  62. // 计划-给指定期安排的教师确认状态
  63. async confirmPlan({ commit }, { planid, ...info }) {
  64. const res = await this.$axios.$post(`${api.confirm}/${planid}`, info);
  65. return res;
  66. },
  67. async mergeRequest({ commit, dispatch }, { method, data }) {
  68. let toRequest = () => {
  69. let res = [];
  70. for (const i of data) {
  71. res.push(dispatch(method, i));
  72. }
  73. return res;
  74. };
  75. let result = await axios.all(toRequest());
  76. let newFilter = data => {
  77. let res = data.map(i => {
  78. let type = _.isArray(i);
  79. if (!type) {
  80. //fetch的多个请求 是object 将errcode为0的data取出来
  81. return _.get(i, `data`, i);
  82. } else {
  83. //query的多个请求 array 将此数据再次走这个方法
  84. return newFilter(i);
  85. }
  86. });
  87. return res;
  88. };
  89. let returns = _.flattenDeep(newFilter(result));
  90. return returns;
  91. },
  92. };
  93. export default {
  94. namespaced: true,
  95. state,
  96. mutations,
  97. actions,
  98. };