selects.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* eslint-disable no-empty */
  2. // import { branchQueryPage } from '@/api/specialSetting'
  3. import { getSubject, getTeacher,findEducationUsers,getEmployeeOrgan } from '@/api/buildTeam'
  4. import { getSchool,queryEmployByOrganId } from '@/api/systemManage'
  5. import { vipGroupCategory } from "@/api/vipSeting"
  6. import { findTechnician } from '@/api/repairManager'
  7. const loadings = {}
  8. /**
  9. *
  10. * 为避免重复请求全局参数,将需要使用的全局参数放到vuex中缓存
  11. *
  12. * 使用:
  13. *
  14. * 按照需要直接使用 this.$store.dispatch('action', force: Bool 是否强制刷新)
  15. *
  16. * 直接从this.$store.state.name 中获取数据
  17. */
  18. export default {
  19. state: {
  20. branchs: [],
  21. subjects: [],
  22. teachers: [],
  23. schools: [],
  24. vipGroupCategory: [],
  25. educations:[],
  26. technician: [],
  27. employs:[],
  28. },
  29. mutations: {
  30. commit_branchs: (state, branchs) => {
  31. state.branchs = branchs
  32. },
  33. commit_subjects: (state, subjects) => {
  34. state.subjects = subjects
  35. },
  36. commit_teachers: (state, teachers) => {
  37. state.teachers = teachers.map(teacher=>{
  38. return {
  39. ...teacher,
  40. id:teacher.id,
  41. userId:teacher.id,
  42. userName:teacher.realName,
  43. realName:teacher.realName
  44. }
  45. })
  46. },
  47. commit_schools: (state, schools) => {
  48. state.schools = schools
  49. },
  50. commit_vip_group_category: (state, vipGroupCategory) => {
  51. state.vipGroupCategory = vipGroupCategory
  52. },
  53. commit_educations: (state, educations)=>{
  54. state.educations = educations
  55. },
  56. commit_technician: (state, technician) => {
  57. state.technician = technician
  58. },
  59. commit_employs:(state,employs)=>{
  60. state.employs = employs.map(emloys=>{
  61. return {
  62. ...emloys,
  63. id:emloys.id,
  64. userId:emloys.id,
  65. userName:emloys.realName,
  66. realName:emloys.realName
  67. }
  68. })
  69. }
  70. },
  71. actions: {
  72. async setBranchs ({ commit, state }, force) {
  73. if ((!state.branchs.length || force === true) && !loadings.commit_branchs) {
  74. loadings.commit_branchs = getEmployeeOrgan()
  75. try {
  76. const res = await loadings.commit_branchs
  77. commit('commit_branchs', res.data)
  78. } catch (error) { }
  79. loadings.commit_branchs = false
  80. }
  81. },
  82. async setSubjects ({ commit, state }, force) {
  83. if ((!state.subjects.length || force === true) && !loadings.commit_subjects) {
  84. loadings.commit_subjects = getSubject({rows: 9999, tenantId: '1'})
  85. try {
  86. const res = await loadings.commit_subjects
  87. commit('commit_subjects', res.data)
  88. } catch (error) { }
  89. loadings.commit_subjects = false
  90. }
  91. },
  92. async setTeachers ({ commit, state }, force) {
  93. if ((!state.teachers.length || force === true) && !loadings.commit_teachers) {
  94. loadings.commit_teachers = getTeacher()
  95. try {
  96. const res = await loadings.commit_teachers
  97. commit('commit_teachers', res.data)
  98. } catch (error) { }
  99. loadings.commit_teachers = false
  100. }
  101. },
  102. async setSchools ({ commit, state }, force) {
  103. if ((!state.schools.length || force === true) && !loadings.commit_schools) {
  104. loadings.commit_schools = getSchool()
  105. try {
  106. const res = await loadings.commit_schools
  107. commit('commit_schools', res.data)
  108. } catch (error) { }
  109. loadings.commit_schools = false
  110. }
  111. return loadings.commit_schools
  112. },
  113. async setVipGroupCategory ({ commit, state }, force) {
  114. if ((!state.vipGroupCategory.length || force === true) && !loadings.commit_vip_group_category) {
  115. loadings.commit_vip_group_category = vipGroupCategory()
  116. try {
  117. const res = await loadings.commit_vip_group_category
  118. commit('commit_vip_group_category', res.data)
  119. } catch (error) { }
  120. loadings.commit_vip_group_category = false
  121. }
  122. },
  123. async setEducations({commit,state},force){
  124. if ((!state.educations.length || force === true) && !loadings.commit_educations) {
  125. loadings.commit_educations = findEducationUsers()
  126. try {
  127. const res = await loadings.commit_educations
  128. commit('commit_educations', res.data)
  129. } catch (error) { }
  130. loadings.commit_educations = false
  131. }
  132. },
  133. async setTechnician({commit,state},force){
  134. if ((!state.technician.length || force === true) && !loadings.commit_technician) {
  135. loadings.commit_technician = findTechnician()
  136. try {
  137. const res = await loadings.commit_technician
  138. commit('commit_technician', res.data)
  139. } catch (error) {}
  140. loadings.commit_technician = false
  141. }
  142. },
  143. async setEmploys({commit,state},force){
  144. if ((!state.employs.length || force === true) && !loadings.commit_employs) {
  145. loadings.commit_employs = queryEmployByOrganId({rows:99999})
  146. try {
  147. const res = await loadings.commit_employs
  148. commit('commit_employs', res.data.rows)
  149. } catch (error) {}
  150. loadings.commit_employs = false
  151. }
  152. }
  153. }
  154. }