rosterEdit.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <m-dialog ref="editDialog" :title="title" v-bind="$attrs" @sure="handleSaveEdit">
  3. <m-form ref="formRef" :items="items" v-model="query" v-loading="loading"></m-form>
  4. </m-dialog>
  5. </template>
  6. <script>
  7. import { saveRoster } from '@/api/system'
  8. import { mapGetters } from 'vuex'
  9. import {
  10. getSalaryLevelDict
  11. } from '@/api/salary'
  12. import {
  13. getJobLevel,
  14. getPositionCategory,
  15. getPersonnelCategory,
  16. getPositionSequence,
  17. getJobName
  18. } from '@/api/dictionary'
  19. import DICT from '@/utils/dict'
  20. export default {
  21. name: 'roster-edit',
  22. props: {
  23. title: {
  24. type: String,
  25. default: '新增'
  26. }
  27. },
  28. data () {
  29. return {
  30. query: {},
  31. isEdit: false,
  32. loading: false,
  33. dict: {},
  34. employeeStatus: []
  35. }
  36. },
  37. computed: {
  38. ...mapGetters(['organizationTree']),
  39. items () {
  40. return [
  41. {
  42. prop: 'parentOrganizationName',
  43. hidden: true
  44. },
  45. {
  46. prop: 'parentOrganizationNo',
  47. hidden: true
  48. },
  49. {
  50. prop: 'deptName',
  51. hidden: true
  52. },
  53. {
  54. label: '部门名称',
  55. prop: 'organizationNo',
  56. type: 'cascader',
  57. options: {
  58. ref: 'organizationNo',
  59. filterable: true,
  60. clearable: true,
  61. placeholder: '请选择部门',
  62. options: this.organizationTree,
  63. showAllLevels: false,
  64. props: {
  65. emitPath: false,
  66. value: 'organizationNo',
  67. label: 'organizationName',
  68. children: 'child'
  69. }
  70. },
  71. handles: {
  72. change: this.onChange
  73. }
  74. },
  75. {
  76. label: '通行证号',
  77. prop: 'passes',
  78. type: 'input',
  79. options: { disabled: this.isEdit, placeholder: '请输入通行证号' },
  80. rules: [{ required: true, message: '请输入通行证号', trigger: 'blur' }]
  81. },
  82. {
  83. label: '员工名称',
  84. prop: 'employeeName',
  85. type: 'input',
  86. options: { disabled: this.isEdit, placeholder: '请输入员工名称' },
  87. rules: { required: true, message: '请输入员工名称', trigger: 'blur' }
  88. },
  89. {
  90. label: '工行时间',
  91. prop: 'tradeUnionsTime',
  92. type: 'datePicker',
  93. options: { disabled: this.isEdit, placeholder: '请选择工行时间' },
  94. rules: [{ required: true, message: '请选择工行时间', trigger: 'blur' }]
  95. },
  96. {
  97. label: '员工状态',
  98. prop: 'employeeStatus',
  99. type: 'select',
  100. options: {
  101. placeholder: '请选择员工状态',
  102. filterable: true,
  103. items: this.employeeStatus.map(e => {
  104. return {
  105. ...e,
  106. value: +e.value
  107. }
  108. })
  109. },
  110. rules: { required: true, message: '请输入人员类别', trigger: 'change' }
  111. },
  112. {
  113. label: '人员类别',
  114. prop: 'personnelCategory',
  115. type: 'select',
  116. options: {
  117. disabled: this.isEdit,
  118. placeholder: '请输入人员类别',
  119. filterable: true,
  120. items: this.dict.personnelCategory
  121. },
  122. rules: { required: true, message: '请输入人员类别', trigger: 'change' }
  123. },
  124. {
  125. label: '岗位名称',
  126. prop: 'postName',
  127. type: 'select',
  128. options: {
  129. placeholder: '请输入岗位名称',
  130. filterable: true,
  131. items: this.dict.jobName
  132. },
  133. rules: { required: true, message: '请输入岗位名称', trigger: 'change' }
  134. },
  135. {
  136. label: '岗位序列',
  137. prop: 'positionSequence',
  138. type: 'select',
  139. options: {
  140. placeholder: '请输入岗位序列',
  141. filterable: true,
  142. items: this.dict.positionSequence
  143. },
  144. rules: [{ required: true, message: '请输入岗位序列', trigger: 'change' }]
  145. },
  146. {
  147. label: '岗位类别',
  148. prop: 'positionCategory',
  149. type: 'select',
  150. options: {
  151. placeholder: '请输入岗位类别',
  152. filterable: true,
  153. items: this.dict.positionCategory
  154. },
  155. rules: [{ required: true, message: '请输入岗位类别', trigger: 'change' }]
  156. },
  157. {
  158. label: '职务层级',
  159. prop: 'jobLevel',
  160. type: 'select',
  161. options: {
  162. placeholder: '请输入职务层级',
  163. filterable: true,
  164. items: this.dict.jobLevel
  165. },
  166. rules: [{ required: true, message: '请输入职务层级', trigger: 'change' }]
  167. },
  168. {
  169. label: '薪酬档次',
  170. prop: 'salaryCategory',
  171. type: 'select',
  172. options: {
  173. placeholder: '薪酬档次',
  174. items: this.dict.gradeDict
  175. },
  176. rules: [{ required: true, message: '请输入薪酬档次', trigger: 'blur' }]
  177. },
  178. {
  179. label: '薪酬级别',
  180. prop: 'salaryLevel',
  181. type: 'select',
  182. options: {
  183. placeholder: '薪酬级别',
  184. items: this.dict.levelDict
  185. },
  186. rules: [{ required: true, message: '请输入薪酬级别', trigger: 'blur' }]
  187. }
  188. ]
  189. }
  190. },
  191. methods: {
  192. async open (item) {
  193. this.$refs.editDialog.open()
  194. this.loading = true
  195. await this.getEmployeeStatus()
  196. this.query = this.items.reduce((res, item) => {
  197. res[item.prop] = null
  198. return res
  199. }, {})
  200. this.$nextTick(() => {
  201. this.$refs.formRef.clearValidate()
  202. })
  203. this.isEdit = Boolean(item)
  204. await this.getDict()
  205. await this.getOtherDict()
  206. if (item) {
  207. Object.keys(this.query).forEach(key => {
  208. this.query[key] = item[key]
  209. })
  210. this.query.personnelCode = item.personnelCode
  211. }
  212. this.loading = false
  213. },
  214. async getEmployeeStatus () {
  215. try {
  216. const data = await DICT.get('EMPLOYEE_STATUS')
  217. this.employeeStatus = data
  218. } catch (error) {
  219. this.$snackbar.error(error)
  220. }
  221. },
  222. handleSaveEdit () {
  223. this.$refs.formRef.validate(async valid => {
  224. if (!valid) {
  225. return
  226. }
  227. const { tradeUnionsTime, ...obj } = this.query
  228. const date = new Date(tradeUnionsTime)
  229. // 获取年、月、日
  230. const year = date.getFullYear()
  231. const month = String(date.getMonth() + 1).padStart(2, '0') // 月份从0开始,所以要加1
  232. const day = String(date.getDate()).padStart(2, '0')
  233. try {
  234. await saveRoster({
  235. ...obj,
  236. tradeUnionsTime: `${year}${month}${day}`
  237. })
  238. this.$message.success('保存成功')
  239. this.$refs.editDialog.close()
  240. this.$emit('refresh')
  241. } catch (error) {
  242. this.$message.error(error)
  243. }
  244. })
  245. },
  246. onChange () {
  247. const nodes = this.$refs.formRef.$refs.organizationNo.getCheckedNodes()
  248. const node = nodes[0].data
  249. const parent = nodes[0].parent.data
  250. Object.assign(this.query, {
  251. organizationNo: node.organizationNo,
  252. deptName: node.organizationName,
  253. parentOrganizationName: parent.organizationName,
  254. parentOrganizationNo: parent.organizationNo
  255. })
  256. },
  257. async getDict () {
  258. try {
  259. const { data } = await getSalaryLevelDict()
  260. const dict = { ...this.dict }
  261. Object.assign(dict, {
  262. gradeDict: data.gradeDict.map(e => {
  263. return {
  264. label: e,
  265. value: e
  266. }
  267. }),
  268. levelDict: data.levelDict.map(e => {
  269. return {
  270. label: e,
  271. value: e
  272. }
  273. })
  274. })
  275. this.dict = dict
  276. } catch (error) {
  277. this.$message.error(error)
  278. }
  279. },
  280. async getOtherDict () {
  281. const lists = [
  282. { key: 'jobLevel', fn: getJobLevel },
  283. { key: 'positionCategory', fn: getPositionCategory },
  284. { key: 'personnelCategory', fn: getPersonnelCategory },
  285. { key: 'positionSequence', fn: getPositionSequence },
  286. { key: 'jobName', fn: getJobName }
  287. ]
  288. try {
  289. const result = await Promise.all(lists.map(item => item.fn()))
  290. const dict = { ...this.dict }
  291. Object.assign(dict, lists.reduce((res, item, index) => {
  292. res[item.key] = result[index].data.map(e => ({ label: e, value: e }))
  293. return res
  294. }, {}))
  295. this.dict = dict
  296. } catch (error) {
  297. this.$message.error(error)
  298. }
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss" scoped>
  304. </style>