selects.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* eslint-disable no-empty */
  2. // import { branchQueryPage } from '@/api/specialSetting'
  3. import { getSubject, getTeacher,findEducationUsers,getEmployeeOrgan, getOrganRole } 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. roles: []
  29. },
  30. mutations: {
  31. commit_branchs: (state, branchs) => {
  32. state.branchs = branchs
  33. },
  34. commit_subjects: (state, subjects) => {
  35. state.subjects = subjects
  36. },
  37. commit_teachers: (state, teachers) => {
  38. state.teachers = teachers.map(teacher=>{
  39. return {
  40. ...teacher,
  41. id:teacher.id,
  42. userId:teacher.id,
  43. userName:teacher.realName,
  44. realName:teacher.realName
  45. }
  46. })
  47. },
  48. commit_schools: (state, schools) => {
  49. state.schools = schools
  50. },
  51. commit_vip_group_category: (state, vipGroupCategory) => {
  52. state.vipGroupCategory = vipGroupCategory
  53. },
  54. commit_educations: (state, educations)=>{
  55. state.educations = educations
  56. },
  57. commit_technician: (state, technician) => {
  58. state.technician = technician
  59. },
  60. commit_roles: (state, roles) => {
  61. state.roles = roles
  62. },
  63. commit_employs:(state,employs)=>{
  64. state.employs = employs.map(emloys=>{
  65. return {
  66. ...emloys,
  67. id:emloys.id,
  68. userId:emloys.id,
  69. userName:emloys.realName,
  70. realName:emloys.realName
  71. }
  72. })
  73. }
  74. },
  75. actions: {
  76. async setBranchs ({ commit, state }, force) {
  77. if ((!state.branchs.length || force === true) && !loadings.commit_branchs) {
  78. loadings.commit_branchs = getEmployeeOrgan()
  79. try {
  80. const res = await loadings.commit_branchs
  81. commit('commit_branchs', res.data)
  82. } catch (error) { }
  83. loadings.commit_branchs = false
  84. }
  85. },
  86. async setSubjects ({ commit, state }, force) {
  87. if ((!state.subjects.length || force === true) && !loadings.commit_subjects) {
  88. loadings.commit_subjects = getSubject({rows: 9999, tenantId: '1'})
  89. try {
  90. const res = await loadings.commit_subjects
  91. commit('commit_subjects', res.data)
  92. } catch (error) { }
  93. loadings.commit_subjects = false
  94. }
  95. },
  96. async setTeachers ({ commit, state }, force) {
  97. if ((!state.teachers.length || force === true) && !loadings.commit_teachers) {
  98. loadings.commit_teachers = getTeacher()
  99. try {
  100. const res = await loadings.commit_teachers
  101. commit('commit_teachers', res.data)
  102. } catch (error) { }
  103. loadings.commit_teachers = false
  104. }
  105. },
  106. async setSchools ({ commit, state }, force) {
  107. if ((!state.schools.length || force === true) && !loadings.commit_schools) {
  108. loadings.commit_schools = getSchool()
  109. try {
  110. const res = await loadings.commit_schools
  111. commit('commit_schools', res.data)
  112. } catch (error) { }
  113. loadings.commit_schools = false
  114. }
  115. return loadings.commit_schools
  116. },
  117. async setVipGroupCategory ({ commit, state }, force) {
  118. if ((!state.vipGroupCategory.length || force === true) && !loadings.commit_vip_group_category) {
  119. loadings.commit_vip_group_category = vipGroupCategory()
  120. try {
  121. const res = await loadings.commit_vip_group_category
  122. commit('commit_vip_group_category', res.data)
  123. } catch (error) { }
  124. loadings.commit_vip_group_category = false
  125. }
  126. },
  127. async setEducations({commit,state},force){
  128. if ((!state.educations.length || force === true) && !loadings.commit_educations) {
  129. loadings.commit_educations = findEducationUsers()
  130. try {
  131. const res = await loadings.commit_educations
  132. commit('commit_educations', res.data)
  133. } catch (error) { }
  134. loadings.commit_educations = false
  135. }
  136. },
  137. async setOrganRole({commit,state},force) {
  138. if ((!state.educations.length || force === true) && !loadings.commit_roles) {
  139. loadings.commit_roles = getOrganRole()
  140. try {
  141. const res = await loadings.commit_roles
  142. const tempArr = []
  143. const tempData = res.data
  144. // 初始化数据
  145. for(let i in tempData) {
  146. tempArr[i] = []
  147. if(tempData[i]) {
  148. for(let t in tempData[i]) {
  149. tempArr[i].push({
  150. value: tempData[i][t].userId,
  151. label: tempData[i][t].realName,
  152. ...tempData[i][t]
  153. })
  154. }
  155. }
  156. }
  157. console.log(tempArr, 'tempArr')
  158. commit('commit_roles', tempArr)
  159. } catch (error) { }
  160. loadings.commit_roles = false
  161. }
  162. getOrganRole
  163. },
  164. async setTechnician({commit,state},force){
  165. if ((!state.technician.length || force === true) && !loadings.commit_technician) {
  166. loadings.commit_technician = findTechnician()
  167. try {
  168. const res = await loadings.commit_technician
  169. commit('commit_technician', res.data)
  170. } catch (error) {}
  171. loadings.commit_technician = false
  172. }
  173. },
  174. async setEmploys({commit,state},force){
  175. if ((!state.employs.length || force === true) && !loadings.commit_employs) {
  176. loadings.commit_employs = queryEmployByOrganId({rows:99999})
  177. try {
  178. const res = await loadings.commit_employs
  179. commit('commit_employs', res.data.rows)
  180. } catch (error) {}
  181. loadings.commit_employs = false
  182. }
  183. }
  184. }
  185. }