rosterEdit.vue 8.4 KB

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