handover.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div >
  3. <el-form ref="form" inline :model="form" v-if="!isEmpty">
  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. :employeeByOrganId="employeeByOrganId"
  12. :technicianByOrganId="technicianByOrganId"
  13. />
  14. </template>
  15. </el-form>
  16. <empty v-else>
  17. <p>无需交接,点击确定继续操作离职</p>
  18. </empty>
  19. <span slot="footer" class="dialog-footer">
  20. <el-button @click="$listeners.close">取 消</el-button>
  21. <el-button @click="submit" type="primary">确 定</el-button>
  22. </span>
  23. </div>
  24. </template>
  25. <script>
  26. import { array2object } from '@/helpers/utils'
  27. import { employeeOperate } from '@/api/systemManage'
  28. import { employeeLevelDetail, employeeLevel, employeeFindEmployeeByRole } from '../api'
  29. import selectUser from './select-user'
  30. export default {
  31. props: ['detail'],
  32. components: {
  33. 'select-user': selectUser
  34. },
  35. data() {
  36. return {
  37. list: [],
  38. form: {
  39. repair: [],
  40. director: [],
  41. education: [],
  42. teamTeacher: [],
  43. },
  44. employees: [],
  45. loading: false,
  46. }
  47. },
  48. computed: {
  49. isEmpty() {
  50. let empty = true
  51. for (const key in this.form) {
  52. if (Object.hasOwnProperty.call(this.form, key)) {
  53. const item = this.form[key];
  54. if (item.length > 0) {
  55. empty = false
  56. }
  57. }
  58. }
  59. return empty
  60. },
  61. branchsyId() {
  62. return array2object(this.selects.branchs, 'id')
  63. },
  64. technicianByOrganId() {
  65. const data = {}
  66. for (const item of this.selects.roles?.REPAIR) {
  67. if (item.organIdList) {
  68. for (const organId of item.organIdList) {
  69. if (!data[organId]) {
  70. data[organId] = []
  71. }
  72. data[organId].push(item)
  73. }
  74. }
  75. }
  76. return data
  77. },
  78. employeeByOrganId() {
  79. const data = {}
  80. for (const item of this.employees) {
  81. if (item.organIdList) {
  82. for (const organId of item.organIdList) {
  83. if (!data[organId]) {
  84. data[organId] = []
  85. }
  86. data[organId].push(item)
  87. }
  88. }
  89. }
  90. console.log(data)
  91. return data
  92. }
  93. },
  94. async mounted() {
  95. this.$store.dispatch('setBranchs')
  96. await this.$store.dispatch("setOrganRole");
  97. this.FetchDetail()
  98. },
  99. methods: {
  100. async submit() {
  101. if (!this.$refs.form) {
  102. try {
  103. await employeeOperate({
  104. employeeId: this.detail.id,
  105. operate: 'DEMISSION'
  106. })
  107. this.$message.success('提交成功')
  108. this.$listeners.close()
  109. this.$listeners.submited()
  110. } catch (error) {}
  111. return
  112. }
  113. this.$refs.form.validate(async valid => {
  114. if (valid) {
  115. let list = []
  116. for (const key in this.form) {
  117. if (Object.hasOwnProperty.call(this.form, key)) {
  118. const item = this.form[key];
  119. list = list.concat(item.map(row => ({...row, roleName: key})))
  120. }
  121. }
  122. try {
  123. await employeeLevel(list)
  124. this.$message.success('提交成功')
  125. this.$listeners.close()
  126. this.$listeners.submited()
  127. } catch (error) {}
  128. }
  129. })
  130. },
  131. async FetchDetail() {
  132. this.loading = true
  133. try {
  134. const res = await Promise.all([
  135. employeeFindEmployeeByRole({
  136. rows: 99999,
  137. demissionflag: 0
  138. }),
  139. employeeLevelDetail({
  140. userId: this.detail.id
  141. })
  142. ]).then(res => {
  143. this.employees = res[0].data.rows
  144. return res[1]
  145. })
  146. this.list = res.data
  147. for (const key in res.data) {
  148. if (Object.hasOwnProperty.call(res.data, key)) {
  149. const type = res.data[key];
  150. for (const item of type) {
  151. this.form[key].push({
  152. organId: item,
  153. transferUserId: '',
  154. levelUserId: this.detail.id
  155. })
  156. }
  157. }
  158. }
  159. this.form = this.form
  160. } catch (error) {}
  161. this.loading = false
  162. }
  163. }
  164. };
  165. </script>
  166. <style lang="less" scoped>
  167. .dialog-footer{
  168. text-align: right;
  169. display: block;
  170. padding-bottom: 20px;
  171. margin-top: 20px;
  172. }
  173. </style>