enum.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**
  2. * @description store enum (枚举页面)各种配置枚举
  3. */
  4. import {
  5. getTypeList,
  6. } from "@/api/common" /* eslint-disable-line */
  7. const state = {
  8. evectionTypeList: [], // 出差列表
  9. moduleList: [], // 模块列表
  10. degreeList: [], // 缓急程度
  11. applyTypeList: [], // 采购类型
  12. applyPayTypeList: [], // 采购支付类型
  13. offerTypeList: [], // 呈批类型
  14. leaveTypeList: [], // 请假类型
  15. maintainTypeList: [], // 维修类型
  16. contractTypeList: [], // 合同类型
  17. timeList: [], // 请假周期列表
  18. // 1=待审批,2=审批中,3=审批通过,4=审批拒绝
  19. // NOTE: 审批信息中的审核流程枚举
  20. approveFlowPathEnum: [undefined, '待审核', '审核中', '已通过', '已驳回'],
  21. // :2=审批中,3=审批通过,4=审批驳回,5=审批撤销
  22. // NOTE: 申请`status`枚举
  23. approveInfoEnum: [],
  24. enumIsYesOrNo: [
  25. {
  26. id: 0,
  27. name: '否'
  28. },
  29. {
  30. id: 1,
  31. name: '是'
  32. }
  33. ]
  34. }
  35. /**
  36. * 根据id在数据中返回相应的枚举值
  37. * @param {array} arrs 数据列表{name,id}[]
  38. * @param {number} id 需要获取枚举的id
  39. * @returns {string}
  40. */
  41. function getKeyToTxt(arrs, id) {
  42. let target = arrs.filter(row => row.id === id)
  43. if (!target.length) return 'UNKNOW'
  44. return target[0].name
  45. }
  46. const getters = {
  47. // NOTE: 审核流程枚举
  48. getApproveFlowPathEnum: state => (status) => {
  49. if (![1, 2, 3, 4].includes(status)) return 'unknow'
  50. return state.approveFlowPathEnum[status]
  51. },
  52. // NOTE: 获取模块列表的名称; 根据ID去获取
  53. getModuleText: state => id => getKeyToTxt(state.moduleList, id),
  54. // NOTE: 获取缓急程度枚举
  55. getDegreeText: state => id => getKeyToTxt(state.degreeList, id),
  56. // NOTE: 获取维修分类
  57. getMaintainText: state => id => getKeyToTxt(state.maintainTypeList, id),
  58. }
  59. const mutations = {
  60. // NOTE: 出差类型
  61. SET_EVECTION_TYPE_LIST(state, payload) {
  62. state.evectionTypeList = [...payload.list]
  63. },
  64. // NOTE: 模块列表
  65. SET_MODULE_LIST(state, payload) {
  66. state.moduleList = [...payload.list]
  67. },
  68. // NOTE: 缓急程度
  69. SET_DEGREE_LIST(state, payload) {
  70. state.degreeList = [...payload.list]
  71. },
  72. // NOTE: 采购类型
  73. SET_APPLY_TYPE_LIST(state, payload) {
  74. state.applyTypeList = [...payload.list]
  75. },
  76. // NOTE: 采购支付类型
  77. SET_APPLY_PAY_TYPE_LIST(state, payload) {
  78. state.applyPayTypeList = [...payload.list]
  79. },
  80. // NOTE: 呈批类型
  81. SET_OFFER_TYPE_LIST(state, payload) {
  82. state.offerTypeList = [...payload.list]
  83. },
  84. // NOTE: 请假类型
  85. SET_LEAVE_TYPE_LIST(state, payload) {
  86. state.leaveTypeList = [...payload.list]
  87. },
  88. // NOTE: 维修类型
  89. SET_MAINTAIN_TYPE_LIST(state, payload) {
  90. state.maintainTypeList = [...payload.list]
  91. },
  92. // NOTE: 合同类型
  93. SET_CONTRACT_TYPE_LIST(state, payload) {
  94. state.contractTypeList = [...payload.list]
  95. },
  96. // NOTE: 请假周期列表
  97. SET_TIME_LIST (state, payload) {
  98. state.timeList = [...payload.list]
  99. }
  100. }
  101. const actions = {
  102. getTypeList({ commit }) {
  103. return new Promise((resolve, reject) => {
  104. getTypeList().then(result => {
  105. if (result.code === 1) {
  106. const {
  107. module_list,
  108. degree_list,
  109. pay_type_list,
  110. data1,
  111. data2,
  112. data5,
  113. data6,
  114. data8,
  115. data9,
  116. time_list
  117. } = result.data
  118. commit({
  119. type: 'SET_EVECTION_TYPE_LIST',
  120. list: data5
  121. })
  122. commit({
  123. type: 'SET_MODULE_LIST',
  124. list: module_list
  125. })
  126. commit({
  127. type: 'SET_DEGREE_LIST',
  128. list: degree_list
  129. })
  130. commit({
  131. type: 'SET_APPLY_PAY_TYPE_LIST',
  132. list: pay_type_list
  133. })
  134. commit({
  135. type: 'SET_APPLY_TYPE_LIST',
  136. list: data1
  137. })
  138. commit({
  139. type: 'SET_OFFER_TYPE_LIST',
  140. list: data2
  141. })
  142. commit({
  143. type: 'SET_LEAVE_TYPE_LIST',
  144. list: data6
  145. })
  146. commit({
  147. type: 'SET_MAINTAIN_TYPE_LIST',
  148. list: data8
  149. })
  150. commit({
  151. type: 'SET_CONTRACT_TYPE_LIST',
  152. list: data9
  153. })
  154. commit({
  155. type: 'SET_TIME_LIST',
  156. list: time_list
  157. })
  158. resolve()
  159. }
  160. }).catch(error => reject(error))
  161. })
  162. },
  163. // 获取出差类型
  164. // getEvectionTypeList({ commit }) {
  165. // return new Promise((resolve, reject) => {
  166. // getAwayType().then(result => {
  167. // if (result.code === 1) {
  168. // commit({
  169. // type: 'SET_EVECTION_TYPE_LIST',
  170. // list: result.data
  171. // })
  172. // resolve(result.data)
  173. // }
  174. // }).catch(error => {
  175. // console.log('getEvectionTypeList error>', error);
  176. // reject([])
  177. // })
  178. // })
  179. // }
  180. }
  181. export default {
  182. namespaced: true,
  183. state,
  184. getters,
  185. mutations,
  186. actions
  187. }