handover.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div v-loading="loading">
  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.technician) {
  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. return data
  91. }
  92. },
  93. async mounted() {
  94. this.$store.dispatch('setBranchs')
  95. this.$store.dispatch('setTechnician')
  96. this.FetchDetail()
  97. },
  98. methods: {
  99. async submit() {
  100. if (!this.$refs.form) {
  101. try {
  102. await employeeOperate({
  103. employeeId: this.detail.id,
  104. operate: 'DEMISSION'
  105. })
  106. this.$message.success('提交成功')
  107. this.$listeners.close()
  108. this.$listeners.submited()
  109. } catch (error) {}
  110. return
  111. }
  112. this.$refs.form.validate(async valid => {
  113. if (valid) {
  114. let list = []
  115. for (const key in this.form) {
  116. if (Object.hasOwnProperty.call(this.form, key)) {
  117. const item = this.form[key];
  118. list = list.concat(item.map(row => ({...row, roleName: key})))
  119. }
  120. }
  121. try {
  122. await employeeLevel(list)
  123. this.$message.success('提交成功')
  124. this.$listeners.close()
  125. this.$listeners.submited()
  126. } catch (error) {}
  127. }
  128. })
  129. },
  130. async FetchDetail() {
  131. this.loading = true
  132. try {
  133. const res = await Promise.all([
  134. employeeFindEmployeeByRole({
  135. rows: 99999
  136. }),
  137. employeeLevelDetail({
  138. userId: this.detail.id
  139. })
  140. ]).then(res => {
  141. this.employees = res[0].data.rows
  142. return res[1]
  143. })
  144. this.list = res.data
  145. for (const key in res.data) {
  146. if (Object.hasOwnProperty.call(res.data, key)) {
  147. const type = res.data[key];
  148. for (const item of type) {
  149. this.form[key].push({
  150. organId: item,
  151. transferUserId: '',
  152. levelUserId: this.detail.id
  153. })
  154. }
  155. }
  156. }
  157. this.form = this.form
  158. } catch (error) {}
  159. this.loading = false
  160. }
  161. }
  162. };
  163. </script>
  164. <style lang="less" scoped>
  165. .dialog-footer{
  166. text-align: right;
  167. display: block;
  168. padding-bottom: 20px;
  169. margin-top: 20px;
  170. }
  171. </style>