handover.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div>
  3. <el-form ref="form" inline :model="form">
  4. <template v-for="(item, key) in form">
  5. <select-user
  6. v-if="item.length > 0"
  7. :key="key"
  8. :name="key"
  9. :item="item"
  10. :branchsyId="branchsyId"
  11. :teachersByOrganId="teachersByOrganId"
  12. />
  13. </template>
  14. </el-form>
  15. <span slot="footer" class="dialog-footer">
  16. <el-button @click="$listeners.close">取 消</el-button>
  17. <el-button @click="submit" type="primary">确 定</el-button>
  18. </span>
  19. </div>
  20. </template>
  21. <script>
  22. import { array2object } from '@/helpers/utils'
  23. import { employeeLevelDetail, employeeLevel } from '../api'
  24. import selectUser from './select-user'
  25. export default {
  26. props: ['detail'],
  27. components: {
  28. 'select-user': selectUser
  29. },
  30. data() {
  31. return {
  32. list: [],
  33. form: {
  34. repair: [],
  35. director: [],
  36. education: [],
  37. teamTeacher: [],
  38. }
  39. }
  40. },
  41. computed: {
  42. branchsyId() {
  43. return array2object(this.selects.branchs, 'id')
  44. },
  45. teachersByOrganId() {
  46. const data = {}
  47. for (const item of this.selects.teachers) {
  48. if (!data[item.organId]) {
  49. data[item.organId] = []
  50. }
  51. data[item.organId].push(item)
  52. }
  53. return data
  54. }
  55. },
  56. mounted() {
  57. this.$store.dispatch('setBranchs')
  58. this.$store.dispatch('setTeachers')
  59. this.FetchDetail()
  60. },
  61. methods: {
  62. async submit() {
  63. this.$refs.form.validate(async valid => {
  64. if (valid) {
  65. let list = []
  66. for (const key in this.form) {
  67. if (Object.hasOwnProperty.call(this.form, key)) {
  68. const item = this.form[key];
  69. list = list.concat(item.map(row => ({...row, roleName: key})))
  70. }
  71. }
  72. await employeeLevel(list)
  73. this.$message.success('提交成功')
  74. this.$listeners.submited()
  75. }
  76. })
  77. },
  78. async FetchDetail() {
  79. try {
  80. const res = await employeeLevelDetail({
  81. userId: this.detail.id
  82. })
  83. this.list = res.data
  84. for (const key in res.data) {
  85. if (Object.hasOwnProperty.call(res.data, key)) {
  86. const type = res.data[key];
  87. for (const item of type) {
  88. this.form[key].push({
  89. organId: item,
  90. transferUserId: '',
  91. levelUserId: this.detail.id
  92. })
  93. }
  94. }
  95. }
  96. this.form = this.form
  97. } catch (error) {}
  98. }
  99. }
  100. };
  101. </script>
  102. <style lang="less" scoped>
  103. .dialog-footer{
  104. text-align: right;
  105. display: block;
  106. padding-bottom: 20px;
  107. }
  108. </style>