enum.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. getPayTypeText: state => id => getKeyToTxt(state.applyPayTypeList, id),
  59. getapplyTypeText: state => id => getKeyToTxt(state.applyTypeList, id),
  60. }
  61. const mutations = {
  62. // NOTE: 出差类型
  63. SET_EVECTION_TYPE_LIST(state, payload) {
  64. state.evectionTypeList = [...payload.list]
  65. },
  66. // NOTE: 模块列表
  67. SET_MODULE_LIST(state, payload) {
  68. state.moduleList = [...payload.list]
  69. },
  70. // NOTE: 缓急程度
  71. SET_DEGREE_LIST(state, payload) {
  72. state.degreeList = [...payload.list]
  73. },
  74. // NOTE: 采购类型
  75. SET_APPLY_TYPE_LIST(state, payload) {
  76. state.applyTypeList = [...payload.list]
  77. },
  78. // NOTE: 采购支付类型
  79. SET_APPLY_PAY_TYPE_LIST(state, payload) {
  80. state.applyPayTypeList = [...payload.list]
  81. },
  82. // NOTE: 呈批类型
  83. SET_OFFER_TYPE_LIST(state, payload) {
  84. state.offerTypeList = [...payload.list]
  85. },
  86. // NOTE: 请假类型
  87. SET_LEAVE_TYPE_LIST(state, payload) {
  88. state.leaveTypeList = [...payload.list]
  89. },
  90. // NOTE: 维修类型
  91. SET_MAINTAIN_TYPE_LIST(state, payload) {
  92. state.maintainTypeList = [...payload.list]
  93. },
  94. // NOTE: 合同类型
  95. SET_CONTRACT_TYPE_LIST(state, payload) {
  96. state.contractTypeList = [...payload.list]
  97. },
  98. // NOTE: 请假周期列表
  99. SET_TIME_LIST (state, payload) {
  100. state.timeList = [...payload.list]
  101. }
  102. }
  103. const actions = {
  104. getTypeList({ commit }) {
  105. return new Promise((resolve, reject) => {
  106. getTypeList().then(result => {
  107. if (result.code === 1) {
  108. const {
  109. module_list,
  110. degree_list,
  111. pay_type_list,
  112. data1,
  113. data2,
  114. data5,
  115. data6,
  116. data8,
  117. data9,
  118. time_list
  119. } = result.data
  120. commit({
  121. type: 'SET_EVECTION_TYPE_LIST',
  122. list: data5
  123. })
  124. commit({
  125. type: 'SET_MODULE_LIST',
  126. list: module_list
  127. })
  128. commit({
  129. type: 'SET_DEGREE_LIST',
  130. list: degree_list
  131. })
  132. commit({
  133. type: 'SET_APPLY_PAY_TYPE_LIST',
  134. list: pay_type_list
  135. })
  136. commit({
  137. type: 'SET_APPLY_TYPE_LIST',
  138. list: data1
  139. })
  140. commit({
  141. type: 'SET_OFFER_TYPE_LIST',
  142. list: data2
  143. })
  144. commit({
  145. type: 'SET_LEAVE_TYPE_LIST',
  146. list: data6
  147. })
  148. commit({
  149. type: 'SET_MAINTAIN_TYPE_LIST',
  150. list: data8
  151. })
  152. commit({
  153. type: 'SET_CONTRACT_TYPE_LIST',
  154. list: data9
  155. })
  156. commit({
  157. type: 'SET_TIME_LIST',
  158. list: time_list
  159. })
  160. resolve()
  161. }
  162. }).catch(error => reject(error))
  163. })
  164. },
  165. // 获取出差类型
  166. // getEvectionTypeList({ commit }) {
  167. // return new Promise((resolve, reject) => {
  168. // getAwayType().then(result => {
  169. // if (result.code === 1) {
  170. // commit({
  171. // type: 'SET_EVECTION_TYPE_LIST',
  172. // list: result.data
  173. // })
  174. // resolve(result.data)
  175. // }
  176. // }).catch(error => {
  177. // console.log('getEvectionTypeList error>', error);
  178. // reject([])
  179. // })
  180. // })
  181. // }
  182. }
  183. export default {
  184. namespaced: true,
  185. state,
  186. getters,
  187. mutations,
  188. actions
  189. }